function SetCookie(sName, sValue)
{

//date = new Date();
//date.setFullYear(date.getFullYear() + 1); // expire cookie in 1 year
document.cookie = sName + "=" + escape(sValue) + ";";

}

function DelCookie(sName)
{
  document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}
function GetCookie(sName)
{
  var cookies = document.cookie.split(";");
  for (i = 0; i < cookies.length; i++)
  {
	var p = cookies[i].split("=");
	if (p.length >= 2)
	{
//		p[0] = p[0].replace(/^ *(.*?) *$/, "$1"); // trim spaces
// line above is for IE 5.5 and up -- IE 5.0 can't do non-greedy

		p[0] = p[0].replace(/^ */, ""); // trim spaces
		p[0] = p[0].replace(/ *$/, ""); // trim spaces

		if (p[0] == sName)
		{
			return unescape(p[1]);
		}
	}
  }
  return "";
}



function DelCookie(sName)
{
  document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}


function pictureGallery()
{
	
	var picNum = (swfArray.length  ) * Math.random();
	picNum = Math.floor(picNum) + "";



	var oldCookie = GetCookie("KGD");


	if (oldCookie == "")
	{
		picNum = 0;
		SetCookie("KGD", picNum + ",-1");
	}
	else
	// need to see if current cookie shows this pic Num already and if so get new 		//pic number then append cookie with pic Num
	{
		var newCookie = picNum + ",-1";
		var picNumArray = oldCookie.split(",");
		if (picNumArray.length >= 2)
		{
			while (picNumArray[0] == picNum || picNumArray[1] == picNum)
			{
				picNum = (swfArray.length  ) * Math.random();
				picNum = Math.floor(picNum);
			}

		
			newCookie = picNumArray[1] + ","  + picNum ;
			//document.write("new cookie is" + oldCookie +  picNum);
		
		}
				
		SetCookie("KGD", newCookie);
	}

	
	return picNum;
}
