$(document).ready(function(){
    
    overlayContainer = $("#popupContainer");

    // overlays
    var activate_callback = function(options){
          adjustToCenter($("#popupContainer"));
          $("a.close-overlay").click(function(){
              $("#popup-background").remove();
              $("#popupContainer").html('');
              return false;
       });
    };

    register_popup = function(url) {
        var popup_options = {};
        popup_options.url = url;
        //popup_options.close_call = close_callback;
        popup_options.activate_call = activate_callback,
   
        overlayContainer.loadJFrame(popup_options);
    };

    bootstrap_popup = function() {
        $("a[target='"+overlayContainer.attr('id')+"']").click(function() {
            var url = $(this).attr('href');

            var popup_options = {};
            popup_options.url = url;
            register_popup(url);
            return false;
         });
    };

    bootstrap_popup(); 



    redirect=false;
    $('#tlf__header').after('<div id="overlay" style="display:none;"></div>');
    $(".lightbox").lightbox();
    
    $('div#tlf__content div.info').each(function() { 
        if(parseInt($(this).height()) >= 300) 
            $(this).addClass("scroll");
    });

    $(".more-handler").click(function() {
        $this = $(this);
        $more = $this.next(".more-content");
        $more.toggleClass("hide");
        $this.remove();
    });


    $('div.shopbox #tlf__map')
        .after($(document.createElement('br')).addClass('cl'))
        .prepend($(document.createElement('a'))
                .attr({'class':'expand-map underline', href:'#'})
                .text(GMAP_INCREASE_HEIGHT)
                .click(function() {
                    gm_toggleHeight();
                    return false;
                })
        )
    ;

    //WSL
    wsl.initialize();
	//globalsearch
	gs.initialize();
    stour.loadTour();

    // jump to selected option anchor (outside scrollpane area)
    $('#jumpto2').change(function() {
        $.scrollTo("#jump_"+this.value, 700 );
        return false;
    });
    $("#detailedShoplist").click(function() {
        $.scrollTo($(".shoplistbox")[0],700);
        return false;
    });
    
    $('a.scroll-link').click(function() {
        $.scrollTo($(this).attr('href'), 700);
        return false;
    });

    // default values for form inputs
    initDefaultInputValues($('form label.default'));

    // focus on input targets of error links
    $('div.error a').click(function() {
        var e_obj = $($(this).attr('href'))[0];
        // only because ie6 knows no :focus
        $($(this).attr('href')).focus(function(){
            $(this).css('background-color','#ccc')
        }).blur(function(){
            $(this).css('background-color','#fff')
        });
        if (e_obj) {e_obj.focus();return false;}
        else return true;
    });

    $('p.labelenum a').click(function(e) {
        //$('div.label').css('background-color','#ededed');
        /*
        var e_obj = $($(this).attr('href'));
        e_obj.parent().find('tr').removeAttr('style');
        e_obj.css('background-color','#fff');
        $.scrollTo(e_obj, 700 , {offset : -150 });
        */
        var id = $(this).attr('href').split('_')[1];
        var teaser = $("#lbl_"+id);
        $(".labelinfo").removeClass('teaserActive');
        teaser.toggleClass('teaserActive');
        $.scrollTo(teaser, 700 , {offset : -150 });

        return false;
    });

    $("#show_phone").click(function() {
        var $this = $(this);
        $.get(siteURL('shop/track_phone/' + $this.attr('rel')));
//        $this.parent().html($this.text());
        $this.remove();
        $(".phone-number:first").slideDown(500);
        return false;
    });


    $(".viewOnMap a").click(
        function() {
            var $this = $(this);
            var toggleParent = $this.parent();
            if(toggleParent.hasClass("opened")) {
                toggleParent.removeClass("opened");
                $this.text(lang.line('show_map'));
            } else {
                toggleParent.addClass("opened");
                $this.text(lang.line('close_map'));
            }
        }
    );
    $("#show_all_maps").click(function(){
        $(".viewOnMap").addClass("opened");
        $(".viewOnMap a").text(lang.line('close_map'));
    });
    $("#hide_all_maps").click(function(){
        $(".viewOnMap").removeClass("opened");
        $(".viewOnMap a").text(lang.line('show_map'));
    });

    $("a.stlistmorelbls").click(function(){
      var id = $(this).parent().parent().attr("id");
      $("#"+id+" p.labels span.stlistmorelbls").toggle();
      $("#"+id+" p.labels a.stlistmorelbls").toggle();
    });

    $("a.print").click(function(){
        url = $(this).attr('href');
        window.open(url,'tlf_print','width=660,height=600,top=0,scrollbars=yes,menubar=yes,toolbar=yes,resizable=yes').focus();
        return false;
    });


    var findValueLabel = function(li) {
        // if coming from an AJAX call, let's use the CityId as the value
        if( li.row )
        { 
            var sValue = li.row.data.name;
            $("#selectedLabelId").val(li.row.data.id);
            $("#label").change(function(){$("#selectedLabelId").val("")});
        } else {
            var sValue = li.selectValue;
        }
    };

    var onChangeLabel = function(li) {
        $("#labelissuperbrand").val('false');
        $("#selectedLabelId").val("");
    };



    var selectItemLabel = function (li) {
        if ($(li).hasClass('unselectable')) {
            return false;
        }

        findValueLabel(li);
        if(li.row.type == "superbrand") {
            $("#label").val($("#label").val() + " " + SUPERBRAND_GROUP);
        }
        $("#label").focus();

    };

    var formatItemLabel = function (entry) {
        var entry_name=entry.data.name_formatted;
        var disallowed ="The URI you submitted has disallowed characters.";
        var row = entry_name;
        if(entry.type == "superbrand")
            row += " " + SUPERBRAND_GROUP;

        if ( entry.type == "label" ) {
            if ( !entry.data.parent_id ) {
                row = '<div>'+entry_name+'</div>';
            } else {
                row = '<div class="indent">'+entry_name+'</div>';
            }
        } else if ( !entry.data.is_selectable ) {
            row = '<div class="unselectable">' + entry.data.name + '</div>';
        } 

        if(row != disallowed){
            return row;
        }

        else
        {
            //disallowed
        }
    };

$("#search #label").autocomplete(
        BASE_URL+"index.php/autocompletion/searchlabel/",
        {
            delay:10,
            minChars:2,
            matchSubset:0,
            maxItemsToShow:30,
            onItemSelect:selectItemLabel,
            onFindValue:findValueLabel,
            onChangeInput:onChangeLabel,
            formatItem:formatItemLabel,
            autoFill:false,
            resultsClass: "ac_results",
            width: "156",
            call_submit: function() {
                $(".ac_results").each(function() {
                    $(this).css("display","none");
                });
                gs.submitButton();
            },
            call_on_item_selected: function(li, v) {
                if(li.row.type == 'superbrand') {
                    $("#labelissuperbrand").val('true');
                    var tmpSuperbrand = v.toLowerCase();
                } else if(li.row.type == 'label') {
                    $("#labelissuperbrand").val('false');
                }
            }
        }
);

        var findValueShop = function(li) {
            $("#selectedShopId").val(li.row.data.id);
        }
        
        var onChangeShop = function(li) {
            $("#selectedShopId").val("");
        }

        var selectItemShop = function (li) {
            findValueShop(li);
             $("#shop").focus();
        }

        var formatItemShop = function (entry) {
            var row = entry.data.name_formatted;
            row += "<br /><div class='indent'>"+entry.data.street+"</div>";
            return row;
        }


$("#search #shop").autocomplete(
        BASE_URL+"index.php/autocompletion/searchshop/",
        {
            delay:10,
            minChars:2,
            matchSubset:0,
            onItemSelect:selectItemShop,
            onFindValue:findValueShop,
            onChangeInput:onChangeShop,
            formatItem:formatItemShop,
            cacheLength: 0,
            autoFill:false,
            resultsClass: "ac_results",
            width: "156",
            call_submit: function() {
                $(".ac_results").each(function() {
                    $(this).css("display","none");
                });
                gs.submitButton();
            }
        }
);

//city-autocompletion


    var findValueCity = function(li) {
        $("#selectedCityId").val(li.row.data.id);
    };

    var onChangeCity = function(li) {
        $("#selectedCityId").val("");
    };

    var selectItemCity = function (li) {
        findValueCity(li);
        $("#city").focus();
    };

    var formatItemCity = function (entry) {
        row = entry.data.name_formatted;
        if ( entry.data.alternative_name_formatted ) { 
            row += " (" + entry.data.alternative_name_formatted+ ")";
        }
        return row;
    };


$("#search #city").autocomplete( 
        BASE_URL+"index.php/autocompletion/searchcity/",
        {
            delay:10,
            minChars:2,
            matchSubset:0,
            onItemSelect:selectItemCity,
            onFindValue:findValueCity,
            onChangeInput:onChangeCity,
            formatItem:formatItemCity,
            autoFill:false,
            resultsClass: "ac_results",
            width: "206",
            call_submit: function() {
                $(".ac_results").each(function() {
                    $(this).css("display","none");
                });
                gs.submitButton();
            }
        }
);



    // stop flash when user moves mouse outside of flash
    if(!$.browser.msie || $.browser.version >= 7) { // for all browsers except IE 6
        $('.imagesFlashContent > embed, .imagesFlashContent > object').mouseout(function() {
            try {
                this.SetVariable('scrolling', '0');
            } catch(e) {
            }
        });
    }


    // setup sortable shopping tours
    $('.sortme').sortable({
        items: '.sorty',
        containment: 'parent',
        hoverClass: 'sorting'
    });
    $('#tourlist').bind('submit',saveshoppingtour);

/*
    $('#search-button').click(function(e){
        $("#search").submit();
		//globalSearch(e,searchform);
    });
*/

    $("#captcha_box a").click(function(){resetCaptcha();return false;});


    shoppingtour_initialize_bindings();

    // shop/label infotext local language selection
    
    $("p.infoTextLangSel a[name^=lang]").click(function() {
        $(this).addClass("active");
        $(".info .infoText").addClass("hide");
        var t = $(".info .infoText[lang='"+$(this).attr('name').split('_')[1]+"']").removeClass("hide");
        // hide other language fields
        $(this).siblings().removeClass("active");
        
	    
        return false;
    });

});// end $(document).ready(...)

/**
 * Initializes bindings for shoppingtour elements
 * @author Tilo Baller <baller@cosmocode.de>
 */
function shoppingtour_initialize_bindings() {
    $("#shoppingtour_line a:first").click(function(){
      shoppingtour_addform_toggle();
      return false;
    });

    $("#shoppingtouradd").submit(function(){
      shoppingtour_add();
      return false;
    });

    $("#shoppingtours li>a:first-child").click(function(){
      shoppingtour_add_remove(this);
      return false;
    });

}

/**
 * Shows/hides form to add a shoppingtour
 * @author Tilo Baller <baller@cosmocode.de>
 */
function shoppingtour_addform_toggle() {
    if(!$("#shoppingtouradd").length) return;
    elem = $("#shoppingtouradd")[0];
    
    if(elem.style.display == "none")
        elem.style.display = "block";
    else
        elem.style.display = "none";
}

/**
 * Adds a shoppingtour by submitting the form
 * @author Tilo Baller <baller@cosmocode.de>
 */
function shoppingtour_add() {
    shopId = $("#shoppingtouradd input[name='shopId']")[0].value;
    tour = $("#shoppingtouradd input[name='tour']")[0].value;

    $("#shoppingtour_container").load(
        BASE_URL+"index.php/shoppingtour/add",
        {tour: tour, shopId: shopId},
        function(){
            $("#shoppingtouradd").submit(function(){
                shoppingtour_add();
                return false;
            });
            $("#shoppingtours li>a:first-child").click(function(){
              shoppingtour_add_remove(this);
              return false;
            });
            //reinit default values
            initDefaultInputValues($('#shoppingtouradd label.default'));
        }
    );
}

/**
 * Evaluates click on a single shoppingtour and decides addition or deletion of the entry
 * @author Tilo Baller <baller@cosmocode.de>
 */
function shoppingtour_add_remove(sender) {
    data = sender.hash.split("_");

    action = data[0].substr(1,data[0].length);
    tourId = data[1];
    shopId = data[2];

    $("#shoppingtour_container").load(
        BASE_URL+"index.php/shoppingtour/"+action+"/"+tourId+"/"+shopId,
        function(){
            $("#shoppingtouradd").submit(function(){
                shoppingtour_add();
                return false;
            });
            $("#shoppingtours li>a:first-child").click(function(){
              shoppingtour_add_remove(this);
              return false;
            });
            //reinit default values
            initDefaultInputValues();
        }
    );
}

/**
 * Saves the shopping tour notes and sorting
 * @author Andreas Gohr <gohr@cosmocode.de>
 */
function saveshoppingtour(e) {
    var shoptour = $('#tourlist');
    var data = {};
    data['tourname'] = shoptour.find('#tourname').val();
    data['updatetour_button'] = 1;
    data['shopids'] = shoptour.find('.sorty').map(function(){
                        data['comments_'+this.id] = $(this).find('textarea').val();
                        return this.id;
                   }).get().join(',');

    $('#tourlist input#shopids').val(data['shopids']);

//submit via ajax
    $.post(shoptour.attr('action'),data,function(){ $('#sendSL').vkfade() });
    e.preventDefault();
    return false;


}

/** creates new captcha
 * captcha controller url must end with 'captcha'
 * @author Detlef Huettemann <huettemann@cosmocode.de>
 */
function resetCaptcha() {
    var img = $('#captcha_box img');
    if ( img ) {
        img.attr('src', img.attr('src').replace(/\/captcha.*/,'/captcha/' + ((new Date()).getTime() )));
    }
}
/* open big image out of flash
*/
function openBigImage (imageUrl) {
    // workaround for image names with special chars  / images with encoded names
    if($("a[title='"+imageUrl+"']").length)
        $("a[title='"+imageUrl+"']").click();
    else if($("a[href='"+imageUrl+"']").length)
        $("a[href='"+imageUrl+"']").click();
}

var search={
	initialize: function(){
		$("#shop").focus(function(){
			search.shop();
		});
		$("#search").click(function(){
			search.submitButton();
		});
	},
	shop: function(){
		$("#search").attr("action",BASE_URL+"index.php/shop/bySearch");
	},
	submitButton: function(){
	}
}
//globalsearch
var gs={
	data: {},
	searchController:"",
	initialize : function() {
		this.handleFocus();
		gs.fieldAction();
        $("#search").submit(function(){
            return false;
        });
        $("#search-button").click(function(){
            gs.submitButton();
		});
    this.setDisabled($("#shop"));
	},
	submitButton: function(){
		$("#search").ajaxSubmit(function(data){
			var searchResult=JSON.parse(data);
			gs.lookup(searchResult);
		});
	},
	fieldAction: function()
	{
		$("#label").change(function(){
			gs.setDisabled($("#shop"));
		});
		$("#city").keydown(function(){
			gs.setEnabled($("#shop"));
         $("#shop").val("");
			gs.setEnabled($("#label"));
		}).change(function() {
      var citylabel = $("#city").parent().find('label.default');
      if($.trim($("#city").val())=='' || $("#city").val().indexOf(citylabel.text())===0)
          $("#shop").mouseover().mouseout();
    });
		$("#label").mouseover(function(){
      gs.setEnabled($("#label"));
      if($.trim($(this).val()) != '' && $(this).val() != $(this).parent().find('label.default').text())
    			gs.setDisabled($("#shop"));
		});
		$("#shop").mouseover(function(){
      var citylabel = $("#city").parent().find('label.default');
      if($.trim($("#city").val())=='' || $("#city").val().indexOf(citylabel.text())===0) {
          gs.setDisabled($("#shop"));
          var tmp = $("#shop").parent().find('label.default').text();
          $("#shop").val(ENTER_TOWN_FIRST);
//          $("#shop").unbind('mouseout').mouseout(function() {
//              $("#shop").val(tmp);
//              $("#shop").unbind('mouseout');
//          });
      } else {
          gs.setEnabled($("#shop"));
          if($.trim($("#shop").val()) != '' && $("#shop").val() != $("#shop").parent().find('label.default').text())
              gs.setDisabled($("#label"));
      }
		});
		$("#shop").keydown(function(){
      if($(this).hasClass('disabled')) return;
      if($.trim($(this).val()) != '' && $(this).val() != $(this).parent().find('label.default').text())
          gs.setDisabled($("#label"));
      $("#shop").focus();
		});
	},
  setDisabled: function(elem) {
      if(!$(elem).length || $(elem).hasClass('disabled')) return;
      $(elem).addClass('disabled')
      .click(function(){ $('#city').focus(); return false;})
      .css('cursor','default')
      .keydown(function() { if($(this).hasClass('disabled')) return false; })
      .blur();
      hiddenDisabledElem = $(elem).parent().find("input[name='"+$(elem).attr('id')+"Disabled']");
      if(!hiddenDisabledElem.length)
          $(elem).parent().append('<input type="hidden" name="'+$(elem).attr('id')+'Disabled" value="1">');
      else
          hiddenDisabledElem.val("1");
          
      initDefaultInputValues($(elem).parent().find('label.default'));
  },
  setEnabled: function(elem) {
      if(!$(elem).length || !$(elem).hasClass('disabled')) return;
      $(elem).removeClass('disabled')
      .unbind('click')
      //.unbind('focus')
      .css('cursor','auto');
      hiddenDisabledElem = $(elem).parent().find("input[name='"+$(elem).attr('id')+"Disabled']");
      if(hiddenDisabledElem.length)
          hiddenDisabledElem.val("");
      initDefaultInputValues($(elem).parent().find('label.default'));
  },
	lookup: function(result){
			switch(result.status){
   				case "error":
					$("#morelabels").html('<p class="morelabels error">'+result.message+'</p>');

                                        bootstrap_popup(); 
					return false;
					break;
				case "success":
					window.location.href = result.message;
					break;
				default:
			}
	},
	disable: function(element)
	{
		$(element).attr("disabled","disabled");
	},
	enable: function(element)
	{
		$(element).removeAttr("disabled");
	},

	handleFocus: function(){
		$("#shop").focus(function(){});
		$("#label").focus(function(){
			gs.setDisabled($("#shop"));
		});
		$("#city").focus(function(){});
	}
}
var stour = {
    loadTour : function(){
        //text while loading wsl data
        /*$("#wslContainer").text("loading wsl...");
        $("#continentChoose").text(this.data.continentId);
        $("#countryChoose").text(this.data.countryId);
        $("#cityChoose").text(this.data.cityId);*/
        //initialize click handlers
        if($('#shopId').length && $("#shoppingtour").length)
        {
            var shopId = $('#shopId').val();
            if($("#shoppingtour").length) {
                $("#shoppingtour").load(BASE_URL+'index.php/shoppingtour/view/'+shopId,function(){
                    shoppingtour_initialize_bindings();

                
                    return false;
                });
            }
            return false;
        }
    }
}

//load wsl section
var wsl={
    data: {},
    seperator: "",
    initialize : function(){
    this.data.labelId=$("#labelId").val();
    this.data.continentId=$("#continentId").val();
    this.data.continentName=$("#continentName").val();
    this.data.countryId=$("#countryId").val();
    this.data.countryName=$("#countryName").val();
    this.data.cityId=$("#cityId").val();
    this.data.cityName=$("#cityName").val();
    this.data.wslLayover=$("#wslLayover");
    //seperator to split the id's of continent/country/city
    this.seperator="__";
    this.loadWsl();
    },
    loadMenuHandler : function ()
    {
        $("#continentChoose").unbind().click(function(){wsl.continents();return false;});
        $("#countryChoose").unbind().click(function(){wsl.countries();return false;});
        $("#cityChoose").unbind().click(function(){wsl.cities();return false;});
    },

    reset : function () {
        this.resetContinent();
        this.resetCountry();
        this.resetCity();
    },
    loadWsl : function(){
        //text while loading wsl data
        /*$("#wslContainer").text("loading wsl...");
        $("#continentChoose").text(this.data.continentId);
        $("#countryChoose").text(this.data.countryId);
        $("#cityChoose").text(this.data.cityId);*/
        //initialize click handlers

        if($("#wslContainer").length) {
            $("#wslContainer").load(BASE_URL+'index.php/wsl/getWsl/'+$.base64Encode(this.data.labelId),function(){
                wsl.loadMenuHandler();
                //wsl.addCloseButton();
                wsl.reset();
                return false;
            });
        }
        return false;
    },
    continents: function(){
        $("#treeCountries").css('visibility','hidden');// silly IE
        $("#treeCities").css('visibility','hidden');// silly IE
        $("#listOfContinents").load(BASE_URL+'index.php/wsl/getContinents/'+wsl.data.labelId,{show:$("#show").val()},function(){
            $('.scroll').jScrollPane({scrollbarWidth:7,dragMinHeight:25});
            wsl.closeOtherLayovers($(this).attr('id'));
            wsl.addCloseOnHead($(this).attr('id'));
            $("#listOfContinents a").click(function(){
                $("#treeCountries").css('visibility','visible');// silly IE
                $("#treeCities").css('visibility','visible');// silly IE
                wsl.setContinent(this);
                wsl.countries();
                return false;
            });
        });
        return false;
    },
    countries: function(){
        //$("#listOfCountries").addClass("hide");
        $("#treeCities").css('visibility','hidden');// silly IE
        $("#listOfCountries").load(BASE_URL+'index.php/wsl/getCountries/',{labelId:wsl.data.labelId,continentId:wsl.data.continentId,show:$("#show").val()},function(){
                $('.scroll').jScrollPane({scrollbarWidth:7,dragMinHeight:25});
                wsl.closeOtherLayovers($(this).attr('id'));
                wsl.addCloseOnHead($(this).attr('id'));
                $("#listOfCountries a").unbind().click(function(){
                    $("#treeCities").css('visibility','visible');// silly IE
                    wsl.setCountry(this);
                    wsl.cities();
                    return false;
                });
                if($("#listOfCountries a").length == 1) {
                    $("#listOfCountries a").click();
                    return;
                }
                $("#listOfCountries").removeClass("hide");
        });
        return false;
    },
    cities: function(){
        //$("#listOfCities").addClass("hide");
        $("#listOfCities").load(BASE_URL+'index.php/wsl/getCities/',{labelId:wsl.data.labelId,countryId:wsl.data.countryId,show:$("#show").val()},function(){
                $('.scroll').jScrollPane({scrollbarWidth:7,dragMinHeight:25});
                wsl.closeOtherLayovers($(this).attr('id'));
                wsl.addCloseOnHead($(this).attr('id'));
                $("#listOfCities a").unbind().click(function(){
                    wsl.setCity(this);
                    wsl.closeLayover(this);
                });
                if($("#listOfCities a").length == 1) {
                    wsl.setCity($("#listOfCities a")[0]);
                    window.location = $("#listOfCities a:first").attr('href');
                    return;
                }
                $("#listOfCities").removeClass("hide");
        });
        return false;
    },
    addCloseOnHead: function(elementId)
    {
        $(".closeTree").click(function(ce){
            $("#"+elementId).empty();
            $("#treeCountries").css('visibility','visible');// silly IE
            $("#treeCities").css('visibility','visible');// silly IE
        });
    },

    addCloseButton:  function() {
        $('#overlay').show().css("background-image","none");
        $(".layover").prepend('<div class="close"></div>');
        $(".layover .close").css("cursor","pointer").unbind().click(function(){
            wsl.closeLayover();
        });
    },
    closeOtherLayovers: function(currentLayover) {
        $(".wslList").each(function(){
            if($(this)[0].id != currentLayover)
            {
                $(this).empty();
            }
        });
    },
    closeLayover : function(ce) {
        //clear for example continents-tree
        $(ce).parents().find(".wslList:first").empty();
    },
    //Example id continent__5__Europe
    setContinent : function(ce) {
        var id=ce.id.split(wsl.seperator);
        wsl.data.continentId=id[1];
        $("#continentId").val(id[1]);
        $("#continentChoose").text(id[2]);
        if(id[3] == 1) {
            $("#continentChoose").unbind()
            .click(function(){return false})
            .addClass('single');
        }
        this.loadMenuHandler();
        $("#countryChoose").text(wsl.getDefault('country')).removeClass('single');
        $("#cityChoose").text(wsl.getDefault('city')).removeClass('single').css('font-weight','normal');
        wsl.data.countryId = '';
        wsl.data.cityId = '';
    },
  resetContinent : function() {
        if(wsl.data.continentName.length)
            $("#continentChoose").text(wsl.data.continentName)
        if($("#continentCount").val() == "1") {
            $("#continentChoose").unbind()
            .click(function(){return false})
            .addClass('single');
        }
        $("#treeCountries").show();
        $("#treeCities").show();
    },
    setCountry : function(ce) {
        var id=ce.id.split(wsl.seperator);
        wsl.data.countryId=id[1];
        $("#countryId").val(id[1]);
        $("#countryChoose").text(id[2]);
        if(id[3] == 1) {
            $("#countryChoose").unbind()
            .click(function(){return false})
            .addClass('single');
        }
        this.loadMenuHandler();
        $("#cityChoose").text(wsl.getDefault('city')).removeClass('single').css('font-weight','normal');
        wsl.data.cityId = '';
    },
  resetCountry : function() {
        if(wsl.data.countryName.length)
            $("#countryChoose").text(wsl.data.countryName)
        if($("#countryCount").val() == "1") {
            $("#countryChoose").unbind()
            .click(function(){return false})
            .addClass('single');
        }
    },
    setCity : function(ce) {
        var id=ce.id.split(wsl.seperator);
        wsl.data.cityId=id[1];
        $("#cityId").val(id[1]);
        $("#cityChoose").text(id[2]);
        if(id[3] == 1) {
            $("#cityChoose").unbind()
            .click(function(){return false})
            .addClass('single');
        }
    },
  resetCity : function() {
        if(wsl.data.cityName.length)
            $("#cityChoose").text(wsl.data.cityName)
            .css("font-weight", "bold");
        if($("#cityCount").val() == "1") {
            $("#cityChoose").unbind()
            .click(function(){return false})
            .addClass('single');
        }
    },
    getDefault : function(strItem) {
        defaultVal="default";
        defaultVal=$.ajax({type: "GET", url:BASE_URL+"index.php/wsl/getDefault/"+strItem,async:false}).responseText;
        return defaultVal;

    }

}

// default values for form inputs
function initDefaultInputValues(elem) {
    return; //q&d workaround for not showing text in inputs
    if(typeof(elem) == "undefined" || !elem.length) return;
    elem.hide().siblings('input,textarea').each(function() {
         if(this.value=='') this.value=$(this).prev().text();
    }).focus(function() {
         if (this.value==$(this).prev().text())
            this.value='';
    }).blur(function() {
        if (this.value=='')
            this.value=$(this).prev().text();
    });
}

// overlays
var overlayContainer;
function adjustToCenter(obj) {
    var top = $(window).scrollTop() + Math.floor(($(window).height() - obj.height()) / 2);
    if (top < $(window).scrollTop()) top = $(window).scrollTop();
    obj.css('top', top);
    obj.css('left', Math.floor( 867 - obj.width()) /2) ;
}
