// JavaScript Document

var introImage = new Image();
introImage.src = "../images/2011/Hy-Vee-Curtis-Stone-Meals.jpg";

jQuery(document).ready(function($){
jQuery("#welcome-heading").css({"opacity" : 0});
setPage();



$(function () {
var iscountpage = document.getElementById('defaultCountdown');

if (iscountpage != null){
var austDay = new Date();
	austDay = new Date(austDay.getFullYear(), 11, 30, 12);
	$('#defaultCountdown').countdown({until: austDay, layout: '{dn} : {hnn} : {mnn} : {snn}'});
	//$('#year').text(austDay.getFullYear());
		}	
	});

if( typeof lightbox_init == "function") {
    lightbox_init();
}

checkCookie();	



}); // end of document ready

/* Cookies */

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function checkCookie()
{
var view=getCookie("view");
if (view)
  { 
  
  //setCookie("view",true,-7);
  jQuery("#welcome-heading").fadeTo(1200,1.0);
  
  }
else 
  {
	  
	  topWidth = jQuery(window).width();
	  newLeft = topWidth-520;
	  newLeft = newLeft/2;
	  topHeight = jQuery(window).height();
	  topHeight = topHeight - 300;
	  topHeight = topHeight/2;
	  jQuery("#curtis-stone").css({"top" : topHeight+"px"});
	  jQuery("#curtis-stone").animate({left : newLeft+"px"},2000,function(){
		  
		  
		  setCookie("view",true,3);
		  
		  
		  
		  
		  }).delay(1800).animate({left : topWidth+10+"px"},2000,function(){
			  
			jQuery("#welcome-heading").fadeTo(1200,1.0);
			jQuery("#curtis-stone").css({"display" : "none"});  
			
			 });
	  
         
  }
}



/* Highlighting the links */

function extractPageName(hrefString)
{
	var arr = hrefString.split('/');
	return  (arr.length < 2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase();
}
 
function setActiveMenu(arr, crtPage)
{
	for (var i=0; i < arr.length; i++)
	{
		if(extractPageName(arr[i].href) == crtPage)
		{
			if (arr[i].parentNode.tagName != "DIV")
			{
				arr[i].className = "active";
				arr[i].parentNode.className = "active";
			}
		}
	}
}
 
function setPage()
{
	hrefString = document.location.href ? document.location.href : document.location;
 
	if (document.getElementById("menu") !=null )
	setActiveMenu(document.getElementById("menu").getElementsByTagName("a"), extractPageName(hrefString));
}

