﻿// JScript File

function NewWin(url, winHeight, winWidth)
{
    var myWin = window.open(url, "NewWin", "width=" + winWidth + ",height=" + winHeight + ",scrollbars=yes,location=no,toolbar=no,menubar=no,resizable=no,top=0,left=0");
	myWin.focus();
}

function NewResizableWin(url, winHeight, winWidth)
{
    var myWin = window.open(url, "NewWin", "width=" + winWidth + ",height=" + winHeight + ",scrollbars=yes,location=no,toolbar=no,menubar=no,resizable=yes,top=0,left=0");
	myWin.focus();
}

function NewResizableWindow(url, winHeight, winWidth)
{
    var myWin = window.open(url, "NewWin", "width=" + winWidth + ",height=" + winHeight + ",scrollbars=yes,location=yes,toolbar=yes,menubar=yes,resizable=yes,top=0,left=0");
	myWin.focus();
}

function ImagePopUp(url)
{
    var height = 506;
	var width = 400;
	
	var xposition = (screen.width-width)/2;
	var yposition = (screen.height-height)/2;
	
	var argWindow = "width=" + width + ",height=" + height + ",scrollbars=no,location=no,toolbar=no,menubar=no,resizable=no,left=" + xposition + ",top=" + yposition + ",screenx=" + xposition + ",screeny=" + yposition;
	
	var newWindow = window.open( url, "ImagePopUp", argWindow );
	
	if( newWindow )
		newWindow.focus();
}

function VideoPopUp(url)
{
    var height = 400;
	var width = 440;
	
	var xposition = (screen.width-width)/2;
	var yposition = (screen.height-height)/2;
	
	var argWindow = "width=" + width + ",height=" + height + ",scrollbars=no,location=no,toolbar=no,menubar=no,resizable=no,left=" + xposition + ",top=" + yposition + ",screenx=" + xposition + ",screeny=" + yposition;
	
	var newWindow = window.open( url, "VideoPopUp", argWindow );
	
	if( newWindow )
		newWindow.focus();
}

function OpenMaximizedWindow(url)
{
	top.window.moveTo(0,0);
	
	var winHeight, winWidth;

	if (document.all) 
	{
		winHeight = screen.availHeight;
		winWidth = screen.availWidth;
		
		top.window.resizeTo(screen.availWidth, screen.availHeight);
	}
	else if (document.layers||document.getElementById) 
	{
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
		{
			winHeight = screen.availHeight;
			winWidth = screen.availWidth;
		}
	}
	
	var myWin = window.open(url, "NewWin", "width=" + winWidth + ",height=" + winHeight + ",scrollbars=yes,location=yes,toolbar=yes,menubar=yes,resizable=yes,status=yes,top=0,left=0");

	myWin.resizeTo(winWidth, winHeight);
	myWin.focus();
}


var num=0;

function checkLoad() 
{   
    allImagesLoaded = true;
     for (i = 0; i <= preImages.length-1; i++) 
     {
          if (!preImages[i].complete) 
          {
            allImagesLoaded = false;
          }
     }

   if (allImagesLoaded==false)
   {
        
      //setTimeout("checkLoad()",10) ;
   }
   else
   {
      //document.getElementById("test2").style.visibility="visible";
      //document.getElementById("test2").style.filter="alpha(opacity=0)";
      initialize();
      //alert('initialize');
   }
}


function CenterElement( element , strId ) { 
		alert(id);
		var d = document; 
		var rootElm = (d.documentElement && d.compatMode == 'CSS1Compat') ? d.documentElement : d.body; 
		var vpw = self.innerWidth ? self.innerWidth : rootElm.clientWidth; // viewport width 
		var vph = self.innerHeight ? self.innerHeight : rootElm.clientHeight; // viewport height 
		
		element.style.position = 'absolute'; 
		element.style.left = ((vpw - 100) / 2) + 'px';  
		element.style.top = (rootElm.scrollTop + (vph - 100)/2 ) + 'px'; 
		element.style.left = '100 px';
		element.style.top =  '100 px'; 
		
	} 	



//jquery popup
$(document).ready(function() {	

//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
	//Cancel the link behavior
	e.preventDefault();
	//Get the A tag
	var id = $(this).attr('href');
	//alert(id);
	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	//Set height and width to mask to fill up the whole screen
	$('#mask').css({'width':maskWidth,'height':maskHeight});
	
	//transition effect		
	$('#mask').fadeIn(100);	
	$('#mask').fadeTo("fast",0.8);	

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();
          
          
//          alert(id);
//		alert("Mask height=" + $(id).width());
//		alert("window height=" + winH);
//		
	//Set the popup window to center
//	if($(id).height() > winH)
//		$(id).css('top',  winH/2 - 260);
//	else
//		$(id).css('top',  winH/2-$(id).height()/2);
//		
//	$(id).css('left', winW/2-$(id).width()/2);
	
	var strElement = id.split("#");
	var element = document.getElementById(strElement[1]);
	//CenterElement(strElement , id);
	
	   var d = document; 
		var rootElm = (d.documentElement && d.compatMode == 'CSS1Compat') ? d.documentElement : d.body; 
		var vpw = self.innerWidth ? self.innerWidth : rootElm.clientWidth; // viewport width 
		var vph = self.innerHeight ? self.innerHeight : rootElm.clientHeight; // viewport height 
		
		element.style.position = 'absolute'; 
		element.style.left = ((vpw - ($(id).width())) / 2) + 'px';  
		
		if($(id).height() > winH)
		{
			//alert("11");
			
			$($(element).children().get(1)).css("height",500); 
			$($(element).children().get(1)).css("overflow","scroll");	
			
			element.style.top = (rootElm.scrollTop + (vph - ($(id).height()))/2 ) + 'px'; 
					
		}
		else
		{
			//alert("22");
			element.style.top = (rootElm.scrollTop + (vph - ($(id).height()))/2 ) + 'px'; 
		}
			
	//transition effect
	$(id).fadeIn(100); 

});

//if close button is clicked
 $('.window .close').click(function (e) {
	//Cancel the link behavior
	
	e.preventDefault();
	$('#mask, .window').hide();
});		

$(document).keypress(function(e) 
{   
	if (e.keyCode == 27) 
	 {
		 e.preventDefault();
		 $('#mask, .window').hide();
	 }
});
$(document).keydown(function(e) 
{   
	if (e.keyCode == 27) 
	 {
		 e.preventDefault();
		 $('#mask, .window').hide();
	 }
	
});

//if mask is clicked
$('#mask').click(function () {
	//$(this).hide();
	//$('.window').hide();
});			

});

	