// Author: Al Sierra
// Version: 6.03.2009
// Description: AJAX for main functions
tfy.shop = {};
tfy.shop.dataURL = false;
tfy.shop.countdown = false;
tfy.shop.rocheBrosUrl = false;
tfy.shop.pageDimensions = {};
tfy.shop.pageDimensions.height = false;
tfy.shop.pageDimensions.width = false;
tfy.shop.Init =
	 function (s){
		//tfy.shop.dataURL = 'scripts/php/shop.php?';
		//tfy.shop.rocheBrosUrl = 'http://www.rochebros.com';
		//tfy.shop.countdown = 20;
		//tfy.shop.Countdown();
    };
tfy.shop.ShowPop =
	function(shop_item_id){
		$('popcontents-'+shop_item_id).style.display="block";
		$('pop_shop_item-close').onclick = function() {tfy.shop.ClosePop(shop_item_id);};
		if(tfy.main.CheckBrowserIE6()){
			Effect.Center($('shop_item_pop_window'));
		}else{
			tfy.shop.positionPop();
			$('shop_item_pop_window').style.position="fixed";
		}
		new Effect.Appear($('shop_item_pop_window'),{duration: .1, to:1.0});
	};
	
tfy.shop.ClosePop =
	function(shop_item_id){
		 $('shop_item_pop_window').style.display="none";
		 $('popcontents-'+shop_item_id).style.display="none";
	};
	
tfy.shop.Countdown =
	function(){
		tfy.shop.countdown = tfy.shop.countdown-1;
		if(tfy.shop.countdown == 0){
			window.location = tfy.shop.rocheBrosUrl;
			return false;
		}
		$('page_countdown').innerHTML = tfy.shop.countdown;
		setTimeout('tfy.shop.Countdown();',1000); 
	};

//positioning the email popup layer in the center of the screen.
tfy.shop.positionPop =
	function () {
 	var a = tfy.main.getScreen();
	var myWidth = a[0], myHeight = a[1];
	
	var cWindowHeight = parseInt($('shop_item_pop_window').style.height);
	var cWindowWidth = parseInt($('shop_item_pop_window').style.width);
	var cWindowX = myWidth/2 - cWindowWidth/2;
	var cWindowY = myHeight/2 - cWindowHeight/2;
	$('shop_item_pop_window').style.left =cWindowX + "px";
	$('shop_item_pop_window').style.top = cWindowY + "px";
	
};
				
tfy.shop.NoShowShop =
	function(){
		var msg_data = {};
		msg_data.cmd = 'NoShowShop';
		new Ajax.Request(tfy.shop.dataURL, {
			parameters: $H(msg_data).toQueryString(),
			evalScripts: true,
			onSuccess: function(transport) {
				try {
					var JSON = eval("("+transport.responseText+")");
					if (JSON.emsg) {
						alert(JSON.emsg);
						return false;
					}
					alert('You will now be automatically redirected to Roche Brothers\' website from now on.');
					window.location = tfy.shop.rocheBrosUrl;
				}catch(e) {
					alert("The server's response could not be understood.\nPlease try again.");
					return false;
				}
			},
			onComplete: function(){
				
			}			
		});
	};