//Choose sects snipettes from list to include in page prior to cookies
function dbug (content)
{
debugText += (content)
var debugDiv = document.getElementById("dbtext");

debugDiv.innerHTML = debugText;

}

//find the length of the chosen secs
function getSecLength ()
{
var k = 0;
var n = (ct4SecSlots );

for (i=0; i <= ct4SecSlots; i++)
	{
	//take the name and go build an array in secbin
	
	buildSecSnipettes (secNames[i],secBin)
	//have the length of secBin be the the seclength for the sec name
	
		secLength[i] = (secBin.length -1)
		
	}
buildCookies ()
}


//build the cookies that need to be built
function buildCookies ()
{
var x;
//check to see if there is a cookie and if so what value the cookie holds
//increment, or reset the cookie value and then build the page
//if no cookies, write the cookies with base values and build the page
for (i=0; i < secNames.length;i++)
	{
	if (GetCookie(secNames[i]) != null)
		{
		// same as getSecLength
		buildSecSnipettes (secNames[i],secBin)
		this.name = secNames[i];
		if (GetCookie(secNames[i])< secLength[i])
			{
			x = (GetCookie(secNames[i]))
			
			secsUsed[i] = new sec ( secBin[x].href, secBin[x].title, secBin[x].body , secBin[x].bkg , secBin[x].label);
			this.value = (x);
			
			}
		else if (GetCookie(secNames[i])== secLength[i])
			{
			x = (0)
			secsUsed[i] = new sec ( secBin[x].href, secBin[x].title, secBin[x].body , secBin[x].bkg , secBin[x].label);
			this.value = (x);
			}
		updateSec (secsUsed[i], i, value)
		setC (this)
		
		}
	else if (GetCookie(secsUsed[i]) == null)
		{
		buildSecSnipettes (secNames[i],secBin)
		this.name = secNames[i];
		x = (0)
		this.value = (x)
		secsUsed[i] = new sec ( secBin[x].href, secBin[x].title, secBin[x].body , secBin[x].bkg , secBin[x].label);
		updateSec (secsUsed[i], i, value)
		secsUsed[i] = new sec ( secBin[x].href, secBin[x].title, secBin[x].body , secBin[x].bkg , secBin[x].label);
		
		setC (this)
		//ignight sec footer function
		}
	}



}


function getCookieVal(offset) 
{ 
var endstr = document.cookie.indexOf (";", offset); 
if (endstr == -1) endstr = document.cookie.length; 
return unescape (document.cookie.substring(offset, endstr)); 
} 

// Get Cookie function 
function GetCookie(name) 
{ 
var arg = name+"="; 
var alen = arg.length; 
var clen = document.cookie.length; 
var i = 0; 
while (i < clen) 
	{ 
	var j = i + alen; 
	if (document.cookie.substring(i, j) == arg) return getCookieVal(j); 
	i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; 
	} 
return null; 
}

//write cookie minimum values are name & value
function SetCookie (name, value) 
{ 

//build the var to pars the args
var argv = SetCookie.arguments;
//find the length of args
var argc = SetCookie.arguments.length;
//start checking for more args than are listed as min 
var expires = (argc > 2) ? argv[2] : null; 
var path = (argc > 3) ? argv[3] : null; 
var domain = (argc > 4) ? argv[4] : null; 
var secure = (argc > 5) ? argv[5] : false; 
document.cookie = name + "=" + escape (value) + 
//if the extra args are null expire/path/secure are empty otherwise pass the args 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + 
((secure == true) ? "; secure" : ""); 
}

//collect cookie args and send to set cookie
function setC(args) 
{ 

var expdate = new Date ( ); 
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 365)); 
SetCookie ( name,  value, expdate); 
}

//Special Notice 
var announcement = ("<h1>Holiday Hours</h1><h2>Cantu will close Thursday, Dec. 24 and will reopen Monday, January 4, 2010.</h2><h1>Happy Holidays!</h1>");
var announceDiv = ("<div class='notice'><div class='noticehead'><div class='noticeclose'><a href='javascript:aKill()'>X</a></div><h1>Special Notice</h1></div>"+announcement+"<p><a href='javascript:aKill()'>continue...</a></p></div><div class='noticebkg'></div>");
var today = new Date();
today.setDate(today.getDate()+1);

function announce(){
	//alert (GetCookie("specialnotice"))
	//if (GetCookie("holidayNotice") != 'true')
	//{
	//$("body").append(announceDiv)
	//SetCookie ( "holidayNotice",  true, today);
	//alert (today)
	//}
}


function aKill(){
$(".notice").hide()
$(".noticebkg").hide()
}
	

