$(document).ready(function(){

	var loginMsg = "login";
	var passwordMsg = "hasło";
	var informerMsg = "wpisz swój adres e-mail";
	var queryMsg = "szukaj";
	
	if(navigator.appName.toLowerCase() == "opera"){
		$(".products.mini fieldset").css("top", "10px");
		$(".products.mini fieldset input").css("top", "14px");
		$("button").css("paddingTop", "2px");
		$(".pForm button,.product button").css("paddingTop", "5px");
	}else if(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
		$(".product form span").css("top", "0");
		
		if(/Firefox[\/\s](2\.\d+)/.test(navigator.userAgent)){
			queryMsg = "";
			$(".product form span").css("top", "-1em");
			$(".products li fieldset").css("top", "1.5em");
			$(".products li fieldset input").css("top", "0.75em");
			$(".pForm dd input,.pForm dd textarea").css("marginLeft", "190px")
		}
	}
	else if($.browser.msie){
		$("button[name=zamTowTab]").attr("name","iekupa");
		
		$("button[name=iekupa]").click(function(){
			var html = $(this).parent().html();
			var regexp = /value="([^"]+)"/i;
			var m = html.match(regexp);
			$(this).parent().parent().append('<input type="hidden" name="zamTowTab" value="'+m[1]+'" />');
		});
	}

	$(".box.bBasket fieldset label,.menu label").css('display', 'none');
	$("#inLogin").val(loginMsg).focus(function(){if($(this).val() == loginMsg){$(this).val("");}})
	                           .blur(function(){if($(this).val() == ""){$(this).val(loginMsg);}});
	$("#inPassword").val(passwordMsg).focus(function(){if($(this).val() == passwordMsg){$(this).val("");}})
	                                 .blur(function(){if($(this).val() == ""){$(this).val(passwordMsg);}});
	$("#inInformer").val(informerMsg).focus(function(){if($(this).val() == informerMsg){$(this).val("");}})
	                                 .blur(function(){if($(this).val() == ""){$(this).val(informerMsg);}});
	$("#inQuery").val(queryMsg).focus(function(){if($(this).val() == queryMsg){$(this).val("");}})
	                                 .blur(function(){if($(this).val() == ""){$(this).val(queryMsg);}});
	
	$("#orderByForm button").css("display", "none");
	$("#orderByForm select").change(function(){
		$("#orderByForm").submit();
	})
	$("#qLogin").submit(function(){return setHttps(this);});
	$(".nTitle").each(function(){
		var link = $(this).parent().children('.nLink');
		if (link!=null) {
			$(this).css('cursor','pointer');
			$(this).click(function(){location = link.attr('href')});
		}
	})
});

function setHttps(f) {
	if(f.loginSSL.checked) {
		f.action = f.action.replace('http://','https://');
	}
	return true;
}

function openPicture(imagePath,imageWidth,imageHeight,alt,posLeft,posTop) {
	newWindow = window.open('','newWindow','width='+imageWidth+',height='+imageHeight+',left='+posLeft+',top='+posTop);
	newWindow.resizeTo(imageWidth+10,imageHeight+40);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body style="background-color:White;margin:0;" onclick="self.close()">');
	newWindow.document.write('<img src="'+imagePath+'" style="width:'+imageWidth+'px;height:'+imageHeight+'px" alt="'+alt+'">');
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}