/**
* @Description
* This file will create a class called VideoIntro. It's used to control
* the work flow of video introduction on home page, account home and why join us.
* Once you want to use this, you need to create a new object named videoIntro of this class.
* And at the same time declare the video path and skip type of it. Then call playVideoIntro.
* @Author rui_zhang
* @Created 2007-11-16
* @Company Infolexllc
* @Copy Right 2007
*/
/**
* Define attributes of Video Intro
*/
function VideoIntro(videoPath,skipType,videoLeft,videoTop) {
	//this is the left of the video intro div
	this._videoLeft=videoLeft;
	//this is the top of the video intro div
	this._videoTop=videoTop;
 	//this is the path of video on current page
 	this._videoPath=videoPath;
 	//this  is the type code of the page position. It can be 0,1,2,3 for now.
 	this._skipType=skipType;
 	//this is the debug switch
 	this._debug=false;
 	//this is the id of video intro div
 	this._viDivId="viDiv";
 	//this is the id of video intro object
 	this._viObjectId="viObject";
 	//this is the code of video intro object
 	this._introObjectCode=
	'<object id=\"'+this._viObjectId+'\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"336\" height=\"280\" id=\"flvplayer\" align=\"middle\">'
	+'<param name=\"allowScriptAccess\" value=\"sameDomain\" />'
	+'<param name=\"movie\" value=\"/efp/flash/efpflvplayer.swf?file='+this._videoPath+'\" />'
	+'<param name=\"menu\" value=\"false\" />'
	+'<param name=\"quality\" value=\"high\" />'
	+'<param name=\"wmode\" value=\"transparent\">  '
	+'<embed src=\"/efp/flash/efpflvplayer.swf?file='+this._videoPath+'\" menu=\"false\" quality=\"high\" bgcolor=\"#ffffff\" width=\"336\" height=\"280\" name=\"flvplayer\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" wmode=\"transparent\" />'
	+'</object>'; 	
 	//this is the code of video intro div
 	//this._introDivCode="<div id=\""+this._viDivId+"\" style=\"position:relative;left: 540px; top: 210px;width:336px;height:280px;border:1px solid #1465AD;z-index:1000;\">"+this._introObjectCode+"</div>";	
}
/**
* Define the functions of Video Intro
*/
VideoIntro.prototype = {
	/**
	* Play the video introduction
	*/
	playVideoIntro:function(){
		if(this._videoPath && this._skipType){
			if(this._debug){
				alert("Got videoPath and skip type to play video. _videoPath:"+this._videoPath+"	_skipType:"+this._skipType);
			}
			var viDiv=document.getElementById(this._viDivId);
			if(viDiv){
				if(this._debug){
					alert("We had div with id "+this._viDivId+" already.");
				}
				this.hideIntro();
				//create the div for video introduction
				viDiv.style.display="block";
				viDiv.innerHTML=this._introObjectCode;
			}else{
				//create the div for video introduction
				var viDiv = document.createElement('div');
		        viDiv.id = this._viDivId;
		        //style #viDiv{position:absolute;width:336px;height:280px;border:1px solid #1465AD;}
		        viDiv['style']['left']=this._videoLeft;
		        viDiv['style']['top']=this._videoTop;
		        if(browerType.isFirefox){
		        	  viDiv['style']['overflow']='auto';	
		        }
		        document.body.appendChild(viDiv); 
		        viDiv.innerHTML=this._introObjectCode;		
			}			
		}else{
			if(this._debug){
				alert("The video path or skip code is null. _videoPath:"+this._videoPath+"	_skipType:"+_skipType);
			}
		}
		//do an ajax call to update cookie to none
		doPost(contextpath+'/videointro.do?operation=play&skiptype='+this._skipType,'','',true);	
	},
	/**
	* Skip the video introduction
	*/
	skipVideoIntro:function(){
		//remove the video intro object from the video intro div
		//do an ajax post to video action, tell it get ready to show the skip message of current skip type	
		doPost(contextpath+'/videointro.do?operation=skip&skiptype='+this._skipType,'',this._viDivId,true);	
	},
	/**
	*
	*/
	finishVideoIntro:function(){
		//do an ajax post to video action, tell it it the video introduction has finished. Pass the skipType=0 to it.
		doPost(contextpath+'/videointro.do?operation=finish&skiptype='+this._skipType,'',this._viDivId,true);		
	},
	/**
	* Remove the video intro object from video intro div
	*/
	_removeVIObject:function(){
		var viObject=document.getElementById(this._viObjectId);
		if(viObject){
			viObject.parentNode.removeChild(viObject);
		}else{
			if(this._debug){
				alert("I can't find the video intro object on this page.");
			}
		}
	},
	/**
	* Remove the video intro div from video intro div
	*/	
	hideIntro:function(){
		var viDiv=document.getElementById(this._viDivId);
		if(viDiv){
			viDiv.style.display="none";
		}else{
			if(this._debug){
				alert("I can't find the video intro div on this page.");
			}
		}
	}
}

function finish(){
		videoIntro.finishVideoIntro();
}

function skipShow(){
		videoIntro.skipVideoIntro();
}

function playIntro(){
		videoIntro.playVideoIntro();	
}

var videoIntro;

function getVideoIntro(flvPath,skipType,videoLeft,videoTop){
	videoIntro=new VideoIntro(flvPath,skipType,videoLeft,videoTop);
	return videoIntro;
}

function  SetCookie(name,  value)
//set cookie value
{
	var  expdate  =  new  Date();
	var  argv  =  SetCookie.arguments;
	var  argc  =  SetCookie.arguments.length;
	var  expires  =  (argc  >  2)  ?  argv[2]  :  null;
	var  path  =  (argc  >  3)  ?  argv[3]  :  null;
	var  domain  =  (argc  >  4)  ?  argv[4]  :  null;
	var  secure  =  (argc  >  5)  ?  argv[5]  :  false;
	if(expires!=null)  expdate.setTime(expdate.getTime()  +  (  expires  *  1000  ));
	document.cookie  =  name  +  "="  +  escape  (value)  +((expires  ==  null)  ?  ""  :  (";  expires="+  expdate.toGMTString()))
	+((path  ==  null)  ?  ""  :  (";  path="  +  path))  +((domain  ==  null)  ?  ""  :  (";  domain="  +  domain))
	+((secure  ==  true)  ?  ";  secure"  :  "");
}
function  DelCookie(name)
//remove cookie
{
	var  exp  =  new  Date();
	exp.setTime  (exp.getTime()  -  1);
	var  cval  =  GetCookie  (name);
	document.cookie  =  name  +  "="  +  cval  +  ";  expires="+  exp.toGMTString();
}
function  GetCookie(name)
//get value of cookie
{
	var  arg  =  name  +  "=";	
	var cookies  =  document.cookie.split(";");
	var argIndex=-1;
	for  (var i=0;i<cookies.length;i++)
	{
		argIndex=cookies[i].indexOf(arg);
		if  (argIndex>-1)
		return  cookies[i].substr(argIndex+arg.length);
	}
	return  null;
}
