function changeSortOrder(path)
{
	var end = location.href.indexOf("sortowanie");
	if(end == -1) end = location.href.length;
	window.location.href = location.href.substring(0,end)+"sortowanie/"+$("#sortOrder").attr("value");
}
function showProductTab(tabId)
{
	$(".productTab").hide();
	$($(".productTab").get(tabId)).show();
	$("#minitabs").children().removeClass();
	$($("#minitabs").children().get(tabId)).addClass("current");
}
function estimateShippingCost()
{
	$("#shippingCountryName").attr('value', $("#shippingCountry").attr('value'));
	document.forms["estimateShippingCostForm"].submit();
}
function validateEmail(email)
{
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	if (email.search(validRegExp) == -1) {
		return false;
	} else {
		return true;
	}
}
function sendContactForm()
{
	var send = true;
	if(!validateEmail($("#contactFormEmail").attr("value"))) 	send = false;
	if($("#contactFormName").attr("value").length < 5) 			send = false;
	if($("#contactFormMessage").attr("value").length < 10) 		send = false;

	if(send){
		document.forms["contactForm"].submit();
	} else {
		alert('Proszę wypełnić poprawnie wymagane pola.');
	}
}
function remItem(id)
{
	$("#qty_"+id).attr("value", 0);
	document.forms["shoppingCartForm"].submit();
}
function loadTopAdv()
{
	var flashvars = {};
	flashvars.font = "font.swf";
	var attributes = {};
	attributes.wmode = "transparent";
	attributes.id = "slider";
	
	if($(window).width() > 1024) {
		$("#logo").css("margin-right", (($("#header").width() - 1090)/2) + "px");
		flashvars.xml = "/site/cu3er/config.xml";
		swfobject.embedSWF("/site/cu3er/cu3er.swf", "cu3er", "750", "120", "9", "/site/cu3er/expressInstall.swf", flashvars, attributes);
	} else {
		$("#logo").css("margin-right", "15px");
		flashvars.xml = "/site/cu3er/config_small.xml";
		swfobject.embedSWF("/site/cu3er/cu3er.swf?V=d", "cu3er", "600", "120", "9", "/site/cu3er/expressInstall.swf", flashvars, attributes);
	}
}

function showvideo(videoId, quality)
{
	
$("#playerOuter").html("<div id=\"player\"></div>");

var playerWidth = 552;

if(quality == '1') {
	$("#playerOuter").css("width", "552px");
	$("#playerOuter").css("height", "308px");
} else {
	playerWidth = parseInt($("#outer2").css("width"));
	$("#playerOuter").css("width", playerWidth+"px");
	$("#playerOuter").css("height", parseInt((playerWidth*9)/16) + 'px');
}
//$("#player").html('<object width="550" height="400"><param name="movie" value="/site/player.swf"><param name="flashVars" value="videoId='+videoId+'&videoQuality='+quality+'width='+playerWidth+'"><embed src="/site/player.swf" width="550" height="400"></embed></object>');

            var swfVersionStr = "10.0.0";
			var xiSwfUrlStr = "http://hollex.com.pl/swfobject/expressInstall.swf";
            var flashvars = {};
            flashvars.videoId = videoId;
            flashvars.videoQuality = quality;
						flashvars.width = playerWidth - 20;
            var params = {};
            params.quality = "high";
            params.bgcolor = "#ffffff";
            params.allowscriptaccess = "always";
            params.allowfullscreen = "true";
            var attributes = {};
            attributes.id = "Player";
            attributes.name = "Player";
            attributes.align = "middle";
            swfobject.embedSWF(
                "http://hollex.com.pl/player.swf", "player", 
                playerWidth, parseInt((playerWidth*9)/16), 
                swfVersionStr, xiSwfUrlStr, 
                flashvars, params, attributes);
	return false;
}

function buyvideo(videoId, price)
{
	$("#playerOuter").html("<div id=\"player\"></div>");
	$("#player").css("width", "100%");
	$("#player").css("height", "150px");
	$("#playerOuter").css("height", "150px");
	$("#player").html("<center><img style=\"margin-top: 10px\" src=\"/site/img/ajax-loader.gif\"/></center>");
	
	$.ajax({
		  type: 'POST',
		  url: "/userpanel/getvideopaymentmethods",
		  success: function(data) {
			if(data == "NOTLOGGED") {
				$("#player").css("height", "100px");
				$("#player").html("<center><h3>Proszę się <a href=\"/panel-klienta/\">zalogować</a>.</h3></center>");
			} else if(data == "NOREQUIREDDATA") {
					$("#player").css("height", "100px");
					$("#player").html("<center><h3>Prosze uzupełnić wszystkie wymagane dane w <a href=\"/panel-klienta/\">panelu klienta</a>.</h3></center>");				
			} else {
				$("#player").html(data);
				$("#paymenttitle").html($("#paymenttitle").html() + " (kwota " + price + ")");
				$("#formVideoId").attr("value", videoId);
			}
			}
		});
	return false;
}

$(document).ready(function() {
	
	if($(window).width() < 1024) {
		$("body").css("width", "1000px");
	}
	
	iq = document.getElementById('outer2');
	if(iq.offsetWidth < 600) {
		iq.style.width = '600px';
	} else {
		iq.style.width = iq.offsetWidth + 'px';
	}
	
	if(iq.offsetWidth < 700) {
		$("#product_list").children().css('width', '48%');
		$("#topBoxCats").children().css('background', 'none');
	} else {
		$("#topBoxCats").children().css('width', '24%');
		$("#product_list").children().css('width', '32%');
		$("#fcbif").css('width', '450px');
	}
	
	loadTopAdv();
	
	$("a.productPhotos").fancybox();
});