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 = "";

var vScroll = null;

function SetActiveFlash(FlashId)
{
	ActiveFlash = FlashId;
}

function PlayFlash(Movie_Source,Movie_ID,Movie_Style, FlashVar1_Name, FlashVar1_Value, FlashVar2_Name, FlashVar2_Value)
{
	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 + "' />";
		if (FlashVar1_Name & FlashVar1_Value)
		    Text = Text + "<param name=flashvars value='" + FlashVar1_Name +"="+ FlashVar1_Value +"' />";
        else if (FlashVar1_Name & FlashVar1_Value & FlashVar2_Name & FlashVar2_Value)
		    Text = Text + "<param name=flashvars value='" + FlashVar1_Name +"="+ FlashVar1_Value +"&"+ FlashVar2_Name +"="+ FlashVar2_Value +"' />";
		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);

    if ($("HomeBigBanner"))
    {
        $$("#HomeBigBanner div")[0].style.visibility = "visible";
    }
}


function Play_Flash(Element,Text)
{	
    if ($("HomeBigBanner"))
    {
        $$("#HomeBigBanner div")[0].style.visibility = "hidden";
    }
	document.getElementById(Element).innerHTML = Text;
}

function PlayPromo(CookieName,MovieContainerElementId,PromoName,PromoSrc,PromoType,PromoStyle,CookieExpires)
{		
    if(CookieName != "")
    {
		if (document.cookie.indexOf(CookieName) != -1 && GetCookie(CookieName) == "true" )
		{			
				SetCookie(CookieName,"false",CookieExpires,"false",null);					
				if (PromoType == 1)
					{	
					
						PlayMovingFlashMovie(MovieContainerElementId,PromoName,PromoSrc,PromoStyle);
					}				
		}			
	}
	else 
	{
	    PlayMovingFlashMovie(MovieContainerElementId,PromoName,PromoSrc,PromoStyle);
	}
}	

function PlayMovingFlashMovie(MovieContainerElementId,MovieName,MovieSrc,MovieStyle,ToScrole)
{	
	 var size=0; 			 					 
     
	 Play_Flash(MovieContainerElementId,PlayFlash(MovieSrc,MovieName,MovieStyle));	 			

	 PromoMovieName = MovieName;	 
	 vLeftReletive = 2;
	 ResultPromoMovieLeftRight = size;	 	 
	 if(ToScrole == "true")
	 {
	     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)
		{		
		var e = document.getElementById(PromoMovieName);	
			
		if((getPageSizeWithScroll() - (eval(e.parentNode.style.top.replace("px","")) + eval(e.style.height.replace("px","")) + ResultPromoMovieUpDown) - 20) > 0)
		    {	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 ($(PromoMovieName))		
    {
        if (!IsPromoMovingUpDown)	
        {			    
            IsPromoMovingUpDown = true;
            ShowPromoLoopUpDown = setInterval(MoveMovieSlow_UpDown, 1);	
        }	 
    }	
}
function getPageSizeWithScroll()
{     
    if (window.innerHeight && window.scrollMaxY) 
    {// Firefox         
        yWithScroll = window.innerHeight + window.scrollMaxY;         
        xWithScroll = window.innerWidth + window.scrollMaxX;     } 
    else if (document.body.scrollHeight > document.body.offsetHeight)
    {  // all but Explorer Mac         
        yWithScroll = document.body.scrollHeight;         
        xWithScroll = document.body.scrollWidth;     
    } else 
    { // works in Explorer 6 Strict, Mozilla (not FF) and Safari         
        yWithScroll = document.body.offsetHeight;         
        xWithScroll = document.body.offsetWidth;       
    }     
    arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);     
    //alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );     
    return yWithScroll; 
} 
