$(document).ready(function() {
	
	menuinit();

    $("#menu li.lv1").hover(function () {
		$(this).addClass("selected");
	}, function () {
		$(this).removeClass("selected");
	});
});

function menuinit(){
	$("#menu li.lv1").removeClass("selected");
}

$(document).ready(function() {
	$('.query, .query_tc').bind('click',function(){		
		if ($.trim($('.query').val())=="Enter Keyword")
			$('.query').val("");
		if ($.trim($('.query_tc').val())=="輸入關鍵字")
			$('.query_tc').val("");			
		$('.searchtype').removeClass('inactive');
		$('.searchtype').addClass('active');
		$('#menu').addClass('overlap');
		$('#menu li').addClass('overlap');
		if ($.browser.msie && $.browser.version.substr(0,1)<=7) {
			$('#slidercontainer').addClass('inactive');
			$('#slidercontainer_ie7').removeClass('inactive');		
		}
	});
	
	$('.query').blur(function(){
		if ($.trim($(this).val())=="")
			$(this).val("Enter Keyword");
	});
	
	$('.query_tc').blur(function(){
		if ($.trim($(this).val())=="")
			$(this).val("輸入關鍵字");
	});	
	
	$('.btn_search').click(function(){
		if ($('.query').val()!="Enter Keyword")
			$('#searchform').submit();
		if ($('.query_tc').val()!="輸入關鍵字")
			$('#searchform').submit();			
	});
	
	$('.btn_search').hover(function(){
		$(this).attr('src', 'images/search_button_on.png');
	},function(){
		$(this).attr('src', 'images/search_button.png');
	});
	
	$('.searchbox').bind('mouseleave', function(){
		$('.searchtype').removeClass('active');
		$('.searchtype').addClass('inactive');
		$('#menu').removeClass('overlap');
		$('#menu li').removeClass('overlap');
		
		if ($.browser.msie && $.browser.version.substr(0,1)<=7) {
			$('#slidercontainer').removeClass('inactive');
			$('#slidercontainer_ie7').addClass('inactive');				
		}
	});	
	
	$('input[name="searchtype"]').click(function(){		
			if (searchValueValidation())		
				$('#searchform').submit();		
	});
	
	$('#searchform').submit(function(){	
		if (!searchValueValidation())	
			return false;
	});
	
	MM_preloadImages(
	'images/zh_tw/nav_tc_01.jpg',
	'images/zh_tw/nav_tc_02.jpg',
	'images/zh_tw/nav_tc_03.jpg',
	'images/zh_tw/nav_tc_04.jpg',
	'images/zh_tw/nav_tc_05.jpg',
	'images/zh_tw/nav_tc_06.jpg',
	'images/zh_tw/nav_tc_07.jpg',
	'images/zh_tw/nav_tc_08.jpg',
	'images/zh_tw/nav_tc_09.jpg',
	'images/zh_tw/nav_tc_10.jpg',
	
	'images/zh_tw/nav_en_01.jpg',
	'images/zh_tw/nav_en_02.jpg',
	'images/zh_tw/nav_en_03.jpg',
	'images/zh_tw/nav_en_04.jpg',
	'images/zh_tw/nav_en_05.jpg',
	'images/zh_tw/nav_en_06.jpg',
	'images/zh_tw/nav_en_07.jpg',
	'images/zh_tw/nav_en_08.jpg',
	'images/zh_tw/nav_en_09.jpg',
	'images/zh_tw/nav_en_10.jpg'	
	);
	
	function searchValueValidation(){
		var submit=false;
		if ($('.query').length!=0 ) {
			if ($.trim($('.query').val())!="" && $.trim($('.query').val())!="Enter Keyword")
				submit=true;
		} else if ($('.query_tc').length!=0 ) {
			if ($.trim($('.query_tc').val())!="" && $.trim($('.query_tc').val())!="輸入關鍵字")
				submit=true;
		}		
		return submit;
	};
	
	// GA: outbound tracking 
	$('a[ref="outbound"]').attr("onClick","recordOutboundLink(this, 'Outbound Links', this.href);return false;");
});

$(window).load(function() {
	// GA: outbound tracking 
     $('iframe#newflash, iframe#newflash_tc').contents().find('a[ref="outbound"]').attr("onClick","recordOutboundLink(this, 'Outbound Links', this.href);return false;");
});


