// $Id: product.js,v 1.11 2008/06/05 21:37:58 fwosko Exp $
importStyle("/js/product.css");

function bigPoster(a,w,h)
{
	if (!w) w=getScreenSize('width')-100;
	if (!h) h=getScreenSize('height')-100;

	var id = "big_poster";
	var image = document.getElementById(id);
	if(image) removeElement(image);

	var img = new Image();
	addEvent(img,"load",showPoster)
	//Hack: If image URL isn't changed, IE won't fire "onload" event.
	img.src = "/converter?widthMax="+w+"&heightMax="+h+"&img=" + a.pathname.replace(/\&/,'%26') + "&r=" + Math.random();
	return false;

	function showPoster()
	{
		image = document.createElement("img");
		image.src = img.src;
		image.id = id;
		addClass(image,"bigPoster");
		w = parseInt(image.width);
		h = parseInt(image.height);

		document.getElementById("body").appendChild(image);
		image.onclick = removePoster;

		addEvent(document,"click",removePoster);

		image.title = "Kliknij aby schowa\u0107 ok\u0142adk\u0119";
		var left = Math.round(( ( getScrollX() + (getScreenSize("width") / 2) ) - (w / 2) ));
		var top = Math.round(( ( getScrollY() + (getScreenSize("height") / 2) ) - (h / 2) ));
		image.style.left = left + "px";
		image.style.top = top + "px";

		addShadow(w,h,left,top,1);
		addShadow(w,h,left,top,2);
		addShadow(w,h,left,top,3);
		addShadow(w,h,left,top,4);
		addShadow(w,h,left,top,5);
		addShadow(w,h,left,top,6);

		someVariable = false;
		return false;
	}


	function removePoster()
	{
		var poster = document.getElementById("big_poster");
		if(!poster) return;
		var divs = document.getElementsByTagName("div");
		var shadows = new Array();
		for( var i =0; i < divs.length; i++)
			if(containsClass(divs[i],"shadow"))
				shadows[shadows.length] = divs[i];
		for( var i =0; i < shadows.length; i++)
			removeElement(shadows[i]);
	 	removeElement(poster);
	 	addEvent(document,"click",removePoster);
	}

	function addShadow(w,h,l,t,z)
	{
		var shadow = document.createElement("div");
		shadow.className = "shadow";
		shadow.style.width = w + "px";
		shadow.style.height = h + "px";
		shadow.style.left = (l+z) + "px";
		shadow.style.top = (t+z) + "px";
		shadow.style.zIndex = z;
		setOpacity(shadow,5);
		document.getElementById("body").appendChild(shadow);
	}

	function getScreenSize(mode)
	{
		if (self.innerHeight)
		{
			if(mode == 'width') return self.innerWidth;
			else return self.innerHeight;
		}
		else if (document.body)
		{
			if(mode == 'width') return ( document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth );
			else return  document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
		}
		return 0;
	}

	/* scroll */
	function getScrollY()
	{
		return parseInt( window.pageYOffset ? window.pageYOffset :
			 ( document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) - 20 );
	}

	function getScrollX()
	{
		return parseInt( window.pageXOffset ? window.pageXOffset :
			 ( document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) - 20 );
	}

	function setOpacity(el, o)
	{
		el.style.opacity = o/100;
		el.style.filter = "alpha(opacity="+o+")";
	}

	function removeEvent(o,t,f)
	{
		f=o[t+f];
		return(o.x=o.removeEventListener)?o.x(t,f,!1):(o.x =o.detachEvent)?o.x('on'+t,f):!1
	}

	function removeElement(el)
	{
		if(el && el.parentNode) el.parentNode.removeChild(el);
	}

	/* class */
	function addClass(el,c) { if(!containsClass(el, c)) el.className += " " + c; }
	function removeClass(el, c) { el.className = el.className.replace(new RegExp(c,"g"),""); }
	function containsClass(el, c) { return el.className.indexOf(c) != -1 }
}

/* Check Add To Cart form */
function checkAddToCartForm(form)
{
	var e = form.elements['oi_format'];
	if (!e) return true;
	if (e.length)
	{
		for (var i=0; i<e.length; i++)
			if (e[i].checked) return true;
	}
	else if (e.checked) return true;

	alert("Prosz\u0119 wybra\u0107 format.");
	return false;
}

function openInfo(id)
{
	if (!id) id="PointsInfo";
	var windowPad=Math.round(document.body.clientWidth/2) - 150;
	var w = window.open('/portlets/popup.xml?id='+escape(id),'info',"scrollbars=no, status=no, toolbar=no, location=no, directories=no, width=300, height=300, left=" +windowPad+ ", top=300, alwaysRaised=yes");
	if (w) w.focus()
}

