

function popUp(context)
{
	var pop = document.getElementById("popUpWrapper");
	pop.className = "show";

	this.context=context;

	myInterval = setInterval("fade(document.getElementById('popUpWrapper'), myInterval, .5, .1, context, function(){})",1);


}

function callback(context)
{
	
	var popWrapper = document.getElementById('popUp');
	scrollElement(popWrapper, 50);

	popWrapper.className = "show";
	popWrapper.style.display = "block";

	var popContent = document.createElement('div');
	popContent.setAttribute("id", "popUpContent");
	popContent.style.width = "100px";
	popContent.style.height = "100px";

	popWrapper.appendChild(popContent);

	var popImg = document.createElement('img');
	
	//popImg.style.display = "none";
	popContent.appendChild(popImg);

	popImg.onload = function()
	{
		this.style.display="block";
		var br1 = document.createElement('br');
		var br2 = document.createElement('br');

		var closePop = document.createElement('a');
		closePop.setAttribute("href", "javascript:closePop()");

		var closePopImg = document.createElement('img');
		closePopImg.setAttribute("src", "images/closePop.png");

		popContent.appendChild(br1);	
		//popContent.appendChild(br2);
		popContent.appendChild(closePop);
		closePop.appendChild(closePopImg);
		var height = this.height;
		var width = this.width;

		popContent.style.height = height + 50 + "px";
		popContent.style.width = width + "px";	

	

	}
	
	popImg.setAttribute("src", context);
	popImg.setAttribute("id", "bigpic");

}




function closePop()
{
	var popUpWrapper = document.getElementById('popUp');
	popUpWrapper.style.display = "none";
	popUpWrapper.innerHTML = "";


	myInterval = setInterval("fade(document.getElementById('popUpWrapper'), myInterval, 0, -.1,null,function(){document.getElementById('popUpWrapper').className = 'hide';})",1);
	

}

function fade(context, interval, max, opChange, img, callbackfunc)
{
	var opacity = parseFloat(context.style.opacity);
	if(!opacity)
	{
		opacity = 0;
	}
	if(/MSIE (5|6|7)/.test(navigator.userAgent)){
		var temp = context.style.filter;
		if(temp)
		{
			var temp2 = temp.split("alpha(opacity=");
			var temp3 = temp2[1].split(")");
			opacity = parseFloat(temp3[0]/100);
		}
		else
		{
			opacity = 0;
		}
	}

	if(opChange < 0)
	{
		if (opacity>max)
		{
			opacity+=opChange;
		}
		else
		{
			clearInterval(interval);
			if(img != null) callback(img);
			callbackfunc();
			return;
		}	
	}
	else
	{
		if (opacity<max)
		{
			opacity+=opChange;
		}
		else
		{	
			clearInterval(interval);
			if(img != null) callback(img);
			callbackfunc();
			return;	
		}
	}
	context.style.opacity=opacity;
	context.style.filter = "alpha(opacity=" + opacity*100 + ")";
}


function scrollElement(context, offset)
{
	var elementWidth = context.style.width;
	var elementHeight = context.style.height;

	elementWidth = elementWidth.split("px");

	if (window.innerWidth) { // All browsers but IE

    		var scroll = window.pageYOffset;

    		var width = window.innerWidth;

    		var height = window.innerHeight;

	}
	else if (document.documentElement && document.documentElement.clientWidth) {

		var scroll = document.documentElement.scrollTop;
   		var width = document.documentElement.clientWidth;
    		var height = document.documentElement.clientHeight;
	}



	//context.style.top = scroll + "px";
	context.style.top = offset + scroll + "px";

}


if (window.addEventListener) window.addEventListener("load", init, false);
    else if (window.attachEvent) window.attachEvent("onload", init);
    
function init() 
{  
	setInterval("scrollElement(document.getElementById('popUpWrapper'), 0)", 1);
	//setInterval("scrollElement(document.getElementById('popUp'), 100)", 1);
}
