var menuSemafor = 0;

$(document).ready(function(){

	var HOVER_ON_MENU = 0;
	var HOVER_ON_SUBMENU = 0;
	var HOVER_ON_MENU_SAFE = 0;

	$(".imageBox").imageScrollInit();

	//over na glownym menu
	$("#topMenu a.topMenuLink").hover(function(){
		var img = $("img", this).get(0);
		img.src = IMAGES_OVER[$(img).attr("name")].src;
	},
	function()
	{
		var name = $(this).attr("name");
		var img = $("img", this).get(0);
		img.src = IMAGES[$(img).attr("name")].src;
	});


	//wyslanie formularza
	$("form[name=contactForm]").submit(function(){
		var valid = true;
		if($("textarea", this).val().length == 0) valid = false;

		$("input", this).not(".contactSend").each(function()
		{
			if($(this).val().length == 0)
			{
				valid = false;
			}
		});

		if(valid == false)
		{
			alert("Nie wszystkie wymagane pola zostały wypełnione!");
			return false;
		}
	});


	$("input.searchName").click(function(){
		if($(this).val() == "Wpisz nazwę") $(this).val("");
	});


	$("#offerMenuContent a.offerMenuLink").mouseout(function()
	{
		HOVER_ON_MENU_SAFE = null;
	});

	$("#offerMenuContent a.offerMenuLink").mouseover(function()
	{
		HOVER_ON_MENU_SAFE = this;
		var obj = this;
		setTimeout(function()
		{
			if(HOVER_ON_MENU_SAFE == obj)
			{
				$(".subOfferMenuContent[rel!="+obj.rel+"]").fadeOut("normal");
				$(".subOfferMenuContent[rel="+obj.rel+"]").fadeIn("normal");
			}
		}, 500);
	});

	$("#offerMenuContent").hover(
		function()
		{
			HOVER_ON_MENU=1;
		},
		function()
		{
			//setTimeout(function(){HOVER_ON_MENU=0;}, 1000);
			HOVER_ON_MENU=0;
		});
	$("#subOfferMenu").hover(function(){HOVER_ON_SUBMENU=1;}, function(){HOVER_ON_SUBMENU=0;});

	$("#offerMenuContent, #subOfferMenu").hover(function(){},
	function()
	{
		setTimeout(function(){
			if(HOVER_ON_MENU == 0 && HOVER_ON_SUBMENU == 0)
			{
				$(".subOfferMenuContent").not(".selected").fadeOut("normal");
				$(".subOfferMenuContent").filter(".selected").fadeIn("normal");
			}
		}, 1500);

	});





});


//osadzenie dolnego tla
window.onload = startOnLoad;

function startOnLoad()
{
	properHeight();
	$(".imageBox").imageScroll();
}


function properHeight()
{

	var bodyHeight = $("#mainBody").outerHeight(true);
	var windowHeight = $(window).height();
	var bottom = $("#bottomBg");
	var difference = windowHeight - bodyHeight - bottom.outerHeight(true);

	//alert("body:"+bodyHeight+"\nwindow:"+windowHeight+"\nbottomH:"+bottom.outerHeight(true)+"\ndiff:"+difference);

	if(bodyHeight < windowHeight && difference > 0)
	{
		bottom.css("marginTop", difference + "px");
	}
}



