startList = function() {

  // zarządzanie popowiedziami w polach input
  $(':text').each(function(){ manageInputValue(this) });
  // włączanie / wyłączanie bloku logowania
  $("#login ul li.login").bind("click", function(e){ $('#loginOn').show(); });
  $("#loginClose").bind("click", function(e){ $('#loginOn').hide(); });
  // rozwijane menu ze szczegółami wyszukiwania
  $('.reSearchDetails li a').bind( "click", function(){ $(this).next().toggle().parent().toggleClass("on"); } )
  // jcarousel
  if ( $('#offerGallery').length) { $('#offerGallery ul').jcarousel({ vertical: true, scroll: 3 }); }
  if ( $('#gallery').length) { $('#gallery ul').jcarousel({ scroll: 1 }); }
  // galeria oferty - podmiana dużego zdjęcia
  $('#offerGallery li a').each(function() {
      $(this).attr('rel', $(this).attr('href'));
      $(this).attr('href', '#');
      $(this).bind('click', function() {
          $('#offerGallery div.colRight a').hide();
          $('#fancybox_' + $(this).attr('id')).show();
      });
  })
  

  // zakładki formularzy
  $('#formTabs li[class!=off] a').each(function(){
    var parentId = $(this).parent().attr('id').replace(new RegExp("formTab"), "#formPane");
    $(this).bind('click', function(){
      $('#formTabs li').removeClass('on');
      $('#formTabs li a').removeClass('on');
      $(this).toggleClass('on').parent().toggleClass('on');
      $('#formPanes > div').removeClass('on');
      $('#formPanes ' + parentId).addClass('on');
    })
  })
  // zakładki wyszukiwarki
  $('#tabPanes').css('overflow', 'hidden');
  $('#reTab0').bind('click', function(){
    $('#reSearch').toggleClass('on');
  })
  $('#tabs li:not(:first-child) a').each(function(){
    var detailsId = $(this).attr('name').replace(new RegExp("pane"), "#reSearchDetails");
    $(this).bind('click', function(){
      $('#reSearch[class!=on]').addClass('on');
      $('#tabs li').removeClass('on');
      $(this).parent().toggleClass('on');
      $('#tabPanes > div').removeClass('on');
      $('#tabPanes #' + $(this).attr('name')).addClass('on');
      // obsługa panelu szczegółów wyszukiwania
      $('.reSearchDetails').removeClass('on');
      $(detailsId).addClass('on');
    })
  })
  
// ie6 fix
if (document.all && document.getElementById) {
  $('ul li:first-child').each(function(){ $(this).attr('class', $(this).attr('class') + ' first'); });
  prepareMenu('menu');
  // if ( $('#adminmenu').length ) { prepareMenu('adminmenu'); }
}

if(typeof CheckMapStart == 'function') {
    CheckMapStart();
}

if(typeof CheckOfferMapStart == 'function') {
    CheckOfferMapStart();
}

if(typeof SubscribeLocationFieldsEvents == 'function') {
    SubscribeLocationFieldsEvents();
}


}
window.onload = startList;



manageInputValue = function(iField) {
    // zarządzanie tekstami popowiedzi w polach input
    var iField = $(iField);
    iField.inputContent = '';
    if (iField.attr('value') && iField.attr('value').length) {
        iField.bind("focus", function(e) {
            if (iField.attr('value').indexOf('...') >= 0) {
                iField.inputContent = iField.attr('value');
                iField.attr('value', '');
            }
//            if (!iField.inputContent) {
//                iField.inputContent = iField.attr('value');
//                iField.attr('value', '');
//            }
//            else {
//                if (iField.attr('value') == iField.inputContent) {
//                    iField.attr('value', '');
//                }
//            }
        });

        iField.bind("blur", function(e) {
            if (!iField.attr('value').length) {
                if (typeof ($(this).data('wBsp')) == 'undefined' ||
!($(this).data('wBsp'))) {
                    iField.attr('value', iField.inputContent);
                }
            }
        });

        iField.bind("keypress", function(e) {
            var code = (e.keyCode ? e.keyCode : e.which);
            if (code == 8) {
                $(this).data('wBsp', true);
            }
        });
    }
}
prepareMenu = function(id) {
  // fix dla IE6 i rozwijanego menu
  var sfEls = document.getElementById(id).getElementsByTagName("LI");
  for (var i = 0; i < sfEls.length; i++) {
  	sfEls[i].onmouseover = function() {
  		this.className += " over";
  	}
  	sfEls[i].onmouseout = function() {
  		this.className = this.className.replace(new RegExp(" over\\b"), "");
    }
  }
}

function MainSearchBarClicked(){
    var mainSearchBoxMode = this.document.getElementById("ucMainSearchBox_searchBoxMode");
    if(mainSearchBoxMode!= null){
        if(mainSearchBoxMode.value == "on"){
            //jak on to chowamny
            var mapVisible = this.document.getElementById("ucMainSearchBox_mapVisible");
            if(mapVisible != null){
                if(mapVisible.value == "1"){
                    var isOfferList = this.document.getElementById("ucMainSearchBox_isOfferList");        
                    if(isOfferList != null){
                        if(isOfferList.value == "false"){
                            CloseMap();
                        }
                    }
                }
            }
            
            mainSearchBoxMode.value = "off";
        }
        else{
            mainSearchBoxMode.value = "on";
        }
        
    }
}

function ShowTooltip(text){
    if(typeof Tooltip == 'object') {
        Tooltip.show(text);
    }
}

function HideTooltip(){
    if(typeof Tooltip == 'object') {
        Tooltip.hide();
    }
}
