// <![CDATA[
// set jquery so that it doesn't run into scriptaculous
var $j = jQuery.noConflict();

var sCookieName = 'novideo';

$j(document).ready(function()
{
	preloadFlash();
	$j.preloadImages("images/cunovideo.jpg","images/cunovideo.jpg");

	video_toggle_init();

	$j("#img-video-toggle").click(
	function()
	{
		videoToggle();
		return false;
	}
	);
});

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

function preloadFlash()
{
	jQuery("<div>").html(getFlashFileString('hpnovid.swf'));
}

function video_toggle_init()
{
	if($.cookie(sCookieName) == '1')
	{
		// flip the button image
		sImgName = "images/cuvideo.jpg";
		
		// flip the flash image
		sFlashStr = getFlashFileString('hpnovid.swf');
		
		$j("#img-video-toggle").attr("src",sImgName);
		$j("#main-flash-container").html(sFlashStr);
	}
}

function videoToggle()
{
	// need to determine the current status by checking the cookie value
	if($.cookie(sCookieName) == '1')
	{
		// we're currently skipping video; need to set the cookie's value to zero
		nCookieVal = 0;
		
		// flip the button image
		sImgName = "images/cunovideo.jpg";
		
		// flip the flash image
		sFlashStr = getFlashFileString('hpcomposite9.swf');
		
	}
	else
	{
		// we're currently NOT skipping video, need to set the cookie's value to one
		nCookieVal = 1;
		
		// flip the button image
		sImgName = "images/cuvideo.jpg";
		
		// flip the flash image
		sFlashStr = getFlashFileString('hpnovid.swf');
	}
	
	$.cookie(sCookieName, nCookieVal, { expires: 365, path: '/', domain: '.firstent.org'});
	$j("#img-video-toggle").attr("src",sImgName);
	$j("#main-flash-container").html(sFlashStr);
}

function getFlashFileString(sFlashFile)
{
	sOut  = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"955\" height=\"426\">";
	sOut += "<param name=\"movie\" value=\"" + sFlashFile + "\" />";
	sOut += "<param name=\"quality\" value=\"high\" />";
	sOut += "<param name=\"wmode\" value=\"transparent\" />";
	sOut += "<embed src=\"" + sFlashFile + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"955\" height=\"426\" wmode=\"transparent\"></embed>";
	sOut += "</object>";
	
	return sOut;
}

// ]]>