function otworzFlash (url,stan){
		var flashvars = {"video":url,"autoplay":stan};
		swfobject.embedSWF("/flash/playerOmarce.swf", "flashMarka", "410", "362", "10.0.0","/flash/expressInstall.swf", flashvars);
	}

(function($){


	$.fn.voting = function(options) {
		return this.each(function(){
			$(this).mousemove(function(e){
				var percentage = Math.floor(((e.pageX - $(this).offset().left) / ($(this).width())) * 100);
                                percentage = (3*percentage/100).toFixed(0);   
				$(this).children("div").css("width",(percentage/3*100).toFixed(0) + '%');
                                $(this).attr("vote", percentage );

			});
			$(this).click(function(){
				$(this).unbind();
				var _score = $(this).attr("vote");
                                var g_id = $(this).attr('g_id');
                                $('#g_'+g_id).attr('ocena', _score);
			});
		});
	}
})(jQuery);


function submit_polec(input){
        var pos = $(input).position().top;
                            $.post(input.form.action, $(input.form).serialize(), function (out) {
                                $('#powiadom').remove();
                                $('div.popUPwindow div.popUpContent').append(out);
                            })
                        }

$(document).ready(function(){ 
	//do PopUp

	function popup(html,pos){
		var wysokosc = $(document).height();
		var szerokosc = $(document).width();
		var okno = $(window).height(); 
		$("div#wrapper").after("<div class=\"darkBg\" style=\"width:"+szerokosc+"px;height:"+wysokosc+"px;display:none\"></div>");
		var html = "<div class=\"popUPwindow\" style=\"display:none\"><div class=\"popUpContent\"><div class=\"zamknij\"></div>"+html+"</div><div class=\"popUpBottom\"></div></div>";
		$("div.darkBg").after(html);
		var popWys = $("div.popUPwindow").height();
		var top = pos-popWys;
		$("div.popUPwindow").css("top",top);
		$("div.darkBg,div.popUPwindow").fadeIn("slow");
		$("div.popUpContent div.zamknij").click(function(){
			$("div.darkBg,div.popUPwindow").fadeOut("slow",function(){
				$("div.darkBg,div.popUPwindow").remove();
			});
		});
	}
	$("a.przypomnij").click(function(){
		var pos = $(this).position().top;
		popup("<p class=\"center\">Twoje hasło zostało wysłane na email podany podczas rejestracji</p>",pos);
		return false;
	});
	$("a.poleckonkurs").click(function(){
		var pos = $(this).position().top;
		var plik = $(this).attr("href");
		$.get(plik,function(out, status){
			popup(out,pos);
		});
		return false;
	});

        

	$("a.glosuj").click(function(){
		var pos = $(this).position().top;
                var plik = $(this).attr("href");
                var ocena = parseInt($(this).attr('ocena'));
                if(ocena >= 1 && ocena <= 3)
                {
                    $.post(plik,{ocena:ocena},function(out, status){
                            popup(out,pos);
                    });
                }
                else
                {
                    popup('<p class="center">Wybierz ocenę</p>', pos);
                }
		return false;
	});
        
        $('.kayah_konkurs div.glosowanie div.gwiazdki').voting();
        
	//do o marce
	otworzFlash("Douwe_Egberts_30s_011010.flv","false");
	$("#switch1").click(function(){
		otworzFlash("douwe_egberts_black_v1.flv","true");
		$(this).fadeTo("slow", 0.5);
		});
	$("#switch2").click(function(){
		otworzFlash("douwe_egberts_black_v2.flv","true");
		$(this).fadeTo("slow", 0.5);
		});	
	//do galeri	
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	//do tajemnice kawy
	$("#rotator img.next").click(function(){
		var div = $("#rotator div div.show");
		var stan = $("#rotator div ul#stan li.active");
		if(div.next().length != 0)
		{
			div.toggleClass("show");
			stan.toggleClass("active");
			div.next().toggleClass("show");
			stan.next().toggleClass("active");
		}
	});
	$("#rotator img.prev").click(function(){
		var div = $("#rotator div div.show");
		var stan = $("#rotator div ul#stan li.active");
		if(div.prev().length != 0)
		{
			div.toggleClass("show");
			stan.toggleClass("active");
			div.prev().toggleClass("show");
			stan.prev().toggleClass("active");
		}
	});
	$("#expandTajemniceKawy").click(function(){
		$("div.short").toggleClass("show").toggleClass("hide");
		$("div#news").toggleClass("hide");
		$("div#czyWieszZe").toggleClass("hide")
		$("div.long").toggleClass("show").toggleClass("hide");
	});
        $(".gwiazdki").voting();
		//do popup na home
		$("div#popup").show();
		$("div#popup #zamknij").click(
			function(){
				$("div#popup").hide("slow");
				swfobject.embedSWF("/flash/de_page_top_animation.swf", "flash", "960", "365","9.0.0","/flash/expressInstall.swf");
				return false;
			});
			
	$(".omarce .submenu li:not(.active)").fadeTo("slow", 0.5);

	
	var flashvars_ = {};
	var params_ = { wmode: "opaque" }; 
	var attributes_ = {};
	swfobject.embedSWF("/flash/de_page_top_animation.swf", "flash", "960", "365","9.0.0","/flash/expressInstall.swf",flashvars_, params_, attributes_);
	
	$(".ramki .ramka").each(function(i){
		if ((i + 1) % 2 == 0){
			$(this).after('<div class="clear" />');
		}
	});
	
});

$(window).load(
    function() {
        var packshotheight = 360;
		$(".packshot li").each(function(){
			if ($(this).height() < packshotheight) {
				var roznica = packshotheight - $(this).height();
				$("img",this).css("margin-top",roznica);
			}
		});
    }
);
