// JavaScript Document
var LogoStartLeft = 0;   //left:310px;
var LogoWidth =  0;    //width:260px;
var LogoStartTop = 0;  //top:10px;
var LogoHeight = 0;  //height:436px;

var LogoEndTop = 67;
var LogoEndLeft = 77;
var to=0;
var opacity=0;
var flagFading=0;		// This Flag is used to Eliminate the twice fedding effect of Button

/*	
var myimages5 = new Array();
	function preloading5(){
		for (x=0; x<preloading5.arguments.length; x++){
		myimages5[x] = new Image();
		myimages5[x].src = images/preloading5.arguments[x];
		}
	}
*/
	
	
	function Init()
	{
			main_init();
			applyPropertyToElement('LogoImageDiv',LogoStartTop,LogoStartLeft,LogoHeight,LogoWidth);
			applyPropertyToElement('backGroundDiv',backGroundDivStartTop,backGroundDivStartleft,backGroundDivStartHeight,backGroundDivStartWidth);

	}

	function getNumericVal(val)
	{
	  var arr = new Array();
	  arr = val.split("px");
	  return parseInt(arr[0]);
	}
	
function main_initAnime() {
	
    anime = {elemID:"", 
			 xStart:0, 
             yStart:0, 
             xTarg:0, 
             yTarg:0, 
			 left:0,
			 top:0,
			 width:0,
			 height:0,
			 vel:1,
             interval:null
            };
}



function main_init(){
//PigAPopnLogo
LogoStartLeft = getNumericVal(document.getElementById('LogoImageDiv').style.left);   //left:310px;
LogoWidth =  getNumericVal(document.getElementById('LogoImageDiv').style.width);    //width:260px;
LogoStartTop = getNumericVal(document.getElementById('LogoImageDiv').style.top);  //top:10px;
LogoHeight = getNumericVal(document.getElementById('LogoImageDiv').style.height);  //height:436px;


  	main_initAnimation('LogoImageDiv',LogoStartLeft , LogoStartTop ,LogoEndLeft ,LogoEndTop ,10);
  //  alert("StartTop = "+PigAPopnLogoStartTop);
}


function main_initAnimation(elemID, startX, startY, endX , endY , speed) {
	//alert(5645656);		

	main_initAnime();
	// alert("startX = "+startX+"endX = "+endX);
 //  alert("startY = "+startY+"endY = "+endY);
	anime.elemID = elemID;
	
    anime.xStart = startX ;  //-61     
    anime.yStart = startY ;      
    anime.xTarg = endX;    
    anime.yTarg = endY;   
	
	anime.vel = (speed) ? speed : 1;
	 
    // set element's start position

    document.getElementById(elemID).style.left = anime.xStart ;   
    document.getElementById(elemID).style.top = anime.yStart ;  
	var yStep = -2 * anime.vel;
	
	
	anime.interval = setInterval("main_doAnimation()",1);
	
	
}
opacity=0;
function fadeInMyNumoLogo(){
	fadeLogo=setInterval("fadelogoAni()",10);
}
	
function fadelogoAni(){
	opacity+=0.005;
	document.getElementById('LogoImageDiv').style.opacity=opacity;
	if(opacity>=1) { clearInterval(fadeLogo); opacity=0;}

}

function loading()
{
	document.getElementById('LogoImageDiv').style.opacity=0;
	fadeInMyNumoLogo();
	setTimeout("document.getElementById('logoBackground').style.display='';document.getElementById('logoLoading').style.display='';document.getElementById('LoadingBar').style.display='';", 100 );
	animateLoadGame();
}

function animateLoadGame(){
		tout=setInterval("ani()",300);
}
opacity=0;	
function ani(){
	++to;
	document.getElementById('LoadingBar').innerHTML+="<img src='images_splash/LoadingBall.gif' STYLE='position:relative;margin-top:2;margin-left:3;'>";	
	if(to>9) { clearInterval(tout); Init(); 
	document.getElementById('logoBackground').style.display='none';
	document.getElementById('logoLoading').style.display='none';
	document.getElementById('LoadingBar').style.display='none';
	}

}
opacity=0;
function fadeInButtons(){
	flagFading=1;
	document.getElementById('playButon').style.opacity=0;
	document.getElementById('moreGamesButon').style.opacity=0;
	document.getElementById('instructionsButon').style.opacity=0;
	document.getElementById('highScore').style.opacity=0;

	document.getElementById('playButon').style.display='';
	document.getElementById('moreGamesButon').style.display='';
	document.getElementById('instructionsButon').style.display='';
	document.getElementById('highScore').style.display='';

	fade=setInterval("fadeAni()",20);
}
	
function fadeAni(){
	opacity+=0.02;
	document.getElementById('playButon').style.opacity=opacity;
	document.getElementById('moreGamesButon').style.opacity=opacity;
	document.getElementById('instructionsButon').style.opacity=opacity;
	document.getElementById('highScore').style.opacity=opacity;
	if(opacity>=1) {opacity=1; clearInterval(fade); }

}


function main_doAnimation() {
		document.getElementById('LogoImageDiv').style.display='';

	
	//for(i=anime.yStart;i>=anime.yTarg;i--)
	if(anime.yStart >= anime.yTarg)
	{
		var y = anime.yStart;
		var x = anime.xStart;
		
		//alert("x="+x+"y="+y);
		document.getElementById(anime.elemID).style.left = x ;   
        document.getElementById(anime.elemID).style.top = y ;  
		
		
		anime.yStart = anime.yStart - 10;  // to increase the speed of GAME LOGO on splash screen reduce the value of anime.yStart
		//document.getElementById("PigAPopnSplash").innerHTML="<h4><font color=#FFFFFF>"+currentLevel+"</font></h4>";
	}
	else{
		document.getElementById(anime.elemID).style.left = anime.xTarg ;
    	document.getElementById(anime.elemID).style.top = anime.yTarg;
        clearInterval(anime.interval);
		if(flagFading==0)
		{
		fadeInButtons();;
		}
	}
}
function applyPropertyToElement(id,ntop,nleft,nheight,nwidth,nbackgouundimg)
  {
	  if(ntop)
		document.getElementById(id).style.top = ntop;
	  if(nleft)
		document.getElementById(id).style.left = nleft;
	  if(nheight)
		document.getElementById(id).style.height = nheight;
	  if(nwidth)
		document.getElementById(id).style.width = nwidth;
		//alert('top = '+ntop+' left = '+nleft+' height = '+nheight+' width = '+nwidth);
  }	
 