function menuGorne() {
	$("#menu_gorne ul li").each(function() {
		var opis = $(this).width();
		var link = $(this).children("a").attr("href");
		$(this).text("");
		$(this).append("<div class=\"bialy\"></div>");
		$(this).append("<div class=\"czerwony\"></div>");
		$(this).click(function() {
			window.location.href=link;
		})
	});
	
	$("#menu_gorne .aktywne").each(function() {
		var bpos = $(this).children(".czerwony").css("background-position");
		if (bpos == undefined)
		var bpos = $(this).children(".czerwony").css("background-position-x") + " " + $(this).children(".czerwony").css("background-position-y");
		$(this).parents("#menu_gorne").append("<div class=\"menu_napisy selected\"><div class=\"lewa\"></div><div class=\"bialy\"></div><div class=\"prawa\"></div></div>");
		$(".selected").width($(this).width());
		$(".selected").height($(this).height());
		//$(".selected").position($(this).position());
		//alert($(this).position().left);
		$(".selected").css("left", $(this).position().left);
		
		$(".selected").children(".bialy").css("background-position", bpos);
	});
	
	$("#menu_gorne ul li").ahover({
		easing: "easeOutBack"
	});
	
	$("#menu_gorne").hover(function() {
		$(this).children(".selected").hide();
	}, function() {
		$(this).children(".selected").show();
	});
	
	if($.browser.msie){
		$("#menu_gorne ul li").hover(function() {
			$(this).children(".czerwony").show();
		}, function() {
			$(this).children(".czerwony").hide();
		});
	} else {
		$("#menu_gorne ul li").hover(function() {
			$(this).children(".czerwony").fadeIn();
		}, function() {
			$(this).children(".czerwony").fadeOut();
		});
	}
}


function nazwiska() {
	$("#nazwiska ul li").each(function() {
		var opis = $(this).width();
		var link = $(this).children("a").attr("href");
		$(this).text("");
		$(this).append("<div class=\"bialy\"></div>");
		$(this).append("<div class=\"czerwony\"></div>");
		$(this).click(function() {
			window.location.href=link;
		})
	});

	$("#nazwiska_duze ul li").each(function() {
		var opis = $(this).width();
		var link = $(this).children("a").attr("href");
		$(this).text("");
		$(this).append("<div class=\"bialy\"></div>");
		$(this).append("<div class=\"czerwony\"></div>");
		$(this).click(function() {
			window.location.href=link;
		})
	});


	$("#nazwiska .aktywne").each(function() {
		$(this).children(".bialy").hide();
		$(this).children(".czerwony").show();
	});

	$("#nazwiska_duze .aktywne").each(function() {
		$(this).children(".bialy").hide();
		$(this).children(".czerwony").show();
	});

	$("#nazwiska ul li").ahover({
		easing: "easeOutBack",
		className: "bhover"
	});

	if($.browser.msie)  $("#nazwiska_duze ul li").css("display", "inline");

	$("#nazwiska_duze ul li").hover(function() {
		if (! $(this).hasClass("aktywne")) {
			$("#nazwiska_duze ul li .czerwony").hide();
			$(this).children(".czerwony").fadeIn(600);
		}
	}, function() {
		if (!$(this).hasClass("aktywne")) {
			$(this).children(".czerwony").fadeOut("fast");
		}
	});

}

function antyspam() {
    $(".antyspam").each(function() {
		var c = "";
        var s = $(this).html();
        for (var i=0; i < s.length; i++) {
            l = s.charCodeAt(i)-2;
            c += String.fromCharCode(l);
        }
        kod = c;
        $(this).html(kod);
        $(this).show();
        $(this).attr("rel", s);
    });
}

function formularze(klasa) {

	$(klasa).find(".focus").bind("mouseover focus", function() {
		$(this).css("background-position", "4px 0px");
	});

	$(klasa).find(".focus").bind("mouseout blur", function() {
		var szer = $(this).attr("rel");
		$(this).css("background-position", "-"+szer+"px 0px");
	});

}


function wiecej() {
	$(".wiecej").hover(function() {
		$(this).css("background-position", "-87px 0px");
		$(this).animate({ top: "15px", left: "108px" }, { queue:false, duration:300, easing: "easeOutElastic" });
	}, function() {
		$(this).animate({top: "20px", left: "110px"}, { queue:true, duration:200 });
		$(this).css("background-position", "0px 0px");
	});

	$(".wiecej").each(function() {
		var link = $(this).children("a").attr("href");
		$(this).text("");
		$(this).click(function() {
			window.location.href=link;
		})
	});
}

$().ready(function(){
	menuGorne();
	nazwiska();
    antyspam();
    wiecej();
	formularze(".formularze");

    $().piroBox({
      my_speed: 300, //animation speed
      bg_alpha: 0.5, //background opacity
      radius: 4, //caption rounded corner
      scrollImage : false, // true == image follows the page _|_ false == image remains in the same open position
                           // in some cases of very large images or long description could be useful.
      slideShow : 'true', // true == slideshow on, false == slideshow off
      slideSpeed : 3, //slideshow
      pirobox_next : 'piro_next', // Nav buttons -> piro_next == inside piroBox , piro_next_out == outside piroBox
      pirobox_prev : 'piro_prev', // Nav buttons -> piro_prev == inside piroBox , piro_prev_out == outside piroBox
      close_all : '.piro_close' // add class .piro_overlay(with comma)if you want overlay click close piroBox
      });

      $("#form_kontakt").submit(function()
      {
            var valid = true;
            var nadawca = $.trim($("#nadawca").val());
            var email = $.trim($("#email").val());
            var tresc = $.trim($("#tresc").val());
            if (nadawca == "")
            {
                $("#label_nadawca").addClass("error_form");
                valid = false;
            }
            if (email == "")
            {
                $("#label_email").addClass("error_form");
                valid = false;
            }
            if (tresc == "")
            {
                $("#label_tresc").addClass("error_form");
                valid = false;
            }

            if (!valid)
            {
                $("#label_error").fadeIn(300);
            }
            return valid;
      });

      $("a.link_film").click(function()
      {
        var id = this.id.substring(4);
        $("div#youtube").html($("div#youtube" + id).html());
        return false;
      });
});

 /* przycisk dodaj do ulubionych */
function AddToFavorites()
{
    title = "Oficjalna strona zespołu VOX";
    url = "http://www.voxy.pl";
    if (window.sidebar)
    { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
    }
    else if( window.external)
    { // IE Favorite
        window.external.AddFavorite( url, title);
    }
    else if(window.opera && window.print)
    { // Opera Hotlist
        return true;
    }
}
