// JavaScript Document
var timerCookie;
var continueShoppingLink = "",baskettempsmall = 0,baskettemplarge = 0;
dataid = new Array();
dataid[99] = 0;
dataid[100] = 0;

function openContactUs(){
	$('openContactUs').style.display = "none";
	$('closeContactUs').style.display = "";
	new Effect.BlindDown($('contactustrans'));
}
function closeContactUs(){
	$('closeContactUs').style.display = "none";
	$('openContactUs').style.display = "";
	new Effect.BlindUp($('contactustrans'));
}

function openAreasCovered(){
	$('openAreasCovered').style.display = "none";
	$('closeAreasCovered').style.display = "";
	new Effect.BlindDown($('areascoveredtrans'));
}
function closeAreasCovered(){
	$('closeAreasCovered').style.display = "none";
	$('openAreasCovered').style.display = "";
	new Effect.BlindUp($('areascoveredtrans'));
}
function featureOver(id,pos){
	id.style.backgroundPosition = pos;
	id.style.cursor = "pointer";
}
function featureOut(id,pos){
	id.style.backgroundPosition = pos;
	id.style.cursor = "";
}
function featureClick(id){
	link = $(id).down('a');
	if(link != undefined) {
		location.href = link.href;
	}
}
function headermenu(item){
	if($(item)){
		$(item).addClassName('header-menu-on');
	}
}
function continueShoppingB(cSLink){
	switch (cSLink) {
		case 'doors':
			$('moredoors').show();
		break;
		case 'blinds':
			$('moreblinds').show();
		break;
		case 'shutters':
			$('moreshutters').show();
		break;
	}
}
function additem(itemid){

	quty = $('quantity'+itemid).value;

	new Ajax.Request('/modules/shop/add.php', {
	  method: 'get',
	  parameters: {dataid: itemid, orderquantity: quty},
	  onSuccess: cartchanged
	  });

}
function onLoad() {
	// this doesn't help, Opera is currently broken:
	if (window.opera && window.history) {
		history.navigationMode = 'compatible';
	}
	// Set-up the polling:
	timerCookie = window.setTimeout(onTick, 200);
}
function onUnload() {
	if (timerCookie) {
		window.clearTimeout(timerCookie);
	}
}
function cartchanged(transport){
	$('products_cartnote').style.display = "";
	setTimeout("$('products_cartnote').style.display = 'none';", 2000 );
}
function galleryZoom(id) {

	imagebox = "gallery_image_"+id;
	imagelink = $(imagebox).select('a');
	popUp(imagelink[0].href,300,400);
//	eval("page" + id + " = window.open('" + imagelink[0].href + "', 'page" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=300,height=400');");
//	window.location.href = imagelink[0].href;
}

function temporder(width) {

	tempsmall = 0;

	templarge = Math.floor(width / 1210);

	widthleft = width - (templarge * 1210);

	if(widthleft < 910) {
		tempsmall = 1;
	}
	else {
		templarge = templarge + 1;
	}
	baskettempsmall += tempsmall;
	baskettemplarge += templarge;
}

function tempExtraOrder() {

	baskettempsmall = baskettempsmall - dataid[99];
	baskettemplarge = baskettemplarge - dataid[100];

	if(baskettempsmall > 0 || baskettemplarge > 0) {
		$('extraTemps').style.display = "";
		extraTempsTotal = 0;
		if(baskettempsmall > 0)	{
			extraTempsTotal = baskettempsmall * 5;
		}
		if(baskettemplarge > 0)	{
			extraTempsTotal = extraTempsTotal + (baskettemplarge * 8);
		}
		$('extraTempsPrice').innerHTML = extraTempsTotal;
	}


}
function getDataQuantity(basid) {
	if($('quantity['+basid+']')) {
		return $('quantity['+basid+']').value;
	}
}

function tempExtraOrderAdd() {

	if(baskettempsmall > 0)	{
		new Ajax.Request('/modules/shop/add.php', {method: 'get', parameters: {dataid: 99, orderquantity: baskettempsmall}});
	}
	if(baskettemplarge > 0)	{
		new Ajax.Request('/modules/shop/add.php', {method: 'get', parameters: {dataid: 100, orderquantity: baskettemplarge}});
	}
	setTimeout("window.location = '/Basket/'", 1000 )
}

// cookie handling
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}

// maxmind expander and collapser - prototype
function maxmindExpand(){
	new Effect.SlideDown('maxmindWrapper', { duration: 0.5 });
}
function maxmindCollapse(){
	new Effect.SlideUp('maxmindWrapper', { duration: 0.5 });
}
function maxmind_showDiv(data) {
	if (data == 'US' && (readCookie('shutt_maxmind') == null)) {
		$('maxmind').innerHTML = '<div id="maxmindWrapper"><div id="maxmindWrapper_i"><a href="http://www.theshutterstore.com/" title="Window shutters USA"><img src="/sitestyle/templates/images/USA-flag.jpg" width="43" height="43" alt="USA flag" /></a><p class="maxmindText"><span class="maxmindTitle">Looking for window shutters from USA?</span><br />Click here to visit <a href="http://www.theshutterstore.com/" title="Window shutters USA">The Shutter Store - our USA partners</a> or <span id="maxmindButtonClose" class="like-a-link">click here to close this notice</span></p></div></div>';
		$('maxmindWrapper').hide();
		$('maxmindWrapper').appear({ duration: 2.0 });
		$('maxmindButtonClose').observe('click', function(event){if(this == event.target){maxmindCollapse();createCookie('shutt_maxmind', 'US', 30);}});
	}
}
function maxmind_getMaxmindGeoCountry() {
	new Ajax.Request('/sitestyle/lib/class.maxmind.php', {
		method: 'post',
		parameters: {x: 1},
		onSuccess: function(response) { maxmind_showDiv(response.responseText); }
	});
}
document.observe("dom:loaded", function() {
	maxmind_getMaxmindGeoCountry();
});
