
$(function(){
//alert("sss");	
//tab_ctrl.settab("list", 0); //initialize Tab Menu #1 with 1st tab selected
img_tab_ctrl.settab("videobar", 0); //initialize Tab Menu #1 with 1st tab selected



})

window.onload = function(){
getMarqueeContent();
}
function getMarqueeContent()
{
	var obj = S$syncload("ajax/http_get_marquee.php");
	//S$asycload("ajax/http_get_marquee.php", "", test);
	if (!obj)
	{
		//alert(LANG_ERR['network_error']);
		return;
	}
	
	if (!obj.ret)
	{
		//alert(LANG_ERR['network_error']);
		return;
	}
	
	if (obj.ret.sta == "fail")
	{
		//alert(obj.ret.msg);
		return;
	}	

	var marquee = S$("marquee");
	marquee.innerHTML = obj.ret.marquee;
}

// function test(obj)
// {
	// if (!obj)
	// {
		// alert(LANG_ERR['network_error']);
		// return;
	// }
	
	// if (!obj.ret)
	// {
		// alert(LANG_ERR['network_error']);
		// return;
	// }	
	
	// if (obj.ret.sta == "fail")
	// {
		// alert(obj.ret.msg);
		// return;
	// }		
	// var marquee = S$("marquee");
	// marquee.innerHTML = obj.ret.marquee;	
// }

function sendForm(fmid, chk_type)
{
	var fm = document.getElementById(fmid)
	
	if (!checkForm(chk_type))
	{
		alert("str_checking error");
	}
	
	fm.submit();
}
function checkForm(type)
{
	// switch (type)
	// {
		// case 1:
		// case 2:
		// default:
		
	// }
	
	return 1;
}
function login()
{
	// var fm = document.getElementById(fmid)
	
	// if (!checkForm(chk_type))
	// {
		// alert("str_checking error");
	// }
	
	// fm.submit();
}

function logout()
{
	var obj = S$syncload("ajax/http_logout.php");
	if (!obj)
	{
		alert(LANG_ERR['network_error']);
		return;
	}
	
	if (!obj.ret)
	{
		alert(LANG_ERR['network_error']);
		return;
	}
	
	if (obj.ret.sta == "fail")
	{
		alert(obj.ret.msg);
		return;
	}	

	var dm_state = S$("dm_state");
	dm_state.innerHTML = LANG_COM['login'];
	dm_state.href = "http://login.ictstore.com.tw/login.php";
}

function loading()
{
	//var img = S$("ad");
	document.img_ad.src = "res/images/loading_login.gif";
	//alert("test");
}

	var tab_ctrl={
		settab:function(tab_id, sel_no){
			this[tab_id+"_m_items"]=null;
			this[tab_id+"_m_sel"]=-1;
			this.addEvent(window, function(){tab_ctrl.init(tab_id, sel_no)}, "load");
		},
		showcontent:function(tab_id, targetitem){
			var menuitems = this[tab_id+"_m_items"];
			
		 for (i=0; i<menuitems.length; i++)
		 {
				var menuimg = $("div#list li:eq("+i+") img");
				var strsrc = menuimg.attr("src");
				menuimg.attr("src",strsrc.replace("_c.png",".png"));
				document.getElementById(menuitems[i].getAttribute("rel")).style.display = "none"
		 }
		 
			var imgsrc = targetitem.getElementsByTagName("img")[0].src;
			//targetitem.className = "current";
			targetitem.getElementsByTagName("img")[0].src = imgsrc.replace(".png", "_c.png");
			document.getElementById(targetitem.getAttribute("rel")).style.display = "block";
		},
		addEvent:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
			var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
			if (target.addEventListener)
				target.addEventListener(tasktype, functionref, false)
			else if (target.attachEvent)
				target.attachEvent(tasktype, functionref)
		},
		init:function(tab_id, sel_no){
			var menuitems = document.getElementById(tab_id).getElementsByTagName("a");
			this[tab_id+"_m_items"] = menuitems;
			for (var x=0; x<menuitems.length; x++)
			{
				//menuitems[x].onmouseover = function(){tab_ctrl.showcontent(tab_id, this);};
				menuitems[x].onclick = function(){tab_ctrl.showcontent(tab_id, this);};
				if (parseInt(sel_no) == x)
				{
					tab_ctrl.showcontent(tab_id, menuitems[x])
					this[tab_id+"_m_sel"] = menuitems[x]
				}
			}
		}
	}

	var img_tab_ctrl={
		settab:function(tab_id, sel_no){
			this[tab_id+"_m_items"]=null;
			this[tab_id+"_m_sel"]=-1;
			this.addEvent(window, function(){img_tab_ctrl.init(tab_id, sel_no)}, "load");
		},
		showcontent:function(tab_id, targetitem){
			var menuitems = this[tab_id+"_m_items"];
			
		 for (i=0; i<menuitems.length; i++)
		 {
				// var menuimg = $("div#list li:eq("+i+") img");
				// var strsrc = menuimg.attr("src");
				// menuimg.attr("src",strsrc.replace("_c.png",".png"));
				menuitems[i].getElementsByTagName("div")[0].className ="unclick_video";
				var div_imgid = "imginfo" + menuitems[i].getAttribute("rel");
				var div_vdoid = "video" + menuitems[i].getAttribute("rel");
				
				// to avoid IE Video Deul playing
				var tempsrc = $("#test"+(i+1)).attr("src");
				$("#test"+(i+1)).attr("src", tempsrc);			
				
				document.getElementById(div_imgid).style.display = "none";
				document.getElementById(div_vdoid).style.display = "none";
		 }
		 
			//var imgsrc = targetitem.getElementsByTagName("div")[0].src;
			//targetitem.className = "click_video";
			targetitem.getElementsByTagName("div")[0].className = "click_video";
			//targetitem.getElementsByTagName("img")[0].src = imgsrc.replace(".png", "_c.png");
			var div_tgt_imgid = "imginfo" + targetitem.getAttribute("rel");
			var div_tgt_vdoid = "video" + targetitem.getAttribute("rel");
			document.getElementById(div_tgt_imgid).style.display = "block";
			document.getElementById(div_tgt_vdoid).style.display = "block";
		},
		addEvent:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
			var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
			if (target.addEventListener)
				target.addEventListener(tasktype, functionref, false)
			else if (target.attachEvent)
				target.attachEvent(tasktype, functionref)
		},
		init:function(tab_id, sel_no){
			var menuitems = document.getElementById(tab_id).getElementsByTagName("a");
			this[tab_id+"_m_items"] = menuitems;
			for (var x=0; x<menuitems.length; x++)
			{
				menuitems[x].onclick= function(){img_tab_ctrl.showcontent(tab_id, this);};
				if (parseInt(sel_no) == x)
				{
					img_tab_ctrl.showcontent(tab_id, menuitems[x])
					this[tab_id+"_m_sel"] = menuitems[x]
				}
			}
		}
	}
