// JavaScript Document
//Code Generated by Imad El Anis - imad_a@idm.net.lb
// Variable Declaration 
var MyWidth; 		//Add to Width 
var MyHeight; 		// Add to Height 
var MaxWidth; 		// PopIn Width 
var MaxHeight; 		// PopIn Heigth
var Content;		// Content of PopIN
var HowDisplay;		//Way to Show the space of PopIN
var Displayed;		// Test If PopIn Displayed
var Wait; 			//Timer To Display PopIn
var MyEffect;       //Content Effect
var MySpeed;		//Speed Effect
var MyWaiting; 		//Time given by user before display popin
var Padding			//Padding Variable 
var Border          //Border Width

//All transitions effects.
var tranz=new Array()
tranz[0]="Barn(motion='out', orientation='vertical')"
tranz[1]="Barn(motion='in', orientation='vertical')"
tranz[2]="Barn(motion='out', orientation='horizontal')"
tranz[3]="Barn(motion='in', orientation='horizontal')"
tranz[4]="Blinds(bands=1, direction='up')"
tranz[5]="Blinds(bands=1, direction='down')"
tranz[6]="Blinds(bands=1, direction='right')"
tranz[7]="Blinds(bands=1, direction='left')"
tranz[8]="Blinds(bands=10, direction='up')"
tranz[9]="Blinds(bands=10, direction='down')"
tranz[10]="Blinds(bands=10, direction='right')"
tranz[11]="Blinds(bands=10, direction='left')"
tranz[12]="CheckerBoard(squaresX=12, squaresY=10, direction='up')"
tranz[13]="CheckerBoard(squaresX=12, squaresY=10, direction='down')"
tranz[14]="CheckerBoard(squaresX=12, squaresY=10, direction='right')"
tranz[15]="CheckerBoard(squaresX=12, squaresY=10, direction='left')"
tranz[16]="Fade(overlap=1)"
tranz[17]="GradientWipe(motion='reverse', gradientSize=1, wipestyle=1)"
tranz[18]="GradientWipe(motion='forward', gradientSize=1, wipestyle=1)"
tranz[19]="GradientWipe(motion='forward', gradientSize=1, wipestyle=0)"
tranz[20]="GradientWipe(motion='reverse', gradientSize=1, wipestyle=0)"
tranz[21]="Inset()"
tranz[22]="Iris(motion='in', irisStyle='SQUARE')"
tranz[23]="Iris(motion='out', irisStyle='SQUARE')"
tranz[24]="Iris(motion='in', irisStyle='CIRCLE')"
tranz[25]="Iris(motion='out', irisStyle='CIRCLE')"
tranz[26]="Iris(motion='in', irisStyle='PLUS')"
tranz[27]="Iris(motion='out', irisStyle='PLUS')"
tranz[28]="Iris(motion='in', irisStyle='CROSS')"
tranz[29]="Iris(motion='out', irisStyle='CROSS')"
tranz[30]="Iris(motion='in', irisStyle='DIAMOND')"
tranz[31]="Iris(motion='out', irisStyle='DIAMOND')"
tranz[32]="Iris(motion='in', irisStyle='STAR')"
tranz[33]="Iris(motion='out', irisStyle='STAR')"
tranz[34]="Pixelate(enabled='false', maxSquare=50)"
tranz[35]="RadialWipe(wipeStyle='RADIAL')"
tranz[36]="RadialWipe(wipeStyle='CLOCK')"
tranz[37]="RadialWipe(wipeStyle='WEDGE')"
tranz[38]="RevealTrans(transition=21)"
tranz[39]="RevealTrans(transition=22)"
tranz[40]="RandomDissolve()"
tranz[41]="Slide(bands=4, slideStyle='HIDE')"
tranz[42]="Slide(bands=4, slideStyle='PUSH')"
tranz[43]="Slide(bands=4, slideStyle='SWAP')"
tranz[44]="Slide(bands=1, slideSty59le='HIDE')"
tranz[45]="Slide(bands=1, slideStyle='PUSH')"
tranz[46]="Slide(bands=1, slideStyle='SWAP')"
tranz[47]="Spiral(gridSizeX=16, gridSizeY=16)"
tranz[48]="Spiral(gridSizeX=1, gridSizeY=16)"
tranz[49]="Spiral(gridSizeX=16, gridSizeY=1)"
tranz[50]="Spiral(gridSizeX=2, gridSizeY=2)"
tranz[51]="Spiral(gridSizeX=2, gridSizeY=16)"
tranz[52]="Spiral(gridSizeX=16, gridSizeY=2)"
tranz[53]="Stretch(stretchStyle='PUSH')"
tranz[54]="Stretch(stretchStyle='HIDE')"
tranz[55]="Stretch(stretchStyle='SPIN')"
tranz[56]="Strips(motion='leftdown')"
tranz[57]="Strips(motion='leftup')"
tranz[58]="Strips(motion='rightdown')"
tranz[59]="Strips(motion='rightup')"
tranz[60]="Wheel(spokes=20)"
tranz[61]="ZigZag(gridSizeX=16, gridSizeY=16)"
/////////////////////////////////////////////////////
MyWidth = 0; // Default value;
MyHeight = 0;// Defalult Value;
Displayed = false;
/////////////////////////////////////
// Events
window.onscroll = Display;
/////////////////////////////////////

// PopIn Creation
function WritePopIn(Waiting,Width,Height,MyBackground,MyBgColor,Align,How,Effect,speed,content,PaddingIn,PaddingOut,borderStyle,borderWidth,borderColor){
	//Write the PopIN + content + Width + Height
	document.write('<table id="PopPos" align="'+Align+'" cellpadding="'+PaddingOut+'" cellspacing="0"><tr><td><table  id="PopIn" width="0" height="0" border="'+borderWidth+'" bordercolor="'+borderColor+'" cellpadding="'+PaddingIn+'" cellspacing="0" background="'+MyBackground+'" bgcolor="'+MyBgColor+'" style="display:none;border-style:'+borderStyle+';">')
	document.write('<tr style="display:none" id="PopInTR"><td style="border-style:none">');
	document.write('<table width="'+Width+'" height="'+Height+'" border="0" cellpadding="0" cellspacing="0" style="Filter:revealTrans(duration=2);display:none" id="PopInContent">');
	document.write('<tr><td align="left" valign="top">'+content+'</td></tr>')
	document.write('</table>')
	document.write('</td></tr>');
	document.write('</table></td></tr></table>');
	

	HowDisplay = How;       //set How
	MyEffect = Effect;
	MySpeed = speed
	MyWaiting = Waiting;
	Border = borderWidth * 2;
	Padding = (PaddingIn + PaddingOut)*2;
	MaxWidth = Width+Border+Padding; 		//Set  width
	MaxHeight= Height+Border+Padding;		//set height
	
	//Check Browser Name
	var browsversion=0
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp=navigator.appVersion.split("MSIE")
		browsversion=parseFloat(temp[1])

	}
	
	if (Number(browsversion)<5.5){
		document.getElementById("PopIn").style.display="";
		document.getElementById("PopInContent").style.display="";
		document.getElementById("PopInTR").style.display="";

	}else{
		Display();
	}

}

// Function Test if the PopIn is visible to User 
function Display(){
 clearTimeout(Wait);
 Wait = setTimeout(DisplayPopIn,(MyWaiting *1000));
}

// PopIn Display
function DisplayPopIn(){
	
	SpaceIn = document.body.clientHeight  + document.body.scrollTop
	MySpace = document.getElementById("PopPos").offsetTop + MaxHeight
	if(MySpace>document.body.scrollHeight){
		MySpace = document.getElementById("PopPos").offsetTop

	}


	if(Number(SpaceIn)>= Number(MySpace)){
		if(Displayed == false){
			Displayed = true;
			document.getElementById("PopIn").style.display="";
			document.getElementById("PopInTR").style.display="";
			MyTimer = setInterval(Resize,10);
		}
	}else{
		clearTimeout(Wait);
	}

}
// Resize PopIn
function Resize(){
	
	SpaceIn = document.body.clientHeight  + document.body.scrollTopz
	MySpace = document.getElementById("PopPos").offsetTop + MaxHeight

	if(document.getElementById("PopIn").width >= MaxWidth && document.getElementById("PopIn").height >= MaxHeight){
		clearInterval(MyTimer)
		DisplayContent();
		
	}
	
	// Enlarge Width + Height /////////////////////////////
	if(HowDisplay==0){
		if(document.getElementById("PopIn").width < MaxWidth){
			MyWidth += 1;
			document.getElementById("PopIn").width =  MyWidth;
		}
		if(document.getElementById("PopIn").height < MaxHeight){
			MyHeight +=1;
			document.getElementById("PopIn").height = MyHeight;
		}
		if(SpaceIn<MySpace){document.body.scrollTop+=1}
	}
	//////////////////////////////////////////////////////////
	
	// Enlarge Width ///////////////////////////////////////
	if(HowDisplay==1){
		if(document.getElementById("PopIn").width < MaxWidth){
			MyWidth += 1;
			document.getElementById("PopIn").width =  MyWidth;
		}
		document.getElementById("PopIn").height = MaxHeight;
		if(SpaceIn<MySpace){document.body.scrollTop+=1}
	}
	////////////////////////////////////////////////////////
	
	// Enlarge Height ///////////////////////////////////////
	if(HowDisplay==2){
		document.getElementById("PopIn").width =  MaxWidth;
		if(document.getElementById("PopIn").height < MaxHeight){
			MyHeight +=1;
			document.getElementById("PopIn").height = MyHeight;
		}
	}
	////////////////////////////////////////////////////////

}
//Display PopIn Content
function DisplayContent(){
		document.getElementById("PopInContent").style.filter="progid:DXImageTransform.Microsoft."+tranz[MyEffect]
		document.getElementById("PopInContent").filters[0].apply();

		//document.getElementById("PopInContent").filters[0].transition=MyEffect;
		document.getElementById("PopInContent").filters[0].duration=MySpeed;
		document.getElementById("PopInContent").style.display="";
		document.getElementById("PopInContent").filters[0].play(MySpeed);
		
}