﻿$(document).ready(function(){

	fn_GlobalNavInitialize();
	
	$("#cseSchBoxForm input.kw").bind('click',function(){
		$(this).addClass('focus');
		$(this).focus();
	});
	$("#cseSchBoxForm input.kw").bind('focusout blur',function(){
		var k = $(this).val();
		if(k==''){
			$(this).removeClass('focus');
		}
	});
	
});


function fn_GlobalNavInitialize(){

	globalNavIsBusy = false;
	duration = 200;
	
	$("#pageHeader .nav li a[rel*='refNav']").each(
		function(){
			var rel = $(this).attr('rel');
			$(this).bind("mouseenter mouseover focus focusin click",function(){
				fn_GlobalSubNavAnimate(rel);
				$(this).blur();
				return false;
			});
		}
	);
	
	$("#pageHeader .nav li a[rel*='clear']").each(
		function(){
			$(this).bind("mouseenter mouseover focus focusin click",function(){
				fn_GlobalSubNavClear();
				$(this).blur();
			});
		}
	);
	
	$("#pageHeader .subNav .listing").hide();
	/*
	var currentSubNav = $("#pageHeader .nav li a.selected").attr('rel');
	if(currentSubNav && currentSubNav!='clear'){
		fn_GlobalSubNavAnimate(currentSubNav);
	}
	*/
}

function fn_GlobalSubNavAnimate(target){
	var subNav = $("#pageHeader .subNav").find('div[id="' + target + '"]');
	var currentsubNav = $("#pageHeader .subNav div.current");
	var targetIsShow = $(subNav).hasClass('current');
	
	if(globalNavIsBusy == false && !targetIsShow){

		globalNavIsBusy = true;
		
		$(currentsubNav).hide(
			'fade',
			duration,
			function(){
				$(this).removeClass('current');
			}
		)

		$(subNav).show(
			'fade',
			duration,
			function(){
				$(this).addClass('current');
				$(this).bind("mouseleave",function(){
					fn_GlobalSubNavClear();
				});
				globalNavIsBusy = false;
			}
		);
	}
	
	return false;
}

function fn_GlobalSubNavClear(){

	var target = $("#pageHeader .subNav div.current");

	if(globalNavIsBusy == false && $(target).length>0){
	
		globalNavIsBusy = true;
		
		$("#pageHeader .subNav div.current").hide(
			'fade',
			duration,
			function(){
				$(this).removeClass('current');
				globalNavIsBusy = false;
			}
		);
	}
	
}

function fn_BlockCopyAndPaste(){
	$(document).bind('cut copy paste contextmenu', function(e){
		e.preventDefault();
		return false;
	});
	$(document).keydown(function(e){
        if(e.ctrlKey && (e.keyCode =='65' || e.keyCode=='83')){
            return false;
        }
	})
	$(document).disableSelection();
}

function cseSchBoxSubmit(){
	var k = $("#pageFooter div.cseSchBox input.kw").val();
	if(k!=''){
		window.location.href = '/search/?q='+k;
	}
	return false;
}

function isMobile(){
	if(
		navigator.userAgent.match(/Android/i) ||
		navigator.userAgent.match(/webOS/i) ||
		navigator.userAgent.match(/iPhone/i) ||
		navigator.userAgent.match(/iPod/i) ||
		navigator.userAgent.match(/iPad/i)
	){
		//mobile version
		return true;
	}else{
		return false;
	}
}
