function loadFlash() {
    $('#mapKraje').ready(function(){
        var file=$('#mapKraje').attr("title");
        $('#mapKraje').flash({
            src:'/media/Flash/'+file+'.swf',
            width:'550',
            height:'250',
            wmode: 'transparent',
            allowfullscreen:'true'
        });
    });

//    $('#mapOblasti').ready(function(){
//        $('#mapOblasti').flash({
//            src:'/media/Flash/mapa_turisticke_oblasti.swf',
//            width:'550',
//            height:'250',
//            wmode: 'transparent',
//            allowfullscreen:'true'
//        });
//    });
}

function setCookie (value, show_window) {
    $.cookie('gmap1', value);
    if (show_window) {

    } else {
        $.cookie('gmap2', value);
    }
}

function loadCookie (name) {
    var myCookie = $.cookie(name);
    return myCookie;
}

function palce(palec, souhlas) {
    var parents=$(palec).parents('.usersOpinionPalce');
    var parent=parents[0];
    var parent_id=$(parent).attr('id');
    var temp=parent_id.split('_');
    var prispevek_id=temp[1];  
    $(parent).load("/palce_dokempu.php?dis_id="+prispevek_id+"&hlas="+souhlas);
}

function toggleUserInfo(handler, display) {
    var okno=$(handler).children(".user_info");
    //var parents=$(handler).parents("div");
    //var okno=$(parents[0]).children(".user_info");
    if (display) {
        $(okno[0]).fadeIn(100);
    } else {
        $(okno[0]).fadeOut(100);
    }
}

function showHideCookieTrail (handler) {
    $('#cookieTrailInfoText').slideToggle(300, function () {
        if ($('#cookieTrailInfoText').css('display')=='none') {
            $('.cookieTrailToggle').attr('src', '/media/Image/visual/kempy/dropDownArrow.jpg');
        } else {
            $('.cookieTrailToggle').attr('src', '/media/Image/visual/kempy/backToTop.jpg');
        }
    });
}

function kontakt_show(id, verze, title) {
    $.get('/ajax_call.php?page=save_kontakt_stats&include=yes&typ=tel&id='+id);

    var odkaz="/index.php?page=detail_phone_form&only=yes&verze="+verze+"&id="+id;
    Shadowbox.open({
        content:    odkaz,
        player:     "iframe",
        width:      710,
        height:     550,
        title:      title
    });

}

function listaLink(handler, show) {
    var temp=$(handler).children(".nase-tipy");
    if (show) {
        $(temp[0]).show();
    } else {
        $(temp[0]).hide();
    }
}

function nullSearchFromSelects(handler) {
    var parent=$(handler).parent();
    var sibling=$(parent).siblings(".region_select");
    var select=$(sibling[0]).children("select");
    var options=$(select[0]).children("option"); 
    $(options[0]).siblings().each(function(index, item){
        $(item).attr("selected", "");
    });
    $(options[0]).attr("selected","selected");
} 

function showHideVybaveni(handle, updown, zobraz, skryj) {
    if(zobraz==undefined)
        zobraz = 'zobrazit';
    
    if(skryj==undefined)
        skryj = 'skrýt';
    
    var parent=$(handle).parent();  
    if ($(parent[0]).hasClass('toggleEquipShown')) {        
        if (updown!=1) {
            $(handle).next().slideUp("slow", function (){
                $(handle).children("a").each(function (index, item){
                    $(item).html(zobraz);
                });
                $(handle).children("img").each(function (index, item){
                    $(item).attr('src',"/media/Image/visual/kempy/toggleDown.png");
                });
            });    
            $(handle).parent().toggleClass("toggleEquipShown", 500);      
        }
    } else {          
        if (updown!=2) {
            $(handle).next().slideDown("slow", function (){                        
                $(handle).children("a").each(function (index, item){
                    $(item).html(skryj);
                }); 
                $(handle).children("img").each(function (index, item){
                    $(item).attr('src',"/media/Image/visual/kempy/toggleUp.png");
                });                     
            });           
            $(handle).parent().toggleClass("toggleEquipShown", 500);   
        }
    }
}

/*ceník*/
//function getCeny(countable){
function getCeny(){
    $(".closed").hide();
    var prijezd=$("#In_Year").val()+"-"+$("#In_Month").val()+"-"+$("#In_Day").val();
    var odjezd=$("#Out_Year").val()+"-"+$("#Out_Month").val()+"-"+$("#Out_Day").val();
    var accId=$("#accId").val();
    var verze=$("#verze").val();
    $.get("/index.php?page=zarizeni_kalkulator&include=yes&ajax=1&prijezd="+prijezd+"&odjezd="+odjezd+"&accId="+accId+"&verze="+verze, function(data){
        var ceny=jQuery.parseJSON(data);
        if (ceny=='closed') {
            $(".closed").show();
        } else { 
            var total=0; 
            var allPrices=1;
            for(i in ceny){
                var count=eval($("li#"+ceny[i].product_id+" option:selected").val());
                if (ceny[i]['ma_cenu']) {
                    var price=count*ceny[i].price; 
                    if (count>0) {
                        $("#"+ceny[i].product_id+" .price").html(price+"");
                        $("#"+ceny[i].product_id+" .price").parent().css('display', 'inline');
                    } else {
                        $("#"+ceny[i].product_id+" .price").html(""); 
                        $("#"+ceny[i].product_id+" .price").parent().css('display', 'none');
                    }
                    total+=price;
                } else {
                    allPrices=0;
                    if (count>0) {                   
                        $("#"+ceny[i].product_id+" .price").parent().html('<span class="price"> - </span>');
                        $("#"+ceny[i].product_id+" .price").parent().css('display', 'inline');                     
                    } else {
                        $("#"+ceny[i].product_id+" .price").html(""); 
                        $("#"+ceny[i].product_id+" .price").parent().css('display', 'none');
                    }
                }
            }
            if (allPrices) {           
                $("#price_total").html(total);
            } else {
                $("#price_total").parent().html(" - ");
            }
        }
    });
}

function getCenyUvod(){
    $(".closed").hide();
    var prijezd=$("#In_Year").val()+"-"+$("#In_Month").val()+"-"+$("#In_Day").val();
    var odjezd=$("#Out_Year").val()+"-"+$("#Out_Month").val()+"-"+$("#Out_Day").val();
    var accId=$("#accId").val();
    var verze=$("#verze").val();
    $.get("/index.php?page=zarizeni_kalkulator&include=yes&ajax=1&prijezd="+prijezd+"&odjezd="+odjezd+"&accId="+accId+"&verze="+verze, function(data){
        var ceny=jQuery.parseJSON(data);
        if (ceny=='closed') {
            $(".closed").show();
        } else { 
            for (i in ceny) {
                var cena=ceny[i].price;
                var cenaCalc= ceny[i].price*parseInt($("#product_"+i).find("option:selected").val());
                var cenaEl= $("#product_"+i).find(".price");
                var cenaCalcEl=$("#product_"+i).find(".priceCalc");  

                var origPrice=parseInt($(cenaEl).html());  
                var origPriceCalc=parseInt($(cenaCalcEl).html());                               
                $(cenaEl).html(cena+"");
                $(cenaCalcEl).html(cenaCalc+""); 

                if (origPrice!=cena) {
                    flashElement($(cenaEl).parent());  
                }
                if (origPriceCalc!=cenaCalc) {
                    flashElement($(cenaCalcEl).parent());  
                }                                     
            }
        } 
    });
}



function getJazyk(){
    var url = window.location;
    var ln = '';
    if((url+'').indexOf('/de/')>0)
        ln = 'de';
    else if((url+'').indexOf('/nl/')>0)
        ln = 'nl';
    else if((url+'').indexOf('/es/')>0)
        ln = 'es';
    else if((url+'').indexOf('/fr/')>0)
        ln = 'fr';
    else if((url+'').indexOf('/pl/')>0)
        ln = 'pl';
    return ln;
}

$(document).ready(function(){
    $('.productCount select').change(function(){
        var element=$($(this).parent("li")).prev();
        var parent=$(this).parent("li");
        var selected=$(parent).find("option:selected");
        if (selected!=undefined){
            if ($(selected[0]).val()>0) {
                if(!$(element).hasClass("active")) {
                    $(element).addClass("active");
                }
            } else {
                $(element).removeClass("active");
            }
        }
    });
});


/**
 * $param int min_pocet - města, která budou mít více nebo rovno budou zvýrazněna
 */
function showMoreCities(min_pocet) {
    var ln = getJazyk();
    if(ln!='')
        ln = '/'.ln;
    $("#mesta").load(ln+"/index.php?page=hlavni_navi_box_mesta&include=yes&min_pocet="+min_pocet+"&all=1&ids="+$("#foundIds").val());
}

function showLessCities() {
    var ln = getJazyk();
    if(ln!='')
        ln = '/'.ln;
    $("#mesta").load(ln+"/index.php?page=hlavni_navi_box_mesta&include=yes&limit=13&ids="+$("#foundIds").val());
}

/*kalkulačka slev*/
slevyKalkulator=function(){
    slevyKalkulator.prototype.root=$("<div></div>");
    slevyKalkulator.prototype.form=$("<div>Zde prosím zadejte cenu ubytování: <input id='price' type='text' size='5'/> <select id='currency'><option value='czk' selected='selected'>Kč</option><option value='eur'>&euro;</option></select><input type='button' id='calculate' value='spo\u010dítat' class='bt'></div>")
    slevyKalkulator.prototype.res=$("<div style='display:none'>Nejvíce se vám vyplatí koupit: <span id='resCount'></span> poukaz\u016f<br />Zakoupením slevových poukaz\u016f ušetříte: <span id='priceSpare'></span><br />Vaše cena bude: <span id='yourPrice'></span></div>")
    slevyKalkulator.prototype.hlaska=$("<div id='hlaska' style='display:none;'></div>")
    slevyKalkulator.prototype.root.append(slevyKalkulator.prototype.form);   
    slevyKalkulator.prototype.root.append(slevyKalkulator.prototype.res); 
    slevyKalkulator.prototype.root.append(slevyKalkulator.prototype.hlaska);     
}
slevyKalkulator.prototype.init=function(id) {
    $("#"+id).html("");
    $("#"+id).append(slevyKalkulator.prototype.root);
    $('#calculate').click(function(e){
        slevyKalkulator.prototype.calculate();
    });    
}
slevyKalkulator.prototype.calculate=function() {
    slevyKalkulator.prototype.hlaska.slideUp();  
    var currency=$("#currency").children('option:selected').val();
    var castka=parseInt($("#price").val());
    
    if (currency=='czk') {
        if (castka<300) {
            slevyKalkulator.prototype.res.slideUp();  
            slevyKalkulator.prototype.hlaska.html("Nevyplatí se vám kupovat žádný poukaz.");
            slevyKalkulator.prototype.hlaska.slideDown();             
        } else {
            var kuponu=Math.floor(castka/500);
            var doplatit=castka%500;
            if (doplatit>299) {
                kuponu++;
                var vaseCena=kuponu*300;  
            } else {
                var vaseCena=kuponu*300+doplatit;  
            }
                 
            var usetrite=Math.ceil(castka-vaseCena);
    
            $("#resCount").html(kuponu);
            $("#priceSpare").html(usetrite+" Kč");
            $("#yourPrice").html(vaseCena+" Kč");
    
            slevyKalkulator.prototype.res.slideDown();  
        }
        
    } else {
        $.get("/getCurrency.php?to=CZK&from=EUR&amount=1", function(kurz){
            if (castka*eval(kurz)<300) {
                slevyKalkulator.prototype.res.slideUp();      
                slevyKalkulator.prototype.hlaska.html("Nevyplatí se vám kupovat žádný poukaz.");
                slevyKalkulator.prototype.hlaska.slideDown();             
            } else {
                var kuponu=Math.floor(castka/20);
                var doplatit=doplatit=castka%20;
                var doplatitCZK=doplatit*eval(kurz);                      
                if (doplatitCZK>300) {
                    kuponu++;
                    var vaseCena=kuponu*300;    
                } else {
                    var vaseCena=kuponu*300+doplatitCZK; 
                }
                var usetrite=Math.ceil((castka*eval(kurz))-vaseCena);
    
                $("#resCount").html(kuponu);
                $("#priceSpare").html(usetrite+" Kč");
                $("#yourPrice").html(Math.ceil(vaseCena)+" Kč");
    
                slevyKalkulator.prototype.res.slideDown();       
                slevyKalkulator.prototype.hlaska.html("Cena je založena na aktuálním středovém kurzu a může se v průbehu doby měnit.");
                slevyKalkulator.prototype.hlaska.slideDown();  
            }
        });   
    }    
}
$(document).ready(function(){
    var sk=new slevyKalkulator();
    sk.init("slevyKalkulator");
})


/*hodnocení*/
$(document).ready(function(){
    $(".star_rating").rating({
        half:true,
        focus:function(value,link) {
            var label=$(link).parents("td").next("td").children(".temp");
            var perm=$(link).parents("td").next("td").children(".sel");
            $(perm).hide();
            $(label).show();
            $(label).html($(link).attr("title"));
        },
        blur:function(value,link){
            var label=$(link).parents("td").next("td").children(".temp");
            var perm=$(link).parents("td").next("td").children(".sel");        
            $(perm).show();
            $(label).hide();    
        }, 
        callback:function(value,link){    
            if (value!=undefined) {
                var label=$(link).parents("td").next("td").children(".temp");
                var perm=$(link).parents("td").next("td").children(".sel");                
                $(perm).html($(link).attr("title"));
                $(perm).show();
                $(label).hide();  
                check_hodnoceni();
            }
            
        },
        drain:function(value,link){    
            
        }
    });
    
    /*fix*/
    $(".rating-cancel").click(function(){
        var label=$(this).parents("td").next("td").children(".temp");
        var perm=$(this).parents("td").next("td").children(".sel");                
        $(perm).hide();
        $(label).hide(); 
        $(perm).html("");                
    });
});

function check_hodnoceni() {
    $(".otazka_max").hide();
    $(".otazka_min").hide();
    $(".otazka_max input").removeClass("validate[required]");
    $(".otazka_min input").removeClass("validate[required]");
    
    var radios=$("input:radio:checked");
    if (radios.length==7) {
        var counterMax=0;
        var counterMin=0;
        for(var i in radios) {
            var r=radios[parseInt(i)];
            if ($(r).val()=="0.5") {
                counterMax++;
            } else if ($(r).val()=="5") {
                counterMin++;
            }
        }
        
        if (counterMax==7) {
            $(".otazka_max").show();  
            $(".otazka_max input").addClass("validate[required]");
        } else if (counterMin==7){
            $(".otazka_min").show(); 
            $(".otazka_min input").addClass("validate[required]");
        }
    }
}

function hodnotit(params) {
    var p=params;       
    $( "#hodnoceni_popup iframe").attr("width",params.width-2);
    $( "#hodnoceni_popup iframe").attr("height",params.height);
    p.closeText="";
    p.draggable=false;
    $( "#hodnoceni_popup" ).dialog(p); 
}
    
function hodnotitClose(handle) {
    window.parent.$( "#hodnoceni_popup" ).dialog('close');
}
  
