var first = 0;
var timerID = 0;
var loaded = false;
var w_ini = 220;
var h_ini = 16;
var inc_ratio = 8;
var cur_w = w_ini;
var cur_h = h_ini;
var final_w;
var final_h;
var img = new Image();
var f_aux = '';

function alertSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		  //Non-IE
		  myWidth = window.innerWidth;
		  myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		  //IE 6+ in 'standards compliant mode'
		  myWidth = document.documentElement.clientWidth;
		  myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		  //IE 4 compatible
		  myWidth = document.body.clientWidth;
		  myHeight = document.body.clientHeight;
		}
		var data = new Array();
		data[0] = myWidth;
		data[1] = myHeight;
		return data;
	}






function Timer() 
{	
		if (loaded)
			{
			clearTimeout(timerID);	
			}
		if (!loaded)
		{
			if (cur_w < final_w)
				 {
					cur_w = cur_w + inc_ratio;
					document.getElementById('zoom').style.width = cur_w + 'px';
				 }
			if (cur_h < final_h)
				{
					cur_h = cur_h + inc_ratio;
					document.getElementById('zoom').style.height = cur_h + 'px';
				}
			if (cur_w >= final_w && cur_h >= final_h)
				{
				loaded = true;
				document.getElementById('zoom_close').style.visibility = 'visible';
				document.getElementById('zoomPic').src = f_aux;
				}
		timerID = setTimeout("Timer()", 1);
		}
}

function OSZoom(file,w,h)
{
	viewport = alertSize();
	f_aux = 'phpThumb.php?src=cms/photos/' + file + '&w=800';
	loaded = false;
	final_w = w;
	final_h = h;
	cur_w = w_ini;
	cur_h = h_ini;
	// BKG Height //
	pic_h = parseFloat(h);
	var bkg_height = pic_h + 250;
	if (viewport[1] > bkg_height)
		{
		bkg_height = viewport[1];	
		}
	if (document.getElementById('container').offsetHeight > bkg_height)
		{
		bkg_height = document.getElementById('container').offsetHeight;	
		}
	// Get View Port Size for BKG width and make visible //
	//document.getElementById('zoom_bkg').style.width = bkg_w + 'px';
	document.getElementById('zoom_bkg').style.width = viewport[0] + 'px';
	document.getElementById('zoom_bkg').style.height = bkg_height + 'px';
	document.getElementById('zoom_bkg').style.visibility = 'visible';
	// Center Img //
	var pos_left = parseFloat(screen.width);
	pos_left_n = pos_left/2;
	img_w = parseFloat(w);
	img_half = img_w/2;
	img_left = pos_left_n - img_half;
	// Make Zoom visible and position //
	document.getElementById('zoom').style.visibility = 'visible';
	document.getElementById('zoom').style.left = img_left + 'px';
	// Create Img and set onload instructions //
	img.src = 'phpThumb.php?src=cms/photos/cms/photos/' + file + '&w=800';	
	img.onload = Timer;
}

function OSClose()
	{
	document.getElementById('zoomPic').src = 'images/8-1.gif';
	document.getElementById('zoom_close').style.visibility = 'hidden';
	document.getElementById('zoom').style.visibility = 'hidden';
	document.getElementById('zoom_bkg').style.visibility = 'hidden';
	document.getElementById('zoom_bkg').style.width = '10px';
	document.getElementById('zoom_bkg').style.height = '10px';
	document.getElementById('zoom').style.width = '220px';
	document.getElementById('zoom').style.height = '16px';
	
	}
