

	var form_list = new Array();
	var session_id = '';

	// plugin pro preload obrazku
	(function($) 
	{
		// preload images
		var cache = [];
		// Arguments are image paths relative to the current page.
		$.preload_images = function() 
		{
			var args_len = arguments.length;
			for (var i = args_len; i--;) 
			{
				var cacheImage = document.createElement('img');
				cacheImage.src = arguments[i];
				cache.push(cacheImage);
			}
		}
	})(jQuery);

       var price_list = {
            "1" : [5.5,4,4],
            "2" : [5.5,4,4],
            "3" : [6.5,5,5],
            "4" : [6.5,5,5],
            "5" : [13],
            "6" : [21],
            "7" : [79],
            "8" : [79],
            "9" : [169],
            "10" : [590],
            "11" : [690],
            "12" : [790],
            "13" : [890],
            "14" : [990]
        };

	function post_file()
	{
		if( form_list.length > 0 )
		{
			var form = form_list.pop();
			var file = $(form).find("input").attr("value");
			var list_item = $("span:contains('" + file + "')").parent();
			
			list_item.find("a").css("visibility", "hidden");
			list_item.append('<img src="/images/loading.gif" class="loading" alt="Nahrávám..." title="Nahrávám..." />');
			
			$("#response").replaceWith( "Odesílám foto: " + file + "...<br />" );
			list_item.addClass("active");
			
			$(form).ajaxForm();
			$(form).ajaxSubmit( function (a,b,c, d,e,f) { 
				$("#response").empty();
				list_item.removeClass("active");
				//list_item.children("a").remove();
				list_item.append('<img src="/images/check.jpg" alt="OK" title="OK" />');
				
				list_item.find(".loading").remove();
				$(form).remove();
				
				post_file();
			});
		} else {
			make_summary();
		}
	}


	function recompute_price( count, single_price, delivery_price )
	{
		var price = 0;
		var count = (count != undefined) ? count : $(".uploadifyQueueItem").length;
		
		if (count > 0)
		{
                    price = Math.ceil(single_price * count);
		} 
		
		price += delivery_price;

                // cekova cena 
		$(".price").find("span:first").text( price );

        // pocet foto
        $(".price").find("span:last").text( count );

        return price;
	}

        function form_check()
        {
            var ok = true;
            var fields = [];

            if ( $("#delivery").val() > 1 )
            {
                fields = [ "first_name", "last_name", "phone", "email", "city", "street", "zip" ];
            } else
            {
                fields = [ "first_name", "last_name", "phone", "email", ] ; 
            }

            $(fields).each( function (index, item) {
                if ( $("input[name=" + item + "]").val().replace(/\s*/g, "") == "" ) ok = false ;
            });
            
            return ok;
        }

	$(document).ready(function() {
	
         $("#new_post form").submit( function(){

            if($("input[name=jmeno]").val()== ""){
                alert("Prosím zadejte jméno");
                return (false);
            }
            if($("input[name=email]").val().indexOf('@', 0) == -1){
                alert("Tato emailová adresa je neplatná!");
                return (false);
            }

            if($("textarea[name=text]").val() == ""){
                alert("Prosím zadejte zprávu");
                return (false);
            }
            return true;
        });
	
	
         $("#new_order_button").click(function () {
             $("#captcha_container").show();
             $("#new_order_button").hide();
             return false;
         });
	
		$(".theme_pic_container > h2").fadeOut(0);

                // zablikat slogan telefonni cislo
		$(".theme_pic_container > h2").fadeIn(3500, function () {
			$(this).fadeTo("slow", 0.01, function () {
				$(this).text("732 578 714").css({"top": "25px", "font-size": "14pt"});
				$(this).fadeTo("fast", 1);
			});
		});

                // preload pomocnych obrazku
		jQuery.preload_images("/images/check.jpg", "/images/delete.jpg", "/images/loading.gif", "/images/choose_files.jpg");
		
		// nastavit prepinani orezu pomoci obrazku
		$(".third").click( function () {
			$(this).find("input").attr("checked", "checked");
		});

		
		// prepocitavani ceny pri zmene zpusobu prevzeti
		$("#delivery").change( function () {
			if ( $(this).val() == 1 && $("#address_container").is(":visible") )
			{
				$("#address_container").hide();
			} else if ( $(this).val() > 1 && !$("#address_container").is(":visible") )
			{
				$("#address_container").show();
			}
		});

                $("#captcha_container form").submit( function(){

                    if($("input[name=first_name]").val()== ""){
                        alert("Prosím zadejte jméno");
		                return (false);
                    }
                    if($("input[name=last_name]").val() == ""){
                        alert("Prosím zadejte příjmení");
		                return (false);
                    }
                    
                    if($("input[name=phone]").val() == ""){
                        alert("Prosím zadejte telefon");
		                return (false);
                    }

                    if($("input[name=email]").val().indexOf('@', 0) == -1){
                        alert("Tato emailová adresa je neplatná!");
		                return (false);
                    }

                    if($("input[name=delivery]").val()> 1){
                        if($("input[name=city]").val() == "" || $("input[name=street]").val() == "" || $("input[name=zip]").val() == ""){
                            alert("Zadejte adresu, na kterou si přejete zásilku doručit");
		                return (false);
                        }

                    }
                    if($("input[name=captcha]").val()== ""){
                        alert("Zadejte ověřovací kód");
		                return (false);
                    }
                    
                    return (true);

                });
                $("#recaptcha").click( function () {
                    $("#captcha").attr("src", "/lib/captcha/securimage_show.php?sid=" + Math.random());
                    return false;
                } );
                
                
                $(".files #send_data").click( function () {
                    // upozornit a skoncit, pokud nebyly vybrany soubory
                    if ( $(".uploadifyQueueItem").length == 0 )
                    {
                        alert( "Vyberte prosím alespoň jeden soubor!");
                        return false;
                    }
                    $("#send_data_div").hide();
                    
                    // dojet na seznam souboru
                    window.location += "#upload_title";

                    $("#upload_title .warning").slideDown(500);

                    // start posting files
                    $("#fileInput").uploadifyUpload();
                    return false;
                    
                    
                });
                
                $(".files2 #send_data").click( function () {
                    
                    $("#send_data_div").hide();

                    $("#upload_title .warning").slideDown(500);

                });

		// udalosti pri odeslani formulare
/*		$("#send_data").click( function () {
                    // upozornit a skoncit, pokud nebyly vybrany soubory
                    if ( $(".uploadifyQueueItem").length == 0 )
                    {
                        alert( "Vyberte prosím alespoň jeden soubor!");
                        return false;
                    }

                    // upozornit a skoncit, pokud nejsou spravne vyplnena data
                    if ( !form_check() )
                    {
                        alert( "Vyplňte prosím všechna pole!");
                        return false;
                    }

                    // nedrive overit captchu
                    $.getJSON(
                        "ajax.php",
                        {
                            action  : "captcha_validate",
                            captcha : $("input[name=captcha]").val()
                        },
                        function ( data ) {
                            if ( true )
                            {   
                                // captcha je v poradku, zablokovat opakovane odeslani
                                $("#send_data").attr("disabled", true);
                                
                                // a odeslat pozadavek na inicializaci odesilaciho sezeni
                                $.getJSON(
                                        "/inc/ajax.php",
                                        {
                                            action      : "session_start",
                                            first_name  : $("input[name=first_name]").val(),
                                            last_name   : $("input[name=last_name]").val(),
                                            phone       : $("input[name=phone]").val(),
                                            email       : $("input[name=email]").val(),
                                            city        : $("input[name=city]").val(),
                                            street      : $("input[name=street]").val(),
                                            zip         : $("input[name=zip]").val(),
                                            cut         : $("input[name=cut]:checked").val(),
                                            delivery    : $("select[name=delivery]").val(),
                                            size        : $("select[name=size]").val(),
                                            message     : $("input[name=message]").val(),
                                            count       : $(".uploadifyQueueItem").length,
                                            price       : recompute_price()
                                        },
                                        function (data) {
                                            // zobrazeni cisla objednavky
                                            $(".price.small").after( '<h2 class="order">Číslo objednávky je: ' + data.order_id + "</h2>" );

                                            // dojet na seznam souboru
                                            window.location += "#upload_title";

                                            $("#upload_title .warning").slideDown(500);

                                            // start posting files
                                            $("#fileInput").uploadifyUpload();

                                        }
                                );
                            } else
                            {
                                alert( "Vyplňte prosím správně ověřovací kód!");
                            }
                    });

                    // zabranit odeslani hlavniho formulare
                    return false;
		});*/
	}); 

