function emoticon_initialize()
{
	var lang = (location.host.indexOf("en.utf8art.com")>=0)?"en":"ja";
	var aaid = $(".AA_TextArea").attr("aaid");
	var lstDT = document.getElementsByTagName("DT");
	for (var numIx=0;lstDT.length>numIx;numIx++)
	{
		var elmDT = lstDT[numIx];
		switch(elmDT.className)
		{
			case "AA_ImageTitle":
			case "AA_HtmlTitle":
			case "AA_TextTitle":
			case "AA_IconTitle":
			case "AA_SourceTitle":
			case "AA_SampleTitle":
			{
				//elmDT Init
				var cssDisplay	= "";
				try {
					var elmDD = elmDT.nextSibling;

					if (elmDT.className=="AA_SourceTitle"){
						elmDD.style.display="none";
						cssDisplay = "none";
					}else if (typeof(elmDD.currentStyle)!="undefined"){
						cssDisplay = elmDD.currentStyle.display;
					}else{
						cssDisplay = getComputedStyle(elmDD,'').getPropertyValue("display");
					}
				}catch(e){};

				var elmStatus = document.createElement("SPAN");
				elmStatus.style.fontFamily	= "MS Gothic";
				elmStatus.style.margin		= "0px";
				elmStatus.style.padding		= "2px";
				elmStatus.innerHTML			=(cssDisplay=="none")?"+":"-";

				var elmTitle				= document.createElement("SPAN");
				elmTitle.innerHTML			= elmDT.innerHTML;

				//elmdt create
				elmDT.title					= "Click Here!! " + elmDT.innerHTML + " Open";
				elmDT.innerHTML				= "";
				elmDT.appendChild(elmStatus);
				elmDT.appendChild(elmTitle);


				//function
				elmTitle.onclick=function()
				{
					var elmTgt		= (typeof(this.parentElement)!="undefined")?this.parentElement:this.parentNode;
					var cssDisplay	= "";
					try {
						if (typeof(elmTgt.nextSibling.currentStyle)!="undefined"){
							cssDisplay = elmTgt.nextSibling.currentStyle.display;
						}else{
							cssDisplay = getComputedStyle(elmTgt.nextSibling,'').getPropertyValue("display");
						}
					}catch(e){};
					elmTgt.nextSibling.style.display=(cssDisplay=="none")?"block":"none";
					elmTgt.childNodes[0].innerHTML = (cssDisplay=="none")?"-":"+";
				};
				elmStatus.onclick=elmTitle.onclick;

				break;
			}
		}
		if (elmDT.className=="AA_TextTitle"){
			try{
				var elmCmt=document.getElementById('comment');
				if (elmCmt){elmCmt.value=elmDT.nextSibling.childNodes[0].value;};
			}catch(e){};
			try{
				var elmCopy = document.createElement("INPUT");
				elmCopy.type				= "button";
				elmCopy.value				= (typeof(window.clipboardData)!="undefined")?"Copy":"Text Highlight";
				elmCopy.style.fontFamily	= "MS Gothic";
				elmCopy.style.margin		= "0px";
				elmCopy.style.padding		= "2px";
				elmCopy.title				= "Click Here!! Copy";
				elmCopy.style.margin		= (typeof(window.clipboardData)!="undefined")?"0 0 0 600px":"0 0 0 500px";
				elmCopy.onclick				= function(){
					var elmTgt = (typeof(this.parentElement)!="undefined")?this.parentElement:this.parentNode;
					elmTgt.nextSibling.style.display="block";
					elmTgt.childNodes[0].innerHTML = "-";
					elmTgt.nextSibling.childNodes[0].select();
					try{window.clipboardData.setData("text",elmTgt.nextSibling.childNodes[0].value);}catch(e){};
				};
				elmDT.appendChild(elmCopy);
			}catch(e){};
		};
		if (elmDT.className=="AA_IconTitle"){
			var ths = $(elmDT).parent().find("th");
			var idx = 0;
			$(elmDT).parent().find("td").each(function(){
				var img = $(this).find("img");
				img.title=img.alt;
//				var html='<A href="http://aa.'+lang+'.utf8art.com/iconaa?baaid=b'+aaid+'&width='+img.attr('aaw')+'&height='+img.attr('aah')+'" style="border:4px outset #CCC;width:'+img.attr('aaw')+';height:'+img.attr('aah')+';">';
				var html='<A href="http://aa.'+lang+'.utf8art.com/iconaa?baaid=b'+aaid+'&width='+img.attr('aaw')+'&height='+img.attr('aah')+'">';
				$(this).append($(html).append(img));
//				$(ths[idx]).append($(html).append($(this).find($(ths[idx]).text())));
				ths[idx].innerHTML=html+ths[idx].innerHTML+'</a>';
				idx++;
/*
				var th = ths[idx];
				var link = $(html);
				$(th).
*/
			});
		};
	};
};

function background_preview(img_src)
{
	var objTgt = document.getElementById("wrapper");
	objTgt.style.backgroundImage		= "url("+img_src+")";
	objTgt.style.backgroundRepeat		= "no-repeat";
	objTgt.style.backgroundAttachment	= "fixed";
	objTgt.style.backgroundPosition		= "center center";
};

function mycarousel_initCallback(carousel)
{
	// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.bind('click', function() {
		carousel.startAuto(0);
	});

	carousel.buttonPrev.bind('click', function() {
		carousel.startAuto(0);
	});

	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};

jQuery(document).ready(function() {
	emoticon_initialize();
	basketaa_initialize();
	try{
		var httpObj = jQuery.get("/lib/whatsnew.xml",null,
			 function(){
				try{
					$("#whatsnew").html(httpObj.responseText);
					var tgt = jQuery('#whatsnew ul');
					tgt[0].id = "mycarousel";
					tgt[0].className = "jcarousel-skin-asciiart";
					tgt.jcarousel({
						vertical: false,
						auto: 3,
						wrap: 'last',
						initCallback: mycarousel_initCallback
					});

				}catch(e){}
			 }
		);
	}catch(e){}
	try{
		$.ajax({
			url : "http://ws.utf8art.com/randomcc_json.php",
			dataType : 'jsonp',
			scriptCharset:'UTF-8',
			success : function(data){
				var html = '';
				html+= '<table class="bookmarklet-button" cellpadding="0" cellspacing="0">';
				html+= '<tbody>';
				html+= '<tr>';
				html+= '<td class="bookmarklet-button-1"></td>';
				html+= '<td class="bookmarklet-button-2">';
				html+= '<a href="javascript:(function(){if(!window.utf8art){window.utf8art={aa:{}};};var u=window.utf8art;u.ccid=\''+EscJsc(data.ccid)+'\';if(u.jQuery){if(u.aa[u.cchash]){u.openDialog();}else{u.jQuery.ajax({url:\'http://ws.utf8art.com/collectaa_json.php?ccid=\'+u.ccid,dataType:\'jsonp\'});}}else{var s=document.createElement(\'script\');s.src=\'http://ws.utf8art.com/dialogaa/utf8art_dialogaa_v1.js\';s.type=\'text/javascript\';s.charset=\'UTF-8\';document.body.appendChild(s);}})();"';
				html+= ' title="[AA]'+EscHtm(data.title)+'">';
				html+=   EscHtm(data.title);
				html+= ' </a>';
				html+= '</td>';
				html+= '<td class="bookmarklet-button-3"></td>';
				html+= '</tr>';
				html+= '</tbody>';
				html+= '</table>';
				html+= '<a href="'+EscHtm(data.node_url)+'" style="border:0;margin:0 2px">';
				html+= '<img src="'+EscHtm(data.image_url)+'" alt="'+EscHtm(data.title)+'" style="border:0;" />';
				html+= '</a>';
				$("#randomcc").html(html);
			}
		});
	}catch(e){}
});

