/**
 * Javascript for ToCroatia Theme
 */
function IsEmpty(aTextField) {
   if ((aTextField.length == 0) || (aTextField == null) || (typeof(aTextField) === 'undefined')) {
      return true;
   }
   else { return false; }
}
	
$(document).ready(function(){


    $("#shadow").css({
        visibility: "visible"
    });
    
    $('#AccommodationAddForm [title]').tipsy({
        trigger: 'focus',
        gravity: 'w'
    });
    $('#quick_menu img').tipsy({
        gravity: 'n'
    });
    
    $("#sidebar ul.sf-menu").superfish({
        delay: 400, // delay on mouseout
        animation: {
            opacity: 'show',
            height: 'show'
        }, // fade-in and slide-down animation
        speed: 'fast', // faster animation speed
        autoArrows: true, // disable generation of arrow mark-up
        dropShadows: true // disable drop shadows
    });
    
    
    var pathname = window.location.pathname;
    var cid = null;
    var accid = null;
    var pf = null;
    var pt = null;
    
    //alert(pathname);
    
    var pathElem = pathname.split("/");
    for (i in pathElem) {
        var elem = pathElem[i].split(":");
        if (!IsEmpty(elem[0])) {
            switch (elem[0]) {
                case "cid":
                    cid = elem[1];
                    $("#city_ac").val(cid).trigger("change");
                    break;
                case "accid":
                    accid = elem[1];
                    $("#acctype_id").val(accid).trigger("change");
                    break;
                case "pf":
                    pf = elem[1];
                    break;
                case "pt":
                    pt = elem[1];
                    break;
            }            
        }
    }    
    
    //console.debug(cid + " - " + accid + " - " + pf + " - " + pt);
    
    var max_price = new Number($("#max_price").val());
    var min_price = new Number($("#min_price").val());
    var rd = Math.floor((max_price - min_price) / 3);
	
	if(pf){		
    	var pmin = pf;
    	var pmax = pt;
	}else{
    	var pmin = new Number(Math.floor((min_price + rd)));
    	var pmax = new Number(Math.floor((max_price - rd)));		
	}
    
    $("#span-price-range").text(pmin + '€ - ' + pmax + '€');
    $("#input_price_from").val(pmin);
    $("#input_price_to").val(pmax);
    
    $("#slider-price").slider({
        range: true,
        min: min_price,
        max: max_price,
        values: [pmin, pmax],
        slide: function(event, ui){
            $("#input_price_from").val(ui.values[0]);
            $("#input_price_to").val(ui.values[1]);
            $("#span-price-range").text(ui.values[0] + '€ - ' + ui.values[1] + '€');
        }
    });
    
    
    
    $('#advanced_search select').selectmenu({
        width: 250,
        maxHeight: 250
    });
    
    $("#city_ac-menu, #acctype_id-menu, #city_ac-button, #acctype_id-button").removeClass("ui-corner-all");
    $("#city_ac-button,#acctype_id-button").css({
        background: "none"
    });
    
    
    var message = $('#flashMessage').text();
    if (message) {
        $('#session_for_layout').fadeIn('slow');
        $('#session_for_layout').click(function(){
            $(this).fadeOut('slow');
        });
    }
    
});

