var __model = new Object();
function init(){
	registHolder(__model);
	getArgument();
	var cb = {func:onEndXML, scope:this, args:["keyword"]};
	getXMLData("http://www.hahanohi.com/tags/?TRSID=" + getArgument.data.TRSID ,"data","hahanohi","keyword",cb);	
	//getXMLData("../haha_dat/keyWords.xml","data","hahanohi","keyword",cb);
	
};

function getArgument(){
     getArgument.data = new Array();
     getArgument.string = location.search.substring(1);
     getArgument.string = getArgument.string.split('&');
     for(var i = 0; i != getArgument.string.length; i++) {
         getArgument.data[ck_identifier(getArgument.string[i].split('=')[0])]
                               =  Escape(unescape(getArgument.string[i].split('=')[1]));
     }

     function ck_identifier(arg){ //The naming of property is checked.
         arg_TOP = arg.substring(0,1);
         if(arg_TOP.match(/[a-zA-Z_$]/g) == null){
            //alert(arg+" The argument is illegal. (The first character is either ASCII, _ or $)");
            return null;
         }
         else if(arg.match(/[^a-zA-Z0-9_$]/g) != null){
            //alert(arg+" The argument is illegal. (The naming character is ASCII, and either figure, _ or $)");
            return null;
         } 
         return arg;
     }

     function Escape(str){
          str = str.replace( /\&/g, '&amp;' );
          str = str.replace( /</g, '&lt;' ); 
          str = str.replace( />/g, '&gt;' ); 
          str = str.replace( /\"/g, '&quot;' );
          str = str.replace( /\'/g, '&#39;' );
          return str;
    }
}

function setTagPer(cb) {
//	alert("setTagPer");
//	alert("sid:" + $(__model.root).attr("sid"));	//success
//	alert($(__model.data[0]));						//success
//	alert($(__model.data[0]).attr("id"));			//success
	var keywords = __model.data;	//html collection
//	alert("keywords:" + keywords);					//success
//alert( $(keywords[0]).attr("lank") );				//success

	var MOMID = $(__model.root).attr("sid");
	var TRSID = $(__model.root).attr("areaOpenFlg");
	var lankTotal = 0;
	var temp = "";
	
	if(TRSID == 2)	//has specified　from result page.
		$("#tagArea").hide("fast",function(){
			setTagCloudBtn();
		});
	
	for(var i  = 0; i < keywords.length; i++) {
		temp += '<li title="" class="level' + $(keywords[i]).attr("lank") + '"><a href="' + $(keywords[i]).attr("url") + '?TRSID=' + 1 + '&MOMID=' + MOMID + '">' + $(keywords[i]).text() + '</a></li>';
	};
	$(".tagCloud").html(temp);
	
	if(cb) {
		if(cb.func) {
			cb.args = [TRSID];
			cb.func.apply(cb.scope, cb.args);
		};
	};
	
};

//xmlデータ解析用
function onEndXML(a) {
	//alert("onEndXML");
	
	switch(a) {
		case "keyword":
			var cb = {func:setTagInitShow, scope:this, args:[]};
			setTagPer(cb);
			break;
			
		default:
			alert("error:85");
			break;
	};
};

function setTagCloudBtn() {
	/*$("#areaToggleDiv").click(function() {
		$("#tagArea").slideToggle("slow");
	});*/
	$("#areaOpenDiv").click(function() {
		$("#tagArea").slideDown("slow");
	});
	$("#areaCloseDiv").click(function() {
		$("#tagArea").slideUp("slow");
	});
};

function setTagInitShow(num) {
	
	setTagCloudBtn();
	
//	if(num == 0) setTagCloudBtn();	//no specification.	List display.
//	else if(num == 1)	//has specified　from index page.
//		var intId = setInterval(function(){
//			clearInterval(intId);
//			$("#tagArea").slideUp(1000,function(){
//				setTagCloudBtn();
//			});
//		},2000);
	//else if(num == 2)	//has specified　from result page.
};

$(init());






