/* System banerowy - Popupy */

var HTMLPopup = new Object();
HTMLPopup.BorderSize = 1;
HTMLPopup.IcoCloseHeight = 26;
HTMLPopup.PaddingWidth = 0;
HTMLPopup.PaddingHeight = 0;

HTMLPopup.Popup = function(popup_src,popup_width,popup_height,popup_id,popup_padding)
{	

	var html = '';
	html += '<div id="HTMLPopup$Overlay'+popup_id+'" class="PopupOverlay" style="display:none;"></div>';
	html += '<table cellspacing="0" cellpadding="0" border="0" id="HTMLPopup$Panel'+popup_id+'" class="Popup" style="display:none;">';
	html += '	<tr>';
	html += '		<td align="right">';
	html += '			<a href="javascript:void(0)" onclick="HTMLPopupClose('+popup_id+')" id="HTMLPopup$IcoClose'+popup_id+'" class="IcoClose"></a>';
	html += '		<td>';
	html += '	</tr>';
	html += '	<tr>';
	html += '		<td id="HTMLPopup$Container'+popup_id+'" class="ImageContainer">';
	html += '			<div id="HTMLPopup$Preview'+popup_id+'" class="Preview">';
	html += '				<iframe id="HTMLPopup$Background'+popup_id+'" title="" style="display:none; border:none;" src="'+popup_src+'" width="'+popup_width+'" height="'+popup_height+'"></iframe>';
	html += '			</div>';	
	html += '			<div id="HTMLPopup$Loader'+popup_id+'" class="Loader"></div>';
	html += '		</td>';
	html += '	</tr>';
	html += '</table>';
		
	
	
	var body = document.getElementsByTagName("body")[0];
	var span = document.createElement("span");
	span.innerHTML = html;
	body.appendChild(span);
	
	HTMLPopup.Show(popup_src,popup_width,popup_height,popup_id,popup_padding);
}

HTMLPopup.Item = function(id)
{
	return document.getElementById("HTMLPopup$" + id);
}

HTMLPopup.Screen = function()
{
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		return [window.innerWidth, window.innerHeight];
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//IE 6+ in 'standards compliant mode'
		return [document.documentElement.clientWidth, document.documentElement.clientHeight];
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible
		return [document.body.clientWidth, document.body.clientHeight];
	}
}

HTMLPopup.Show = function(popup_src,popup_width,popup_height,popup_id,popup_padding)
{
	HTMLPopup.Item("Preview"+popup_id).style.display = "none";
	HTMLPopup.Item("IcoClose"+popup_id).style.display = "none";
	HTMLPopup.Item("Loader"+popup_id).style.display = "";
	HTMLPopup.Item("Container"+popup_id).style.width = "500px";
	HTMLPopup.Item("Container"+popup_id).style.height = "400px";
	HTMLPopup.Item("Panel"+popup_id).style.width = "500px";
	HTMLPopup.Item("Panel"+popup_id).style.height = "400px";
	HTMLPopup.Item("Panel"+popup_id).style.position = "absolute";
	HTMLPopup.Item("Panel"+popup_id).style.display = "";
	
	HTMLPopup.ChangePosition(popup_id,5,popup_padding);
	
	//var img = new Image();
	HTMLPopup.HTMLLoad(popup_src,popup_width,popup_height,popup_id,popup_padding);
}


HTMLPopup.HTMLLoad = function(popup_src,popup_width,popup_height,popup_id,popup_padding)
{
	HTMLPopup.Item("Background"+popup_id).style.display = "block";
	HTMLPopup.Item("Panel"+popup_id).style.width = "";
	HTMLPopup.Item("Panel"+popup_id).style.height = "";
		
	HTMLPopup.Item("Container"+popup_id).style.width = parseInt(popup_width) + "px";
	HTMLPopup.Item("Container"+popup_id).style.height = parseInt(popup_height) + "px";
	HTMLPopup.Item("Panel"+popup_id).style.width = parseInt(popup_width)+10 + "px";
	HTMLPopup.Item("Panel"+popup_id).style.height = parseInt(popup_height)+10 + "px";
	
	HTMLPopup.Item("Loader"+popup_id).style.display = "none";
	
	HTMLPopup.Item("Preview"+popup_id).style.display = "";
	HTMLPopup.Item("IcoClose"+popup_id).style.display = "";
	
	
	HTMLPopup.Item("Preview"+popup_id).src = popup_src;


	
	HTMLPopup.ChangePosition(popup_id,5,popup_padding);
	
}


HTMLPopup.ChangePosition = function(popup_id,popup_szablon,popup_padding)
{
	var screen = HTMLPopup.Screen();
	popup_szablon = 5;
	var offsetWidth = parseInt(HTMLPopup.Item("Panel"+popup_id).style.width) + HTMLPopup.PaddingWidth + 4*HTMLPopup.BorderSize;
	var offsetHeight = parseInt(HTMLPopup.Item("Panel"+popup_id).style.height) + HTMLPopup.PaddingHeight + HTMLPopup.IcoCloseHeight + 4*HTMLPopup.BorderSize;
	if (popup_szablon == 1)
	{
		var left = popup_padding;
		var top = popup_padding;
	}
	else if (popup_szablon == 2)
	{
		var left = ((screen[0] - offsetWidth) / 2);
		var top = popup_padding;
	}
	else if (popup_szablon == 3)
	{
		var left = screen[0] - offsetWidth - popup_padding;
		var top = popup_padding;
	}
	else if (popup_szablon == 4)
	{
		var left = popup_padding;
		var top = ((screen[1] - offsetHeight) / 2);
	}
	else if (popup_szablon == 5)
	{
		var left = ((screen[0] - offsetWidth) / 2);
		var top = ((screen[1] - offsetHeight) / 2);
	}
	else if (popup_szablon == 6)
	{
		var left = screen[0] - offsetWidth - popup_padding;
		var top = ((screen[1] - offsetHeight) / 2);
	}
	else if (popup_szablon == 7)
	{
		var left = popup_padding;
		var top = screen[1] - offsetHeight - popup_padding;
	}
	else if (popup_szablon == 8)
	{
		var left = ((screen[0] - offsetWidth) / 2);
		var top = screen[1] - offsetHeight - popup_padding;
	}
	else if (popup_szablon == 9)
	{
		var left = screen[0] - offsetWidth - popup_padding;
		var top = screen[1] - offsetHeight - popup_padding;
	}
	else
	{
		var left = ((screen[0] - offsetWidth) / 2);
		var top = ((screen[1] - offsetHeight) / 2);
	}
	
	HTMLPopup.Item("Panel"+popup_id).style.zIndex = "100";
	HTMLPopup.Item("Panel"+popup_id).style.left = ((left > 0) ? left : 0) + "px";
	HTMLPopup.Item("Panel"+popup_id).style.top = ((top > 0) ? top : 0) + "px";
	
	var overlayHeight = document.body.offsetHeight;
	if(overlayHeight < screen[1])
	{
		overlayHeight = screen[1];
	}
	if(parseInt(HTMLPopup.Item("Panel"+popup_id).style.top) + offsetHeight > overlayHeight)
	{
		overlayHeight = parseInt(HTMLPopup.Item("Panel"+popup_id).style.top) + offsetHeight;
	}
	

	//alert(offsetWidth);
	
	if(!((document.getElementById && !document.all) || window.opera))
	{
		HTMLPopup.Item("Background"+popup_id).style.position = "absolute";
		HTMLPopup.Item("Background"+popup_id).style.zIndex = "95";
		HTMLPopup.Item("Background"+popup_id).style.left = 0+"px";
		HTMLPopup.Item("Background"+popup_id).style.top = 20+"px";
		HTMLPopup.Item("Background"+popup_id).style.height = offsetHeight;
		HTMLPopup.Item("Background"+popup_id).style.width = offsetWidth-6;
		HTMLPopup.Item("Background"+popup_id).style.display = "";
		
	}
	HTMLPopup.Item("Overlay"+popup_id).style.position = "absolute";
	HTMLPopup.Item("Overlay"+popup_id).style.zIndex = "90";
	HTMLPopup.Item("Overlay"+popup_id).style.left = "0px";
	HTMLPopup.Item("Overlay"+popup_id).style.top = "0px";
	HTMLPopup.Item("Overlay"+popup_id).style.height = overlayHeight + HTMLPopup.PaddingHeight + HTMLPopup.IcoCloseHeight + 4*HTMLPopup.BorderSize + "px";
	HTMLPopup.Item("Overlay"+popup_id).style.display = "";
}

function HTMLPopupClose(popup_id)
{
	HTMLPopup.Item("Preview"+popup_id).style.display = "none";
	HTMLPopup.Item("IcoClose"+popup_id).style.display = "none";
	HTMLPopup.Item("Panel"+popup_id).style.display = "none";
	HTMLPopup.Item("Overlay"+popup_id).style.display = "none";
	HTMLPopup.Item("Background"+popup_id).style.display = "none";
}

/* System banerowy - Popupy - koniec */

