//GLOBAL VARIABLES
var firstRun = 1;
var loadingPage = 1;
var passvar = checkvar(window.location.href,"p");
var recipeNumber = checkvar(window.location.href,"r");
var subscriber = false;
//CREATESEND
var action = "http://macintype.createsend.com/t/y/s/ohkirt/";

//DOM BEGINS
$(document).ready(function(){
	//START
	start();
	//PRELOADER FUNCTION
	//QueryLoader.init();
//	preloader("../images",start);

	//PREVENT ENTER KEY FROM SUBMITTING FORM
	$(window).keypress(
		function(event){ 
			if (event.keyCode == 13) {
				event.preventDefault();
			} 
		}
	);

});
//DOM ENDS


//SORTING OBJECTS IN ARRAY BY A FIELD VALUE
function dynamicSort(property) {
    return function (a,b) {
        return (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
    }
}
//CHANGING NATIVE OBJECT PROTOTYPE
//Array.prototype.sortBy = function(property) {
//    return this.sort(dynamicSort(property))
//}


//SAMS ANIMATION FUNCTION
function gifAnimation(){
	//INITIALISE VARIABLES
	gifString = '';
	gifCounter = 0;	
	tallestImage = 0;
	
	//CREATE STRING
	$.each(gifArray, function(){
		gifString+='<div style="position:absolute; width:537px; left:0px; top:0px; z-index:' + (99 - gifCounter) + '; text-align:center;" id="gifImageWrapper' + gifCounter + '" class="gifWrappers"><a rel="' + this.rel + '" class="gifLink"><img src="' + this.img + '" alt="' + this.alt + '" title="' + this.alt + '" id="gifImage' + gifCounter + '" /></a></div>';
		$('#gifAnimation').html(gifString);
		if($('#gifImage' + gifCounter).height() > tallestImage){
			 tallestImage = $('#gifImage' + gifCounter).height();
		}
		gifCounter++;
	});
	
	//INITIALISE VARIABLES
	gifCounter = 0;
	gifPadding = 0;
	
	//VERTICALLY ALIGN IMAGES
	$.each(gifArray, function(){
		if($('#gifImage' + gifCounter).height() < tallestImage){
			//SET GIF PADDING
			gifPadding = (tallestImage - $('#gifImage' + gifCounter).height()) / 2;
			
			//FIX ODD SIZED IMAGES
			if(gifPadding != Math.round(gifPadding)){
				gifPaddingTop = Math.round(gifPadding);
				gifPaddingBottom = (Math.round(gifPadding)) - 1;
			} else {
				gifPaddingTop = gifPadding;
				gifPaddingBottom = gifPadding;
			}
			 
			//WRITE gif PADDING
			//$('#gifImage' + gifCounter).css('padding-top', gifPaddingTop);
			//$('#gifImage' + gifCounter).css('padding-bottom', gifPaddingBottom);			 
		}
		gifCounter++;
	});
	
	//SET gif ANIMATION HEIGHT
	$('#gifAnimation').css('height', tallestImage);
	
	//INITIALISE VARIABLES
	gifCounter = 0;
	
	//LOOP ANIMATION
	if(typeof(gifInterval) != 'undefined'){
		clearInterval(gifInterval);
	}
	gifInterval = setInterval(function(){
		animateGifFunction();
	},5000);
	
	//ANIMATE GIF
	function animateGifFunction(){	
		if(gifCounter == (gifArray.length-1)){
			$('#gifImageWrapper0').css({'display':'block'});
			$('#gifImageWrapper0').animate({'opacity':'1'}, 500, function(){
				$('.gifWrappers').css({'opacity':'1'});
				$('.gifWrappers').css({'display':'block'});			
				gifCounter = 0;
			});
		} else {
			$('#gifImageWrapper' + gifCounter).animate({'opacity':'0'}, 500, function(){
				$(this).css('display', 'none');
			});
			gifCounter++;
		}
	}
	
	$('.gifLink').click(function(){
		if($(this).attr('rel') == 'gourmetClub')
		{
			//$("#btn_subscribe").trigger('click');
			$("#btn_RealgourmetClub").trigger("click");
		} 
		else if($(this).attr('rel') == 'mercurios')
		{
			$('#player').html('<p align="center" id="tutorial"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</p>');
			var FU = {movie:"flvplayer.swf",width:"537",height:"322",majorversion:"8",build:"0",bgcolor:"#FFFFFF",allowfullscreen:"true",flashvars:"file=data.flv&image=video.jpg&autostart=true"};
            UFO.create(	FU, "tutorial");
		}
		else if($(this).attr('rel') == 'bitton')
		{
			$("#btn_store").trigger('click');
		}
		else if($(this).attr('rel') == 'gourmetTraveller')
		{
			var href = '17';
			//Clearing Layout
			$("#canva").html("<div class='columnLeft2' id='columnLeft'></div><div class='columnRight2' id='columnRight'></div><div style='clear:both;height:25px; width:100%;'></div>");
			//Changing navbar current 
			$(".navbutton").removeClass("current").removeClass("hover");
			$("#btn_recipe").addClass("current");
			//Loading Content and passing variable
			loadContent("Left_Panel_txt.html","recipes_main_txt.html?o=" + href);
		}
		else if($(this).attr('rel') == 'peppers')
		{
			$("#btn_promo").trigger("click");
		}
	});
}

//START FUNCTION - AFTER PRELOAD
function start()
{
	//NAVBAR
	navigation();
	//FIRST LOAD
	$("#canva").html("<div class='columnLeft' id='columnLeft'></div><div class='columnRight' id='columnRight'></div><div id='bottomGap' style='clear:both;height:25px; width:100%; font-size:0px; line-height:0px;'></div>");
	loadContent("home_txt.html","Right_Panel_txt.php");

}

//LOADING CONTENT FUNCTION
function loadContent(leftPanelURL, rightPanelURL)
{
	if (leftPanelURL!="" || rightPanelURL !="")
	{
		//One of them has value at least
		if (rightPanelURL=="")
		{
			//Right Panel MUST remain the same
			$("#columnLeft").load(leftPanelURL, function(){
				basics(leftPanelURL, "");											
				});										  
		}
		if (rightPanelURL == "Right_Panel_txt.php")
		{
			$("#columnLeft").load(leftPanelURL, function(){
				$("#columnRight").load(rightPanelURL, function(){
					basics(leftPanelURL, rightPanelURL);											
				});										  
			});	
		}
		if (leftPanelURL == "")
		{
			$("#columnRight").load(rightPanelURL,function(){
				basics("",rightPanelURL);											  
			});
		}
		if (leftPanelURL == "Left_Panel_txt.html")
		{
			$("#columnLeft").load(leftPanelURL, function(){
				$("#columnRight").load(rightPanelURL, function(){
					basics(leftPanelURL, rightPanelURL);											
				});										  
			});	
		}
		if (leftPanelURL.indexOf("prod")!=-1 && rightPanelURL.indexOf("prod")!=-1)
		{
			$("#bottomGap").css("height","0px");
			$("#columnLeft").load(leftPanelURL, function(){
				$("#columnRight").load(rightPanelURL, function(){
					$("#canva").append("<div class='prodResults' id='prodResults' style='display:none;'></div>");										   
					basics(leftPanelURL, rightPanelURL);											
				});										  
			});	
		}
		else
		{
			$("#bottomGap").css("height","25px");
		}
	}
}

//BASICS
function basics(left,right)
{
	if (right == "Right_Panel_txt.php")
	{
		rpNav();
		//PASSING VARIABLES
		if (passvar == "gc" && loadingPage == 1)
		{
//			alert("hello");
			$("#btn_RealgourmetClub").trigger("click");
			loadingPage = 0;
		}
		if (passvar == "promo" && loadingPage == 1)
		{
//			alert("hello");
			$("#btn_promo").trigger("click");
			loadingPage = 0;
		}
		if (passvar == "r" && loadingPage == 1)
		{
//			$("#btn_viewRecipe").trigger("click");	
			$("#site-photography").trigger("click");
			loadingPage = 0;
		}
		if (passvar == "store" && loadingPage == 1)
		{
//			alert("hello");
			$("#btn_retail").trigger("click");
			loadingPage = 0;
		}
		if (recipeNumber != "" && loadingPage == 1)
		{
			var href = recipeNumber;
			//Clearing Layout
			$("#canva").html("<div class='columnLeft2' id='columnLeft'></div><div class='columnRight2' id='columnRight'></div><div style='clear:both;height:25px; width:100%;'></div>");
			//Changing navbar current 
			$(".navbutton").removeClass("current").removeClass("hover");
			$("#btn_recipe").addClass("current");
			//Loading Content and passing variable
			loadContent("Left_Panel_txt.html","recipes_main_txt.html?o=" + href);
		}
		
		if (left == "privacy_txt.html" || left == "terms_txt.html")
		{
//			$.scrollTo( '#top', 1000, {easing:'easeOutBack',queue:true} );
			$.scrollTo( '#top', 1000, {queue:true} );
		}
		if (left == "gourmetClubContent_txt.php")
		{
			//$("#btn_hungerford").colorbox({width:"550px", height:"390px", href:"giveawayForm_txt.html",onComplete:function(){$.colorbox.resize();reloadGiveawayForm();}});
			$("#btn_giveaway").colorbox({width:"550px", height:"390px", href:"giveawayForm_txt.html",onComplete:function(){$.colorbox.resize();reloadGiveawayForm();}});
			$("#btn_feedback").colorbox({width:"550px", height:"470px", href:"feedbackForm_txt.html",onComplete:function(){$.colorbox.resize();reloadFeedbackForm();}});
			//$("#btn_mothersTerms").colorbox({width:"550px", height:"390px", href:"mothersTerms_txt.html",onComplete:function(){Cufon.replace(".btn_Text3,.redHeader");}});
			$("#btn_bigpromoTerms1").colorbox({width:"700px", height:"390px", href:"termsEverdureNSW_txt.html", height:"1000px",onComplete:function(){Cufon.replace(".btn_Text3,.redHeader");$.colorbox.resize();}});
			$("#btn_bigpromoTerms2").colorbox({width:"700px", height:"390px", href:"termsEverdureACT_txt.html", height:"1000px",onComplete:function(){Cufon.replace(".btn_Text3,.redHeader");$.colorbox.resize();}});
			$("#btn_bigpromo").colorbox({width:"550px", height:"600px", href:"bigpromoForm_txt.html",onComplete:function(){$.colorbox.resize();reloadBigpromoForm();}});
			$("#btn_redeem").colorbox({width:"550px", height:"600px", href:"redeemForm_txt.html",onComplete:function(){$.colorbox.resize();reloadRedeemForm();}});
			//HOVER EVENT
			$(".btn_enter").hover(function(){
				$(this).addClass("hover102");							
			},function(){
				$(this).removeClass("hover102");										 
			});
			//HOVER EVENT
			$(".btn_enter100").hover(function(){
				$(this).addClass("hover201");							
			},function(){
				$(this).removeClass("hover201");										 
			});
			
			
			$(".btn_redsmall").hover(function(){
				$(this).addClass("hover93");
			},function(){
				$(this).removeClass("hover93");
			});

			lphe();
			//CLICK EVENT
			$("#btn_open").click(function(){
				var destination = $(this).attr("rel");
				window.open(destination,null, "height=800,width=1000,status=no,toolbar=no,menubar=no,location=no");
			});
			$("#btn_download").click(function(){
				var destination = $(this).attr("rel");
				window.open(destination);
			});
			$("#btn_download2").click(function(){
				var destination = $(this).attr("rel");
				window.open(destination);
			});
			$("#btn_printVoucher").click(function(){
				var destination = $(this).attr("rel");
				window.open(destination);
			});
		}
		if (left.indexOf("promo") != -1)
		{
			//PROMO PAGE
			showpromo();
			
			//pastpromos
			pastpromos();
			//PEPPERS
	//		$("#btn_bigpromoTerms1").colorbox({width:"550px", height:"390px", href:"termsPeppersNSW_txt.html",onComplete:function(){Cufon.replace(".btn_Text3,.redHeader");}});
	//		$("#btn_bigpromoTerms2").colorbox({width:"550px", height:"390px", href:"termsPeppersACT_txt.html",onComplete:function(){Cufon.replace(".btn_Text3,.redHeader");}});
	//		$("#btn_bigpromo").colorbox({width:"550px", height:"390px", href:"bigpromoForm_txt.html",onComplete:function(){$.colorbox.resize();reloadBigpromoForm();}});
			
			//fGoto
			fGoto();
			//HOVER EVENT
			$(".btn_enter").hover(function(){
				$(this).addClass("hover102");							
			},function(){
				$(this).removeClass("hover102");										 
			});
			//HOVER EVENT
			$(".btn_enter100").hover(function(){
				$(this).addClass("hover201");							
			},function(){
				$(this).removeClass("hover201");										 
			});
			
			
		}
		//ANALYTICS
		var analyticsURL = left;
	}
	if (right == "")
	{
	 //RIGHT PANEL IS STILL LOADED
		if (left.indexOf("contact") != -1)
		{
			//SUBMIT BUTTON
			//HOVER EVENT
			$(".btn_submit2").hover(function(){
				$(this).addClass("hover42");				 
			},function(){
				$(this).removeClass("hover42");							  
			});
			//CLICK EVENT
			$("#enquiryFormSubmit").click(function(){validateContact()});
		}
		if (left.indexOf("promo") != -1)
		{
			//PROMO PAGE
			showpromo();
			
			//pastpromos
			pastpromos();
			
			$("#btn_termsPromo").colorbox({width:"550px", height:"390px", href:"termsPromo2_txt.html",onComplete:function(){Cufon.replace(".btn_Text3,.redHeader");}});
			$("#btn_bigpromo").colorbox({width:"550px", height:"390px", href:"bigpromoForm_txt.html",onComplete:function(){$.colorbox.resize();reloadBigpromoForm();}});
			$("#btn_bigpromoTerms1").colorbox({width:"550px", height:"390px", href:"termsEverdureNSW_txt.html", height:"1000px",onComplete:function(){Cufon.replace(".btn_Text3,.redHeader");}});
			$("#btn_bigpromoTerms2").colorbox({width:"550px", height:"390px", href:"termsEverdureACT_txt.html", height:"1000px",onComplete:function(){Cufon.replace(".btn_Text3,.redHeader");}});
			//fGoto
			fGoto();
			//HOVER EVENT
			$(".btn_enter").hover(function(){
				$(this).addClass("hover102");							
			},function(){
				$(this).removeClass("hover102");										 
			});
			//HOVER EVENT
			$(".btn_enter100").hover(function(){
				$(this).addClass("hover201");							
			},function(){
				$(this).removeClass("hover201");										 
			});
			
			
		}
		//ANALYTICS
		var analyticsURL = left;
	}
	if (left == "Left_Panel_txt.html" || left == "")
	{
		//COULD BE RETAIL, FOOD or RECIPE
		lpn(left,right);
		//ANALYTICS
		var analyticsURL = right;
	}
	//HOME PAGE
	if(left == "home_txt.html"){
		gifAnimation();
	}
	//PRODUCT PAGE
	if (left.indexOf("prod") !=-1 && right.indexOf("prod")!=-1)
	{
		//PRODUCTS PAGE
		$(".btn_redBig").hover(function(){
			$(this).addClass("hover6");					  
		},function(){
			$(this).removeClass("hover6");							   
		});
		
		//CLICK EVENT
		$("#btn_gameBirds").click(function(){
			$("#prodResults").html(printElement(gameBirds)).show("fast");
			Cufon.replace(".header4,.btn_Text3,.header6");
			//HOVER EVENT
			$(".btn_submit").hover(function(){
				$(this).addClass("hover4");							
			},function(){
				$(this).removeClass("hover4");										 
			});
			//CLICK EVENT
			$(".btn_submit").click(function(){
				var href = $("a", $(this)).attr("rel");
				//Clearing Layout
				$("#canva").html("<div class='columnLeft2' id='columnLeft'></div><div class='columnRight2' id='columnRight'></div><div style='clear:both;height:25px; width:100%;'></div>");
				//Changing navbar current 
				$(".navbutton").removeClass("current").removeClass("hover");
				$("#btn_recipe").addClass("current");
				//Loading Content and passing variable
				loadContent("Left_Panel_txt.html","recipes_main_txt.html?o=" + href);
			});
		});
		$("#btn_gameMeats").click(function(){ 
			$("#prodResults").html(printDirect()).show("fast");
			Cufon.replace(".header4,.header6");
			//ANCHOR GOTO
			aGoto();
		});
		//FIRST LOAD
		$("#btn_gameBirds").trigger("click");
		//ANALYTICS
		var analyticsURL = right;
	}
	//FONT REPLACEMENT
	replaceCufon();
	//ANCHOR GOTO
	aGoto();
	//FOOTER ANCHOR GOTO
	fGoto();
	//ANALYTICS
	_gaq.push(['_trackEvent', 'name', analyticsURL]);
	_gaq.push(['_trackPageview', analyticsURL]);
	$("#btn_submitRecipe_alt").colorbox({width:"550px", height:"390px", href:"submitRecipe_txt.html",onComplete:function(){$.colorbox.resize();reloadSubmitRecipe();}});
}

//REPLACE CUFON FUNCTION
function replaceCufon()
{
 for (var i in cufonClasses)
 {
	varclass = "." + cufonClasses[i];
//	Cufon.replace(varclass, {color: '-linear-gradient(#CF2626, #232323)'});
	Cufon.replace(varclass);
 }
 return false;
}

//IS IE6?
function isIE6()
{
	var isIE6 = (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1);
	return isIE6;
}

//NAVIGATION
function navigation()
{
	//NAVBAR HOVER EVENT
	$(".navbutton").hover(function(){
		if( $(this).attr("class").indexOf("current") == -1)
		{
		 $(this).addClass("hover");
		};							   
	},function(){
		if( $(this).attr("class").indexOf("current") == -1)
		{
		 $(this).removeClass("hover");
		};							   
	});
			
	//NAVBAR CLICK EVENT
	$(".navbutton").click(function(){
		var href = $("a", $(this)).attr("href");
		var destination = href.substring(0,href.length-5);
		var layout = $("a", $(this)).attr("rel");
		var origin = $(".navbutton").filter(".current").attr("id").substring(4,$(".navbutton").filter(".current").attr("id").length);
		var regLeft = ["home","story", "promo", "contact"]
		var regRight = ["retail", "food", "recipes"]

		//Change the current navbar
		$(".navbutton").removeClass("current").removeClass("hover");
		$(this).addClass("current");

		if(layout == "left")
		{
			if($.inArray(origin,regLeft) != -1)
			{
				//Only loads left panel	- Is going to a Right Panel layout and comes from a Right Panel Layout
				loadContent(destination + "_txt.html","");
			}
			else
			{
				//Both panels need to be loaded
				//Correcting the classes
				$("#canva").html("<div class='columnLeft' id='columnLeft'></div><div class='columnRight' id='columnRight'></div><div id='bottomGap' style='clear:both;height:25px; width:100%; font-size:0px; line-height:0px;'></div>");
				loadContent(destination + "_txt.html","Right_Panel_txt.php");
			}
		}
		else if (layout == "right")
		{
				//Both panels need to be loaded
				$("#canva").html("<div class='columnLeft2' id='columnLeft'></div><div class='columnRight2' id='columnRight'></div><div id='bottomGap' style='clear:both;height:25px; width:100%; font-size:0px; line-height:0px;'></div>");
				loadContent("Left_Panel_txt.html",destination + "_main_txt.html");
		}
		else
		{
			//PRODUCTS
			$("#columnLeft").removeClass().addClass("columnLeft");
			$("#columnRight").removeClass().addClass("columnRight");
			loadContent(destination + "_txt.html #prodLeft",destination + "_txt.html #prodRight");
		}
	});	
}

//RIGHT PANEL
function rpNav()
{
	//RIGHT PANEL
	$(".btn_RightPanel").hover(function(){
		 $(this).addClass("hover");
	},function(){
		 $(this).removeClass("hover");
	});	
	//CLICK EVENT
	$("#btn_store").click(function(){callWebCooking2();}); // WEB COOKING
	$("#btn_subscribe").colorbox({width:"550px", height:"390px", href:"subscribe_txt.html",onComplete:function(){$.colorbox.resize();reloadSubscribe();}});
	$("#btn_gourmetClub").colorbox({width:"550px", height:"390px", href:"gourmetClub_txt.html",onComplete:function(){$.colorbox.resize();reloadGourmet();}});
	
	$("#btn_RealgourmetClub").click(function(){
			//QUERY DATABASE FOR CURRENT USERS
			$.ajax({
				url: 'js/gourmet.php',
				success: function(data){
						if (data == '1')
						{
							loadContent("gourmetClubContent_txt.php","Right_Panel_txt.php");
						}
						else
						{
							$("#btn_gourmetClub").trigger("click");
						}
					},
				error: function(XMLHttpRequest,textStatus, errorThrown) {alert("Status" + textStatus + "Error:" + errorThrown + "<br/>Response:" + XMLHttpRequest.responseText);}
			});
											 
	});

	$("#btn_logout").click(function(){
			//QUERY DATABASE FOR CURRENT USERS
			$.ajax({
				url: 'js/sql.php',
				data: 'query=kill',
				type: 'POST',
				success: function(data){
						if (data == '0')
						{
							loadContent("home_txt.html","Right_Panel_txt.php");
						}
					},
				error: function(XMLHttpRequest,textStatus, errorThrown) {alert("Status" + textStatus + "Error:" + errorThrown + "<br/>Response:" + XMLHttpRequest.responseText);}
			});
											 
	});

	//COMMUNITY NEWS BUTTON
	//HOVER EVENT
	$("#btn_commNews").hover(function(){
		 $(this).addClass("hover2");
	},function(){
		 $(this).removeClass("hover2");
	});
	//CLICK EVENT
	$("#btn_commNews").click(function(){
		if($(this).attr("class").indexOf("collapsed")!=-1)
		{
			//COLLAPSED
			//Changind the button class
			$(this).removeClass("hover2").removeClass("collapsed").addClass("expanded");
			//ANIMATING 
			$("#newsContainer").slideDown("slow");
		}
		else
		{
			//EXPANDED
			//Changing the button class
			$(this).removeClass("hover2").removeClass("expanded").addClass("collapsed");
			//ANIMATING
			$("#newsContainer").slideUp("slow");
		}
	});
	//LOADING COMMUNITY NEWS
	communityNews();
	//RECIPE OF THE MONTH ANIMATION
	recipeMonth();
	$("#site-photography").click(function(){
//	 	$("#btn_viewRecipe").trigger("click");									  
		var href = $("#recipeID").attr("rel");
		//Clearing Layout
		$("#canva").html("<div class='columnLeft2' id='columnLeft'></div><div class='columnRight2' id='columnRight'></div><div style='clear:both;height:25px; width:100%;'></div>");
		//Changing navbar current 
		$(".navbutton").removeClass("current").removeClass("hover");
		$("#btn_recipe").addClass("current");
		//Loading Content and passing variable
		loadContent("Left_Panel_txt.html","recipes_main_txt.html?o=" + href);
	});
	//SMALL BUTTONS BOTTOM
	//HOVER EVENT
	$(".btn_rpBottom").hover(function(){
		 $(this).addClass("hover3");
	},function(){
		 $(this).removeClass("hover3");
	});
	//CLICK EVENT
	$("#btn_viewRecipe").click(function(){
		var href = $("a", $(this)).attr("rel");
		//Clearing Layout
		$("#canva").html("<div class='columnLeft2' id='columnLeft'></div><div class='columnRight2' id='columnRight'></div><div style='clear:both;height:25px; width:100%;'></div>");
		//Changing navbar current 
		$(".navbutton").removeClass("current").removeClass("hover");
		$("#btn_recipe").addClass("current");
		//Loading Content and passing variable
		loadContent("Left_Panel_txt.html","recipes_main_txt.html?o=" + href);
	});
	$("#btn_submitRecipe").colorbox({width:"550px", height:"390px", href:"submitRecipe_txt.html",onComplete:function(){$.colorbox.resize();reloadSubmitRecipe();}});
	$("#btn_viewAllRecipes").click(function(){$("#btn_recipe").trigger("click");});

	$("#btn_gourmetclubArchive").click(function(){printGourmetClubArchive();});

	//SPONSORS ANIMATION
	if(firstRun == 1){
		sponsorAnimation();
		firstRun = 0;
	}
	else
	{
		clearInterval(sponsorsInterval);
		sponsorAnimation();
	}
	
	//FORMS BUTTONS
	//HOVER EVENT
	$(".btn_submit").hover(function(){
		 $(this).addClass("hover4");
	},function(){
		 $(this).removeClass("hover4");
	});
	//HOVER EVENT 2
	$(".btn_submit2").hover(function(){
		 $(this).addClass("hover42");
	},function(){
		 $(this).removeClass("hover42");
	});
	//CLICK EVENT
	$("#enquiryFormSubmit").click(function(){validateContact()});
}

//COMMUNITY NEWS LOADER
function communityNews()
{
	// LOADING NEWS UPDATE
	function pageselectCallback(page_index, jq)
	{
     var items_per_page = 3;
     var max_elem = Math.min((page_index+1) * items_per_page, $('#hiddenresult div.news').length);
     var newcontent = "";
	 $('#Searchresult').empty();
     // Iterate through a selection of the content and build an HTML string
     for(var i=page_index*items_per_page;i<max_elem;i++)
	 {
      var new_content = jQuery('#hiddenresult div.news:eq('+i+')').clone();
      $('#Searchresult').append(new_content);
     }
	  Cufon.replace(".newsHeader,.btn_Text3");

		//"MORE" BUTTONS
		//HOVER EVENT
		$(".btn_search").hover(function(){
			$(this).addClass("hover5");							
		},function(){
			$(this).removeClass("hover5");										 
		});
		//CLICK EVENT
		$(".btn_search").click(function(){
			var href = $("a", $(this)).attr("rel");
			var destination = href.substring(0,href.length-5);
		//	loadContent(destination + "_txt.html","");
		//	alert(href);
			commNewsBig(href)
		//	$("#columnLeft").load(destination + "_txt.html", function(response, status, xhr) {
		//	  alert("response:'" + response + "', status:'" + status + "', xhr.status:'" + xhr.status + "', xhr.statusText:'" + xhr.statusText + "'");
		//	});

		});	
    // Prevent click event propagation
    return false;
   }
           
   function initPagination() 
   {
    var num_entries = $('#hiddenresult div.news').length;
    // Create pagination element
    $("#Pagination").pagination(num_entries, {
                    callback: pageselectCallback,
                    items_per_page:3
     });
   }
	$("#hiddenresult").html(commNewsFeed());
	initPagination();
}

//RECIPE OF THE MONTH ANIMATION
function recipeMonth()
{
   //RECIPE OF THE MONTH ANIMATION
   		// Get DOM references.
		var jPhotoArea = $( "#site-photography" );
		var jPhoto = $( "#site-photography-photo" );
		var jPhotoDetails = $( "#site-photography-details" );
		var jPhotoDescription = $( "#site-photo-details-description" );
		var jPhotoLink = $( "#site-photo-details-link" );
		var jPhotoContacts = $( "#site-photo-details-contacts" );
		var jAjaxLoader = $( "#site-photography-loader" );
		
		// Keep track of properties of the photo details.
		var objBottomProperties = {
			Min: "-56px",
			Max: "-25px"
			};
		
		// The timer for mouseing out of the site photo area.
		var objMouseOutTimeout = null;
		
		// Keep track of which direction we are animating in.
		var objIsAnimatingSitePhotoDetails = {
			Show: false,
			Hide: false
			};
			
		// Keep track of site photo XHR request.
		var objSitePhotoRequest = null;
		
		
		// I show the site photo details (if necesssary).
		function ShowSitePhotoDetails(){
			// We only want to animate the Show if we are:
			// 1. Not currently showing the photo details.
			// 2. Currently hiding the photo details.
			if (
				!objIsAnimatingSitePhotoDetails.Show ||
				objIsAnimatingSitePhotoDetails.Hide
				){
				
				// Check to see if we need to stop any animation.
				if (objIsAnimatingSitePhotoDetails.Hide){
					jPhotoDetails.stop();
				}
				
				// Flag the animations.
				objIsAnimatingSitePhotoDetails.Show = true;
				objIsAnimatingSitePhotoDetails.Hide = false;
				
				// Stop any existing animation and show the details.
				jPhotoDetails.animate(
					{
						bottom: objBottomProperties.Max
					},
					{
						duration: 150,
						
						// When complete, flag all animations as being done.
						complete: function(){
							objIsAnimatingSitePhotoDetails.Show = false;
							objIsAnimatingSitePhotoDetails.Hide = false;
						}
					}
					);

			}
		}
		
		
		// I hide the site photo details.
		function HideSitePhotoDetails(){
			// When mousing down, set the animation flags.
			objIsAnimatingSitePhotoDetails.Show = false;
			objIsAnimatingSitePhotoDetails.Hide = true;
		
			// Slide details down.
			jPhotoDetails
				.animate(
					{
						bottom: objBottomProperties.Min
					},
					{
						duration: 100,
						
						// When complete, flag all animations as being done.
						complete: function(){
							objIsAnimatingSitePhotoDetails.Show = false;
							objIsAnimatingSitePhotoDetails.Hide = false;
						}
					}
					);
		}
		
		
		
		// I handle the mouse over functionality for both the photo and 
		// the photo details as they are going to act in the same fashion.
		function SitePhotoMouseOverHandler(){
			// Clear any mouse out time out so that our details don't disaapear.
			clearTimeout( objMouseOutTimeout );
			
			// Show the photo details.
			ShowSitePhotoDetails();
			
			// Show prev / next arrows.
		}
		
		
		// I handle the mouse out functionality for both the photo and 
		// the photo details as they are going to act in the same fashion.
		function SitePhotoMouseOutHandler(){
			// Because of the way that events happen, set a timeout for this mouse
			// out action. This will give the mouse-over action a change to 
			// cancel the bubble.
			objMouseOutTimeout = setTimeout(
				function(){
					HideSitePhotoDetails();
				},
				100
				);
		}
		
		
		
	
		
		// I handle the mouse over of the photo area.
		$( [] ).add( jPhotoArea ).add( jPhotoDetails ).mouseover(
			function(){
				SitePhotoMouseOverHandler();
				return( false );
			}
			);
		
		// I handle the mouse out of the photo area.
		$( [] ).add( jPhotoArea ).add( jPhotoDetails ).mouseout(
			function(){
				SitePhotoMouseOutHandler();
				return( false );
			}
			);
	
}

//CHECK FOR PASSING VARIABLES IN LOAD
function checkvar(url,name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec(url);
  if( results == null )
    return "";
  else
    return results[1];
}

//UNIQUE GROUP ARRAY
function getUniqueGroup(data, sorted){
    var Groups = [];
    $.each(data, function(){
        if ($.inArray(this.group,Groups) === -1) {
                Groups.push(this.group);
        }
    });
	if (sorted=="sort")
	{
		return Groups.sort();
	}
	else
	{
		return Groups;
	}
}

//LEFT PANEL
function lpn(left,right)
{	
	//CHECK CURRENT NAVBAR
	var origin = $(".navbutton").filter(".current").attr("id").substring(4,$(".navbutton").filter(".current").attr("id").length);
	if (origin=="retail") lpheader = "Where to Buy";
	if (origin=="food") lpheader = "Food Service";
	if (origin=="recipe") lpheader = "Recipes";
	//REPLACING HEADER
	$("#lpHeader").html(lpheader);
	//REPLACING PICTURE
	$(".leftPanelIMG").html("<img src='images/pic_" + origin + ".jpg' alt='" + lpheader + "' />");
	
	//CHECK FOR PASSING VARIABLES
	var o = checkvar(right,"o");
 	if (o!="")
	{
		var groupName = o;
		var recipeID = /\d+(?:\.\d+)?/.exec(o); //EXTRACT NUMBER FROM STRING
		if (recipeID)
		{
			//LOOKING FOR A RECIPE ID
			var groupID = findGroup(recipeID);
			var group = getUniqueGroup(recipes,"");
			for (var i in group)
			{
				$(".leftPanelButtons").append("<div class='btn_leftPanel' id='btn_" + trim(group[i]).toLowerCase() + "'><div class='btn_Text3'>" + group[i].toUpperCase() + "</div></div>");
			}
			//HOVER EVENT
			lphe();
			//CLICK EVENT
			recipeClick();
			//CALLING THE RECIPE
			var clicked = groupID.toLowerCase();
			//HIDE EVERYONE BUT CLICKED ONE
			$(".btn_leftPanel").addClass("hidden2");
			$("#btn_" + clicked).removeClass("hidden2").addClass("current2");
			//ADD HORIZONTAL NAVIGATION
			$(".horizontalNav").html("<a href='#' class='returnRecipe'>Recipes</a> &gt; " + clicked);
			$(".returnRecipe").click(function(){ $("#btn_recipe").trigger("click");});
			//ADD VERTICAL NAVIGATION
			verticalNav(recipes,clicked,"recipe",recipeID);

		}
		else
		{
			//LOOKING FOR A GROUP OF RECIPES
			var group = getUniqueGroup(recipes, "");
			for (var i in group)
			{
				$(".leftPanelButtons").append("<div class='btn_leftPanel' id='btn_" + trim(group[i]).toLowerCase() + "'><div class='btn_Text3'>" + group[i].toUpperCase() + "</div></div>");
			}
			//Applying action to buttons
			//HOVER EVENT
			lphe();
			//CLICK EVENT
			recipeClick();
			//CALLING THE GROUP
			$("#btn_" + groupName.toLowerCase()).trigger("click");
		}
	}
	else
	{
		//NO VARIABLES
		//LEFT PANEL BUTTONS
		if (origin=="retail")
		{
			$(".leftPanelButtons").append("<div class='btn_leftPanel' id='btn_storeLocator'><div class='btn_Text3'>STORE LOCATOR</div></div>");
		//	$(".leftPanelButtons").append("<div class='btn_leftPanel' id='btn_cookingDemo'><div class='btn_Text3'>COOKING DEMOSTRATIONS</div></div>");
			$(".leftPanelButtons").append("<div class='btn_leftPanel' id='btn_rangeProd'><div class='btn_Text3'>VIEW OUR RETAIL RANGE</div></div>");
			//Applying action to buttons
			//HOVER EVENT
			lphe();
			//CLICK EVENT
			retailClick();
			//DEFAULT LOAD
			$("#btn_storeLocator").trigger("click");
		}
		if (origin=="food")
		{
			var group = getUniqueGroup(food, "sort");
			for (var i in group)
			{
				$(".leftPanelButtons").append("<div class='btn_leftPanel' id='btn_" + trim(group[i]).toLowerCase() + "'><div class='btn_Text3'>" + group[i].toUpperCase() + "</div></div>");
			}
			//Applying action to buttons
			//HOVER EVENT
			lphe();
			//CLICK EVENT
			foodClick();
		}
		if (origin=="recipe")
		{
			var group = getUniqueGroup(recipes, "");
			for (var i in group)
			{
				$(".leftPanelButtons").append("<div class='btn_leftPanel' id='btn_" + trim(group[i]).toLowerCase() + "'><div class='btn_Text3'>" + group[i].toUpperCase() + "</div></div>");
			}
			//Applying action to buttons
			//HOVER EVENT
			lphe();
			//CLICK EVENT
			recipeClick();
		}
	}
}

//TRIMMING STRINGS
function trim(str)
{
 var result="";
 for (var i=0; i<=str.length;i++)
 {
	if (str.substring(i,i+1)!=" ")
	{
	 result += str.substring(i,i+1);	
	}
 }
 return result;
}

//LEFT PANEL HOVER EVENT
function lphe()
{
	$(".btn_leftPanel").hover(function(){
		$(this).addClass("hover7");							   
	},function(){
		$(this).removeClass("hover7");											
	});
}

//RETAIL BUTTONS CLICK EVENT
function retailClick()
{
	$(".btn_leftPanel").click(function(){
		var clicked = trim($(this).attr("id").substring(4,$(this).attr("id").length));
		//LOADING CONTENT
		if (clicked == "storeLocator")
		{
		  /* Clear the vertical Nav Bar since Store Locator does not use it */
		  $(".verticalNavBar").html("&nbsp;");
		  $("#columnRight").load("store_txt.html", function(){
			//HOVER EVENT
			$(".btn_submit2").hover(function(){						
				$(this).addClass("hover42");							
			},function(){
				$(this).removeClass("hover42");
			});
			//CLICK EVENT												
			$("#btn_submitStoreLoc").click(function(){
				//DUMMY SINCE THERE IS NO DATABASE
				var sm=$("#sm").val();									
				var st=$("#st").val();
				var pc=$("#pc").val();
				storeFilter(sm,st,pc);
			});	
			
			//ENTER KEY
			$("input").keypress(function(e) {
        		if(e.which == 13) {
					$(this).blur();
					$("#btn_submitStoreLoc").trigger("click");
				}
		    });

			//HYPERLINK
			$("#btn_ourRange").click(function(){
				$("#btn_rangeProd").trigger("click");
			});
			
			//CUFON
			Cufon.replace(".storeHeader,.header5,.btn_Text3");	
		  });
		}
		if (clicked == "rangeProd")
		{
			if (!$("#btn_" + clicked).hasClass("current2"))
			{
				
				var cc = 0;
				$.each(getUniqueGroup(range, ""), function(){
				if (cc==0) 
				{
					 $(".verticalNavBar").append("<div class='vnb_btn current3' id='btn_" + cc + "'><div class='vnb_ico'></div><div class='vnb_text'><a href='#'>" + this + "</a></div></div><div class='vnb_dootedGap'></div>");
					 //PRINT RANGE SELECTED (INITIAL)
					 $("#columnRight").html(printRange(this));
					 Cufon.replace(".storeHeader");
				 }
				 else
				 {
					 $(".verticalNavBar").append("<div class='vnb_btn' id='btn_" + cc + "'><div class='vnb_ico'></div><div class='vnb_text'><a href='#'>" + this + "</a></div></div><div class='vnb_dootedGap'></div>");
				 }
				 //ADDING HOVER EVENT
				 $(".vnb_btn").hover(function(){
						if(!$(this).hasClass("current3"))
						{
							$(this).addClass("hover8");
						}
				 },function(){
						if(!$(this).hasClass("current3"))
						{
							$(this).removeClass("hover8");
						}
				 });
				 //CLICK EVENT
				 $("#btn_" + cc).click(function(){
					//Load recipe in columnRight
					var strid = $(this).attr("id").substring(4,$(this).attr("id").length);
					var arrayid = parseFloat(strid);
					/* Call Recipe this.name to columnRight2 */
					$("#columnRight").html(printRange(getUniqueGroup(range, "")[arrayid]));
					Cufon.replace(".storeHeader");
					//Change the current recipe class
					$(".vnb_btn").removeClass("current3");
					$(this).removeClass("hover8").addClass("current3");
				 });
				 cc++
				});
			}
		}
		//REMOVE CURRENT2 FROM EVERYONE BUT CLICKED ONE
		$(".btn_leftPanel").removeClass("current2");
		$("#btn_" + clicked).addClass("current2");

	});
}

//FOOD SERVICE BUTTONS CLICK EVENT
function foodClick()
{
	$(".btn_leftPanel").click(function(){
		var clicked = trim($(this).attr("id").substring(4,$(this).attr("id").length));
		if (!$("#btn_" + clicked).hasClass("current2"))
		{
			//HIDE EVERYONE BUT CLICKED ONE
			$(".btn_leftPanel").addClass("hidden2");
			$("#btn_" + clicked).removeClass("hidden2").addClass("current2");
			//ADD HORIZONTAL NAVIGATION
			$(".horizontalNav").html("<a href='#' class='returnFood'>Food Service</a> &gt; " + clicked);
			$(".returnFood").click(function(){ $("#btn_food").trigger("click");});
			//ADD VERTICAL NAVIGATION
			verticalNav(food,clicked,"food",0);
		}
	});
}

//RECIPE BUTTONS CLICK EVENT
function recipeClick()
{
	$(".btn_leftPanel").click(function(){
		var clicked = trim($(this).attr("id").substring(4,$(this).attr("id").length));
		if (!$("#btn_" + clicked).hasClass("current2"))
		{
			//HIDE EVERYONE BUT CLICKED ONE
			$(".btn_leftPanel").addClass("hidden2");
			$("#btn_" + clicked).removeClass("hidden2").addClass("current2");
			//ADD HORIZONTAL NAVIGATION
			$(".horizontalNav").html("<a href='#' class='returnRecipe'>Recipes</a> &gt; " + clicked);
			$(".returnRecipe").click(function(){ $("#btn_recipe").trigger("click");});
			//ADD VERTICAL NAVIGATION
			verticalNav(recipes,clicked,"recipe",0);
		}
	});
}

//VERTICAL NAVBAR
function verticalNav(data,btn_pressed,type,recipeID)
{
  var cc = 0;
  var aa = 0;
  $.each(data, function(){
	//alert(trim(this.group).toLowerCase());
	if (trim(this.group).toLowerCase() == trim(btn_pressed))
	{
	 if ((cc==0 && recipeID==0)||(recipeID!=0 && recipeID == this.id)) 
	 {
		 //CURRENT STATE
		 $(".verticalNavBar").append("<div class='vnb_btn current3' id='btn_" + aa + "'><div class='vnb_ico'></div><div class='vnb_text'><a href='#'>" + this.name + "</a></div></div><div class='vnb_dootedGap'></div>");
		 //LOAD CURRENT CONTENT IN COLUMN RIGHT
		 if (type=="food")
		 {
		 	$("#columnRight").load(this.url, function(){Cufon.replace(".redHeader2")});
		 }
		 else
		 {
			 var recipe2print = printRecipe(this);
			 $("#columnRight").html(recipe2print);
			 Cufon.replace(".recipeHeader,.recipeSubheader");

			$.scrollTo( '#recipeTop', 1000, {queue:true} );

		 }
		 //CHANGE IMAGE IN LEFT PANEL IF NEEDED
		 $(".leftPanelIMG").html("<img src='images/pic_" + type + ".jpg'/>");
	 }
	 else
	 {
	  	 $(".verticalNavBar").append("<div class='vnb_btn' id='btn_" + aa + "'><div class='vnb_ico'></div><div class='vnb_text'><a href='#'>" + this.name + "</a></div></div><div class='vnb_dootedGap'></div>");
	 }
	 //ADDING HOVER EVENT
	 $(".vnb_btn").hover(function(){
			if(!$(this).hasClass("current3"))
			{
				$(this).addClass("hover8");
			}
	 },function(){
			if(!$(this).hasClass("current3"))
			{
				$(this).removeClass("hover8");
			}
	 });
	 
	 //ADDING CLICK EVENT
	 $("#btn_" + aa).click(function(){
	  	//Load recipe in columnRight
		var strid = $(this).attr("id").substring(4,$(this).attr("id").length);
		var arrayid = parseFloat(strid);
		// Call Recipe this.name to columnRight2 
		 if (type=="food")
		 {
	    	$("#columnRight").load(food[arrayid].url,function(){
				Cufon.replace(".redHeader2");
				$.scrollTo( '#top', 1000, {queue:true} );
			});
		 }
		 else
		 {
			$("#columnRight").html(printRecipe(recipes[arrayid]));
			Cufon.replace(".recipeHeader,.recipeSubheader");
			var time = 1000;
			$.scrollTo( '#recipeTop', time, {queue:true} );
		 }
		// Changing the LeftPanelIMG 
		$(".vnb_btn").removeClass("current3");
		$(this).removeClass("hover8").addClass("current3");
	 });
	 cc++
	}
	aa++
  });
}

//PRINT RECIPE
function printRecipe(data)
{
	var str="<div id='recipeTop' style='height:111px;'></div>";
	if (data.img !="")
	{
		str += "<span><img src='" + data.img + "' height='290'/></span><div style='height:8px;'></div>";
	}
	str += "<div class='recipeHeader' style='float:left; width:470px;'>" + data.name + "</div><div style='float:left; width:67px; height:25px;'><a style='float:right;' href='pdf/recipe" + data.id + ".pdf' target='_blank'><img src='images/ico_pdf.gif' style='border:none;'/></a></div>";
	str += "<div class='recipeServe' style='float:left; width:100%;'>Serve " + data.serve + "</div>";
	str += "<div class='recipeIngredients'>";
	str += " <div class='recipeSubheader'>Ingredients</div><br/>";
	str += data.ingredients;
	str += "</div>";
	str += "<div class='recipeTip'>";
	if (data.tip != "")
	{
		str += "<div class='tipHead'>Recipe Tips...</div>" + data.tip 
	}
	str += "</div>";
	
	str += "<div class='recipeMethod'>";
	str += "<br/><div class='recipeSubheader'>Method</div><br/>";
	str += data.method;
	str += "</div><div style=\"float:left;color:#950029;\"><a href=\"pdf/recipe" + data.id + ".pdf\" style='color:#950029;'>Click here to Download the PDF</a></div>";
	
  return str;	
}

//PRINT RANGE
function printRange(group)
{
 var strResult = "<div style='margin-top:80px;'></div>";
 $.each(range, function(){
  if (this.group == group)
  {
	strResult += "<div class='columnLeftStore'>";
	strResult += " <div class='storeHeader'>" + this.name + "</div>";
	strResult += " <p>Weight: " + this.weight + "</p>";
	if (this.available != "no")
	{
		strResult += " <p>" + this.available + "</p>";
	}
	if (this.ico != "no")
	{
		strResult += " <p><img src='images/icon_threeChecks_black.gif' alt='Free of added Hormones and Grain Fed'/></p>";
	}
	strResult += "</div>";
	strResult += "<div class='columnRightStore'>";
	if (this.img != "")
	{
		strResult += " <img src='" + this.img + "' />";
	}
	strResult += "</div>";
	strResult += "<div class='gapStore'></div>";
  }
 });
 return strResult;
}

//PRINT COOKING EVENT
function printCookEvents(today)
{
 var strResult = "";
 $.each(cooking, function(){
  var eventDate = new Date(this.date);
  if(today <= eventDate)
  {
	strResult += "<div class='gapStore'></div>";
	strResult += "<div class='columnLeftStore'>";
	strResult += " <div class='storeHeader'>" + this.name + "</div>";
	strResult += " <p>Location: " + this.location + "<br/>";
	strResult += " Date: " + eventDate.getDate() + "/" + eval(eventDate.getMonth() +1) + "/" + eventDate.getFullYear() + "<br/>";
	strResult += " Time: " + this.time + "<br/>";
	strResult += " Details: " + this.descr + "</p>";
	strResult += "</div>";
	strResult += "<div class='columnRightStore'>";
	strResult += " <span><img src='" + this.img + "' /></span><br/>";
	strResult += "</div>";
  }
 });
 return strResult;
}

//PRINT STORE
function printStore(data)
{
	var strResult = "";
	strResult += "<div class='storeFeed'>";
	strResult += "<div class='columnLeftStore'>";
	strResult += " <div class='storeHeader'>" + data.name + "</div>";
	strResult += " <p>";
	
	if (data.address != "") strResult += data.address + "<br/>";
	
	strResult += data.suburb + " " + data.state + " " + data.pcode + "<br/>";
	
	if (data.phone != "") strResult += "Phone: " + data.phone + "<br/>";
	
	strResult += " </p>";
	strResult += "</div>";
	strResult += "<div class='gapStore'></div>";
	strResult += "</div>";
	return strResult;
}

//GO TO STORE LOCATOR (CALLSTORE)
function callStore()
{
	//CHANGING LAYOUT
	$("#columnLeft").removeClass().addClass("columnLeft2");
	$("#columnRight").removeClass().addClass("columnRight2");
	//CHANGING THE CURRENT NAVBAR BUTTON
	$(".navbutton").removeClass("current").removeClass("hover");
	$("#btn_retail").addClass("current");
	//LOADING CONTENT
	leftPanelURL="Left_Panel_txt.html";
	rightPanelURL = "retail_main_txt.html";
	$("#columnLeft").load(leftPanelURL, function(){
		$("#columnRight").load(rightPanelURL, function(){
			basics(leftPanelURL, rightPanelURL);	
			$("#btn_storeLocator").trigger("click");
		});										  
	});	
}

//STORE LOCATOR FILTER 
function storeFilter(name,state,pcode)
{
	var selection = [];
	$.each(stores,function(){
		if ($.inArray(this,selection) == -1)
		{
			var check=0;
			if (this.name != null && this.state != null && this.pcode !=null)
			{
				if(name==""){check++}else{if(this.name.toLowerCase().indexOf(name.toLowerCase())!=-1){check++}}
				
				if(state==""){check++}else{if(this.state.toLowerCase().indexOf(state.toLowerCase())!=-1){check++}}
				
				if(pcode==""){check++}else{if(this.pcode.toLowerCase().indexOf(pcode.toLowerCase())!=-1 || this.suburb.toLowerCase().indexOf(pcode.toLowerCase())!=-1){check++}}
	
				if (check==3) {selection.push(this);}
			}
		}
	});
	//Clearing the room
	$(".storeResults").html("&nbsp;");
	//Checking if there are results to print.
	if (selection.length == 0)
	{
		$(".storeResults").html("<p>There are no matching results.</p>");
	}
	else
	{
		//SETTING UP THE LAYOUT
		$(".storeResults").html("<div id='newsContainer'><div id='Searchresult'><img src='images/ajax-loader.gif' alt='Loading content...' /></div><div id='Pagination'></div><div id='hiddenresult' style='display:none;'></div></div>");
		//FILLING hiddenresult DIV WITH ALL MATCHES
		//$.each(selection, function(){
		$.each(selection.sort(dynamicSort("name")), function(){
				$("#hiddenresult").append(printStore(this));
				//Cufon.replace(".storeHeader");
		});
		//PAGINATION
		function pageselectCallback(page_index, jq)
		{
		 var items_per_page = 10;
		 var max_elem = Math.min((page_index+1) * items_per_page, $('#hiddenresult div.storeFeed').length);
		 var newcontent = "";
		 $('#Searchresult').empty();
		 // Iterate through a selection of the content and build an HTML string
		 for(var i=page_index*items_per_page;i<max_elem;i++)
		 {
		  var new_content = jQuery('#hiddenresult div.storeFeed:eq('+i+')').clone();
		  $('#Searchresult').append(new_content);
		  //Cufon.replace(".storeHeader");
		 }
		// Prevent click event propagation
		return false;
	   }
			   
	   function initPagination() 
	   {
		var num_entries = $('#hiddenresult div.storeFeed').length;
		// Create pagination element
		$("#Pagination").pagination(num_entries, {
						callback: pageselectCallback,
						items_per_page:10
		 });
	   }
		initPagination();
		
	}
}

//PRINTING ELEMENTS OF PRODUCT PAGE
function printElement(data){
	var strResult = "";
	strResult += "<div class='header6' style='margin-left:25px; margin-top:5px; margin-bottom:-25px;'>Retail Products</div>";
	for (var i in data)
	{
		strResult += "<div class='gapProductsDotted'></div>";
		strResult += "<div class='columnLeft'>";
		strResult += " <div class='header4'>" + data[i].name + "</div>";
		strResult += "<div style='margin-top:-8px;'>";
		strResult += " <p>" + data[i].desc + "</p>";
		strResult += "</div>";
		strResult += " <div class='navMenu' style='margin-top:2px;'>";
		strResult += "   <div class='btn_submit' id='btn_ViewRecipes'><div class='btn_Text3'>View Recipes</div><a rel='" + data[i].group  + "'/></div>";
		strResult += " </div>";
		strResult += "</div>";
		strResult += "<div class='columnRight'>";
		strResult += " <span><img src='images/" + data[i].imgMain + "' alt='" + data[i].name + "'/></span><br/>";
		strResult += "</div>";
	}
	strResult += "<div style='clear:both; height:30px; width:100%;'></div>";
	return strResult;
};

//VALIDATE CONTACT FORM
function validateContact()
{
	//Form fields
	var name = $("#name").val();
	var email = $("#email").val();
	var comment = $("#comment").val();
	
	//REGEX
	var regEmail = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);
	var regPhone = new RegExp(/^[0-9]{10}$|^\(0[1-9]{1}\)[0-9]{8}$|^[0-9]{8}$|^[0-9]{4}[ ][0-9]{3}[ ][0-9]{3}$|^\(0[1-9]{1}\)[ ][0-9]{4}[ ][0-9]{4}$|^[0-9]{4}[ ][0-9]{4}$/);
	
	var errorNumber = 0;
	
	if (name == "Name*") 
	{
		$("#eName").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eName").css("display","none");
	}
	

	if (email == "Email Address*") 
	{
		$("#eEmail").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
	 if (!regEmail.test(email))
	 {
	 	$("#eEmail").css("display", "block").html("Please enter a valid Email Address."); 
		errorNumber++
	 }
	 else
	 {
		$("#eEmail").css("display","none");
	 }
	}
	if (errorNumber == 0)
	{
	 //Ready to Send
	   var dataString = 'Name='+ name + '&email=' + email + '&comment=' + comment;  
	   $.ajax({  
		 type: "POST",  
		 url: "contacts.php",  
		 data: dataString,  
		 success: function(data) {  
			 //Leave a confirmation message
			$(".columnRight4").html("<div style='height:131px; padding-top:100px; padding-bottom:82px;'>" + data + "</div>");
		 }  
	   });  
	   return false;  
	}
}

//VALIDATE SUBSCRIBE FORM
function validateSubscribe()
{
	//Form fields
	var name = $("#name").val();
	var email = $("#email").val();
	//var dob = $("#dob").val();
	var addr = $("#addr").val();
	
	//REGEX
	var regEmail = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);
	var regDate = new RegExp(/^\d{2}\/\d{2}\/\d{4}$/);

	var errorNumber = 0;
	
	if(name == "Name*")
	{
		$("#eName").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	} else { 
		$("#eName").css("display","none");
	}
/*
	if(dob == "Date of Birth*")
	{
		$("#eDob").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	} 
	else if(!regDate.test(dob))
	{
		$("#eDob").css("display", "block").html("Please use the DD/MM/YYYY format."); 
		errorNumber++;
	} 
	else 
	{ 
		$("#eDob").css("display","none");
		var realDob = dob.substring(6,10) + "-" + dob.substring(3,5) + "-" + dob.substring(0,2);
		
	}
*/	
	if (addr == "Address*")
	{
		$("#eAddr").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	} 
	else 
	{ 
		$("#eAddr").css("display","none");
	}

	if(email == "Email Address*")
	{
		$("#eEmail").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	} 
	else 
	{ 
		if(!regEmail.test(email))
		{
	 		$("#eEmail").css("display", "block").html("Please enter a valid Email Address."); 
			errorNumber++
	 	} 
		else 
		{
			//QUERY DATABASE FOR CURRENT USERS
			/*
			$.ajax({
				url: 'js/sql.php',
				data: 'query=getUsers&email=' + email,
				type: 'POST',
				success: function(data){show(data);},
				error: function(XMLHttpRequest,textStatus, errorThrown) {alert("Status" + textStatus + "Error:" + errorThrown + "<br/>Response:" + XMLHttpRequest.responseText);}
			});
			*/
			/*			
			function show(data)
			{
				if(data == '1')
				{
					$("#eEmail").css("display", "block").html("That Email Address is already taken.");
					errorNumber++;
				} 
				else 
				{
					$("#eEmail").css("display","none");
					
					if (errorNumber == 0)
					{
						$.ajax({
							url: 'js/sql.php',
							data: 'query=addUser&name=' + name + '&email=' + email + '&dob=' + realDob + '&address=' + addr,
							type: 'POST',
							success: function(data){show(data);},
							error: function(XMLHttpRequest,textStatus, errorThrown) {alert("Status" + textStatus + "Error:" + errorThrown + "<br/>Response:" + XMLHttpRequest.responseText);}
						});
									
						function show(data)
						{
							var dataString = 'Name='+ name + '&email=' + email + '&dob=' + dob + '&addr=' + addr;  
							$.ajax({  
								type: "POST",  
								url: "subscribe.php",  
								data: dataString,  
								success: function(data){$("#subscribe").html("<div style='height:131px; padding-top:100px; padding-bottom:82px;'>" + data + "</div>");}  
							});  
							return false;
						}  
					}
				}
			}
			*/
	 		$("#eEmail").html("").css("display","none");
		}
	}
	
	if (errorNumber == 0)
	{
			//CREATESEND - INSERT SUBSCRIBER
			var str = $("form#subForm").serialize();
			var serialized = str + "&action=" + action;

			$.ajax({
				url: "js/createsend/proxy.php",
				type: "POST",
				data: serialized,
				success: function(data){
					// Server-side validation
					if (data.search(/invalid/i) != -1) 
					{
						$("#eEmail").html('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.').css("display","block");
					}
					else
					{
						//SHOW THANKS MESSAGE
						$("#subForm").hide();
						$("#subscribe").html("<span style='color:#000; font-size:14px;line-height:20px;'>Thanks for subscribing to our eMagazine.</span>");
						$.colorbox.resize();
						var t=setTimeout($.fn.colorbox.close,5000);
					}
				}
			});
			return false;
		
	}
	else
	{
		$.colorbox.resize();
	}
}

//VALIDATE GOURMET FORM
function validateGourmet()
{
	//Form fields
	var email = $("#gemail").val();
	
	//REGEX
	var regEmail = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);	
	
	if (email == "Email Address*") {
		$("#geEmail").css("display", "block").html("This field is mandatory"); 
	} else { 
		if (!regEmail.test(email)){
			$("#geEmail").css("display", "block").html("Please enter a valid Email Address."); 
		 } else {			
			//QUERY DATABASE FOR CURRENT USERS
			$.ajax({
				url: 'js/sql.php',
				data: 'query=getUsers&email=' + email,
				type: 'POST',
				success: function(data){show(data);},
				error: function(XMLHttpRequest,textStatus, errorThrown) {alert("Status" + textStatus + "Error:" + errorThrown + "<br/>Response:" + XMLHttpRequest.responseText);}
			});
						
			function show(data){
				if(data == '1'){
					loadContent("gourmetClubContent_txt.php","Right_Panel_txt.php");
					$("#btn_gourmetClub").colorbox.close();	
				} else {
					$("#geEmail").css("display", "block").html("<span style='text-align:left;'>This Email Address is not registered.<br/>If you are experiencing log in difficulties, please re-enter your details <a class='fgoto' rel='btn_subscribe' style='font-size:10px;'>here</a>.</span>");
					fGoto();
				}
			}
		}
	}
}

//VALIDATE GIFT VOUCHER FORM
function validateGiftVoucherForm()
{
	//FORM FIELDS
	var name = $("#name").val();
	var email = $("#email").val();
	var comment = $("#comment").val();
	var promoID = $("#promoID").val();
	
	//REGEX
	var regEmail = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);	
	var errorNumber = 0;
	
	if (name == "Name*") 
	{
		$("#eName").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eName").css("display","none");
	}

	if (comment == "Tell us what your favourite Game Farm product is and how you prepare/serve it.")
	{
		$("#eComment").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{
		$("#eComment").css("display","none");
	}


	if (email == "Email Address*") 
	{
		$("#eEmail").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
	 if (!regEmail.test(email))
	 {
	 	$("#eEmail").css("display", "block").html("Please enter a valid Email Address."); 
		errorNumber++
	 }
	 else
	 {
		 //CHECK IF EMAIL HAS BEEN USED BEFORE
		$.ajax({
			url: 'js/giftVoucher.php',
			data: 'action=checkemail&email=' + email + '&promoID=' + promoID,
			type: 'POST',
			success: function(data){show(data);},
			error: function(XMLHttpRequest,textStatus, errorThrown) {alert("Status" + textStatus + "Error:" + errorThrown + "<br/>Response:" + XMLHttpRequest.responseText);}
		});
					
		function show(data)
		{
			if(data == '1')
			{
				$("#eEmail").css("display", "block").html("That Email Address has been used in this promotion.");
				errorNumber++;
			} 
			else 
			{
				$("#eEmail").css("display","none");
				
				if (errorNumber == 0)
				{
				   var dataString = 'action=insert&name='+ name + '&email=' + email + '&comment=' + comment + '&promoID=' + promoID;  
				   $.ajax({  
					 type: "POST",  
					 url: "js/giftVoucher.php",  
					 data: dataString,  
					 success: function(data) {  
						 //Leave a confirmation message
						$("#giftVoucherForm").html("<div style='height:131px; padding-top:100px; padding-bottom:82px;'>" + data + "</div>");
					 }  
				   });  
				   return false;  

				}
			}
		}
	  }
	}
}

//VALIDATE FEEDBACK FORM
function validateFeedbackForm()
{
	//FORM FIELDS
	var name = $("#name").val();
	var email = $("#email").val();
	var address = $("#addr").val();//mandatory
/*	
	var question1 = $("#question1").val();
	var question2 = $("#question2").val();
	var question3 = $("#question3").val();
	var question4 = $("#question4").val();
*/
	var question5 = $("#question5").val();

	//var buyingFrequency = $("#buyingFrequency").val();
	
	//REGEX
	var regEmail = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);	
	var errorNumber = 0;
	
	if (name == "Name*") 
	{
		$("#eName").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eName").css("display","none");
	}

	if (address == "Address*") 
	{
		$("#eAddr").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eAddr").css("display","none");
	}
/*
	if (question1 == "") 
	{
		$("#eQuestion1").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eQuestion1").css("display","none");
	}
	
	if (buyingFrequency == "How often would you eat this product a month?*") 
	{
		$("#eBuyingFrequency").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eBuyingFrequency").css("display","none");
	}
	
	if (question2 == "") 
	{
		$("#eQuestion2").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eQuestion2").css("display","none");
	}

	if (question3 == "") 
	{
		$("#eQuestion3").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eQuestion3").css("display","none");
	}

	if (question4 == "") 
	{
		$("#eQuestion4").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eQuestion4").css("display","none");
	}
*/
	if (question5 == "What you like about the Gourmet Club?*") 
	{
		$("#eQuestion5").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eQuestion5").css("display","none");
	}


	if (email == "Email Address*") 
	{
		$("#eEmail").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
	 if (!regEmail.test(email))
	 {
	 	$("#eEmail").css("display", "block").html("Please enter a valid Email Address."); 
		errorNumber++
	 }
	 else
	 {
		 if (subscriber)
		 {
			$("#eEmail").css("display","none");
		 }
	 }
	}
	
	if (errorNumber == 0)
	{
		$('#feedbackFormSubmit').css('display', 'none');

		if(!subscriber)
		{
			//CREATESEND - INSERT SUBSCRIBER
			var str = "cm-name=" + name + "&cm-ohkirt-ohkirt=" + email + "&cm-f-dumlt=" + address;
			var serialized = str + "&action=" + action;

			$.ajax({
				url: "js/createsend/proxy.php",
				type: "POST",
				data: serialized,
				success: function(data){
					// Server-side validation
					if (data.search(/invalid/i) != -1) 
					{
						$("#eEmail").html('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.').css("display","block");
						return false;
					}
					else
					{
						//ADD TO PROMO MAIL
					 //  var dataString = 'name='+ name + '&email=' + email + '&addr=' + address + '&question1=' + question1 + '&buyingFrequency=' + buyingFrequency + '&question2=' + question2 + '&question3=' + question3 + '&question4=' + question4;  
					   var dataString = 'name='+ name + '&email=' + email + '&addr=' + address + '&question5=' + question5 ;  
					   $.ajax({  
						 type: "POST",  
						 url: "js/feedback.php",  
						 data: dataString,  
						 success: function(data) {  
							 //Leave a confirmation message
							$("#feedbackForm").html("<div style='height:131px; padding-top:100px; padding-bottom:82px;'>" + data + "</div>");
							$.colorbox.resize();	
							var t=setTimeout($.fn.colorbox.close,5000);
						 }  
					   });  
					   return false;  
					}
				}
			});
			
		}
		else
		{
			//ALREADY A SUBSCRIBER - ADD TO PROMO MAIL
		   //var dataString = 'name='+ name + '&email=' + email + '&addr=' + address + '&question1=' + question1 + '&buyingFrequency=' + buyingFrequency + '&question2=' + question2 + '&question3=' + question3 + '&question4=' + question4;  
		   var dataString = 'name='+ name + '&email=' + email + '&addr=' + address + '&question5=' + question5 ;  
		   $.ajax({  
			 type: "POST",  
			 url: "js/feedback.php",  
			 data: dataString,  
			 success: function(data) {  
				 //Leave a confirmation message
				$("#feedbackForm").html("<div style='height:131px; padding-top:100px; padding-bottom:82px;'>" + data + "</div>");
				$.colorbox.resize();	
				var t=setTimeout($.fn.colorbox.close,5000);
			 }  
		   });  
		   return false;  
		}
	}
	else
	{
		$.colorbox.resize();	
		return false;  
	}

}

//VALIDATE FEEDBACK FORM
function validateHungerfordForm()
{
	//FORM FIELDS
	var name = $("#name").val();
	var email = $("#email").val();
	var favouriteProduct = $("#favouriteProduct").val();
	
	//REGEX
	var regEmail = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);	
	var errorNumber = 0;
	
	if (name == "Name*") 
	{
		$("#eName").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eName").css("display","none");
	}
	
	if (email == "Email Address*") 
	{
		$("#eEmail").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
	 if (!regEmail.test(email))
	 {
	 	$("#eEmail").css("display", "block").html("Please enter a valid Email Address."); 
		errorNumber++
	 }
	 else
	 {
		//CHECK IF EMAIL HAS BEEN USED BEFORE
		$("#eEmail").css("display","none");
	  }
	}
	
	if (favouriteProduct == "What is your favourite Game Farm product and how do you prepare and serve it?*") 
	{
		$("#eFavouriteProduct").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eFavouriteProduct").css("display","none");
	}
	
	if (errorNumber == 0)
	{
	   var dataString = 'name='+ name + '&email=' + email + '&favouriteProduct=' + favouriteProduct;  
	   $.ajax({  
		 type: "POST",  
		 url: "js/hungerford.php",  
		 data: dataString,  
		 success: function(data) {  
			 //Leave a confirmation message
			$("#hungerfordForm").html("<div style='height:131px; padding-top:100px; padding-bottom:82px;'>" + data + "</div>");
		 }  
	   });  
	   return false;  

	}

}

//VALIDATE GIVEAWAY FORM
function validateGiveawayForm()
{
	//FORM FIELDS
	var name = $("#name").val();
	var email = $("#email").val();
	var address = $("#addr").val();//mandatory
	var favouriteProduct = $("#favouriteProduct").val();
	
	//REGEX
	var regEmail = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);	
	var errorNumber = 0;
	
	if (name == "Name*") 
	{
		$("#eName").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eName").css("display","none");
	}

	if (address == "Address*") 
	{
		$("#eAddr").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eAddr").css("display","none");
	}

	
	if (email == "Email Address*") 
	{
		$("#eEmail").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
	 if (!regEmail.test(email))
	 {
	 	$("#eEmail").css("display", "block").html("Please enter a valid Email Address."); 
		errorNumber++
	 }
	 else
	 {
		 if (subscriber)
		 {
			$("#eEmail").css("display","none");
		 }
	 }
	}
	
	if (favouriteProduct == "What is your favourite Game Farm product and how do you prepare and serve it?*") 
	{
		$("#eFavouriteProduct").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eFavouriteProduct").css("display","none");
	}
	
	if (errorNumber == 0)
	{

		$('#formSubmit').css('display', 'none');

		if(!subscriber)
		{
			//CREATESEND - INSERT SUBSCRIBER
			var str = "cm-name=" + name + "&cm-ohkirt-ohkirt=" + email + "&cm-f-dumlt=" + address;
			var serialized = str + "&action=" + action;

			$.ajax({
				url: "js/createsend/proxy.php",
				type: "POST",
				data: serialized,
				success: function(data){
					// Server-side validation
					if (data.search(/invalid/i) != -1) 
					{
						$("#eEmail").html('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.').css("display","block");
						return false;
					}
					else
					{
						//ADD TO PROMO MAIL
					   var dataString = 'name='+ name + '&email=' + email + '&addr=' + address + '&favouriteProduct=' + favouriteProduct;  
					   $.ajax({  
						 type: "POST",  
						 url: "js/giveaway.php",  
						 data: dataString,  
						 success: function(data) {  
							 //Leave a confirmation message
							$("#giveawayForm").html("<div style='height:131px; padding-top:100px; padding-bottom:82px;'>" + data + "</div>");
							$.colorbox.resize();	
							var t=setTimeout($.fn.colorbox.close,5000);
						 }  
					   });  
					   return false;  
					}
				}
			});
			
		}
		else
		{
			//ALREADY A SUBSCRIBER - ADD TO PROMO MAIL
		   var dataString = 'name='+ name + '&email=' + email + '&addr=' + address + '&favouriteProduct=' + favouriteProduct;  
		   $.ajax({  
			 type: "POST",  
			 url: "js/giveaway.php",  
			 data: dataString,  
			 success: function(data) {  
				 //Leave a confirmation message
				$("#giveawayForm").html("<div style='height:131px; padding-top:100px; padding-bottom:82px;'>" + data + "</div>");
				$.colorbox.resize();	
				var t=setTimeout($.fn.colorbox.close,5000);
			 }  
		   });  
		   return false;  
		}
	}
	else
	{
		$.colorbox.resize();	
		return false;  
	}

}

//VALIDATE SUBMIT RECIPE FORM
function validateSubmitRecipe()
{
	//Form fields
	var name = $("#sname").val();
	var email = $("#semail").val();
	var recipeName = $("#srecipeName").val();
	var ingredients = $("#sIngredients").val();
	var method = $("#sMethod").val();
	var tips = $("#sTips").val();
	
	//REGEX
	var regEmail = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);
	
	var errorNumber = 0;
	
	if (name == "Name*") 
	{
		$("#eSname").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eSname").css("display","none");
	}
	

	if (email == "Email Address*") 
	{
		$("#eSemail").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
	 if (!regEmail.test(email))
	 {
	 	$("#eSemail").css("display", "block").html("Please enter a valid Email Address."); 
		errorNumber++
	 }
	 else
	 {
		$("#eSemail").css("display","none");
	 }
	}
	
	if (recipeName == "Recipe Name*")
	{
		$("#eSrecipeName").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{
		$("#eSrecipeName").css("display","none");
	}

	if (ingredients == "Ingredients*")
	{
		$("#eSingredients").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{
		$("#eSingredients").css("display","none");
	}

	if (method == "Method*")
	{
		$("#eSmethod").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{
		$("#eSmethod").css("display","none");
	}

	if (errorNumber == 0)
	{
	 //Ready to Send
	   var dataString = 'Name='+ name + '&email=' + email + '&recipeName=' + recipeName + '&ingredients=' + ingredients  + '&method=' + method + '&tips=' + tips;  
	//    alert (dataString);return false;  
	   $.ajax({  
		 type: "POST",  
		 url: "submitRecipe.php",  
		 data: dataString,  
		 success: function(data) {  
			 //Leave a confirmation message
			$("#submitRecipe").html("<div style='height:131px; padding-top:100px; padding-bottom:82px;'>" + data + "</div>");
		 }  
	   });  
	   return false;  
	}
}

//FIND GROUP GIVEN RECIPE ID
function findGroup(id)
{
	var result = "";
	$.each(recipes,function(){
		if(this.id == parseInt(id))
		{
			result=this.group;	
		}
	});	
	return result;
}

//ANCHOR GOTO
function aGoto()
{
	$(".goto").click(function(){
		var goto = $(this).attr("rel");
		$("#btn_" + goto).trigger("click");
	});
}

//FOOTER ANCHOR GOTO
function fGoto()
{
	$(".fgoto").click(function(){
		var goto = $(this).attr("rel");
		//alert(goto);
		if (goto != "contact")
		{
			if (goto.indexOf("btn")!=-1)
			{	
				//$("#btn_subscribe").colorbox.close();
				$("#" + goto).trigger("click");
			}
			else
			{
				loadContent(goto + "_txt.html","Right_Panel_txt.php");
				$("#btn_subscribe").colorbox.close();
			}
		}
		else
		{
			$("#btn_contact").trigger("click");
			$("#btn_subscribe").colorbox.close();
		}
	});
}

//PRINT COMMUNITY NEWS FROM DB
function commNewsFeed()
{	
	//PRINTING
	var strResult = "";
	$.each(commNews,function(){
		strResult += "<div class='news' id='" + this.id + "'>";
		strResult += " <div class='newsHeader'>" + this.header + "</div><div style='height:8px;'></div>";
		strResult += " <div class='text'>" + this.text.replace(/<\/?[^>]+(>|$)/g, "").substring(0,100).substring(0,this.text.replace(/<\/?[^>]+(>|$)/g, "").substring(0,100).lastIndexOf(" ")) + "...</div>";
		if (this.thumb != "")
		{
			strResult += " <div class='newsImg'><img src='" + this.thumb + "' alt='" + this.header + "' width='78' height='78' /></div>";
		}
		strResult += " <div style='clear:both;height:8px;'></div><div class='btn_search'><div class='btn_Text3'>More...</div><a rel='" + this.id + "'></a></div>";
		strResult += " <div class='dottedLineNews'></div>";
		strResult += "</div>"; 
	});
	return strResult;
}

//PRINT COMMUNITY NEWS ON LEFT PANEL
function commNewsBig(id)
{
	//CREATING HTML TO PRINT
	var strResult = "";
	var nr_news = commNews.length;
	var curr_news = 0;
	$.each(commNews, function(){
		curr_news++					  
		if (this.id == id)
		{
			strResult+="<div id='top' style='height:25px;'></div>";
			strResult+="<div class='header3'>Game Farm <span style='font-size:35px;'>in the Community</span></div>";
			strResult+="<p>Game Farm is proud to support a range of worthwhile causes in Australia and internationally, with a particular focus on the local community in and around Galston, NSW where our main farm and production facilities are situated.</p>";
			strResult+="<p>Game Farm also supports local schools, preschools and community groups in the Galston area and participates in community fundraising activities.</p>";
			strResult+="<br/><div class='header4'>" + this.header + "</div>";
			if(this.img !="")
			{
				strResult+="<br/><img src='" + this.img + "' alt='" + this.header + "'/>";	
			}
			strResult+= this.text;			
			strResult+="<div style='float:left;'><div class='btn_search' id='btn_Back'><div class='btn_Text3'>Back</div></div></div>";
			if (curr_news<nr_news)
			{
				strResult+="<div style='float:right;'><div class='btn_search' id='btn_Next'><div class='btn_Text3'>Next</div><a rel='" + commNews[curr_news].id + "'></a></div></div>";
			}
			else
			{
				strResult+="<div style='float:right;'><div class='btn_search' id='btn_Next'><div class='btn_Text3'>Next</div><a rel='" + commNews[0].id + "'></a></div></div>";
			}
			strResult+="<div style='clear:both'></div>";
		}
	});
	//PRINTING
	$("#columnLeft").html(strResult);
	Cufon.replace(".header3,.header4,.btn_Text3");
	//SCROLLING UP
	$.scrollTo( '#top', 1000, {easing:'easeOutBack'} );
	//BUTTON EVENTS
	//HOVER EVENT
	$(".btn_search").hover(function(){
		$(this).addClass("hover5");							
	},function(){
		$(this).removeClass("hover5");										 
	});
	//CLICK EVENT
	$("#btn_Back").click(function(){
		loadContent($(".navbutton").filter(".current").attr("id").substring(4,$(".navbutton").filter(".current").attr("id").length)	+ "_txt.html", "");						  
	});
	$("#btn_Next").click(function(){
		var layout = $("a", $(this)).attr("rel");
		//loadContent(layout + "_txt.html","");
		commNewsBig(layout);
	});
	
}

//PRINT DIRECT LISTS
function printDirect()
{
 	var strResult = "";
	strResult += "<div class='header6' style='margin-left:25px; margin-top:5px; margin-bottom:-25px;'>Direct Products</div>";
	strResult += "<div class='gapProductsDotted'></div>";
	strResult += "<div style='margin-top:8px; margin-left:25px; margin-right:0px; margin-bottom:25px;width:510px;'>";
	strResult += " <p>Game Farm also supplies the following additional game birds, specialty poultry and game meat products direct to consumers and the food service market from our farm at Galston, NSW.<br/>";
	strResult += " <a class='goto' rel='contact'>Contact us</a> for details and enquiries.</p>";
	strResult += " <p>Farm Gate open Monday to Friday from 8:30am to 4:00pm.</p>";
	strResult += "</div>";
	strResult += "<div class='directProductsContainer'>";
	for (var i in directProducts)
	{
			strResult += "<div class='colDirProd'>";
			strResult += " <div class='header4'>" + directProducts[i].group + "</div>";
			$.each(directProducts[i].products,function(){
				strResult += "<p class='dpp'>" + this + "</p>";									   
			});
			strResult += "</div>";
	}
	strResult += "</div>";
	strResult += "<div style='clear:both; height:30px; width:100%;'></div>";
	return strResult;
}

//PRINT VIDEO ARCHIVE
function printVideoArchive()
{
	var strResult = "";
	strResult+="<div style='height:25px;'></div>";
	strResult+="<div class='header3'>Video Archive</div>";
	strResult+="<p>Click on any of the images below to view our cooking demonstrations.</p>";
	
	$.each(videos,function(){
		strResult+="<div class='header4'>" + this.description + "</div>";
		strResult+='<div class="box" rel="' + this.file + '" style="background:url(' + this.img + ') no-repeat 0px 0px;"></div>';
		strResult+="<div class='videoGap'></div>";
	});
	strResult+="<div style='float:left;'><div class='btn_search' id='btn_Back'><div class='btn_Text3'>Back</div></div></div>";
	strResult+="<div style='clear:both'></div>";

	//PRINTING
	$("#columnLeft").html(strResult);
	
	$('a.youtubin').youtubin({
        swfWidth : 540,
        swfHeight : 329
    });
	$('.box').click(function(){
		$(this).append("<a id='" + $(this).attr("rel") + "' class='youtubin' rel='nofollow' href='http://www.youtube.com/watch?v=" + $(this).attr("rel") + "'>&nbsp;</a>");
		$("#" + $(this).attr("rel")).youtubin({
			swfWidth : 540,
			swfHeight : 329,
			autoplay : 1
		});
	});
		
	Cufon.replace(".header3,.header4,.btn_Text3");
	//BUTTON EVENTS
	//HOVER EVENT
	$(".btn_search").hover(function(){
		$(this).addClass("hover5");							
	},function(){
		$(this).removeClass("hover5");										 
	});
	//CLICK EVENT
	$("#btn_Back").click(function(){
		loadContent($(".navbutton").filter(".current").attr("id").substring(4,$(".navbutton").filter(".current").attr("id").length)	+ "_txt.html", "");						  
	});	
}

//PRINT GOURMET CLUB PAST EDITIONS - ARCHIVE
/*
function printGourmetClubArchive(){
	var strResult = "";
	strResult += "<div style='height:25px;'></div>";
	strResult += "<div class='header3'>Gourmet Club Editions</div>";
	strResult += "<p style=\"margin-top:-10px;\">Check out our latest issue or previous editions.</p>";
	strResult += '<div style="float:left; width:538px; height:518px; border:solid 1px #000; position:relative; background:url(images/gourmetClubArchive/background.jpg) center; overflow:hidden;" id="gourmetClubArchiveWrapper">';
		strResult += '<div style="float:left; padding:28px 25px 27px 28px;"><img class="gourmetFix" id="gourmetArchiveImage" src="images/gourmetClubArchive/image9.png" alt="Gourmet Club Issue 9" title="Gourmet Club Issue 9" /></div>';
		strResult += '<div style="float:left; padding:161px 0px 0px 0px; font-size:18px; font-family:Georgia; font-style:italic; line-height:24px; color:#FFF; padding-bottom:15px;" id="gourmetArchiveDate">Issue 9<br />August 2011</div>';
		strResult += '<a style="float:left; position:relative; width:230px; height:43px; overflow:hidden; text-decoration:none; border:none;" class="gourmetRollover" id="gourmetArchiveView" href="gourmetclub/index.php?e=9" target="_blank">';
			strResult += '<div style="position:absolute; left:15px; top:11px; z-index:2;"><div style="font-size:18px; font-family:Georgia; font-style:italic; line-height:21px; color:#FFF;">View Issue</div></div>';
			strResult += '<div style="position:absolute; left:0px; top:0px; z-index:1; width:230px; height:43px;"><img style="border:none;" class="gourmetFix" src="images/gourmetClubArchive/button.png" alt="View Issue" title="View Issue" /></div>';	
		strResult += '</a>';
		strResult += '<a style="float:left; position:relative; width:230px; height:43px; overflow:hidden; text-decoration:none; border:none;" class="gourmetRollover" id="gourmetArchiveDownload" href="gourmetclub/edition_9/GC_ED9_SPREADS.pdf">';
			strResult += '<div style="position:absolute; left:15px; top:10px; z-index:2;"><div style="font-size:18px; font-family:Georgia; font-style:italic; line-height:21px; color:#FFF;">Download</div></div>';
			strResult += '<div style="position:absolute; left:0px; top:0px; z-index:1; width:230px; height:43px;"><img style="border:none;" class="gourmetFix" src="images/gourmetClubArchive/button.png" alt="Download" title="Download" /></div>';	
		strResult += '</a>';
		strResult += '<div style="float:left; left:0px; position:relative; width:1200px; padding-left:30px;" id="gourmetThumbs">';		
			strResult += '<img src="images/gourmetClubArchive/thumb1.png" alt="Gourmet Club Issue 1" title="Gourmet Club Issue 1" class="gourmetArchiveIssue" style="float:left; padding-right:2px; cursor:pointer;" />';
			strResult += '<img src="images/gourmetClubArchive/thumb2.png" alt="Gourmet Club Issue 2" title="Gourmet Club Issue 2" class="gourmetArchiveIssue" style="float:left; padding-right:2px; cursor:pointer;" />';
			strResult += '<img src="images/gourmetClubArchive/thumb3.png" alt="Gourmet Club Issue 3" title="Gourmet Club Issue 3" class="gourmetArchiveIssue" style="float:left; padding-right:2px; cursor:pointer;" />';
			strResult += '<img src="images/gourmetClubArchive/thumb4.png" alt="Gourmet Club Issue 4" title="Gourmet Club Issue 4" class="gourmetArchiveIssue" style="float:left; padding-right:2px; cursor:pointer;" />';
			strResult += '<img src="images/gourmetClubArchive/thumb5.png" alt="Gourmet Club Issue 5" title="Gourmet Club Issue 5" class="gourmetArchiveIssue" style="float:left; padding-right:2px; cursor:pointer;" />';
			strResult += '<img src="images/gourmetClubArchive/thumb6.png" alt="Gourmet Club Issue 6" title="Gourmet Club Issue 6" class="gourmetArchiveIssue" style="float:left; padding-right:2px; cursor:pointer;" />';
			strResult += '<img src="images/gourmetClubArchive/thumb7.png" alt="Gourmet Club Issue 7" title="Gourmet Club Issue 7" class="gourmetArchiveIssue" style="float:left; padding-right:2px; cursor:pointer;" />';
			strResult += '<img src="images/gourmetClubArchive/thumb8.png" alt="Gourmet Club Issue 8" title="Gourmet Club Issue 8" class="gourmetArchiveIssue" style="float:left; padding-right:2px; cursor:pointer;" />';
			strResult += '<img src="images/gourmetClubArchive/thumb9.png" alt="Gourmet Club Issue 9" title="Gourmet Club Issue 9" class="gourmetArchiveIssue" style="float:left; cursor:pointer;" />';
		strResult += '</div>';		
	strResult += '</div>';
	$("#archiveHolder").html(strResult);
	
	$('.gourmetArchiveIssue').click(function(){
		var gourmetEditionID = parseInt($(this).attr('alt').substr($(this).attr('alt').length - 1));
		$('#gourmetArchiveImage').animate({opacity:'0'}, 250, 'linear', function(){
			$('#gourmetArchiveImage').attr({'src':'images/gourmetClubArchive/image' + gourmetEditionID + '.png', 'alt':'Gourmet Club Issue ' + gourmetEditionID, 'title':'Gourmet Club Issue ' + gourmetEditionID});
			$('#gourmetArchiveImage').animate({opacity:'1'}, 250, 'linear');
		});
		$('#gourmetArchiveDate').html('Issue ' + gourmetEditionID + '<br />' + gourmetclubEditions[gourmetEditionID-1].date);
		$('#gourmetArchiveView').attr('href', 'gourmetclub/index.php?e=' + gourmetEditionID);
		$('#gourmetArchiveDownload').attr('href', 'gourmetclub/edition_' + gourmetEditionID + '/GC_ED' + gourmetEditionID + '_SPREADS.pdf');
	});
	
	$('.gourmetRollover').hover(function(){
		$('.gourmetFix', this).parent().css('top','-44px');
	}, function(){
		$('.gourmetFix', this).parent().css('top','0px');
	});
	
	//VARIABLES
	limit = 13;
	easeOut = 1.3;
	easeIn = 0.7;
	easingSteps = 5;
	direction = 'middle';
	speed = 0;	
	easing = 0;
	steps = 0;
	
	//GENERIC ANIMATION STEP VALUE GENERATOR BY WWW.HESIDO.COM
	function easeInOut(minValue, maxValue, totalSteps, actualStep, powr) { 
		var delta = maxValue - minValue; 
		var stepp = minValue + (Math.pow(((1 / totalSteps) * actualStep), powr) * delta); 
		return Math.ceil(stepp);
	}
	
	//MAIN GOURMET CLUB ANIMATION FUNCTION
	function gourmetClubAnimation(){
		//CURRENT POSITION
		currentLeft = parseInt($('#gourmetThumbs').css('left'));
		//RESET EASING DISTANCE
		easingDistance = 0;
		//CALCULATE CURRENT BRAKING DISTANCE
		for(counter = steps; counter >= 0; counter--){
			easingDistance += easeInOut(0, limit, easingSteps, counter, easeOut);
		}
		if(direction == 'right'){
			//FUNCTION
			if(currentLeft - easingDistance > 0 - 600){
				//CALCULATE CURRENT EASING STEP
				easing = easeInOut(0, limit, easingSteps, steps, easeIn);
				//ACCELERATE OR CONTINUE
				if(speed < limit){
					//ACCELERATING
					speed = easing;
				} else {
					speed = limit;
				}
				if(steps < easingSteps) steps++;
			} else {
				//CALCULATE CURRENT EASING STEP
				easing = easeInOut(0, limit, easingSteps, steps, easeOut);
				//REDUCE SPEED
				if(speed > 0){
					speed = easing;
				} else {
					speed = 0;
				}
				if(steps > 0) steps--;
			}
			//SET NEW LEFT
			newLeft = parseInt($('#gourmetThumbs').css('left')) - speed;
		} else if(direction == 'left'){
			//FUNCTION
			if(currentLeft + easingDistance < 0){
				//CALCULATE CURRENT EASING STEP
				easing = easeInOut(0, limit, easingSteps, steps, easeIn);
				//ACCELERATE OR CONTINUE
				if(speed < limit){
					//ACCELERATING
					speed = easing;
				} else {
					speed = limit;
				}
				if(steps < easingSteps) steps++;
			} else {
				//CALCULATE CURRENT EASING STEP
				easing = easeInOut(0, limit, easingSteps, steps, easeOut);
				//REDUCE SPEED
				if(speed > 0){
					speed = easing;
				} else {
					speed = 0;
				}
				if(steps > 0) steps--;
			}
			//SET NEW LEFT
			newLeft = parseInt($('#gourmetThumbs').css('left')) + speed;
		}
		
		//MOVEMENT
		$('#gourmetThumbs').css({'left':newLeft});
	}
	
	//DIRECTION TRIGGER
	$('#gourmetClubArchiveWrapper').mousemove(function(element){
		if(element.pageX - $(this).offset().left > $(this).width() - 75 && speed == 0){
			direction = 'right';
		} else if(element.pageX - $(this).offset().left < 75 && speed == 0){
			direction = 'left';
		}
	});
	
	//ANIMATION TRIGGER
	$('#gourmetClubArchiveWrapper').hover(function(){
		gourmetArchiveInterval = setInterval(gourmetClubAnimation, 40);
	}, function(){
		clearInterval(gourmetArchiveInterval);
	});
	
	Cufon.replace(".header6,.header3,.header4,.btn_Text3");
}
*/

//PRINT GOURMET CLUB PAST EDITIONS - ARCHIVE
function printGourmetClubArchive(){

	var NrEditions = editions.length;
	var maxNrVisibleEditions = 18;
	var imgPaddingRight = 2;
	
	if (NrEditions<=maxNrVisibleEditions)
	{
		var startcountgal = 1
		var endcountgal = NrEditions;
	}
	else
	{
		var startcountgal = NrEditions - maxNrVisibleEditions;
		var endcountgal = NrEditions;
	}
	var validcount = endcountgal - startcountgal;

	var strResult = "";
	strResult += "<div style='height:25px;'></div>";
	strResult += "<div class='header3'>Gourmet Club Editions</div>";
	strResult += "<p style=\"margin-top:-10px;\">Check out our latest issue or previous editions.</p>";
	strResult += '<div style="float:left; width:538px; height:518px; border:solid 1px #000; position:relative; background:url(images/gourmetClubArchive/background.jpg) center; overflow:hidden;" id="gourmetClubArchiveWrapper">';
	
	strResult += '<div class="positionShow"></div>';
	
		strResult += '<div style="float:left; padding:28px 25px 27px 28px;"><img class="gourmetFix" id="gourmetArchiveImage" src="images/gourmetClubArchive/image' + NrEditions + '.png" alt="Gourmet Club Issue ' + NrEditions + '" title="Gourmet Club Issue ' + NrEditions + '" /></div>';
		strResult += '<div style="float:left; padding:170px 0px 0px 0px; font-size:18px; font-family:Georgia; font-style:italic; line-height:24px; color:#FFF; padding-bottom:15px;" id="gourmetArchiveDate">Issue ' + NrEditions + '<br />' + editions[NrEditions - 1].date + '</div>';
		strResult += '<a style="float:left; position:relative; width:230px; height:43px; overflow:hidden; text-decoration:none; border:none;" class="gourmetRollover" id="gourmetArchiveView" href="gourmetclub/index.php?e=' + NrEditions + '" target="_blank">';
			strResult += '<div style="position:absolute; left:15px; top:11px; z-index:2;"><div style="font-size:18px; font-family:Georgia; font-style:italic; line-height:21px; color:#FFF;">View Issue</div></div>';
			strResult += '<div style="position:absolute; left:0px; top:0px; z-index:1; width:230px; height:43px;"><img style="border:none;" class="gourmetFix" src="images/gourmetClubArchive/button.png" alt="View Issue" title="View Issue" /></div>';	
		strResult += '</a>';
		strResult += '<a style="float:left; position:relative; width:230px; height:43px; overflow:hidden; text-decoration:none; border:none;" class="gourmetRollover" id="gourmetArchiveDownload" href="gourmetclub/edition_' + NrEditions + '/GC_ED' + NrEditions + '_SPREADS.pdf">';
			strResult += '<div style="position:absolute; left:15px; top:10px; z-index:2;"><div style="font-size:18px; font-family:Georgia; font-style:italic; line-height:21px; color:#FFF;">Download</div></div>';
			strResult += '<div style="position:absolute; left:0px; top:0px; z-index:1; width:230px; height:43px;"><img style="border:none;" class="gourmetFix" src="images/gourmetClubArchive/button.png" alt="Download" title="Download" /></div>';	
		strResult += '</a>';
		strResult += '<div style="float:left; left:0px; position:relative; width:' + (validcount * (140 + imgPaddingRight))  + 'px; padding-left:18px;" id="gourmetThumbs">';	
		
		$.each(editions, function(){
			strResult += '<img src="images/gourmetClubArchive/thumb' + this.issue + '.png" alt="Gourmet Club Issue ' + this.issue + '" title="Gourmet Club Issue ' + this.issue + '" class="gourmetArchiveIssue" style="float:left; padding-right:' + imgPaddingRight + 'px; cursor:pointer;" />';
		});
			
		strResult += '</div>';		
	strResult += '</div>';
	$("#archiveHolder").html(strResult);
	
	$('.gourmetArchiveIssue').click(function(){
		var gourmetEditionID = parseInt($(this).attr('alt').split(' ')[3]);
		$('#gourmetArchiveImage').animate({opacity:'0'}, 250, 'linear', function(){
			$('#gourmetArchiveImage').attr({'src':'images/gourmetClubArchive/image' + gourmetEditionID + '.png', 'alt':'Gourmet Club Issue ' + gourmetEditionID, 'title':'Gourmet Club Issue ' + gourmetEditionID});
			$('#gourmetArchiveImage').animate({opacity:'1'}, 250, 'linear');
		});
		$('#gourmetArchiveDate').html('Issue ' + gourmetEditionID + '<br />' + editions[gourmetEditionID-1].date);
		$('#gourmetArchiveView').attr('href', 'gourmetclub/index.php?e=' + gourmetEditionID);
		$('#gourmetArchiveDownload').attr('href', 'gourmetclub/edition_' + gourmetEditionID + '/GC_ED' + gourmetEditionID + '_SPREADS.pdf');
	});
	
	$('.gourmetRollover').hover(function(){
		$('.gourmetFix', this).parent().css('top','-44px');
	}, function(){
		$('.gourmetFix', this).parent().css('top','0px');
	});
	
	//GLOBAL VARIABLES
		var posX = 0;
		var posY = 0;
		var posXrel = $('#gourmetClubArchiveWrapper').offset().left;
		var posYrel = $('#gourmetClubArchiveWrapper').offset().top;
		var width = $('#gourmetClubArchiveWrapper').width();
		var height = $('#gourmetClubArchiveWrapper').height();
		var midpos = posXrel + width / 2;
		var delayingFactor = 0.0005;

	$('#gourmetClubArchiveWrapper').mousemove(function(element){
													   
		posX = element.pageX;
		posY = element.pageY;
		posXrel = $(this).offset().left;
		posYrel = $(this).offset().top;
		midpos = posXrel + width / 2;
		galanim(posX, posY, posXrel, posYrel, midpos);
		
	}).hover(function(){
		var loop = setInterval(function(){galanim(posX, posY, posXrel, posYrel, midpos)},2);
	},function(){
		clearInterval(loop);
	});
	
	function galanim(posX, posY, posXrel, posYrel, midpos)
	{
		if (posY>= 341 + posYrel && posY<=501 + posYrel)
		{
			if (posX< midpos && posX <= posXrel + 50)
			{
				var time = posX - posXrel;
				var far2go = 0;
				if (parseFloat($("#gourmetThumbs").css("left")) < far2go) 
				{
					$("#gourmetThumbs").stop().animate({left: "+=10px"}, time * delayingFactor);
				}
				else
				{
					$("#gourmetThumbs").stop();
				}
			}
			if (posX>midpos && posX >= posXrel + width - 50)
			{
				var time = width - (posX - posXrel);
				var far2go = -1 * (parseFloat($("#gourmetThumbs").css("width")) - (width + 30));
				if (parseFloat($("#gourmetThumbs").css("left")) > far2go) 
				{
					$("#gourmetThumbs").stop().animate({left: "-=10px"}, time * delayingFactor);
				}
				else
				{
					$("#gourmetThumbs").stop();
				}
			}
		}
	}
	
	Cufon.replace(".header6,.header3,.header4,.btn_Text3");
}

/*
function printGourmetClubArchive(){

	var NrEditions = editions.length;
	var maxNrVisibleEditions = 18;
	var imgPaddingRight = 2;
	
	if (NrEditions<=maxNrVisibleEditions)
	{
		var startcountgal = 1
		var endcountgal = NrEditions;
	}
	else
	{
		var startcountgal = NrEditions - maxNrVisibleEditions;
		var endcountgal = NrEditions;
	}
	var validcount = endcountgal - startcountgal;

	var strResult = "";
	strResult += "<div style='height:25px;'></div>";
	strResult += "<div class='header3'>Gourmet Club Editions</div>";
	strResult += "<p style=\"margin-top:-10px;\">Check out our latest issue or previous editions.</p>";
	strResult += '<div style="float:left; width:538px; height:518px; border:solid 1px #000; position:relative; background:url(images/gourmetClubArchive/background.jpg) center; overflow:hidden;" id="gourmetClubArchiveWrapper">';
	
	
		strResult += '<div style="float:left; padding:28px 25px 27px 28px;"><img class="gourmetFix" id="gourmetArchiveImage" src="images/gourmetClubArchive/image' + NrEditions + '.png" alt="Gourmet Club Issue ' + NrEditions + '" title="Gourmet Club Issue ' + NrEditions + '" /></div>';
		strResult += '<div style="float:left; padding:170px 0px 0px 0px; font-size:18px; font-family:Georgia; font-style:italic; line-height:24px; color:#FFF; padding-bottom:15px;" id="gourmetArchiveDate">Issue ' + NrEditions + '<br />' + editions[NrEditions - 1].date + '</div>';
		strResult += '<a style="float:left; position:relative; width:230px; height:43px; overflow:hidden; text-decoration:none; border:none;" class="gourmetRollover" id="gourmetArchiveView" href="gourmetclub/index.php?e=' + NrEditions + '" target="_blank">';
			strResult += '<div style="position:absolute; left:15px; top:11px; z-index:2;"><div style="font-size:18px; font-family:Georgia; font-style:italic; line-height:21px; color:#FFF;">View Issue</div></div>';
			strResult += '<div style="position:absolute; left:0px; top:0px; z-index:1; width:230px; height:43px;"><img style="border:none;" class="gourmetFix" src="images/gourmetClubArchive/button.png" alt="View Issue" title="View Issue" /></div>';	
		strResult += '</a>';
		strResult += '<a style="float:left; position:relative; width:230px; height:43px; overflow:hidden; text-decoration:none; border:none;" class="gourmetRollover" id="gourmetArchiveDownload" href="gourmetclub/edition_' + NrEditions + '/GC_ED' + NrEditions + '_SPREADS.pdf">';
			strResult += '<div style="position:absolute; left:15px; top:10px; z-index:2;"><div style="font-size:18px; font-family:Georgia; font-style:italic; line-height:21px; color:#FFF;">Download</div></div>';
			strResult += '<div style="position:absolute; left:0px; top:0px; z-index:1; width:230px; height:43px;"><img style="border:none;" class="gourmetFix" src="images/gourmetClubArchive/button.png" alt="Download" title="Download" /></div>';	
		strResult += '</a>';
		strResult += '<div style="float:left; left:0px; position:relative; width:' + (validcount * (140 + imgPaddingRight))  + 'px; padding-left:30px;" id="gourmetThumbs">';	
		
		$.each(editions, function(){
			strResult += '<img src="images/gourmetClubArchive/thumb' + this.issue + '.png" alt="Gourmet Club Issue ' + this.issue + '" title="Gourmet Club Issue ' + this.issue + '" class="gourmetArchiveIssue" style="float:left; padding-right:' + imgPaddingRight + 'px; cursor:pointer;" />';
		});
			
		strResult += '</div>';		
	strResult += '</div>';
	$("#archiveHolder").html(strResult);
	
	$('.gourmetArchiveIssue').click(function(){
		var gourmetEditionID = parseInt($(this).attr('alt').split(' ')[3]);
		$('#gourmetArchiveImage').animate({opacity:'0'}, 250, 'linear', function(){
			$('#gourmetArchiveImage').attr({'src':'images/gourmetClubArchive/image' + gourmetEditionID + '.png', 'alt':'Gourmet Club Issue ' + gourmetEditionID, 'title':'Gourmet Club Issue ' + gourmetEditionID});
			$('#gourmetArchiveImage').animate({opacity:'1'}, 250, 'linear');
		});
		$('#gourmetArchiveDate').html('Issue ' + gourmetEditionID + '<br />' + editions[gourmetEditionID-1].date);
		$('#gourmetArchiveView').attr('href', 'gourmetclub/index.php?e=' + gourmetEditionID);
		$('#gourmetArchiveDownload').attr('href', 'gourmetclub/edition_' + gourmetEditionID + '/GC_ED' + gourmetEditionID + '_SPREADS.pdf');
	});
	
	$('.gourmetRollover').hover(function(){
		$('.gourmetFix', this).parent().css('top','-44px');
	}, function(){
		$('.gourmetFix', this).parent().css('top','0px');
	});
	
	//VARIABLES
	limit = 13;
	easeOut = 1.3;
	easeIn = 0.7;
	easingSteps = 5;
	direction = 'middle';
	speed = 0;	
	easing = 0;
	steps = 0;
	
	//GENERIC ANIMATION STEP VALUE GENERATOR BY WWW.HESIDO.COM
	function easeInOut(minValue, maxValue, totalSteps, actualStep, powr) { 
		var delta = maxValue - minValue; 
		var stepp = minValue + (Math.pow(((1 / totalSteps) * actualStep), powr) * delta); 
		return Math.ceil(stepp);
	}
	
	//MAIN GOURMET CLUB ANIMATION FUNCTION
	function gourmetClubAnimation(){
		//CURRENT POSITION
		currentLeft = parseInt($('#gourmetThumbs').css('left'));
		//RESET EASING DISTANCE
		easingDistance = 0;
		//CALCULATE CURRENT BRAKING DISTANCE
		for(counter = steps; counter >= 0; counter--){
			easingDistance += easeInOut(0, limit, easingSteps, counter, easeOut);
		}
		if(direction == 'right'){
			//FUNCTION
			if(currentLeft - easingDistance > 0 - 82*validcount){
				//CALCULATE CURRENT EASING STEP
				easing = easeInOut(0, limit, easingSteps, steps, easeIn);
				//ACCELERATE OR CONTINUE
				if(speed < limit){
					//ACCELERATING
					speed = easing;
				} else {
					speed = limit;
				}
				if(steps < easingSteps) steps++;
			} else {
				//CALCULATE CURRENT EASING STEP
				easing = easeInOut(0, limit, easingSteps, steps, easeOut);
				//REDUCE SPEED
				if(speed > 0){
					speed = easing;
				} else {
					speed = 0;
				}
				if(steps > 0) steps--;
			}
			//SET NEW LEFT
			newLeft = parseInt($('#gourmetThumbs').css('left')) - speed;
		} else if(direction == 'left'){
			//FUNCTION
			if(currentLeft + easingDistance < 0){
				//CALCULATE CURRENT EASING STEP
				easing = easeInOut(0, limit, easingSteps, steps, easeIn);
				//ACCELERATE OR CONTINUE
				if(speed < limit){
					//ACCELERATING
					speed = easing;
				} else {
					speed = limit;
				}
				if(steps < easingSteps) steps++;
			} else {
				//CALCULATE CURRENT EASING STEP
				easing = easeInOut(0, limit, easingSteps, steps, easeOut);
				//REDUCE SPEED
				if(speed > 0){
					speed = easing;
				} else {
					speed = 0;
				}
				if(steps > 0) steps--;
			}
			//SET NEW LEFT
			newLeft = parseInt($('#gourmetThumbs').css('left')) + speed;
		}
		
		//MOVEMENT
		$('#gourmetThumbs').css({'left':newLeft});
	}
	
	//DIRECTION TRIGGER
	$('#gourmetClubArchiveWrapper').mousemove(function(element){
		if(element.pageX - $(this).offset().left > $(this).width() - 75 && speed == 0){
			direction = 'right';
		} else if(element.pageX - $(this).offset().left < 75 && speed == 0){
			direction = 'left';
		}
	});
	
	//ANIMATION TRIGGER
	$('#gourmetClubArchiveWrapper').hover(function(){
		gourmetArchiveInterval = setInterval(gourmetClubAnimation, 40);
	}, function(){
		clearInterval(gourmetArchiveInterval);
	});
	
	Cufon.replace(".header6,.header3,.header4,.btn_Text3");
}
*/

//RELOAD BIG PROMO FORM AFTER SUBMITTION
function reloadBigpromoForm()
{
	Cufon.replace(".btn_Text3,.redHeader");
	//HOVER EVENT
	$(".btn_submit").hover(function(){
		 $(this).addClass("hover4");
	},function(){
		 $(this).removeClass("hover4");
	});
	/*
	$("#email").change(function(){
		var subscr = checkEmailCreateSend();
	});
	*/

	$("#btn_termsPromo").colorbox({width:"550px", height:"390px", href:"termsPromo2_txt.html",onComplete:function(){Cufon.replace(".btn_Text3,.redHeader");$.colorbox.resize();}});
	//CLICK EVENT
	$("#bigPromoFormSubmit").click(function(){
		validateBigPromo();
	});
}


//RELOAD BIG PROMO FORM AFTER SUBMITTION
function reloadRedeemForm()
{
	Cufon.replace(".btn_Text3,.redHeader");
	//HOVER EVENT
	$(".btn_submit").hover(function(){
		 $(this).addClass("hover4");
	},function(){
		 $(this).removeClass("hover4");
	});
	
	$("#email").change(function(){
		var subscr = checkEmailCreateSend();
	});
	

	//$("#btn_termsPromo").colorbox({width:"550px", height:"390px", href:"termsPromo2_txt.html",onComplete:function(){Cufon.replace(".btn_Text3,.redHeader");$.colorbox.resize();}});
	//CLICK EVENT
	$("#redeemFormSubmit").click(function(){
		validateRedeem();
	});
}


//RELOAD SUBSCRIBE FORM AFTER SUBMITTION
function reloadSubscribe()
{
	Cufon.replace(".btn_Text3,.redHeader");
	//HOVER EVENT
	$(".btn_submit").hover(function(){
		 $(this).addClass("hover4");
	},function(){
		 $(this).removeClass("hover4");
	});
	//FGOTO
	fGoto();

	//CLICK EVENT
	$("#subscribeFormSubmit").click(function(){validateSubscribe()});

}

//RELOAD SUBMIT RECIPE FORM AFTER SUBMITTION
function reloadSubmitRecipe()
{
	Cufon.replace(".btn_Text3,.redHeader");
	
	$(".btn_submit").hover(function(){
		 $(this).addClass("hover4");
	},function(){
		 $(this).removeClass("hover4");
	});
	//CLICK EVENT
	$("#recipeFormSubmit").click(function(){validateSubmitRecipe()});
}

//RELOAD GOURMET FORM AFTER SUBMITTION
function reloadGourmet()
{
	Cufon.replace(".btn_Text3,.redHeader");
	//HOVER EVENT
	$(".btn_submit").hover(function(){
		 $(this).addClass("hover4");
	},function(){
		 $(this).removeClass("hover4");
	});
	//AGOTO
	aGoto();
	//CLICK EVENT
	$("#gourmetFormSubmit").click(function(){validateGourmet()});
	//ENTER KEY
	$("input").keypress(function(e) {
		if(e.which == 13) {
			$(this).blur();
			$("#gourmetFormSubmit").trigger("click");
		}
	});
}

//RELOAD GIFTVOUCHER FORM
function reloadGiftVoucherForm()
{
	Cufon.replace(".btn_Text3,.redHeader");
	//HOVER EVENT
	$(".btn_submit").hover(function(){
		 $(this).addClass("hover4");
	},function(){
		 $(this).removeClass("hover4");
	});
	//CLICK EVENT
	$("#giftVoucherFormSubmit").click(function(){validateGiftVoucherForm()});
	//ENTER KEY
	$("input").keypress(function(e) {
		if(e.which == 13) {
			$(this).blur();
			$("#giftVoucherFormSubmit").trigger("click");
		}
	});
}

//RELOAD FEEDBACK FORM
function reloadFeedbackForm()
{
	Cufon.replace(".btn_Text3,.redHeader");
	//HOVER EVENT
	$(".btn_submit").hover(function(){
		 $(this).addClass("hover4");
	},function(){
		 $(this).removeClass("hover4");
	});
	//CREATESEND
	$("#email").change(function(){
		var subscr = checkEmailCreateSend();
	});
	
	//CLICK EVENT
	$("#feedbackFormSubmit").click(function(){validateFeedbackForm()});
	//ENTER KEY
	$("input").keypress(function(e) {
		if(e.which == 13) {
			$(this).blur();
			$("#feedbackFormSubmit").trigger("click");
		}
	});
}

//RELOAD HUNGERFORD FORM
function reloadHungerfordForm()
{
	Cufon.replace(".btn_Text3,.redHeader");
	//HOVER EVENT
	$(".btn_submit").hover(function(){
		 $(this).addClass("hover4");
	},function(){
		 $(this).removeClass("hover4");
	});
	//CLICK EVENT
	$("#formSubmit").click(function(){validateHungerfordForm()});
	//ENTER KEY
	$("input").keypress(function(e) {
		if(e.which == 13) {
			$(this).blur();
			$("#formSubmit").trigger("click");
		}
	});
}

//RELOAD HUNGERFORD FORM
function reloadGiveawayForm()
{
	Cufon.replace(".btn_Text3,.redHeader");
	//HOVER EVENT
	$(".btn_submit").hover(function(){
		 $(this).addClass("hover4");
	},function(){
		 $(this).removeClass("hover4");
	});

	//CREATESEND
	$("#email").change(function(){
		var subscr = checkEmailCreateSend();
	});
	
	//CLICK EVENT
	$("#formSubmit").click(function(){validateGiveawayForm()});
	//ENTER KEY
	$("input").keypress(function(e) {
		if(e.which == 13) {
			$(this).blur();
			$("#formSubmit").trigger("click");
		}
	});
}

//coupon Form
function couponForm()
{
//	alert("test");

	var strResult = "";

	strResult+="<div id='top' style='height:25px;'></div>";
	strResult+="<div class='header3'>Spring into Summer</span></div>";
	
    strResult+="<div class='enquiry'>";
	strResult+="	 <p>Thank you for purchasing Game Farm products.<br/>To enter into the Spring into Summer promotion, please include all the<br/>details below:</p>";
   	strResult+="     <form id='enquiryForm2' name='enquiryForm2' method='post'>";
    strResult+="     <fieldset>";
    strResult+="      <input type='text' tabindex='1' name='name' id='name' class='inputbox' value='Name*' onfocus='if(document.getElementById(\"name\").value==\"Name*\"){document.getElementById(\"name\").value=\"\";}' onblur='if(document.getElementById(\"name\").value==\"\"){document.getElementById(\"name\").value=\"Name*\";}'/>";
    strResult+="        <div class='formError2' id='eName'></div>";
    strResult+="      <input type='text' tabindex='2' name='address' id='address' class='inputbox' value='Address*' onfocus='if(document.getElementById(\"address\").value==\"Address*\"){document.getElementById(\"address\").value=\"\";}' onblur='if(document.getElementById(\"address\").value==\"\"){document.getElementById(\"address\").value=\"Address*\";}'/>";
    strResult+="        <div class='formError2' id='eAddress'></div>";
    strResult+="      <input type='text' tabindex='3' name='email' id='email' class='inputbox' value='Email Address*' onfocus='if(document.getElementById(\"email\").value==\"Email Address*\"){document.getElementById(\"email\").value=\"\";}' onblur='if(document.getElementById(\"email\").value==\"\"){document.getElementById(\"email\").value=\"Email Address*\";}'/>";
    strResult+="        <div class='formError2' id='eEmail'></div>";
    strResult+="      <input type='text' tabindex='4' name='tel' id='tel' class='inputbox' value='Telephone*' onfocus='if(document.getElementById(\"tel\").value==\"Telephone*\"){document.getElementById(\"tel\").value=\"\";}' onblur='if(document.getElementById(\"tel\").value==\"\"){document.getElementById(\"tel\").value=\"Telephone*\";}'/>";
    strResult+="        <div class='formError2' id='eTel'></div>";
	strResult+="	  <div style='float:left; width:100%; margin:0px; padding:0px; height:8px;'></div>";

	strResult+="	  <div class='storeLocator'>";
	strResult+="		<div style='float:left; width:200px;'>";
	strResult+="			<input type='text' tabindex='5' name='code1' id='code1' class='inputboxC' value='Promotional Code 1*'  onfocus='if(document.getElementById(\"code1\").value==\"Promotional Code 1*\"){document.getElementById(\"code1\").value=\"\";}' onblur='if(document.getElementById(\"code1\").value==\"\"){document.getElementById(\"code1\").value=\"Promotional Code 1*\";}'/>";
	strResult+="			<div class='formError2' id='eCode1'></div>";
	strResult+="		</div>";
	strResult+="		<div style='float:left; width:200px;'>";
	strResult+="			<input type='text' tabindex='6' name='code2' id='code2' class='inputboxC' value='Promotional Code 2*'  onfocus='if(document.getElementById(\"code2\").value==\"Promotional Code 2*\"){document.getElementById(\"code2\").value=\"\";}' onblur='if(document.getElementById(\"code2\").value==\"\"){document.getElementById(\"code2\").value=\"Promotional Code 2*\";}'/>";
	strResult+="			<div class='formError2' id='eCode2'></div>";
	strResult+="		</div>";
	strResult+="	  </div>";
	
	strResult+="	  <div style='float:left; width:100%; margin:0px; padding:0px; height:0px;'></div>";

	strResult+="	  <div style='float:left; width:100%; margin:0px; padding:0px; height:8px;'></div>";
    strResult+="      <input style='float:left;' type='checkbox' tabindex='7' name='gourmet' id='gourmet' value='checked'/><div style='float:left;'>I would like to know more about Game Farm&acute;s <a class='goto' rel=''>Gourmet Club</a>.</div><br/>";
	strResult+="	  <div style='float:left; width:100%; margin:0px; padding:0px; height:12px;'></div>";
	strResult+="	  <div class='header4' style='float:left;'>Where did you buy your products?</div>";
	strResult+="	  <div style='float:left; width:100%; margin:0px; padding:0px; height:8px;'></div>";
	strResult+="	  <div class='storeLocator'><input type='text' tabindex='8' name='st' id='st' class='inputboxC' value='Store'  onfocus='if(document.getElementById(\"st\").value==\"Store\"){document.getElementById(\"st\").value=\"\";}' onblur='if(document.getElementById(\"st\").value==\"\"){document.getElementById(\"st\").value=\"Store\";}'/><input type='text' tabindex='9' name='pc' id='pc' class='inputboxC' value='Suburb'  onfocus='if(document.getElementById(\"pc\").value==\"Suburb\"){document.getElementById(\"pc\").value=\"\";}' onblur='if(document.getElementById(\"pc\").value==\"\"){document.getElementById(\"pc\").value=\"Suburb\";}'/></div>";
	strResult+="	  <div style='float:left; width:100%; margin:0px; padding:0px; height:12px;'></div>";
	strResult+="	  <div class='header4' style='float:left;'>What products did you buy?</div>";
	strResult+="	  <div style='float:left; width:100%; margin:0px; padding:0px; height:8px;'></div>";
    strResult+="      <input type='text' tabindex='10' name='prod1' id='prod1' class='inputbox' value='Product 1' onfocus='if(document.getElementById(\"prod1\").value==\"Product 1\"){document.getElementById(\"prod1\").value=\"\";}' onblur='if(document.getElementById(\"prod1\").value==\"\"){document.getElementById(\"prod1\").value=\"Product 1\";}'/>";
    strResult+="      <input type='text' tabindex='11' name='prod2' id='prod2' class='inputbox' value='Product 2' onfocus='if(document.getElementById(\"prod2\").value==\"Product 2\"){document.getElementById(\"prod2\").value=\"\";}' onblur='if(document.getElementById(\"prod2\").value==\"\"){document.getElementById(\"prod2\").value=\"Product 2\";}'/>";
	strResult+="	  <div style='float:left; width:100%; margin:0px; padding:0px; height:8px;'></div>";
	strResult+="		<div style='float:left;'><div class='btn_search' id='btn_Back'><div class='btn_Text3'>Back</div></div></div>";
    strResult+="       	<div style='float:right;padding-right:45px;'><div class='btn_submit2' id='promoSubmit'><div class='btn_Text3'>Submit</div></div></div>";
    strResult+="     </fieldset>";
    strResult+="    </form>";
    strResult+="</div> ";
	
	strResult+="<div style=''></div>";

	//PRINTING
	$("#columnLeft").html(strResult);
	Cufon.replace(".header3,.header4,.btn_Text3");
	//SCROLLING UP
	$.scrollTo( '#top', 1000, {easing:'easeOutBack'} );
	//BUTTON EVENTS
	//HOVER EVENT
	$(".btn_search").hover(function(){
		$(this).addClass("hover5");							
	},function(){
		$(this).removeClass("hover5");										 
	});
	//CLICK EVENT
	$("#btn_Back").click(function(){
		loadContent($(".navbutton").filter(".current").attr("id").substring(4,$(".navbutton").filter(".current").attr("id").length)	+ "_txt.html", "");						  
	});
	//SUBMIT
	//HOVER EVENT
	$(".btn_submit2").hover(function(){
		$(this).addClass("hover42");				 
	},function(){
		$(this).removeClass("hover42");							  
	});
	$("#promoSubmit").click(function(){
		promoValidator();								 
	});
	
}

//VALIDATION BIG PROMO FORM
function validateBigPromo()
{
	//FORM FIELDS
	var name = $("#name").val(); //mandatory
	var address = $("#addr").val();//mandatory
	var email = $("#email").val();//mandatory
	var tel = $("#phone").val();//mandatory
	var dob = $("#dob").val();//mandatory
	var suburb = $("#suburb").val();//mandatory
	var store = $("#store").val();//mandatory
	var product1 = $("#product1").val();//mandatory
	var product2 = $("#product2").val();//mandatory
	var promoID = $("#promoID").val();//mandatory
	
	//REGEX
	var regEmail = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);
	var regDate = new RegExp(/^\d{2}\/\d{2}\/\d{4}$/);
	var regNumeric = new RegExp(/^[0-9 _]*$/);
	
	var errorNumber = 0;

	if (name == "Name*") 
	{
		$("#eName").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eName").css("display","none");
	}
	
	if (address == "Address*") 
	{
		$("#eAddr").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eAddr").css("display","none");
	}

	if (email == "Email*") 
	{
		$("#eEmail").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
	 if (!regEmail.test(email))
	 {
	 	$("#eEmail").css("display", "block").html("Please enter a valid Email Address."); 
		errorNumber++
	 }
	 else
	 {
		 //if (subscriber)
		 //{
			$("#eEmail").css("display","none");
		 //}
	 }
	}
	
	if (tel == "Telephone*") 
	{
		$("#ePhone").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{
		if(!regNumeric.test(tel))
		{ 
			$("#ePhone").css("display", "block").html("Please enter numeric values only."); 
			errorNumber++
		}
		else
		{ 
			$("#ePhone").css("display","none");
		}
	}
/*
	if(dob == "Date of Birth*")
	{
		$("#eDob").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	} 
	else if(!regDate.test(dob))
	{
		$("#eDob").css("display", "block").html("Please use the DD/MM/YYYY format."); 
		errorNumber++;
	} 
	else 
	{ 
		$("#eDob").css("display","none");
		var realDob = dob.substring(6,10) + "-" + dob.substring(3,5) + "-" + dob.substring(0,2);
		
	}
*/	
	if (suburb == "Suburb where purchased*") 
	{
		$("#eSuburb").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eSuburb").css("display","none");
	}
	
	if (store == "") 
	{
		$("#eStore").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eStore").css("display","none");
	}	
	
	if (product1 == "") 
	{
		$("#eProduct1").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eProduct1").css("display","none");
	}
	
	if (product2 == "") 
	{
		$("#eProduct2").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eProduct2").css("display","none");
	}
	

	if (errorNumber == 0)
	{
		$('#bigPromoFormSubmit').css('display', 'none');
/*
		if(!subscriber)
		{
			//CREATESEND - INSERT SUBSCRIBER
			var str = "cm-name=" + name + "&cm-ohkirt-ohkirt=" + email + "&cm-f-dumlt=" + address;
			var serialized = str + "&action=" + action;

			$.ajax({
				url: "js/createsend/proxy.php",
				type: "POST",
				data: serialized,
				success: function(data){
					// Server-side validation
					if (data.search(/invalid/i) != -1) 
					{
						$("#eEmail").html('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.').css("display","block");
						return false;
					}
					else
					{
						//ADD TO PROMO MAIL
					   var dataString = 'name='+ name + '&email=' + email + '&addr=' + address + '&phone=' + tel  + '&suburb=' + suburb + '&store=' + store + '&product1=' + product1 + '&product2=' + product2 + '&promoID=' + promoID;  
					   $.ajax({  
						 type: "POST",  
						 url: "bigpromoForm_db.php",  
						 data: dataString,  
						 success: function(data) {  
							 //Leave a confirmation message
							$("#bigpromoForm").html("<div style='height:131px; padding-top:100px; padding-bottom:82px;'>" + data + "</div>");
							$.colorbox.resize();	
							var t=setTimeout($.fn.colorbox.close,5000);
						 }  
					   });  
					   return false;  
					}
				}
			});
			
		}
		else
		{
*/			//ALREADY A SUBSCRIBER - ADD TO PROMO MAIL
		   var dataString = 'name='+ name + '&email=' + email + '&addr=' + address + '&phone=' + tel  + '&suburb=' + suburb + '&store=' + store + '&product1=' + product1 + '&product2=' + product2 + '&promoID=' + promoID;  
		   $.ajax({  
			 type: "POST",  
			 url: "bigpromoForm_db.php",  
			 data: dataString,  
			 success: function(data) {  
				 //Leave a confirmation message
				$("#bigpromoForm").html("<div style='height:131px; padding-top:100px; padding-bottom:82px;'>" + data + "</div>");
				$.colorbox.resize();	
				var t=setTimeout($.fn.colorbox.close,5000);
			 }  
		   });  
		   return false;  
//		}
	}
	else
	{
		$.colorbox.resize();
		return false;
	}
}


//VALIDATION REDEEM FORM
function validateRedeem()
{
	//FORM FIELDS
	var name = $("#name").val(); //mandatory
	var address = $("#addr").val();//mandatory
	var email = $("#email").val();//mandatory
	var tel = $("#phone").val();//mandatory
	var dob = $("#dob").val();//mandatory
	var suburb = $("#suburb").val();//mandatory
	var store = $("#store").val();//mandatory
	var promoID = $("#promoID").val();//mandatory
	
	//REGEX
	var regEmail = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);
	var regDate = new RegExp(/^\d{2}\/\d{2}\/\d{4}$/);
	var regNumeric = new RegExp(/^[0-9 _]*$/);
	
	var errorNumber = 0;

	if (name == "Name*") 
	{
		$("#eName").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eName").css("display","none");
	}
	
	if (address == "Address*") 
	{
		$("#eAddr").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eAddr").css("display","none");
	}

	if (email == "Email*") 
	{
		$("#eEmail").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
	 if (!regEmail.test(email))
	 {
	 	$("#eEmail").css("display", "block").html("Please enter a valid Email Address."); 
		errorNumber++
	 }
	 else
	 {
		 if (subscriber)
		 {
			$("#eEmail").css("display","none");
		 }
	 }
	}
	
	if (tel == "Telephone*") 
	{
		$("#ePhone").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{
		if(!regNumeric.test(tel))
		{ 
			$("#ePhone").css("display", "block").html("Please enter numeric values only."); 
			errorNumber++
		}
		else
		{ 
			$("#ePhone").css("display","none");
		}
	}
	
	if (store == "") 
	{
		$("#eStore").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eStore").css("display","none");
	}	
	
	if (errorNumber == 0)
	{
		$('#bigPromoFormSubmit').css('display', 'none');

		if(!subscriber)
		{
			//CREATESEND - INSERT SUBSCRIBER
			var str = "cm-name=" + name + "&cm-ohkirt-ohkirt=" + email + "&cm-f-dumlt=" + address;
			var serialized = str + "&action=" + action;

			$.ajax({
				url: "js/createsend/proxy.php",
				type: "POST",
				data: serialized,
				success: function(data){
					// Server-side validation
					if (data.search(/invalid/i) != -1) 
					{
						$("#eEmail").html('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.').css("display","block");
						return false;
					}
					else
					{
						//ADD TO PROMO MAIL
					   var dataString = 'name='+ name + '&email=' + email + '&addr=' + address + '&phone=' + tel  + '&store=' + store + '&promoID=' + promoID;  
					   $.ajax({  
						 type: "POST",  
						 url: "redeemForm_db.php",  
						 data: dataString,  
						 success: function(data) {  
							 //Leave a confirmation message
							$("#redeemForm").html("<div style='height:131px; padding-top:100px; padding-bottom:82px;'>" + data + "</div>");
							$.colorbox.resize();	
							var t=setTimeout($.fn.colorbox.close,5000);
						 }  
					   });  
					   return false;  
					}
				}
			});
			
		}
		else
		{
			//ALREADY A SUBSCRIBER - ADD TO PROMO MAIL
		   var dataString = 'name='+ name + '&email=' + email + '&addr=' + address + '&phone=' + tel  + '&store=' + store + '&promoID=' + promoID;  
		   $.ajax({  
			 type: "POST",  
			 url: "redeemForm_db.php",  
			 data: dataString,  
			 success: function(data) {  
				 //Leave a confirmation message
				$("#redeemForm").html("<div style='height:131px; padding-top:100px; padding-bottom:82px;'>" + data + "</div>");
				$.colorbox.resize();	
				var t=setTimeout($.fn.colorbox.close,5000);
			 }  
		   });  
		   return false;  
		}
	}
	else
	{
		$.colorbox.resize();
		return false;
	}
}



//VALIDATION FORM PROMO
function promoValidator()
{
	//Form fields
	var name = $("#name").val(); //mandatory
	var address = $("#address").val();//mandatory
	var email = $("#email").val();//mandatory
	var tel = $("#tel").val();//mandatory
	var code1 = $("#code1").val();//mandatory
	var code2 = $("#code2").val();//mandatory
	if ($("#gourmet").is(":checked")){ var gourmet = "Yes"; }else{ var gourmet = "No";}
//	var gourmet = $("#gourmet :checked").text();
	var store = $("#st").val();
	var suburb = $("#pc").val();
	var prod1 = $("#prod1").val();
	var prod2 = $("#prod2").val();
	
	//REGEX
	var regEmail = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);
	var regCode = new RegExp(/^[A-Za-z]{3}[0-9]{3}[A-Za-z]{2}$/);
	
	var errorNumber = 0;
	
	if (name == "Name*") 
	{
		$("#eName").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eName").css("display","none");
	}
	
	if (address == "Address*") 
	{
		$("#eAddress").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eAddress").css("display","none");
	}

	if (email == "Email Address*") 
	{
		$("#eEmail").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
	 if (!regEmail.test(email))
	 {
	 	$("#eEmail").css("display", "block").html("Please enter a valid Email Address."); 
		errorNumber++
	 }
	 else
	 {
		$("#eEmail").css("display","none");
	 }
	}
	if (tel == "Telephone*") 
	{
		$("#eTel").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{ 
		$("#eTel").css("display","none");
	}
	if (code1 == "Promotional Code 1*") 
	{
		$("#eCode1").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{
		if(!regCode.test(code1))
		{
			$("#eCode1").css("display", "block").html("Code is incorrect."); 
			errorNumber++
		}
		else
		{ 
			$("#eCode1").css("display","none");
		}
	}
	if (code2 == "Promotional Code 2*") 
	{
		$("#eCode2").css("display", "block").html("This field is mandatory"); 
		errorNumber++
	}
	else
	{
		if(!regCode.test(code2))
		{
			$("#eCode2").css("display", "block").html("Code is incorrect."); 
			errorNumber++
		}
		else
		{ 
			$("#eCode2").css("display","none");
		}
	}
	//CLEANING NON-MANDATORY FIELDS
	if (store == "Store") store = "";
	if (suburb == "Suburb") suburb = "";
	if (prod1 == "Product 1") prod1 = "";
	if (prod2 == "Product 2") prod2 = "";
	
	//ACTION AFTER SUBMITTING - NO ERRORS
	if (errorNumber == 0)
	{
		 //Ready to Send
		var dataString = 'name='+ name + '&address=' + address +  '&email=' + email + '&tel=' + tel + '&code1=' + code1 + '&code2=' + code2 + '&gourmet=' + gourmet + '&store=' + store + '&suburb=' + suburb + '&prod1=' + prod1 + '&prod2=' + prod2;  
		//alert(dataString);


		$.ajax({  
			type: "POST",  
			url: "coupon.php",  
			data: dataString,  
			success: function(data) {  
				//Leave a confirmation message
				strResult = "<div style='float:left; width:100%;padding-top:0px;'>" + data + "</div>";
				strResult+="<div style='float:left; width:100%; margin:0px; padding:0px; height:12px;'></div>";
				strResult+="<div style='float:left;'><div class='btn_search' id='btn_Back'><div class='btn_Text3'>Back</div></div></div>";

				$(".enquiry").html(strResult);
				//BUTTON EVENTS
				//HOVER EVENT
				$(".btn_search").hover(function(){
					$(this).addClass("hover5");							
				},function(){
					$(this).removeClass("hover5");										 
				});
				//CLICK EVENT
				$("#btn_Back").click(function(){
					loadContent($(".navbutton").filter(".current").attr("id").substring(4,$(".navbutton").filter(".current").attr("id").length)	+ "_txt.html", "");						  
				});
				Cufon.replace(".header3,.header4,.btn_Text3");
			}  
		});  
		return false;  

	}
}

//WEB COOKING 2
function callWebCooking2()
{
	var strResult = "";
	strResult+="<div style='height:25px;'></div>";
	strResult+="<div class='header3'>Web Cooking Videos</div>";
	strResult+="<p>Click on any of the images below to view our cooking demonstrations.</p>";
	
	$.each(webCooking,function(){
		strResult+="<div class='header4'>" + this.description + "</div>";
		
		strResult+='<div class="box" rel="' + this.file + '" style="background:url(' + this.img + ') no-repeat 0px 0px;"></div>';
		
		if(this.recipe != 0)
		{
			strResult+="<div class='webCookingRecipe' id='webCookingRecipe" + this.id + "' style='padding-bottom:5px;'><div class='btn_redsmall' rel='" + this.id + "'><div class='btn_Text3'>View this Recipe</div></div><div class='wpGap2'></div><div class='wcIco'><a href='http://www.bittongourmet.com.au/' target='_blank'><img src='images/bitton_logo.png' alt='Bitton' title='Bitton'/></a></div><div class='wpGap'></div><div class='wcIco'><a href='http://e.everdure.com/' target='_blank'><img src='images/everdure_logo.png' alt='everdure' title='everdure'/></a></div></div>";
			strResult+="<div style='float:left; width:100%; margin-top:-10px;' id='recipeText" + this.id + "'></div>";
		}
		
		strResult+="<div class='videoGap' style='margin-bottom:10px;'></div>";
	});
	strResult+="<div style='float:left;'><div class='btn_search' id='btn_Back'><div class='btn_Text3'>Back</div></div></div>";
	strResult+="<div style='clear:both'></div>";
		
	//PRINTING
	$("#columnLeft").html(strResult);
	Cufon.replace(".header3,.header4,.btn_Text3");
	
	//BUTTON EVENTS	
	strResult+='<div class="box" rel="' + this.file + '" style="background:url(' + this.img + '") no-repeat 0px 0px;></div>';
	
	
	$('a.youtubin').youtubin({
        swfWidth : 540,
        swfHeight : 329
    });
	$('.box').click(function(){
		$(this).append("<a id='" + $(this).attr("rel") + "' class='youtubin' rel='nofollow' href='http://www.youtube.com/watch?v=" + $(this).attr("rel") + "'>&nbsp;</a>");
		$("#" + $(this).attr("rel")).youtubin({
			swfWidth : 540,
			swfHeight : 329,
			autoplay : 1
		});
	});
	
	//HOVER EVENT
	$(".btn_search").hover(function(){
		$(this).addClass("hover5");							
	},function(){
		$(this).removeClass("hover5");										 
	});
	//RECIPE HOVER BUTTON
	$(".btn_redsmall").hover(function(){
		 $(this).addClass("hover93");
	},function(){
		 $(this).removeClass("hover93");
	});
	//CLICK EVENT
	$("#btn_Back").click(function(){
		loadContent($(".navbutton").filter(".current").attr("id").substring(4,$(".navbutton").filter(".current").attr("id").length)	+ "_txt.html", "");						  
	});
	
	$(".btn_redsmall").click(function(){
		recipeID = $(this).attr('rel');
		if ($("#recipeText" + recipeID).html() == "")
		{
			$.get(webCooking[recipeID].recipe, function(data){
				//recipeData = data;
				$('#recipeText' + recipeID).html(data);
			});
		}
		else
		{
			$("#recipeText" + recipeID).html("")
		}
	});
	
}

//SPONSORS ANIMATION
function sponsorAnimation(){
	//INITIALISE VARIABLES
	sponsorString = '';
	sponsorCounter = 0;	
	tallestImage = 0;
	
	//CREATE STRING
	$.each(sponsorsArray, function(){
		sponsorString+='<div style="position:absolute; width:276px; left:0px; top:0px; z-index:' + (99 - sponsorCounter) + '; text-align:center;" id="sponsorImageWrapper' + sponsorCounter + '" class="sponsorWrappers"><a href="' + this.href + '" target="_blank" style="border:none;"><img style="border:none;padding:0px !important;" src="' + this.img + '" alt="' + this.alt + '" title="' + this.alt + '" id="sponsorImage' + sponsorCounter + '" /></a></div>';
		$('#sponsorsAnimation').html(sponsorString);
		if($('#sponsorImage' + sponsorCounter).height() > tallestImage){
			 tallestImage = $('#sponsorImage' + sponsorCounter).height();
		}
		sponsorCounter++;
	});
	
	//INITIALISE VARIABLES
	sponsorCounter = 0;
	sponsorPadding = 0;
	
	//VERTICALLY ALIGN IMAGES
	$.each(sponsorsArray, function(){
		if($('#sponsorImage' + sponsorCounter).height() < tallestImage){
			//SET SPONSOR PADDING
			sponsorPadding = (tallestImage - $('#sponsorImage' + sponsorCounter).height()) / 2;
			
			//FIX ODD SIZED IMAGES
			if(sponsorPadding != Math.round(sponsorPadding)){
				sponsorPaddingTop = Math.round(sponsorPadding);
				sponsorPaddingBottom = (Math.round(sponsorPadding)) - 1;
			} else {
				sponsorPaddingTop = sponsorPadding;
				sponsorPaddingBottom = sponsorPadding;
			}
			 
			//WRITE SPONSOR PADDING
			$('#sponsorImage' + sponsorCounter).css('padding-top', sponsorPaddingTop);
			$('#sponsorImage' + sponsorCounter).css('padding-bottom', sponsorPaddingBottom);			 
		}
		sponsorCounter++;
	});
	
	//SET SPONSOR ANIMATION HEIGHT
	$('#sponsorsAnimation').css('height', tallestImage);
	
	//INITIALISE VARIABLES
	sponsorCounter = 0;
	
	//LOOP ANIMATION
	sponsorsInterval = setInterval(function(){
		animateSponsorsFunction();
	},5000);
	
	//ANIMATE SPONSORS
	function animateSponsorsFunction(){	
		if(sponsorCounter == (sponsorsArray.length-1)){
			$('#sponsorImageWrapper0').css({'display':'block'});
			$('#sponsorImageWrapper0').animate({'opacity':'1'}, 500, function(){
				$('.sponsorWrappers').css({'opacity':'1'});
				$('.sponsorWrappers').css({'display':'block'});			
				sponsorCounter = 0;
			});
		} else {
			$('#sponsorImageWrapper' + sponsorCounter).animate({'opacity':'0'}, 500, function(){
				$(this).css('display', 'none');
			});
			sponsorCounter++;
		}
	}
}

//SHOW PROMO
function showpromo()
{
	$(".promo").click(function(){
		var clicked = $(this).attr("id");
		if ($("#" + clicked + "_desc").css("display") == "none")
		{
			$("#" + clicked + "_desc").slideDown("slow");
			
		}
		else
		{
			$("#" + clicked + "_desc").slideUp("slow");
		}
	});	
}

//PAST PROMOS
function pastpromos()
{
	$("#btn_pastpromo").click(function(){
		//CHECK DISPLAY of pastpromoContainer div
		var displayValue = $(".pastpromoContainer").css("display");
		if (displayValue == "none")
		{
			//CHANGING ICO
			$("#expIco").removeClass().addClass("up");
			//SLIDING DOWN
			$(".pastpromoContainer").slideDown("slow");
		}
		else
		{
			//CHANGING ICO
			$("#expIco").removeClass().addClass("down");
			//SLIDING UP
			$(".pastpromoContainer").slideUp("slow");
		}
	});
}

//CHECK PASSING VARS
function checkvar(url,name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec(url);
  if( results == null )
    return "";
  else
    return results[1];
}

//CHECK SUBSCRIPTION TO CREATESEND LIST
function checkEmailCreateSend()
{
		var val = $("#email").val();
		subscriber = false;
		$("#eEmail").css("display","block").html('<span style="float:left;">Checking... Please wait </span><span style="float:left; margin-left:5px; margin-top:3px;"><img src="images/ajax-loader.gif" /></span>');
		$.colorbox.resize();
		// Submit the form via ajax
		$.ajax({
			url: "js/createsend/get_active_subscribers.php",
			type: "POST",
			data: "e=" + escape(val),
			success: function(data){
				// Server-side validation
				if (data == "") 
				{
					$("#eEmail").css("display","block").html('Email address not registered. By submitting this form you agree to be subscribed to our eMagazine.');
					$.colorbox.resize();
				}
				else
				{
					$("#eEmail").css("display","none").html("");
					subscriber = true;
					$.colorbox.resize();
					//var t=setTimeout($.fn.colorbox.close,5000);
				}
				return subscriber;
			}
		});
	
}
