var fopacity=0.0;
var url, stream=null;
var iWidth, iHeight;

function ShowScreenshot(URL)
{
	var winX = (document.all)?window.screenLeft:window.screenX;
	var URLparts = URL.split("/");
	URLjpg = "gallery/?image=" + URLparts[URLparts.length-1];
	URLjpg = URLjpg.substring(0, URLjpg.length-4) +".jpg";

	//Do a pop up HTML page. Sweet
	var winl = (screen.width-800)/2;
	var wint = (screen.height-600)/2;
	if (winX + 5 >= screen.width)
		winl += screen.width;
	var 	settings  ='width=800,';	
		settings +='height=600,';
		settings +='top='+wint+',';
		settings +='left='+winl+',';
		settings +='titlebar=no,';
		settings +='scrollbars=no,';
		settings +='resizable=no';

	searchwindow = window.open(URLjpg, 'screenshot', settings);
	if (window.focus) 
		searchwindow.focus();		
}

function popup_fade()
{
	if (url=="")
		return;

	fopacity += 0.1;
	if (fopacity > 1.0)
		fopacity = 1.0;
			
	document.getElementById('popup_menu').style.opacity = fopacity;
	document.getElementById('popup_menu').style.filter = 'alpha(opacity='+fopacity*100+')';
	
	if (fopacity < 1.0)
	{
		setTimeout ('popup_fade()', 20);
		popup_prepare();
	}
}

function popup_prepare()
{
	//Determine the Available Width on the page
	var fWidth;

	//For old IE browsers
	if(document.all)
		fWidth = document.body.clientWidth;
	else 
		fWidth = innerWidth;
	if(document.all)
		fHeight = document.body.clientHeight;
	else 
		fHeight = innerHeight;
	
	layerTop  = (fHeight/2) - (document.getElementById('popup_menu').clientHeight/2) 
	layerLeft = (fWidth/2)  - (document.getElementById('popup_menu').clientWidth/2); 
	if (layerTop < 0)
    layerTop = 0;
	document.getElementById('popup_menu').style.left   = layerLeft + 'px';
	document.getElementById('popup_menu').style.top    = layerTop  + 'px';
}

function popup_show()
{ 
	if (!stream.complete)
	{
		setTimeout("popup_show()", 50);
		return;
	}


	document.getElementById('popupcontent').src = stream.src;
	document.getElementById('popupcontent').style.margin = '0px';	

	//Determine the Available Width on the page
	popup_prepare();   
	popup_fade();
}

function popup_open(obj)
{
	/*
	thumbs = document.images;
	for (i = 0; i < thumbs.length; i++)
	{
		if (thumbs[i] == obj)
		{
			if (i < thumbs.length-1)
				
		}
	}
	*/

	url = obj.src;
	url = url.substring(0, url.length-4) + ".jpg";
	document.getElementById('popupcontent').src = 'res/loader.gif';
	document.getElementById('popupcontent').style.border = '0px';
	document.getElementById('popupcontent').style.margin = '40px';
	document.getElementById('popup_menu').style.display='block';
	popup_prepare();

	stream = new Image();
	stream.src = url;
	popup_show();
}

function popup_close()
{
  url="";
  fopacity = 0.0;
	document.getElementById('popup_menu').style.display="none";
}

function ytpopup_fade()
{
  if (url=="")
    return;
  fopacity += 0.1;
  if (fopacity > 1.0)
    fopacity = 1.0;
		
	document.getElementById('ytpopup_menu').style.opacity = fopacity;
  document.getElementById('ytpopup_menu').style.filter = 'alpha(opacity='+fopacity*100+')';
	
	if (fopacity < 1.0)
	{
    setTimeout ('ytpopup_fade()', 20);
    ytpopup_prepare();
  }
}

function ytpopup_prepare()
{
	//Determine the Available Width on the page
	var fWidth;

	//For old IE browsers
	if(document.all)
		fWidth = document.body.clientWidth;
	else 
		fWidth = innerWidth;
	if(document.all)
		fHeight = document.body.clientHeight;
	else 
		fHeight = innerHeight;
	
	layerLeft = (fWidth/2)  - (iWidth/2); 
	layerTop  = (fHeight/2) - (iHeight/2) 
	if (layerTop < 0)
	layerTop = 0;
	document.getElementById('ytpopup_menu').style.left   = layerLeft + 'px';
	document.getElementById('ytpopup_menu').style.top    = layerTop  + 'px';
}

function ytpopup_open(video)
{
	iWidth = 800;
	iHeight = 600;
	document.getElementById('ytpopupcontent').innerHTML = "<!-- Inserted Video --><object width=" + iWidth + " height=" + iHeight + ">\n<param name=\"movie\" value=\"http://www.youtube.com/v/" + video + "&hd=1&loop=1&hl=en&fs=1&autoplay=1&showinfo=0&rel=0\"></param>\n<param name=\"allowFullScreen\" value=\"true\"></param>\n<param name=\"allowscriptaccess\" value=\"always\"></param>\n<embed id=\"embed\" src=\"http://www.youtube.com/v/" + video + "&loop=1&hd=1&hl=en&fs=1&autoplay=1&showinfo=0&rel=0\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=" + iWidth + " height=" + iHeight + "></embed>\n</object>";
	document.getElementById('ytpopup_menu').style.display="block";
	ytpopup_prepare();
}

function ytpopup_close()
{
	//iWidth = 320;
	//iHeight = 240;
	//document.getElementById('embed').width = iWidth;
	//document.getElementById('embed').height = iHeight;
	ytpopup_prepare();
	url="";
	fopacity = 0.0;
	document.getElementById('ytpopupcontent').innerHTML = "";
	document.getElementById('ytpopup_menu').style.display="none";
}