/**
 * Podpinanie parametru target dla link�w
 * rel = blank | top | self | parent
 */

window.onload = externalLinks;

function externalLinks() 
{
	if (!document.getElementsByTagName) 
	{
		return;
	}
	
	var anchors = document.getElementsByTagName("a");
	
	for (var i=0; i<anchors.length; i++) 
	{
		var anchor = anchors[i];
		
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "blank" || anchor.getAttribute("rel") == "top" || anchor.getAttribute("rel") == "self" || anchor.getAttribute("rel") == "parent"))
		{
			anchor.target = "_" + anchor.getAttribute("rel");
		}
	}
}

/**
 * Detekcja przegladarki
 */
function loadBrowserStyle()
{
	if($.browser.name == 'msie')
	{
		document.write(unescape('%3Clink href="/theme/css/style-' + $.browser.name + $.browser.versionNumber + '.css"  type="text/css" rel="stylesheet" /%3E'));
	}
	else
	{
		document.write(unescape('%3Clink href="/theme/css/style-' + $.browser.name + '.css"  type="text/css" rel="stylesheet" /%3E'));
	}
}
loadBrowserStyle();

/*
 * Obsluga elementow ladowanych podczas ladowania sie strony
 */
$(document).ready(function()
{   
	//blokowanie kontekstowego menu
	$(document).rightClick( 		function(e) {});
	$(document).rightMouseDown( 	function(e) {});	
	$(document).rightMouseUp( 	function(e) {});
	$(document).noContext();
	

	// wyśrodkowanie górnego menu
	menuMargin = 15;
	//for(i = 0; i < $("div#menu-top ul li").length; i++)
	//{
	//	menuMargin += parseInt($("div#menu-top ul li:eq(" + i + ")").width());
	//}
	//$("div#menu-top ul").css("margin-left", ((970 - menuMargin) / 2) + "px");
	$("div#menu-top ul").css("margin-left", menuMargin + "px");
	
	$("div#wrap").css("margin-top", parseInt(($(window).height() - $("div#wrap").height()) / 2) + "px");
});

var viewBackground = 1;

function runBackground()
{
	$("div#wrap-content").css("background", "url('/theme/img/foto_ciemnia.png') no-repeat");
}

function viewProduct(id, foto)
{
	$.ajax({ 
		type: 		"POST",
		url: 		"/engine/lib/viewAjax.php",
		data: 		"action=products&id=" + id,
	
		success: 	function(msg)
		{
			//alert(msg);
			msg = eval(msg);
			
			$("div#kolekcje-info h3").html(msg[0]);
			$("div#kolekcja-scroll").html(msg[4]);
			
			if(foto == 3)
			{
				$("div#product-foto").html('<img src="/' + msg[3] + '" style="width: 360px; height: 486px;" />');
			}
			else if(foto == 2)
			{
				$("div#product-foto").html('<img src="/' + msg[2] + '" style="width: 360px; height: 486px;" />');
			}
			else
			{
				$("div#product-foto").html('<img src="/' + msg[1] + '" style="width: 360px; height: 486px;" />');
			}
			
			if(msg[2] != '')
			{
				$("a#product-foto2").css("display", "block");
				$("a#product-foto2").html('<img src="/theme/img/icons.php?file=../../' + msg[2] + '&amp;width=60&amp;height=74&amp;zoom=1&amp;crop=1" />');
				$("a#product-foto2").attr("href", "javascript:viewProduct(" + id + ", 2);");
			}
			else
			{
				$("a#product-foto2").css("display", "none");
				$("a#product-foto2").attr("href", "javascript:void(0);");
			}
			
			if(msg[3] != '')
			{
				$("a#product-foto3").css("display", "block");
				$("a#product-foto3").html('<img src="/theme/img/icons.php?file=../../' + msg[3] + '&amp;width=60&amp;height=74&amp;zoom=1&amp;crop=1" />');
				$("a#product-foto3").attr("href", "javascript:viewProduct(" + id + ", 3);");
			}
			else
			{
				$("a#product-foto3").css("display", "none");
				$("a#product-foto3").attr("href", "javascript:void(0);");
			}
			
			$("div#kolekcja-scroll").jScrollPane({scrollbarWidth: 9, scrollbarMargin: 25, dragMinHeight: 23, dragMaxHeight: 23, showArrows: false});
			
			$("#product-foto").miniZoomPan({
				sW: 360,
				sH: 486,
				lW: 1080,
				lH: 1458
			});
		},
		error: function(xhr, desc, e)
		{
			
		}
	});
}

/*
 * Obsluga drukowania
 */
function PagePrint(url)
{
	noweOkno = window.open(url, 'okienko', 'menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=no, status=no, width=570, height=500')
}


