
/*
 *Copyright 2009 Creativa Web Videos
 */
 
 function FlashWrapper_constructor () {
 	//constant

 	this.CLASSID = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
 	this.CODEBASE = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0";
 	this.PLUGINSPAGE = "http://www.macromedia.com/go/getflashplayer";
 
 	this.embed = function ( parentid , id , swfurl, attrs   ) {
 			
 			var pname ;
 			var pelement = document.getElementById( parentid );
 			
 			if( !attrs.allowScriptAccess ) {
 				attrs.allowScriptAccess = "always";
 			} 
 			
 			if( navigator.appName.indexOf("Microsoft") == -1 ) {
 				//non ie
 				var objNode = document.createElement("object");
				var embNode = document.createElement("embed");
				
				//set object and embed attributes
				
				//specific for object
				objNode.setAttribute ( "id", id ) ;
				objNode.setAttribute ( "classid" , this.CLASSID );
				objNode.setAttribute ( "codebase" , this.CODEBASE );
				
				
				 
				var movieNode = document.createElement( "param" ) ;
				movieNode.setAttribute("name" , "movie");
				movieNode.setAttribute ("value" ,  swfurl     );
			 	objNode.appendChild ( movieNode ) ;
 				
 				//specific for embed
 				embNode.setAttribute ("pluginspage" , this.PLUGINSPAGE ) ;
 				embNode.setAttribute ("src" , swfurl ) ;
 				embNode.setAttribute ("name", id ) ;
 				//traverse attributes
 				
 				for( pname in attrs ) {
 				 	embNode.setAttribute ( pname , attrs[pname] );
	 				if( this.isAttribute( pname ) ){
	 					 objNode.setAttribute( pname , attrs[pname] ) ;
	 				}	else {
	 					var pnode = document.createElement ("param" ) ;
	 					pnode.setAttribute( "name" , pname ) ;
	 					pnode.setAttribute( "value" , attrs[pname]);
	 					objNode.appendChild( pnode );
	 					 
	 				} 
	 			}
	 			
	 			if( pelement ) {
	 				objNode.appendChild( embNode );
 					pelement.appendChild( objNode );
	 			}
	 			
 			} else  {
 				//ie
				var paramStr = "";
 				var objStr = "<object ";
 				objStr += " classid=\"" + this.CLASSID + "\" ";
 				objStr += " codebase=\"" + this.CODEBASE + "\" ";
 				objStr += " id=\"" + id + "\" ";
 				
 				paramStr += this.createParam ( "movie", swfurl );
 				
 				for( pname in attrs ) {
 				 	if( this.isAttribute( pname ) ){
	 					 objStr += " " + pname + "=\"" + attrs[pname] + "\" ";
	 				} else {
	 					paramStr += this.createParam ( pname ,attrs[pname] );
	 				} 
	 			}
	 			
	 			objStr += ">" + paramStr + "</object>";
	 			if( pelement ) {
	 				pelement.innerHTML = objStr;
	 			}
 			}
 	}
 	
 	
 	this.createParam  = function ( name, value ) {
 		var p = "";
 		p = "<param name=\"" + name + "\" value=\"" + value + "\" />";
 		return p;
 		if( name == "movie" ) { 
 		 	p = "<param name=" + name + " value=\"" + value + "\" />";
 		} else {
 			p = "<param name=" + name + " value=" + value + " />";
 		}
 		return p;
 	}
 	
 	this.remove = function ( id ) {
		 
		
		
 		var embnode,objnode;
 		objnode = document.getElementById(id);
 			
 		if( navigator.appName.indexOf("Microsoft") == -1 ) {
 			var embeds = document.getElementsByTagName("embed");
 			for( var i = 0 ; i < embeds.length ; i++ ) {
 				embnode = embeds[i];
 				if( embnode.getAttribute("name") == id ) break;	
 			}
 			objnode.removeChild ( embnode );
 		
 			if( objnode.parentNode ) {
 				objnode.parentNode.removeChild( objnode ) ;	
 			}
 		} else{
 			objnode.parentNode.removeChild( objnode );
 		}
 		
 	}
 	
 	this.isAttribute = function ( pname ) {
 		var lcaseName = pname.toLowerCase();
 		 if( lcaseName == "align" ) {
 		 	return true;
 		 } else if ( lcaseName == "width" ) {
 		 	return true;
 		 } else if ( lcaseName == "height" ) {
 		 	return true;
 		 }
 		 return false;
 	}
 	
 }
 
 var FlashWrapper = new FlashWrapper_constructor();
 
 /*
  * Flash Wrapper class ends here
  *
  */
  
 
 
 
 function CookieUtil_constructor() {
	
	this.cookies = new Object();  
	this.createCookie = function ( cookieName , value  ) {
		var name = cookieName + "=" + value + "";
		var path = "path=/";
		document.cookie = name + "; " + path;
				
	}
	
	this.insert = function ( name , value ) {
		 
		this.cookies [ name ] = value;
		var newVP ;
		
		if( document.cookie == "" ) {
			newVP = name + "=" + value;
			document.cookie = newVP + "; path=/";
			 
		} else {
		 
			newVP = "; " + name + "=" + value;
			document.cookie += newVP;
		}
		
	}
	
	this.deleteCookie = function ( ) {
		document.cookie = "";
	}
	
	this.initCookies = function  () {
	  	if( document.cookie.indexOf ("=") != -1 ) {
			var cookieArray = document.cookie.split("; ");
		 	for( var i = 0; i < cookieArray.length ; i++ ) {
				var valuePairString = cookieArray[i];
				if( valuePairString.indexOf("=") != -1 ) {
					var valuePair = valuePairString.split("=");
					if( valuePair[0] != "path" || valuePair[0] != "expires" ) {
						var cname = valuePair[0];
						var cvalue = valuePair[1];
						this.cookies[cname] = cvalue;
					 
					} 
				}
			}
		}
		
	}
	 
	this.getCookieByName = function ( name ) {
		return { name: name , value : this.cookies[name] };	
	}
	 
	this.initCookies();
	 
}
			
var CookieUtil = new CookieUtil_constructor();
 
 
/*
 * DelegateUtil class helps methods delegation to access different kind of methods
 * in the original context
 */
 
function inherits( subclass, o ) {
	for( var i in o ) {
		subclass[i] = o[i];
	}
} 
 
function EventDispatcher () {
	this.hash = [];
	
	this.addEventListener = function ( type, obj , methodName ) {
		var info = { type:type , owner: obj , method: methodName };
		this.hash.push ( info ) ;
	}
	
	this.dispatchEvent = function (   info  ) {
		for( var i = 0; i < this.hash.length; i++ ) {
			var obj = this.hash[i];
			if( obj.type == info.type ) {
				var method = obj.method;
				if( obj.owner  ) {
				 	obj.owner[method]( info ) ;
				} else {
					eval( method + "(info)");
				}
			} 
		}
	}

	this.removeEventListener = function  ( type , owner , methodName ) {
		for( var i = 0; i < this.hash.length; i++ ) {
			var item = this.hash[i];
			if( item.type == type && item.owner == owner && item.method == methodName ) {
			 	this.hash.splice(i,1);
			 	break;
			} 
		}
	}
	 
}

/*
################################ BrowserWindow ####################################
################################ BrowserWindow ####################################
################################ BrowserWindow ####################################
*/


var BrowserWindow = new Object();

function tryTrace( value ) {
	try {
		jshelper.trace( value );
	} catch ( err ) {
	
	}
}

function browserWindowSize() {
 	 
    
 	 
  	if ( document.documentElement && ( typeof( document.documentElement.clientWidth ) == "number" || typeof( document.documentElement.clientHeight ) == "number" )) {
  		BrowserWindow.width = document.documentElement.clientWidth;
  		BrowserWindow.height = document.documentElement.clientHeight;
  	}
  	
  	if( typeof( window.innerWidth ) == 'number' ) {
    	//Non-IE
    	BrowserWindow.width = window.innerWidth;
    	BrowserWindow.height = window.innerHeight;
    } else if( BrowserWindow.width == 0 &&  document.body && ( typeof( document.body.clientWidth ) == "number"  || typeof( document.body.clientHeight) == "number" ) ) {
    
    	BrowserWindow.width = document.body.clientWidth;
    	BrowserWindow.height = document.body.clientHeight;
    
    }   
   
   
   if( navigator.appName.indexOf("Microsoft") != -1 ) {
   		BrowserWindow.type = "IE";
   	 
   } else {
	   	BrowserWindow.type = "nonIE";
   		 
   }
 
}

browserWindowSize();


/*
################################ CreativaSystem ####################################
################################ CreativaSystem ####################################
################################ CreativaSystem ####################################
*/

function CreativaSystem_constructor() {
	inherits ( this , new EventDispatcher() ) ;
	var myinstance = this;
	 
	this.resizeDOM = function (  target , width , height ) {
	 	target.style.pixelWidth = width;
	 	target.style.pixelHeight =  height;
		if( navigator.appName != "Microsoft Internet Explorer" ) {
			target.style.width = width + "px";
	 		target.style.height = height + "px";
		}
	}
	
	this.positionDOM = function   ( target , x , y ) {
		target.style.pixelLeft =  x;
	 	target.style.pixelTop =  y;
	 	if( navigator.appName != "Microsoft Internet Explorer" ) {
	 		target.style.left =  x + "px";
	 		target.style.top =  y + "px";
	 	}
	}

	this.getXY = function ( info ) {
		var p = {x : info.x , y: info.y };
		browserWindowSize();
		var bw = BrowserWindow;
		
		if( info.halign ) {
			if( info.halign == "center" ) {
				p.x = ( bw.width - info.width ) / 2;
			} else if ( info.halign == "left" ) {
				p.x = 0;
			} else if ( info.halign == "right" ) {
				p.x = bw.width - info.width;
				 
			}
		}
		if( info.valign ) {
			if ( info.valign == "middle" ) {
				p.y = ( bw.height - info.height) / 2;
			} else if (  info.valign == "bottom" ) {
				p.y = bw.height - info.height;
			} else if ( info.valign == "top" ) {
				p.y = 0;
			}
		}
	 
		
		var vpx = CreativaSystem.validatePercent ( info.x ) ;
		var vpy = CreativaSystem.validatePercent ( info.y ) ;
		
		if( (!info.halign || info.halign == "" ) && vpx.isPercent  ) {
			var xratio = vpx.value / 100;
			//p.x = ( bw.width   ) * xratio;	 
			p.x = ( bw.width - info.width ) * xratio;
	 	} 
		
		if( (!info.valign || info.valign == "") && vpy.isPercent   )  {
			 
			var yratio = vpy.value / 100;
			//p.y = ( bw.height  ) * yratio;
			p.y = ( bw.height - info.height ) * yratio;
		}
		return p;
	}
	 
	this.validatePercent = function ( num ) {
		 
		var vp = { isPercent: false , value: num } ;
		var nstr = "" + num + " ";
		 
		
		if( nstr.indexOf("%") != -1 ) {
			vp.isPercent = true;
			vp.value =  nstr.replace("%", "" )  ;
		}
		
		 
		return vp;
	}
	 
	
	this.getMouseXY  = function ( e ) {
		var ostr = "", pr = "";
		var mouse = new Object();
	 	browserWindowSize();
	  	if( BrowserWindow.type == "IE" ) {
	  		mouse.x =  window.event.clientX;
	  		mouse.y = window.event.clientY;
	  		for( pr in window.event)  {
	  			ostr += "" + pr  + "=[" + window.event[pr] + "], " ;
	  		}
	  		//jshelper.trace( "String: " + ostr );
	  		
	  	} else {
	  		for( pr in  e)  {
	  			ostr += "" + pr  + "=[" +  e[pr] + "], " ;
	  		}
	  		//jshelper.trace( "String: " + ostr );
	  		mouse.x = e.pageX;
	  		mouse.y = e.pageY;
	  	}
	  	return mouse;
	}
	
	 
	
	this.createMouseCatcher = 	function () {
		
		var size = 20 , color = "#FF0000", alpha = 0.0;
		document.body.onmouseout = function ( e ) {
			var mouse = CreativaSystem.getMouseXY ( e );
		    CreativaSystem.mouseDispatcher( e ) ;
		  	if( mouse.x < size ||  mouse.x  >= BrowserWindow.width  - size ) {
				CreativaSystem.dispatchEvent ( {type: "bodyMouseOut" }  );  		 
		  	} else if( mouse.y < size || mouse.y >= BrowserWindow.height  - size) {
		  	 	CreativaSystem.dispatchEvent ( {type: "bodyMouseOut" }  );
		  	}
		}
		 
		browserWindowSize();
		
		var dleft = new DisplayObject();
		dleft.id = "mouseCatcherLeft";
		dleft.width = size;
		dleft.height = BrowserWindow.height;
		dleft.alpha = alpha;
		dleft.backgroundColor = color;
		dleft = DisplayUtil.toHTMLDom ( dleft );
		document.body.appendChild( dleft );
		
		CreativaSystem.mouseCatcherLeft = dleft;
		
		var dright = new DisplayObject();
		dright.id = "mouseCatcherRight";
		dright.width = size;
		dright.height = BrowserWindow.height;
		dright.x = BrowserWindow.width - dright.width;
		dright.alpha = alpha;
		dright.backgroundColor = color;
		dright = DisplayUtil.toHTMLDom( dright );
		document.body.appendChild( dright );
	 	CreativaSystem.mouseCatcherRight = dright;
	 	
		var dtop = new DisplayObject();
		dtop.id = "mouseCatcherTop";
		dtop.width = BrowserWindow.width;
		dtop.height = size;
		dtop.alpha = alpha;
		dtop.backgroundColor = color;
		dtop = DisplayUtil.toHTMLDom( dtop );
		document.body.appendChild( dtop );
		CreativaSystem.mouseCatcherTop = dtop;
		
		var dbottom = new DisplayObject();
		dbottom.id = "mouseCatcherBottom";
		dbottom.width = BrowserWindow.width;
		dbottom.height = size;
		dbottom.alpha = alpha;
		dbottom.y = BrowserWindow.height - dbottom.height;
		dbottom.backgroundColor = color;
		dbottom = DisplayUtil.toHTMLDom( dbottom );
		document.body.appendChild( dbottom );
	
		CreativaSystem.mouseCatcherBottom = dbottom;
		
		
		var trigger = "onmouseout";
		
		CreativaSystem.mouseDispatcher = function ( e ) {
			var mouse = CreativaSystem.getMouseXY ( e );
			if( mouse.x < size ||  mouse.x  >= BrowserWindow.width  - size ) {
				CreativaSystem.dispatchEvent ( {type: "bodyMouseOut" }  );  		 
		  	} else if( mouse.y < size || mouse.y >= BrowserWindow.height  - size) {
		  	 	CreativaSystem.dispatchEvent ( {type: "bodyMouseOut" }  );
		  	}
		}
		
		dleft[trigger] = CreativaSystem.mouseDispatcher;
		dright[trigger] = CreativaSystem.mouseDispatcher;
		dtop[trigger] = CreativaSystem.mouseDispatcher;
		dbottom[trigger] = CreativaSystem.mouseDispatcher;
		
		
		var resizer = new Object() ;
		
		resizer.resizeCallback = function (  bounds )  {
			 
			CreativaSystem.resizeDOM ( dleft ,  size , BrowserWindow.height ) ;
			CreativaSystem.resizeDOM ( dright ,  size , BrowserWindow.height ) ;
			CreativaSystem.positionDOM ( dright ,  BrowserWindow.width - size ,  0) ;
			
			CreativaSystem.resizeDOM ( dtop ,  BrowserWindow.width , size ) ;
			CreativaSystem.resizeDOM ( dbottom ,  BrowserWindow.width , size ) ;
			CreativaSystem.positionDOM ( dbottom , 0 ,  BrowserWindow.height - size) ;
		}
		
		CreativaSystem.addEventListener( "windowResize", resizer , "resizeCallback" ) ;
		
	}
	
}

var CreativaSystem = new CreativaSystem_constructor();


/*
################################ CreativaSystem ####################################
################################ CreativaSystem ####################################
################################ CreativaSystem ####################################
*/

function DelegateUtil_constructor ()  {
	this.create = DelegateUtil_create;
}


function DelegateUtil_create( objectInstance , methodName ) {
	
	var _delegate = function  ( params ) {
			objectInstance [ methodName ] ( params ) ;
	}
	return _delegate; 
}

var DelegateUtil = new DelegateUtil_constructor();
 


/*
 * DisplayObject Block
 */
 
 //DisplayObject constructor
function DisplayObject() {
 	this.x = 0;
 	this.y = 0;
 	this.alpha = null;
 	this.width = 0;
 	this.height = 0;
 	this.tagType = "div";
 	this.name = null;
 	this.position = "absolute";
 	 this.positionType = "pixel";
 	this.id = null;
 	this.backgroundColor = null;
}
 
 
 
 /*
  *End of DisplayObject Block
  */ 
  

 
 function ObjectUtil_constructor () {
 	this.clone = ObjectUtil_clone_method;
 }
 
 
 function ObjectUtil_clone_method( source )  {
 	var cloned = new Object();
 	for( var i in source ) {
 		cloned[i] = source[i];
 	}
 	return cloned;
 }
 
 
var ObjectUtil = new ObjectUtil_constructor();


/*
 *The succeeding block contains all the DisplayUtil methods
 */
 
 
 
 /*
 * DisplayUtil
 */
 
// DisplayUtil constructor
 
function DisplayUtil_constructor () {
	//register all display util methods and properties
	
	this.init = DisplayUtil_init; 
	this.toHTMLDom = DisplayUtil_toHTMLDom;
	this.alignContainer = DisplayUtil_alignContainer_method;
	
}
 
 
 
 function DisplayUtil_init() {
 	 this.htmlBody = document.body;
 	
 }
 
 
 // converts DisplayObject to HtmlDocument
 

 
 function DisplayUtil_toHTMLDom( display ) {
 	var htmlDom = document.createElement( display.tagType ) ;
  
 	htmlDom.setAttribute("id" , display.id );
 	//styles
 
 	htmlDom.style.position = display.position;
 	htmlDom.style.pixelWidth = display.width;
 	htmlDom.style.pixelHeight =  display.height;
 	
  
 	htmlDom.style.pixelLeft = display.x;
 	htmlDom.style.pixelTop = display.y;
  
 	
 	 
 	if( display.backgroundColor != null ) {
 		htmlDom.style.backgroundColor = display.backgroundColor;
 	}
 	
 	if( navigator.appName != "Microsoft Internet Explorer" ) {
 	 
 		htmlDom.style.left = display.x + "px";
 		htmlDom.style.top = display.y + "px";
 		 
 		
 		htmlDom.style.width = display.width + "px";
 		htmlDom.style.height = display.height + "px";
 		
 		if( display.alpha != null ) {
 			htmlDom.style.MozOpacity = display.alpha;
  			htmlDom.style.opacity = display.alpha;
 		}
 		
 		
 	} else {
 		
 		if( display.alpha != null ) {
 			var iealpha = "alpha( opacity=\"" + (display.alpha * 100)+ "\")";
 			htmlDom.style.filter  = iealpha;
 		}
 		
 	}
 	
 	return htmlDom;
 }
 
 
 
 function DisplayUtil_alignContainer_method ( halign, valign, display ) {
	
	if( halign != null ) {
		if( halign == "center" ) {
			display.x = ( BrowserWindow.width - display.width ) / 2;
		} else if( halign == "left" ) {
			display.x = 0;
		} else if( halign == "right" ) {
			display.x = BrowserWindow.width - display.width;
		}		
	}
	
	if( valign != null ) {
		if( valign == "middle" ) {
			display.y = ( BrowserWindow.height  - display.height ) / 2;
		} else if( valign == "bottom" ) {
			display.y = BrowserWindow.height - display.height; 
		} else if( valign == "top" ) {
			display.y = 0;
		}		
	}
}
 
 
//create an instance of DisplayUtil to act like static class
var DisplayUtil = new DisplayUtil_constructor();

/*
 *End Block for DisplayUtil methods
 */
 



/*
 * Succeeding block contains CreativePlayer implementation
 */
 
 
 /** 
 *************************************************************************************
 *************************************************************************************
 *************************************************************************************
 */
 
function CreativaPlayer_loadPlayer_method( config  ) {
	 
	//configurationURL is the url that contains the xml configuration file
	this.configurationURL = config;
	DisplayUtil.init();
 	this.config = config;
  	this.displayVideo();
} 

 
 
// display the swf creativa player

 
function CreativaPlayer_alignContainer_method ( halign, valign, display ) {
	var info = new Object();
	info.halign = halign;
	info.valign = valign;
	info.width = display.width;
	info.height = display.height;
	info.x = display.x;
	info.y = display.y;
	var p = CreativaSystem.getXY ( info ) ;
 	display.x = p.x;
	display.y = p.y;
}
  
  
function CreativaPlayer_displayVideo_method() {
 	
	//dynamically create display
     
	
	var ccon = new DisplayObject();
	ccon.id = this.config.containerId;
	ccon.position = this.config.position;
	
	ccon.width = this.config.width;
	ccon.height= this.config.height;
	
 	ccon.x = this.config.x;
	ccon.y = this.config.y;
	
	this.alignContainer ( this.config.halign, this.config.valign, ccon ) ;
	 
	if( this.config.backgroundColor != null || this.config.backgroundColor != "" ) {
		ccon.backgroundColor =  this.config.backgroundColor;
	} else {
		ccon.backgroudnColor = null;
	}
	 
	var containerDom = DisplayUtil.toHTMLDom( ccon );
	document.body.appendChild ( containerDom ) ;
	
	 
	var attrs = this.config.embedAttributes ;
	attrs.flashVars += "&cpid=" + this.cpid +  "&persistentFLV=" + this.persistentFLV;
	FlashWrapper.embed ( ccon.id , this.config.flashId,  this.config.swfurl, attrs );
}

 
function CreativaPlayer_jshelperCallback ( data ) {
  
	var player = CreativaFactory.getPlayer( data.cpid );
	player.xmlLoaded ( data ) ;
}

 
 
// CreativaPlayer constructor and attach all the neccessary methods

function CreativaPlayer_hideVideo_method(   )  {
 	var config = this.config;
 	FlashWrapper.remove ( config.flashId );
	var container = document.getElementById( config.containerId);
	container.parentNode.removeChild( container );

}

 
function CreativaPlayer_constructor ( cpid ) {
	
	this.persistentFLV = null;
	this.isVideo = true;
	
	this.name = "CreativaPlayer";
	this.cpid = cpid;
	// attach all the methods to CreativePlayer
	 
	this.loadPlayer = CreativaPlayer_loadPlayer_method;
	  
	this.alignContainer = CreativaPlayer_alignContainer_method;
	 
	this.displayVideo =  CreativaPlayer_displayVideo_method;
	this.hideVideo = CreativaPlayer_hideVideo_method;
	 
	 
	
	this.client = new Object();
	this.client.callback = null  ;
	//create all properties of CreativePlayer
	this.browser = new Object();
	this.browser.name = navigator.appName;;
	this.browser.version = navigator.appVersion;
	
	this.config  = new Object();
	
}
 
/*
 * End block for CreativePlayer implementation
 */

/** CreativaFacotory
 *************************************************************************************
 *************************************************************************************
 *************************************************************************************
 */

function CPlayerFactory_createPlayer_method() {
	 
	this.playerCount++;
	var player = new CreativaPlayer_constructor(this.playerCount);
	this.playerlist[ "player" + this.playerCount ] = player;
	return player;
	 
}
 
function CPlayerFactory_getPlayer_method( cpid ) {
	return this.playerlist[ "player" + cpid ];
}

function CPlayerFactory_getPlayers_method() {
	return this.playerlist;
}

function CPlayerFactory_constructor() {
	//Remove Firefox Dotted Border
	//swfobject.createCSS( "object" , "outline:none;" );
	this.playerCount = 0;
	this.playerlist = new Object();
	this.getPlayer =  CPlayerFactory_getPlayer_method;
	this.getPlayers = CPlayerFactory_getPlayers_method;
	this.createPlayer = CPlayerFactory_createPlayer_method;
}

var CreativaFactory =  new CPlayerFactory_constructor();

/**************************************************************************************
 *************************************************************************************
 *************************************************************************************
 * ExternalInterface Implementaton Block starts here
 */

function getSWF( movieName ) {
 	if (navigator.appName.indexOf("Microsoft") != -1) {
         return window[movieName];
    } else {
         return document[movieName];
    } 
}


// to invoke flash just invoke this method on javascript
function invokeFlash( player , type , params ) {
	
	var flashId = player.config.attributes.id;
	//alert("invoking: " + flashId +  " type: " + type ) ;
	var flashName = player.config.attributes.name;
	var swf = getSWF  ( flashId );
	swf.flashGateway ( type , params );
	//alert("invoke Flash: " + type ) ;
	
}

// this function will serves as a gateway  for interfacing flash with javascript

function resizeContainerVideo( player ,   width, height)  {
	 
	var config = player.config;
	var eswf = getSWF ( config.flashId ) ;
	var divcon = document.getElementById( config.containerId  );
	
	config.width = width;
	config.height = height;
	CreativaSystem.resizeDOM (  divcon, width , height );
	
	if(navigator.appName.indexOf("Microsoft") != -1) {
		eswf.style.width = width;
		eswf.style.height = height;
	} else  {
		eswf.width = width;
		eswf.height =height;
	}
	
	var info = new Object();
	info.width = width;
	info.height = height;
	 
	if( player.isVideo  == true ) {
	  
	  
	  	info.x = config.x;
	  	info.y = config.y;
	  	info.halign = config.halign;
	  	info.valign = config.valign;
	 		
	 } else if( player.isVideo == false ) {
    
   		info.x = config.playVideoX;
   		info.y = config.playVideoY;
   		info.halign = config.playVideoHAlign;
   		info.valign = config.playVideoVAlign;
   		 
	 }
	 
	 var point = CreativaSystem.getXY( info ) ;
	 CreativaSystem.positionDOM ( divcon , point.x , point.y ) ; 
}

 

function alignPlayer ( player ) {
	var point, xpercent, ypercent ;
	var info = new Object();
	var config = player.config;
	try {
		var divcon = document.getElementById (  config.containerId  );
	} catch (err ) {
		return;
	}
	 
	if( player.isVideo  == true ) {
	  
	  	info.width = config.containerWidth;
	  		 
	  	info.height = config.containerHeight;
	  	info.x = config.containerX;
	  	info.y = config.containerY;
	  	info.halign = config.containerHorizontalAlign;
	  	info.valign = config.containerVerticalAlign;
	 		
	 } else if( player.isVideo == false ) {
   		
   		info.width = config.playVideoWidth;
   		info.height = config.playVideoHeight;  
   		info.x = config.playVideoX;
   		info.y = config.playVideoY;
   		info.halign = config.playVideoHAlign;
   		info.valign = config.playVideoVAlign;
   		 
	 }
	  
	 point = CreativaSystem.getXY( info ) ;
	 
	 CreativaSystem.positionDOM ( divcon , point.x , point.y ) ;
	 
}
 
function javascriptGateway (  type , params  ) {
	 
	 var cplayer = CreativaFactory.getPlayer( params.cpid ) ;
	
	 switch( type ) {
		
		case "resizeContainer":
			resizeContainerVideo ( cplayer,    params.width , params.height ) ;			
		break;
		
		case "isReady":
			 invokeFlash ( cplayer,  "jsReady", params ) ;
		break;
		 
		case "closePlayer":
		  	cplayer.hideVideo();   
		break;
	 	
	 	case "playAgain":
	 		resizeContainerVideo ( cplayer,    params.width , params.height ) ;	
	 		
	 	break;
	 	
	 	case "showPlayAgain":
	 	
	 		resizeContainerVideo ( cplayer, cplayer.config.playAgainWidth, cplayer.config.playAgainHeight );
	 	
	 	break;
	 	
	 	
		case "clientGateway":
			if( cplayer.client != null && cplayer.client.callback != null ) {
			 	cplayer.client.callback( params ) ;
			}
		break;
	 
	}
	
}

function verifySession (  info  ) {
	 
	var cplayer = CreativaFactory.getPlayer( info.cpid ) ;
	 
	if( cplayer ) {
		
		var cookie = CookieUtil.getCookieByName( info.cookieName );
		 
		if( cplayer.fromPlayAgain == true ) {
			cplayer.fromPlayAgain = false;
			return true;
		}
		
		if ( cookie.value == null ) {
			 	CookieUtil.insert ( info.cookieName , "on" ) ;
		} else {
			if( cookie.name == info.cookieName && cookie.value == "on" ) {
			 	swfobject.removeSWF ( info.flashId ) ;
		  		var e = document.getElementById( info.containerId  );
		   		CreativaSystem.resizeDOM ( e, 10,10);
				return false;
			}  
		}
	}
	
	return true;
}
 
function creativaUnload() {
	 CreativaSystem.dispatchEvent( { type: "windowUnload" } ) ;
	 var players = CreativaFactory.getPlayers();
	 for( var i in players ) {
	 	var cplayer = players[i];
	 	var p = new Object();
	 	
	 	invokeFlash ( cplayer,  "endSession", p  ) ;
	 }
	 
}
  
function creativaResize() {
	
	 browserWindowSize();
	 CreativaSystem.dispatchEvent( { type: "windowResize" , width: BrowserWindow.width , height: BrowserWindow.height } ) ;
	 var players = CreativaFactory.getPlayers();
	
	 for( var i in players ) {
	 	var cplayer = players[i];
	 	var p = new Object();
	 	 
	 	 alignPlayer( cplayer );
	 }
	 
}

window.onunload = creativaUnload;
window.onresize = creativaResize;
 
CreativaSystem.initialize = function () {
	CreativaSystem.createMouseCatcher();
} 
 