var posX = new Array(12,76,162,267,430,542,606,742);
var widthA = new Array();
var linkA = new Array();
var sublinkA = new Array();
var conA = new Array();
var subA = new Array();
var colorA = new Array('#5d5d5d','#ee222b','#046fb7','#8ec63d','#5d5d5d','#ee222b','#046fb7','#8ec63d');
var cursec = 0;
var menuArray = new Array();

//$(document).ready(function(){
function menuset(sec){
	var menupath = "../xml/sitemap.xml";
	$.ajax({
		type: "GET",
		url: menupath,
		dataType: "xml",
		success: function(xml) {	
			$('<div id="submenu"><div id="submenucontainer"></div></div>').appendTo('body');	
			$('<div id="mainmenubk"></div>').appendTo('body');	
			
			$('#submenu').css({'opacity':0});
			$(xml).find('sec').each(function(value){
				var title = $(this).attr('title');
				var url = $(this).attr('url');
				linkA[value] = url;
				
				menuArray[value] = $('<div><img src="../images/menu/'+title+'.jpg"><img src="../images/menu/'+title+'_up.jpg" class="over"></div>').appendTo('#mainmenu');	
				menuArray[value].bind('mouseover.shift', secover);
				menuArray[value].bind('mouseout.menufadeout', menufadeout);
				menuArray[value].bind('click.secdown', secdown);
				
				conA[value] = $('<div class="sublevel"></div>').appendTo('#submenucontainer');	
				conA[value].css({'opacity':0});
				conA[value].bind('mouseover.subover', subover);
				conA[value].bind('mouseout.subout', subout);
				
				
				subA[value] = new Array();
				sublinkA[value] = new Array();
				
				$(xml).find('sec').eq(value).find('subsec').each(function(subvalue){
					var url = $(this).attr('url');
					sublinkA[value][subvalue] = url;
				
					var subtitle = $(this).attr('title');
					subA[value][subvalue] = $('<span class="submenutab"><img src="../images/menu/subtab_'+subtitle+'.png" class="original"></span>').appendTo(conA[value]);	
					subA[value][subvalue].css({'left':posX[value]+'px'});
					subA[value][subvalue].bind('mouseover.subsecover', subsecover);
					subA[value][subvalue].bind('mouseout.subsecout', subsecout);
					subA[value][subvalue].bind('click.subsecdown', subsecdown);
					$('.over').css({'opacity':0});
				})
				if(value!=sec){
					$('#mainmenu div').eq(value).find('.over').animate({'opacity':0},0);
				}else{
					var curwidth = $('#mainmenu div').eq(value).width()+'px';
					$('#cursor').animate({'left':posX[value], 'width':curwidth, 'background-color':colorA[value]},500,'easeOutCubic');
				}
			})
		}
	})
	var zi = 10;
	function secover(){
		zi++;
		var no = $('#mainmenu div').index($(this));
		if(sublinkA[no].length>0){
			$('#submenu').stop();
			$('#submenu').animate({'opacity':1});
			$('#submenu').css({'border-bottom':'1px solid '+colorA[no]});
		}
		 
		conA[no].stop();
		conA[no].css({'display':'block','z-index':zi});
		conA[no].animate({'opacity':1});
		var tarX = (posX[no])+'px';
		var curwidth = $(this).width()+'px';
		$('#cursor').stop();
		$('#cursor').animate({'left':tarX, 'width':curwidth, 'background-color':colorA[no]},500,'easeOutCubic');
		
		$('#mainmenu div').eq(cursec).find('.over').stop();
		$('#mainmenu div').eq(cursec).find('.over').animate({'opacity':0});
		
		$(this).find('.over').stop();
		$(this).find('.over').animate({'opacity':1});
		cursec = no;
	}
	function secdown(){
		var no = $('#mainmenu div').index($(this));
		window.location.href = linkA[no];
	}
	function menufadeout(){
		$('#submenu').stop();
		$('#submenu').animate({'opacity':0});
		var no = $('#mainmenu div').index($(this));
		conA[no].stop();
		conA[no].animate({'opacity':0}, 300, function() {
			 $(this).css({'display':'none'});
   		});
	}
	function subover(){
		$('#submenu').stop();
		$('#submenu').animate({'opacity':1});
		var no = $('#submenucontainer .sublevel').index($(this));
		if(cursec==no){
			$(this).stop();
			 $(this).css({'display':'block'});
			$(this).animate({'opacity':1});
		};
	}
	function subout(){
		$('#submenu').stop();
		$('#submenu').animate({'opacity':0});
		$(this).stop();
		$(this).animate({'opacity':0}, 300, function() {
			 $(this).css({'display':'none'});
   		});
	}
	function subsecover(){
		$(this).find('.over').stop();
		$(this).find('.over').animate({'opacity':1});
	}
	function subsecout(){
		$(this).find('.over').stop();
		$(this).find('.over').animate({'opacity':0});
	}
	function subsecdown(){
		var no = $('#submenucontainer .sublevel').index($(this).parent());
		var subno = $(this).parent().find('.submenutab').index($(this));
		window.location.href = sublinkA[no][subno];
	}
}

$(document).ready(function(){
	if($.browser.msie && $.browser.version=="6.0"){DD_belatedPNG.fix('img');}
	
	//update footer
	var currentYear = new Date().getFullYear();	
	$('span#footer_year').html(currentYear);
	
	//left menu mouse over
	$("div#leftmenu > a").hover(function(){
		$(this).stop().animate({color:'#fff'}, 700, 'easeOutQuart');
	},function(){
		if(!$(this).hasClass('active')){
			$(this).stop().animate({color:'#9d9d9d'}, 700, 'easeOutQuart');
		}
	});
	
	$('a.disible').click(function(){return false; });
	
	//switchLang
	var currentLang = $('div#global a.currentlang').attr('id');
	//$('div#global a#en').click(function(){switchLang(currentLang, 'en')});
	$('div#global a#tc').click(function(){switchLang(currentLang, 'tc')});
	$('div#global a#sc').click(function(){switchLang(currentLang, 'sc')});
})

function switchLang(from,to) {
	var currentStr = window.location.href;
	currentStr = currentStr.replace("/" + from + "/", "/" + to + "/");
	currentStr = currentStr.replace("lang=" + from, "lang=" + to);
	$('div#wrapper').fadeOut(400, function(){window.location.href = currentStr;});
	return false;
}

function getIn(){
	var animation = true;
	if(animation){
		$('#topnav').fadeIn(1000, 'easeOutQuart');
		$('#insidebannercontainer').delay(500).fadeIn(1000, 'easeOutQuart');
		$('#insidecontent').delay(1000).fadeIn(1000, 'easeOutQuart');
		$('#footer').delay(1500).fadeIn(1000, 'easeOutQuart');
	}else{
		$('#topnav, #insidebannercontainer, #insidecontent, #footer').show();
	}
}
function colorboxClose()
{
    parent.$.fn.colorbox.close();// Usage from within an iframe
}



