
function get_flash() 
{	
	div = document.getElementById("flash_container");
	
	div.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='965' height='467' id='home_v2' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='flash/home_v2.swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='/external/flash/home_v2.swf' quality='high' wmode='transparent' width='965' height='467' name='home_v2' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}

function get_flash_small(movie_id) 
{	
	div2 = document.getElementById("flash_container_small");
	
	div2.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='453' height='227' id='" + movie_id + "' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='/external/flash/" + movie_id + ".swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='/external/flash/" + movie_id + ".swf' quality='high' wmode='transparent' width='453' height='227' name='" + movie_id + "' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}

function giveaway_flash() {
	
	if(document.getElementById("flashvid")) {
		div = document.getElementById("flashvid");
		div.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='640' height='410' id='texas' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='/external/flash/winner.swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='/external/flash/winner.swf' quality='high' wmode='transparent' width='640' height='410' name='texas' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
	}
	
	if (document.getElementById('flash_finalists')) {
		div = document.getElementById('flash_finalists');
		div.innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="956" height="399" id="finalists" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="/external/flash/finalists.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="/external/flash/finalists.swf" quality="high" wmode="transparent" width="956" height="399" name="finalists" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	}
	
	if(document.getElementById("vid_ut")) {
		div = document.getElementById("vid_ut");
		div.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='640' height='360' id='utah' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='/external/flash/videos/utah.swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='/external/flash/videos/utah.swf' quality='high' wmode='transparent' width='640' height='360' name='utah' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}
if(document.getElementById("vid_co")) {
		div = document.getElementById("vid_co");
		div.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='640' height='360' id='colorado' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='/external/flash/videos/colorado.swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='/external/flash/videos/colorado.swf' quality='high' wmode='transparent' width='640' height='360' name='colorado' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}
if(document.getElementById("vid_or")) {
		div = document.getElementById("vid_or");
		div.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='640' height='360' id='oregon' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='/external/flash/videos/oregon.swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='/external/flash/videos/oregon.swf' quality='high' wmode='transparent' width='640' height='360' name='oregon' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}
if(document.getElementById("vid_md")) {
		div = document.getElementById("vid_md");
		div.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='640' height='360' id='maryland' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='/external/flash/videos/maryland.swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='/external/flash/videos/maryland.swf' quality='high' wmode='transparent' width='640' height='360' name='maryland' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}
if(document.getElementById("vid_pa")) {
		div = document.getElementById("vid_pa");
		div.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='640' height='360' id='pennsylvania' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='/external/flash/videos/pennsylvania.swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='/external/flash/videos/pennsylvania.swf' quality='high' wmode='transparent' width='640' height='360' name='pennsylvania' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}
if(document.getElementById("vid_nc")) {
		div = document.getElementById("vid_nc");
		div.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='640' height='360' id='northcarolina' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='/external/flash/videos/northcarolina.swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='/external/flash/videos/northcarolina.swf' quality='high' wmode='transparent' width='640' height='360' name='northcarolina' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}
if(document.getElementById("vid_fl")) {
		div = document.getElementById("vid_fl");
		div.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='640' height='360' id='florida' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='/external/flash/videos/florida.swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='/external/flash/videos/florida.swf' quality='high' wmode='transparent' width='640' height='360' name='florida' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}
if(document.getElementById("vid_ar")) {
		div = document.getElementById("vid_ar");
		div.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='640' height='360' id='arkansas' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='/external/flash/videos/arkansas.swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='/external/flash/videos/arkansas.swf' quality='high' wmode='transparent' width='640' height='360' name='arkansas' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}
if(document.getElementById("vid_mo")) {
		div = document.getElementById("vid_mo");
		div.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='640' height='360' id='missouri' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='/external/flash/videos/missouri.swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='/external/flash/videos/missouri.swf' quality='high' wmode='transparent' width='640' height='360' name='missouri' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}
if(document.getElementById("vid_tx")) {
		div = document.getElementById("vid_tx");
		div.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='640' height='360' id='texas' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='/external/flash/videos/texas.swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='/external/flash/videos/texas.swf' quality='high' wmode='transparent' width='640' height='360' name='texas' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}


if(document.getElementById("flash_landing")){
			if (FlashDetect.installed){
			   	document.getElementById('flash_landing').innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='770' height='475'id='video_landing' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='/external/flash/video_landing.swf' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><embed src='/external/flash/video_landing.swf' quality='high' wmode='transparent' width='770' height='475' name='video_landing' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
			} else {
				document.getElementById('flash_landing').innerHTML = '<img src="/external/images/flash_placeholder.jpg" width="770" height="475" border="0" usemap="#Map" /><map name="Map" id="Map"><area shape="rect" coords="79,30,213,94" href="/giveaway/videos/or" /><area shape="rect" coords="35,156,167,213" href="/giveaway/videos/ut" /><area shape="rect" coords="200,146,333,208" href="/giveaway/videos/co" /><area shape="rect" coords="348,140,480,199" href="/giveaway/videos/mo" /><area shape="rect" coords="589,102,719,157" href="/giveaway/videos/pa" /><area shape="rect" coords="570,270,701,328" href="/giveaway/videos/nc" /><area shape="rect" coords="511,160,645,215" href="/giveaway/videos/md" /><area shape="rect" coords="430,242,561,299" href="/giveaway/videos/ar" /><area shape="rect" coords="229,296,364,350" href="/giveaway/videos/tx" /><area shape="rect" coords="485,363,619,423" href="/giveaway/videos/fl" /></map>';
			}						   					   
}

}

function sessionFlashCheckReverse() {
	// this function gets called from the flash_check page and returns
	// the user to a landing page if they actually have flash installed
	if(FlashDetect.installed){
		var flashInstalled = true;
		window.location = "/";
	}else{
		var flashInstalled = false;
	}
	return flashInstalled;
}

function sessionFlashCheck() 
{
	if(FlashDetect.installed){
		var flashInstalled = true;
	}else{
		var flashInstalled = false;
		if (window.location.href.indexOf("flash_needed") < 0 )
			window.location = "/pages/page/flash_needed";
	}
	/*
	var xmlHttp=GetXmlHttpObject();
	url = "/tv/saveFlash/"+flashInstalled;
	
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			//alert(flashInstalled);
		}
	}		
	xmlHttp.send(null);*/
	
	return flashInstalled;
}
function GetXmlHttpObject()	{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
 		xmlHttp=new XMLHttpRequest();
 	}
	catch (e)
 	{
	 //Internet Explorer
	 try
	  {
	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	 catch (e)
	  {
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	 }
	return xmlHttp;
}


var FlashDetect = new function()
{
    var self = this;
    self.installed = false;
    self.raw = "";
    self.major = -1;
    self.minor = -1;
    self.revision = -1;
    self.revisionStr = "";
    var activeXDetectRules = [
        {
            "name":"ShockwaveFlash.ShockwaveFlash.7",
            "version":function(obj){
                return getActiveXVersion(obj);
            }
        },
        {
            "name":"ShockwaveFlash.ShockwaveFlash.6",
            "version":function(obj){
                var version = "6,0,21";
                try{
                    obj.AllowScriptAccess = "always";
                    version = getActiveXVersion(obj);
                }catch(err){}
                return version;
            }
        },
        {
            "name":"ShockwaveFlash.ShockwaveFlash",
            "version":function(obj){
                return getActiveXVersion(obj);
            }
        }
    ];
    /**
     * Extract the ActiveX version of the plugin.
     * 
     * @param {Object} The flash ActiveX object.
     * @type String
     */
    var getActiveXVersion = function(activeXObj){
        var version = -1;
        try{
            version = activeXObj.GetVariable("$version");
        }catch(err){}
        return version;
    };
    /**
     * Try and retrieve an ActiveX object having a specified name.
     * 
     * @param {String} name The ActiveX object name lookup.
     * @return One of ActiveX object or a simple object having an attribute of activeXError with a value of true.
     * @type Object
     */
    var getActiveXObject = function(name){
        var obj = -1;
        try{
            obj = new ActiveXObject(name);
        }catch(err){
            obj = {activeXError:true};
        }
        return obj;
    };
    /**
     * Parse an ActiveX $version string into an object.
     * 
     * @param {String} str The ActiveX Object GetVariable($version) return value. 
     * @return An object having raw, major, minor, revision and revisionStr attributes.
     * @type Object
     */
    var parseActiveXVersion = function(str){
        var versionArray = str.split(",");//replace with regex
        return {
            "raw":str,
            "major":parseInt(versionArray[0].split(" ")[1], 10),
            "minor":parseInt(versionArray[1], 10),
            "revision":parseInt(versionArray[2], 10),
            "revisionStr":versionArray[2]
        };
    };
    /**
     * Parse a standard enabledPlugin.description into an object.
     * 
     * @param {String} str The enabledPlugin.description value.
     * @return An object having raw, major, minor, revision and revisionStr attributes.
     * @type Object
     */
    var parseStandardVersion = function(str){
        var descParts = str.split(/ +/);
        var majorMinor = descParts[2].split(/\./);
        var revisionStr = descParts[3];
        return {
            "raw":str,
            "major":parseInt(majorMinor[0], 10),
            "minor":parseInt(majorMinor[1], 10), 
            "revisionStr":revisionStr,
            "revision":parseRevisionStrToInt(revisionStr)
        };
    };
    /**
     * Parse the plugin revision string into an integer.
     * 
     * @param {String} The revision in string format.
     * @type Number
     */
    var parseRevisionStrToInt = function(str){
        return parseInt(str.replace(/[a-zA-Z]/g, ""), 10) || self.revision;
    };
    /**
     * Is the major version greater than or equal to a specified version.
     * 
     * @param {Number} version The minimum required major version.
     * @type Boolean
     */
    self.majorAtLeast = function(version){
        return self.major >= version;
    };
    /**
     * Is the minor version greater than or equal to a specified version.
     * 
     * @param {Number} version The minimum required minor version.
     * @type Boolean
     */
    self.minorAtLeast = function(version){
        return self.minor >= version;
    };
    /**
     * Is the revision version greater than or equal to a specified version.
     * 
     * @param {Number} version The minimum required revision version.
     * @type Boolean
     */
    self.revisionAtLeast = function(version){
        return self.revision >= version;
    };
    /**
     * Is the version greater than or equal to a specified major, minor and revision.
     * 
     * @param {Number} major The minimum required major version.
     * @param {Number} (Optional) minor The minimum required minor version.
     * @param {Number} (Optional) revision The minimum required revision version.
     * @type Boolean
     */
    self.versionAtLeast = function(major){
        var properties = [self.major, self.minor, self.revision];
        var len = Math.min(properties.length, arguments.length);
        for(i=0; i<len; i++){
            if(properties[i]>=arguments[i]){
                if(i+1<len && properties[i]==arguments[i]){
                    continue;
                }else{
                    return true;
                }
            }else{
                return false;
            }
        }
    };
    /**
     * Constructor, sets raw, major, minor, revisionStr, revision and installed public properties.
     */
    self.FlashDetect = function(){
        if(navigator.plugins && navigator.plugins.length>0){
            var type = 'application/x-shockwave-flash';
            var mimeTypes = navigator.mimeTypes;
            if(mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description){
                var version = mimeTypes[type].enabledPlugin.description;
                var versionObj = parseStandardVersion(version);
                self.raw = versionObj.raw;
                self.major = versionObj.major;
                self.minor = versionObj.minor; 
                self.revisionStr = versionObj.revisionStr;
                self.revision = versionObj.revision;
                self.installed = true;
            }
        }else if(navigator.appVersion.indexOf("Mac")==-1 && window.execScript){
            var version = -1;
            for(var i=0; i<activeXDetectRules.length && version==-1; i++){
                var obj = getActiveXObject(activeXDetectRules[i].name);
                if(!obj.activeXError){
                    self.installed = true;
                    version = activeXDetectRules[i].version(obj);
                    if(version!=-1){
                        var versionObj = parseActiveXVersion(version);
                        self.raw = versionObj.raw;
                        self.major = versionObj.major;
                        self.minor = versionObj.minor; 
                        self.revision = versionObj.revision;
                        self.revisionStr = versionObj.revisionStr;
                    }
                }
            }
        }
    }();
};


