// $Id: header-functions.js 6748 2011-05-27 00:52:24Z jrlenz $

var cid = '51c2b39efcad3595538423b55652b990';

var thisPage = '';
var hdr_countryOn = false;
var hdr_cartOn = false;
var hdr_timeOut = false; // bogus value
var hdr_Country_fn = false;
var hdr_Cart_fn = false;

function getAbsPos( oId, tl ) {
	var o = document.getElementById( oId );
	var val = 0;
	while ( o.nodeName != "BODY" ) {
		val += parseInt( ( tl == 'top' ) ? o.offsetTop : o.offsetLeft );
		o = o.parentNode;
		}
	return val;
	}

function countryOn() { 
	if (hdr_countryOn == true) return;
	if (hdr_cartOn == true) { cartOff(); }
	document.getElementById('country-dropdown').style.left=getAbsPos('topnav-country', 'left');
	// hax for non-ie browsers
	if ("Default Browser" != "IE") {
		var myPos = getAbsPos('country-dropdown', 'left') / 2;
		// alert('lpos: '+myPos);
		document.getElementById('country-dropdown').style.left=myPos;
	}
	/* this is now static 
	// load content here
	$.get(
		'/active/hdr-choosecountry.html',
		function(data) {
			$('#country-dropdown').html(data);
			-- end ajax load */
			$('#country-dropdown').slideDown(200);
			// hdr_Country_fn = setTimeout("countryOff()", 10000);
			$('#country-dropdown').mouseenter(function() {
				clearTimeout(hdr_Country_fn);
				$('#country-dropdown').mouseleave(
						function() { 
							//clearTimeout(hdr_timeOut);
							//hdr_timeOut = setTimeout("countryOff()",3000);
							hdr_Country_fn = setTimeout("countryOff()", 200);
						}
				);
				// $('#country-dropdown').mouseover(function() {});
			});
			/* start wrapper of end of ajax load stuff
		}
	);
	*/
	hdr_countryOn = true;
}

function countryOff() {
	$('#country-dropdown').slideUp(
		'fast',
		function() {
			//$('#cart-dropdown').html('');
		}
	);
	// hdr_timeOut = setTimeout("void(0)",86400);
	hdr_countryOn = false;
}

function cartOn() { 
	if (hdr_cartOn == true) return;
	if (hdr_countryOn == true) { countryOff(); }
	document.getElementById('cart-dropdown').style.left=getAbsPos('topnav-cart', 'left');
	// hax for non-ie browsers
	
	if ("Default Browser" != "IE") {
		var myPos = getAbsPos('cart-dropdown', 'left') / 2;
		// alert('lpos: '+myPos);
		document.getElementById('cart-dropdown').style.left=myPos;
	}
	// display temporary ajax loading message
	$('#cart-dropdown').html('Loading...');
	$('#cart-dropdown').slideDown('fast');
	$('#cart-dropdown').mouseenter(function() {
		clearTimeout(hdr_Cart_fn);
		$('#cart-dropdown').mouseleave(
				function() { 
					hdr_Cart_fn = setTimeout("cartOff()",200);
				}
		);
		// $('#cart-dropdown').mouseover(function() {});
	});
	
	// load content here
	$.get(
		'/active/hdr-showcart.html',
		function(data) {
			$('#cart-dropdown').html(data);
		}
	);
	
	hdr_cartOn = true;
}

function cartOff() {
	$('#cart-dropdown').slideUp(
		'fast',
		function() {
			$('#cart-dropdown').html('');
		}
	);
	hdr_timeOut = setTimeout("void(0)",86400);
	hdr_cartOn = false;
}

function setCountry(theCountry) {
	countryOff();
	if (theCountry == 'CN') window.location = 'http://cn.krypt.com' + thisPage;
	if (theCountry == 'US') window.location = 'http://www.krypt.com' + thisPage;
	if (theCountry == 'TH') window.location = 'http://th.krypt.com' + thisPage;
	/*
	$.get(
		'http://www.krypt.com/active/setcountry.html?ccode='+theCountry,
		function(data) { 
			window.location.reload();
			if (theCountry == 'CN') window.location = 'http://cn.krypt.com/';
			if (theCountry == 'US') window.location = 'http://www.krypt.com/';
		}
	);
	*/
}

function dediListPrint() { 
	
}

function searchGo() { 
	document.getElementById('hdr_search').submit();
}
