document.write('<scr'+'ipt type="text/javascript" src="http://games.mtvnservices.com/scripts/swfobject.js" ></scr'+'ipt>');

function GamePlayer(){
	this.adLoaderURL =  "http://games.mtvnservices.com/swf/gameadloader/gameadloader.1.1.0.swf";
	this.expressInstall = "http://games.mtvnservices.com/swf/expressinstall/expressInstall.swf";
	this.gameHeight = "";
	this.gameWidth = "";
	this.coadDiv = null;
	this.adURL = "";
	
	//Ad configuration
	this.gamePerAd = 1;//Ad Freq
	this.adWidth = 640;
	this.adHeight = 480;
	this.timeDisplayEnabled = true;
	this.guiEnabled = true;
	this.disableAds = false;
	
	//Quantcast details
	this.quantCast = {};
	this.quantCast.quantcastEnabled = true;
	this.quantCast.quantcastId = "p-94wNw88f65Rhk";
	
	//Game Metadata
	this.gameMetaData = {};
	this.gameMetaData.gameURL = "NA";
	this.gameMetaData.gameTitle = "NA";
	this.gameMetaData.gameId = "NA";
	this.gameMetaData.gameType = "NA";
	this.gameMetaData.gameGenre = "NA";
	this.gameMetaData.gameSWF = "NA";
	this.gameMetaData.group = "NA";
	this.gameMetaData.type = "network";
	this.gameMetaData.ref=location.href;
	this.gameMetaData.orig="NA"
	
	//DoubleClick Details
	this.doubleClick = {};	
	this.doubleClick.doubleClickEnabled = true;
	
	//FreeWheel details
	this.freeWheel = {};
	this.freeWheel.freeWheelEnabled = false;
	this.freeWheel.networkId = "82124";
	this.freeWheel.siteSection = "cc site_home";
	this.freeWheel.assetId = "all_temporal_test_asset";
	
	
	this.params = {dartSite:"", showId:"", rugrat:"", revenue:""};
	
	//this.omnitureEnabled= false;
	
	this.freeWheelEnabled = false; 
	 
	

	this.addAlternateContent=function(divId){
			this.parentDiv.innerHTML = "";
			var alternateContent = '<p><a href="http://www.adobe.com/go/getflashplayer">Download the free Flash Player now!</a><br/><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /> </a></p>';
			var divInnerHTML = '<div id="'+(divId?divId:"adLoader_div")+'">';
			divInnerHTML += alternateContent;
			divInnerHTML += '</div>';
			this.parentDiv.innerHTML += divInnerHTML;
	}

	this.init = function(parent_div){		
		
		this.gameMetaData.gameSWF = this.gameMetaData.gameURL = this.gameURL;
		//assign this object ot he global activeGamePlayer so we can reference it on the flash callback
		activeGamePlayer = this;
		this.parentDiv = parent_div;
		
		var adPlayCounter = this.get_cookie("adPlayCounter");
		if(!adPlayCounter){
			this.set_cookie("adPlayCounter", 0);	
		}
	
		if(adPlayCounter >= this.gamePerAd && !(this.disableAds)){
			adPlayCounter = 0;
			this.embedAdLoader();	
		}else{
			adPlayCounter++;
			this.embedGame();	
		}
		this.set_cookie("adPlayCounter", adPlayCounter);	
	}

	this.embedAdLoader = function(){
		this.addAlternateContent();
		this.flash_Embed(this.adLoaderURL, "adLoader_div", this.adWidth, this.adHeight, true);
	}
	
	this.embedGame = function(){
		this.parentDiv.innerHTML = "";
		var game_url =this.gameURL;		
		var gameFlashVars = game_url.split("?");
		if (this.gameURL.match(/\.swf(\?|#)/gi) || this.gameURL.match(/(.swf)$/gi)){
			this.addAlternateContent("game_div");			
			this.flash_Embed(gameFlashVars[0], "game_div", this.gameWidth, this.gameHeight,"",gameFlashVars[1]?gameFlashVars[1]:false);
		}else{				
			divInnerHTML = '<div id="game_div">';
			divInnerHTML += this.flash_Iframe();
			divInnerHTML += '</div>';		
			this.parentDiv.innerHTML = divInnerHTML;			
		}
	}
	

	this.swapGame = function(){
		this.Hide_DIV('adLoader_div');		
		this.embedGame();
		
	}

	this.flash_Iframe = function(){
	writeVar= '<iframe src="'+this.gameURL+ '" height="'+this.gameHeight+'"width="'+this.gameWidth+'" scrolling="no" frameborder="0"></iframe>';
	return writeVar;
	}

	this.flash_Embed = function(path, id, width, height, addFlashVars, gameFlashVars){
		
			var flashVars = {};
			var params = {allowfullscreen:'true',allowscriptaccess:'always'};
			if(addFlashVars ){
				flashVars = {};
				flashVars.allowscriptaccess = "always";
				flashVars.bgcolor = "black";
				flashVars.sWidth= width;
				flashVars.sHeight=height;
				flashVars.timeDisplayEnabled=this.timeDisplayEnabled;
				flashVars.guiEnabled=this.guiEnabled;
				if(this.adURL){
					flashVars.adURL= this.adURL;
				}		
				if( this.params){
					for(var param in  this.params)
						if( this.params[param] != ""){
							flashVars[param] =this.params[param];
							params[param] = this.params[param];
						}
				}
				if( this.doubleClick){
					for(var key in  this.doubleClick)
						if( this.doubleClick[key] != "")
							flashVars[key] = this.doubleClick[key];	
							
				}
				if(this.freeWheel){
					for(var key in this.freeWheel)
						if(this.freeWheel[key] != "")
							flashVars[key]= this.freeWheel[key];		
				}
				if(this.quantCast){
					for(var key in this.quantCast)
						if(this.quantCast[key] != "")
							flashVars[key] = this.quantCast[key];
				}
				if(this.gameMetaData){
					for(var key in this.gameMetaData)
						if(this.gameMetaData[key] != "")
							flashVars[key]=this.gameMetaData[key];
				}
			}
			else if(gameFlashVars){			
				flashVars = {};
				var gameFlashVarsArr = gameFlashVars.split("&");
				for(var i=0;i<gameFlashVarsArr.length;i++){					
					var key = gameFlashVarsArr[i].split("=")[0];
					var val = gameFlashVarsArr[i].split("=")[1];
					if(key)
						flashVars[key] = (val?val:"");
				}				
			}
			var x='';
			//for(var i in flashVars)x+="\n"+i+"="+flashVars[i];alert(x);
            if((swfobject.getFlashPlayerVersion()).major<10)
            	swfobject.showExpressInstall({data:this.expressInstall, width:width, height:height }, {}, id, function(){});
            else
				swfobject.embedSWF(path, id, width, height, "10.0.0", this.expressInstall, flashVars,params);
		}
			 
		this.Hide_DIV = function(d) {
			document.getElementById(d).style.display = "none";
		}

		this.Display_DIV = function(d) { 
			document.getElementById(d).style.display = "block";
		}

		this.set_cookie= function( name, value )
		{
		  var cookie_string = name + '=' + escape ( value );
		  document.cookie = cookie_string;
		}

		this.get_cookie = function( cookie_name )
		{
		  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

		  if ( results )
			return ( unescape ( results[2] ) );
		  else
			return null;
		}

		 

}


	function launchGame(){
		setTimeout('activeGamePlayer.swapGame()',1);//setTimeout is used because of a bug in swfObject when invoked using ExternalInterface
	}
	//var declaration as placeholder for the gamePlayer object
	var activeGamePlayer = "";


//-------------------------------------------------------------------------------------



