var aniMenu = {
	showShadow:0
}
aniMenu.init = function(elements){	
	$(elements.cecMore.id).onclick = new Function("aniMenu.cec("+elements.name+")");
	$(elements.elMore.id).onclick = new Function("aniMenu.el("+elements.name+")");
}
aniMenu.cec = function(elements){
	if($(elements.cecSubMenu).getStyle("display") === "none"){
		$(elements.cecSubMenu).setStyle({
			//display:"block"
		});
		Effect.SlideDown(elements.cecSubMenu);
		
		$(elements.cecMore.id).removeClassName(elements.cecMore.classNormal);
		$(elements.cecMore.id).addClassName(elements.cecMore.classMore);
		
		aniMenu.showShadow += 1;
		aniMenu.change(elements);
	} else {
		Effect.SlideUp(elements.cecSubMenu);
		
		$(elements.cecMore.id).removeClassName(elements.cecMore.classMore);
		$(elements.cecMore.id).addClassName(elements.cecMore.classNormal);
		
		aniMenu.showShadow -= 1;
		aniMenu.change(elements);
	}
}
aniMenu.el = function(elements){
	if($(elements.elSubMenu).getStyle("display") === "none"){
		$(elements.elSubMenu).setStyle({
			//display:"block"
		});
		Effect.SlideDown(elements.elSubMenu);
		
		$(elements.elMore.id).removeClassName(elements.elMore.classNormal);
		$(elements.elMore.id).addClassName(elements.elMore.classMore);
		
		aniMenu.showShadow += 1;
		aniMenu.change(elements);
	} else {
		Effect.SlideUp(elements.elSubMenu);
		
		$(elements.elMore.id).removeClassName(elements.elMore.classMore);
		$(elements.elMore.id).addClassName(elements.elMore.classNormal);
		
		aniMenu.showShadow -= 1;
		aniMenu.change(elements);
	}
}
aniMenu.change = function(elements){
	if(this.showShadow){
		$(elements.underLine).setStyle({
			display:"block"
		});
		$(elements.searchSelect).setStyle({
			display:"none"
		});
	} else {
		$(elements.underLine).setStyle({
			display:"none"
		});
		$(elements.searchSelect).setStyle({
			display:""
		});
	}
}






// SwitchTabs
/*
	EXAMPLE:
		var tabInfoForSwitch={
			objname:"tabInfoForSwitch",
			autoTimeInterval:5000,
			menuActiveClass:"active",
			menuSlientClass:"silent",
			element:[
				{menuId:"cecT",contentId:"cecN"},
				{menuId:"elT",contentId:"elN"}
			]
		};
		switchTabs.init(tabInfoForSwitch);
*/
var switchTabs = {
	current:0,
	autoSwitch:0
}
switchTabs.init = function(obj){
	for(var i=0; i < obj.element.length; i++){
		$(obj.element[i].menuId).onmouseover = new Function("switchTabs.pauseSwitch();");
		$(obj.element[i].menuId).onmouseout = new Function("switchTabs.auto("+obj.objname+");");
		
		$(obj.element[i].contentId).onmouseover = new Function("switchTabs.pauseSwitch();");
		$(obj.element[i].contentId).onmouseout = new Function("switchTabs.auto("+obj.objname+");");
	}
	switchTabs.auto(obj);
}
switchTabs.pauseSwitch = function(){
	clearInterval(switchTabs.autoSwitch);
}
switchTabs.auto = function(obj){
	clearInterval(switchTabs.autoSwitch);
	switchTabs.autoSwitch = setInterval(function(){
		switchTabs.change(switchTabs.current === (obj.element.length-1)?0:switchTabs.current+1,obj);
	},obj.autoTimeInterval);
}
switchTabs.change = function(index,obj){
	switchTabs.current = index;
	for(var j=0; j < obj.element.length; j++){
		if(j === index){
			$(obj.element[j].menuId).removeClassName(obj.menuSlientClass);
			$(obj.element[j].menuId).addClassName(obj.menuActiveClass);
			$(obj.element[j].contentId).style.display = "block";
		} else {
			$(obj.element[j].menuId).removeClassName(obj.menuActiveClass);
			$(obj.element[j].menuId).addClassName(obj.menuSlientClass);
			$(obj.element[j].contentId).style.display = "none";
		}
	}
}






// Switch image news
var swtichNews={
	current:0,
	autoScroller:0,
	scrollInterval:0
}
swtichNews.turn=function(index,obj){
	clearInterval(swtichNews.autoScroller);
	swtichNews.scroll(index,obj);
}
swtichNews.init = function(obj){
	$(obj.imgContent).onmouseover = new Function("swtichNews.pauseSwitch();") ;		
	$(obj.imgContent).onmouseout = new Function("swtichNews.auto("+obj.objname+");");
	
	for (i=0;i<obj.totalcount;i++) {	
		if(obj.numPre!=null && obj.numPre!="") {
		 $(obj.numPre+"_"+i).onmouseover = new Function("swtichNews.turn("+i+","+obj.objname+");swtichNews.pauseSwitch();") ;		
		 $(obj.numPre+"_"+i).onmouseout = new Function("swtichNews.auto("+obj.objname+");") ;	
		}
	}
	
	swtichNews.auto(obj);
}
swtichNews.auto = function(obj){
	clearInterval(swtichNews.autoScroller);
	swtichNews.autoScroller=setInterval(function(){
		swtichNews.scroll(swtichNews.current===(obj.totalcount-1)?0:swtichNews.current+1,obj);
	},obj.autoTimeInterval);
}
swtichNews.pauseSwitch = function() {
	clearInterval(swtichNews.autoScroller);
}
swtichNews.scroll = function(index,obj){
	
	var W=swtichNews;
	if(index==W.current){
		return;
	}
	
	var count=0;
	var duration=20;
	
	var imgHeight = obj.imgHeight;
	var spanNum = index-W.current;
	var begin_value=$(obj.imgContent).scrollTop;
	
	var chang_in_value=spanNum*imgHeight+(W.current*imgHeight-begin_value);

	clearInterval(W.scrollInterval);
	for(var i=0;i<obj.totalcount;i++){
		if(i === index){
			$(obj.numPre+"_"+i).addClassName(obj.selectedStyle);
		} else {
			$(obj.numPre+"_"+i).removeClassName(obj.selectedStyle);
		}
	}
	for(var i=0;i<obj.totalcount;i++){
		if(i === index){
			$(obj.textPre+"_"+i).style.display="block";
		} else {
			$(obj.textPre+"_"+i).style.display="none";
		}
	}
	
	
	W.scrollInterval=setInterval(function(){doit(begin_value,chang_in_value)},10);
	function doit(b,c){
		$(obj.imgContent).scrollTop=cpu(count,b,c,duration);
		count++;
		if(count==duration){
			clearInterval(swtichNews.scrollInterval);
			scrollInterval=0;
			count=0;
			$(obj.imgContent).scrollTop=b+c;
			swtichNews.current=index;
		}
	}
	function cpu(t,b,c,d) {return c*((t=t/d-1)*t*t+1)+b;};
}


