function toogleContentById(byId)
{
	var c = '#' + byId;
	if($(c).css('display') == 'none')
	{
		$(c).slideDown(400);
	}
	else
	{
		$(c).slideUp(400);
	}
	return false;
}

function checkForm()
{
	var notFilled = false;
	var selector = "[rel='required']";

	$(selector).each(
		function(intIndex) {
			if($(this).attr("value") == "") {
				notFilled = true;
			}
		}
	);

	if(notFilled == true) {
		alert("Je potrebné vyplniť všetky údaje !");
		return false;
	}

	return true;
}

function checkFormStatus() {
	if(jQuery.url.param("formSent") == 1) {
		$("#contentWrapper").prepend("<div class='defaultBox'>Kontaktný formulár bol úspešne odoslaný na našu emailovú adresu. Ďakujeme...</div>");
	}
	else if(jQuery.url.param("formSent") == 0) {
		$("#contentWrapper").prepend("<div class='defaultBox'>Formulár sa bohužiaľ nepodarilo odoslať. Kontaktujte nás prosím prostredníctvom emailovej adresy.</div>");
	}
}

$(document).ready( function()
{
	//1$("body").pngFix();

	$("#menuWrapper").lavaLamp({ speed: 200 });
	$("#secondaryMenuWrapper").lavaLamp({ speed: 200 });

	$("#centerImage a, #imagesThumbs li a").fancybox();


	$("#centerImage").append('<span class="lupa"></span>');

	var c_thumbs_count = $("#imagesThumbs li").length;
	for(i = 1; i <= (20 - c_thumbs_count); i++)
	{
		$("#imagesThumbs").append("<li></li>");
	}

	$("#imagesThumbs li a").hover( function()
	{
		var parentLi = $(this).parent();
		var c_href_original = $(this).attr("href");
		var c_href = c_href_original.replace(/big\//, "");
		var c_alt = $(this).children("img").attr("alt");

		$(parentLi).append('<span class="loader"></span>');

		var c_image = $("<img />").attr("src", c_href);

		$(c_image).load( function()
		{
			var c_html = '<a href="' + c_href_original + '" rel="gal"><img src="' + c_href +'" alt="' + c_alt + '" /></a><span class="lupa"></span>';

			$("#centerImage").html(c_html);
			$("#centerImage a").fancybox();
			$(".loader").remove();
			$("#imagesThumbs li").removeClass("active");
			$(parentLi).addClass("active");
			$(".ttl").html(c_alt);
		});
	});

	$('a[rel*="openSmoothPopup"], ').fancybox({
				'hideOnContentClick': false,
				'customWidth': function(_this)
								{
									var frameDimensions = $(_this).attr('rel').split(',');
									if(frameDimensions.length == 3)
									{
										return parseInt(frameDimensions[1]);
									}
									else
									{
										return $(window).width() * 0.7;
									}
								},
				'customHeight': function(_this)
								{
									var frameDimensions = $(_this).attr('rel').split(',');
									if(frameDimensions.length == 3)
									{
										return parseInt(frameDimensions[2]);
									}
									else
									{
										return $(window).height() * 0.7;
									}
								}
			});

});

$.fn.lavaLamp = function(o) {
    o = $.extend({ fx: "linear", speed: 500, click: function(){} }, o || {});

    return this.each(function() {
        var me = $(this), noop = function(){},
            $back = $('<li class="back"><div class="left"></div></li>').appendTo(me),
            $li = $("li", this),
			//curr = $("li.current", this)[0] || $($li[0]).addClass("current")[0];
			curr = $("li.current", this)[0] || null;

        $li.not(".back").hover(function() {
        	if($(this, "a").children().length) {
            	move(this);
            }
        }, noop);

        $(this).hover(noop, function() {
        	if(null != curr) {
            	move(curr);
            }
            else {
            	$back.hide(o.speed);
            }
        });

        $li.click(function(e) {
            setCurr(this);
            return o.click.apply(this, [e, this]);
        });

		if(null != curr) {
			setCurr(curr);
		}

        function setCurr(el) {
            $back.css({ "left": el.offsetLeft+"px", "width": el.offsetWidth+"px" });
            curr = el;
        };

        function move(el) {
            $back.each(function() {
                $(this).dequeue(); }
            ).animate({
                width: el.offsetWidth,
                left: el.offsetLeft
            }, o.speed, o.fx);
        };

    });
};
