// JavaScript Document
 if (document.images) {
  pic0= new Image(); 
  pic0.src="images/homepage/vote-mobile_on.png"; 
  pic1= new Image(); 
  pic1.src="images/homepage/vote-fb_on.png"; 
  pic2= new Image(); 
  pic2.src="images/homepage/back-btn_on.png"; 
  pic3= new Image(); 
  pic3.src="images/homepage/bg-feature-topcheesemobile.jpg"; 
}

function lightup(imgName) {
	if(document.images) {
		imgOn=eval(imgName + ".src");
		document[imgName].src= imgOn;
	}
 }

function turnoff(imgName) {
	if(document.images) {
		document[imgName].src = document[imgName].src.replace(/_on.png/g, ".png");
		
	}
 }

popUpWindow = function(URL,windowName,width,height) {
	var w = screen.availWidth;
	var h = screen.availHeight;
	var leftPos = Math.round((w-width)/2);
	var topPos = Math.round((h-height)/2);
	var defaults = "scrollbars=yes,resizable=yes,";
	var centerOnScreen = "top="+topPos+",left="+leftPos+",width="+width+",height="+height;
	// safari seems to need the trailer comma
	var options = defaults + centerOnScreen + ",";
	var msgWindow = window.open(URL,windowName,options);
	msgWindow.focus();
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}


function showfeature(){
	var str='';

	str+='			<a href="https://www.facebook.com/cheezit" title="Cheez-It and ESPN are teaming up - Find out more on Facebook" target="_blank"><img src="images/spacer.gif" width="640" height="360" alt=""/></a>';
		
	//replace what HTML is currently inside the Flash container
	document.getElementById("flashcontent").innerHTML = str;
}

function setVideo(type) {
	if(isObject('jcplayer')){
      replaceSwfWithEmptyDiv('jcplayer');
    }
	var spot = readCookie("tvspot");
	if( spot != null) {
        flashvars.videoURL = spot + type + '.mp4'; 
		flashvars.startPhotoSource = spot + 'high.jpg';
	} else {
		flashvars.videoURL = 'KLCZ0163_' + type + '.mp4';  
		flashvars.startPhotoSource = 'KLCZ0163_' + 'high.jpg';
	}
		flashvars.autoPlay = "true";
        swfobject.embedSWF("jcplayer.swf","jcplayer", "400", "295", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}

function isObject(targetID){
	
   var isFound = false;
   var el = document.getElementById(targetID);
   if(el && (el.nodeName === "OBJECT" || el.nodeName === "EMBED")){
      isFound = true;
   }

   return isFound;
}

function replaceSwfWithEmptyDiv(targetID){
   var el = document.getElementById(targetID);
   if(el){
      var div = document.createElement("div");
      el.parentNode.insertBefore(div, el);
      swfobject.removeSWF(targetID);
      div.setAttribute("id", targetID);
   }
}

function createCookie(name,value,days)
{
      if (days)
      {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
      } else {
            var expires = "";
      }
      document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
      var nameEQ = name + "=";
      var ca = document.cookie.split(';');
      for(var i=0;i < ca.length;i++)
      {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
      }
      return null;
}
function eraseCookie(name)
{
      createCookie(name,"",-1);
}
