var Flash_ID = 1 ;
var PromoMovieName = "";
var vTopMargin = 0;
var vLeftReletive = 2;
var ResultPromoMovieUpDown = 0;
var ResultPromoMovieLeftRight = 0;
var MovePromoJumps = 4;
var ShowPromoLoopLeftRight;
var ShowPromoLoopUpDown;
var IsPromoMovingUpDown = false;
var IsPromoMovingLeftRight = false;
var ActiveFlash = "";

function SetActiveFlash(FlashId)
{
	ActiveFlash = FlashId;
}

function PlayFlash(Movie_Source,Movie_ID,Movie_Style)
{
	var Text="";
	if (typeof(Movie_Source))
	{
		var MovieSrc;	
		var MovieID;
		var MovieStyle	
		
		MovieSrc=Movie_Source;
		
		if (!Movie_ID || Movie_ID=="")
		{
			MovieID = "Movie_" + Flash_ID;
			Flash_ID ++;
		}	
		else
		{
			MovieID = Movie_ID;
		}
		
		if (!Movie_Style || Movie_Style=="")
		{			
			MovieStyle = "";
		}	
		else
		{
			MovieStyle = Movie_Style;
		}
		
		Text = Text + "<object style='" + MovieStyle + "' onMouseOver='SetActiveFlash(" + '"' +  MovieID + '"' + ")' ID='" + MovieID + "' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' VIEWASTEXT>";			
		Text = Text + "<PARAM NAME='MOVIE' value='"+ MovieSrc + "' />";
		Text = Text + "<param name=wmode value='transparent' />";	
		Text = Text + "<param name='MouseEventsEnabled' value='1' />";
		Text = Text + "<PARAM NAME='QUALITY' VALUE='high' />";
		Text = Text + "<PARAM NAME='SCALE' VALUE='SHOWALL' />";
		Text = Text + "<param name='allowScriptAccess' value='always'  />";
		Text = Text + "<embed src='" + MovieSrc + "' name='" + MovieID + "' AllowScriptAccess='always'";
		Text = Text + "quality=high swLiveConnect=true";		
		Text = Text + " pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'";
		Text = Text + "  wmode='transparent' style='" + MovieStyle + "'>";
		Text = Text + "  </embed>";	
		Text = Text + "</object>";
		
		//alert(Text);
	
		
	}	
	else
	{
		Text = "Function 'PlayFlash' not set ! <b>Please</b> send the correct parameters";
	
		
	}
	
	return Text;	
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
  }
function getShockwaveVersion()
{
			//EE
			for(var i=11; i>7; i--){
				try{
					var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
					return i;
				}
				catch(e){}
			}

			//FF
		  for (i=0; i<navigator.plugins.length; i++)
		  {
		      if ((navigator.plugins[i].description.indexOf("Shockwave") != -1))
		        { 
		        return parseInt(navigator.plugins[i].description.substring(navigator.plugins[i].description.indexOf(".") - 2));
		        } 
		   }
		   return 0;
}

function CloseFlash()
{	
        var parent = document.getElementById(ActiveFlash).parentNode.parentNode;
		parent.parentNode.removeChild(parent);
}


function Play_Flash(Element,Text)
{	
	document.getElementById(Element).innerHTML = Text;
}

function PlayPromo(CookieName,MovieContainerElementId,PromoName,PromoSrc,PromoType,PromoStyle,CookieExpires)
{		
		if (document.cookie.indexOf(CookieName) != -1 && GetCookie(CookieName) == "true" )
		{			
				SetCookie(CookieName,"false",CookieExpires,"false",null);					
				if (PromoType == 1)
					{	
					
						PlayMovingFlashMovie(MovieContainerElementId,PromoName,PromoSrc,PromoStyle);
					}				
		}			
}	

function PlayMovingFlashMovie(MovieContainerElementId,MovieName,MovieSrc,MovieStyle)
{	
	 var size=0; 			 					 
     
	 Play_Flash(MovieContainerElementId,PlayFlash(MovieSrc,MovieName,MovieStyle));	 			

	 PromoMovieName = MovieName;	 
	 vLeftReletive = 2;
	 ResultPromoMovieLeftRight = size;	 	 
	 
	 window.addEvent("resize",MovePromoMovie); 
	 window.addEvent("scroll",MovePromoMovie); 
	 
}

function MoveMovieSlow_UpDown()
{    
	if (document.getElementById(PromoMovieName))	
	{
	    var UpperMargin = 0 ;
		var BroswerScrollTop = getScrollTop();
		
		UpperMargin = BroswerScrollTop + vTopMargin ;				
		
		
		// Going Down
		if (UpperMargin>ResultPromoMovieUpDown)
		{					
			if (UpperMargin-ResultPromoMovieUpDown > MovePromoJumps)		
			{
				document.getElementById(PromoMovieName).style.top = (ResultPromoMovieUpDown + MovePromoJumps) + "px" ;					
				ResultPromoMovieUpDown += MovePromoJumps; 
			}	
			else
			{			    
				document.getElementById(PromoMovieName).style.top = UpperMargin + "px";
				ResultPromoMovieUpDown = UpperMargin;
			}	
			 		
		}
		// Going Up
		else
		{			
			if (ResultPromoMovieUpDown - UpperMargin > MovePromoJumps)		
			{
				document.getElementById(PromoMovieName).style.top = (ResultPromoMovieUpDown - MovePromoJumps) + "px";	
				ResultPromoMovieUpDown -= MovePromoJumps; 
			}	
			else
			{
				document.getElementById(PromoMovieName).style.top = UpperMargin + "px" ;
				ResultPromoMovieUpDown = UpperMargin ;
			}			
		
		}	
		
		UpperMargin += "px"; 
		
		if (document.getElementById(PromoMovieName).style.top == UpperMargin)
		{   
			clearInterval(ShowPromoLoopUpDown);
			IsPromoMovingUpDown = false;
		}	
		
	}			
}







function MoveMovieSlow_LeftRight()
{
	
	if (document.getElementById(PromoMovieName))	
	{
		var LeftMargin = 0 ;
		var browserLeft =0;
		var vLeftMargin;
			
		vLeftMargin = parseInt((document.body.clientWidth-(document.getElementById(PromoMovieName).style.width).split("px")[0])/vLeftReletive) ;
			
		browserLeft = document.body.scrollLeft;
				
		LeftMargin =  vLeftMargin + browserLeft	;	
		
		// Going Right
		if (LeftMargin>ResultPromoMovieLeftRight)
		{		
				
			if (LeftMargin-ResultPromoMovieLeftRight > MovePromoJumps)		
			{
			//	document.getElementById(PromoMovieName).style.left = (ResultPromoMovieLeftRight + MovePromoJumps) + "px";	
				ResultPromoMovieLeftRight += MovePromoJumps; 
			}	
			else
			{
			//	document.getElementById(PromoMovieName).style.left = LeftMargin + "px";
				ResultPromoMovieLeftRight = LeftMargin;
			}	
			 		
		}
		// Going Left
		else
		{
			
			if (ResultPromoMovieLeftRight - LeftMargin > MovePromoJumps)		
			{
			//	document.getElementById(PromoMovieName).style.left = (ResultPromoMovieLeftRight - MovePromoJumps) + "px";	
				ResultPromoMovieLeftRight -= MovePromoJumps; 
			}	
			else
			{
			//	document.getElementById(PromoMovieName).style.left = LeftMargin + "px" ;
				ResultPromoMovieLeftRight = LeftMargin ;
			}			
		
		}		
		
		LeftMargin += "px";
		
		if (document.getElementById(PromoMovieName).style.left == LeftMargin)
				{					
					clearInterval(ShowPromoLoopLeftRight);					
					IsPromoMovingLeftRight = false;				
				}		
	}			
}






function MovePromoMovie()
{		

  if (document.getElementById(PromoMovieName))		
	{
	
		if (!IsPromoMovingUpDown)	
			{			    
				IsPromoMovingUpDown = true;
				ShowPromoLoopUpDown = setInterval(MoveMovieSlow_UpDown,1);				
			}	 
//		if (!IsPromoMovingLeftRight)
//			{
//			
//				IsPromoMovingLeftRight = true;
//				ShowPromoLoopLeftRight = setInterval(MoveMovieSlow_LeftRight,1);
//				
//			}	
	}	
}
