$(document).ready(function(){
	$('#thumbscont').width($('#thumbscont img').length*80);
	$("#scrollLeft").click(function(){
   		$("#thumbs").scrollTo('-=80px', 500, {axis:'x'});
 	});
	$("#scrollRight").click(function(){
   		$("#thumbs").scrollTo('+=80px', 500, {axis:'x'});
 	});
 	
 	$('#login').val('login');
   $('#loginform #password').val('heslo');
   
   $('form#recommend input[name=fullName]').val('Vaše jméno');
   $('form#recommend input[name=email]').val('E-mail příjemce');
   
   $("form#recommend input[name=fullName]").focus(function(){
      $('form#recommend input[name=fullName]').val('');
   });
   $("form#recommend input[name=email]").focus(function(){
      $('form#recommend input[name=email]').val('');
   });
   
   $("#login").focus(function(){
      $('#login').val('');
   });
   $("#loginform #password").focus(function(){
      $('#loginform #password').val('');
   });
   
   $("ul.locality a").attr('href', '#');
   $("ul.selectkind a").attr('href', '#');
   
   $("#czmap area").attr('href', '#');
   $("#skmap area").attr('href', '#');
   
   var chVal = 3;
   
   $("label[for=challenge]").parent().replaceWith('<input type="hidden" name="challenge" value="'+chVal+'" />');
 
   
   $("input[name=pbtURI]").click(function(){
      
      selectPublisherType($("input[name=pbtURI]:checked").val(), '/inzerenti/');
   });
   
   $("a[rel=confirm]").click(function(event){
         //event.preventDefault();
         var ok = window.confirm('Opravdu chcete '+$(this).attr('title')+'?');
         if(!ok) {
            return false;
         }
         return true;
   });
   
   if($('#czmap')) {
      var czmapdefault = $('img#mapcz').attr('src');
      $('#czmap area').mouseover(function(){
      
         $('img#mapcz').attr('src', '/imgs/'+$(this).attr('id')+'.jpg');
         //alert('klik'+$(this).attr('href'));
         
      });
      $('#czmap').mouseout(function(){
      
         $('img#mapcz').attr('src', czmapdefault);
         //alert('klik'+$(this).attr('href'));
         
      });
   }
   
   if($('#skmap')) {
      var skmapdefault = $('img#mapsk').attr('src');
      $('#skmap area').mouseover(function(){
      
         $('img#mapsk').attr('src', '/imgs/'+$(this).attr('id')+'.jpg');
         //alert('klik'+$(this).attr('href'));
         
      });
      $('#skmap').mouseout(function(){
      
         $('img#mapsk').attr('src', skmapdefault);
         //alert('klik'+$(this).attr('href'));
         
      });
   }
   
   
   
});

jQuery.extend(DateInput.DEFAULT_OPTS, {
  month_names: ["Leden", "Únor", "Březen", "Duben", "Květen", "Červen", "Červenec", "Srpen", "Září", "Říjen", "Listopad", "Prosinec"],
  short_month_names: ["Led", "Úno", "Bře", "Dub", "Kvě", "Čer", "Čec", "Srp", "Zář", "Říj", "Lis", "Pro"],
  short_day_names: ["Po", "Út", "St", "Čt", "Pá", "So", "Ne"]
});

$.extend(DateInput.DEFAULT_OPTS, {
  stringToDate: function(string) {
    var matches;
    if (matches = string.match(/^(\d{4,4})-(\d{2,2})-(\d{2,2})$/)) {
      return new Date(matches[1], matches[2] - 1, matches[3]);
    } else {
      return null;
    };
  },

  dateToString: function(date) {
  
    var month = (date.getMonth() + 1).toString();
    var dom = date.getDate().toString();
    if (month.length == 1) month = "0" + month;
    if (dom.length == 1) dom = "0" + dom;
    return date.getFullYear() + "-" + month + "-" + dom;
  }
});

$(function() {
  $(".dateDay").date_input();
  $(".dateInput").date_input();
});



function selectDate(date) {

    if (typeof(date) == "undefined") {
      date = this.stringToDate(this.input.val());
    }
    
    if (date) {
      this.selectedDate = date;
      this.selectMonth(date);
      var stringDate = this.dateToString(date);
     
      $('td[date=' + stringDate + ']', this.tbody).addClass("selected");

      if (this.input.val() != stringDate) {
      	this.input.val(stringDate).change();
      
       };
    } else {
      this.selectMonth(new Date());
    }
}

function selectLocality(lcURI) {
   
   var href = window.location.href;
   var prefix;
   var kindURI;
   var kindURI2;
   if(href.match('nove-byty-domy')) {
      prefix = '/nove-byty-domy/';
      if($('input[name=rpkURI]:checked')) {
         kindURI = $('input[name=rpkURI]:checked').val();
      }
      if(!kindURI) {kindURI='vse';}
   }
   else {
      prefix = '/nemovitosti/';
      if($('input[name=puURI]:checked')) {
         kindURI = $('input[name=puURI]:checked').val();
      }
      if(!kindURI) {kindURI='vse';}
      if($('input[name=rkURI]:checked')) {
         kindURI2 = $('input[name=rkURI]:checked').val();
      }
      if(!kindURI2) {kindURI2='vse';}
      kindURI+= '/'+kindURI2;
   }
   window.location.href=prefix+kindURI+'/'+lcURI;
}

function selectPurchaseKind(puURI) {
   $('input[name=puURI]').val([puURI]);
   
}

function selectRealtyProjectKind(rpkURI) {
   $('input[name=rpkURI]').val([rpkURI]);
   
}

function selectRealtyKind(rkURI) {
   $('input[name=rkURI]').val([rkURI]);
   
}

function selectPublisherType(pbtURI, prefix) {
   //var href = window.location.href;
   window.location.href=prefix+pbtURI+'/';
}
  
//DateInput.prototype.selectDate = selectDate;

