$(document).ready(function() {
	var recoLength = ($('#recoContent tr').length);

	$('.previousv').hide();
	
	$('.nextv').click(function(){
		$(this).hide();
		$(this).next('.previousv').show();
		$(this).siblings('.vacancymonthsbox').children('ul').animate({ 
	        marginLeft: "-850px",
	        borderWidth: "0px"
	      }, 500 );
		return false;
	})
	
	$('.previousv').click(function(){
		$(this).hide();
		$(this).prev('.nextv').show();
		$(this).siblings('.vacancymonthsbox').children('ul').animate({ 
	        marginLeft: "20px",
	        borderWidth: "0px"
	      }, 500 );
		return false;
	})
	
	$('.calendartoggle').toggle(
      function () {
    	//alert($(this).parent().parent().next('tr').children('td').children('.vacancy-display').children('.vacancymonthsbox').html());
    	$(this).parent().parent().next('tr').children('td').children('.vacancy-display').show();
        $(this).addClass('active');
        $(this).html('Kalender verstecken');
      },
      function () {
    	  $(this).parent().parent().next('tr').children('td').children('.vacancy-display').hide();
    	  $(this).removeClass('active');
          $(this).html('Kalender anzeigen');
      }
    );	

	imagePreview();
	
	var from = 0, step = 5;
    function showNext(list) {
      list.find('tr').hide().end().find('tr:lt(' + (from + step) + '):not(tr:lt(' + from + '))').show();
      from += step;
    }
    
    function showPrevious(list) {
	  from -= step;
	  list.find('tr').hide().end().find('tr:lt(' + from + '):not(tr:lt(' + (from - step) + '))').show();
    }
    
    // show initial set
    showNext($('#recoContent'));
    
    $('#prevRecos').hide();
    
    $('#moreRecos').click(function(e) {
    	e.preventDefault();
    	showNext($('#recoContent'));
  	  	checkLinkDisplay();
    });
    $('#prevRecos').click(function(e) {
    	e.preventDefault();
    	showPrevious($('#recoContent'));
  	  	checkLinkDisplay();
    });
    
    checkLinkDisplay();
    
    //$('#moreRecos').hide();
    
    function checkLinkDisplay(){
    	var recoLength = ($('#recoContent tr').length);
    	if(recoLength <= 5){
    		$('#moreRecos').hide();
    		$('#prevRecos').hide();
    	}
    	else if(from > step){
      		$('#moreRecos').show();
      		$('#prevRecos').show();
      	}
    	else if(recoLength <= from){
      		$('#moreRecos').hide();
      		$('#prevRecos').show();
      	}
    	else{
    		$('#prevRecos').hide();
    	}
    }
    
    fillVacanca = function(){
        $("#vacanca").val('/available/'+$('#selDates').val()+'/'+$('#selDateDeparture').val()+'');
    };
    
    $('.checkdetaildate').click(function(){
    	$('#selDates').focus();
    	return false;
    });
    
    $("#detaildatesearch").click(function(){
    	if($('#vacanca').val().length > 0){
    		//alert(detailprefix + ''+$('#vacanca').val() +'/people/'+ $('#travellers').val() +'/0/'+ detailsuffix);
    		window.location = detailprefix + ''+$('#vacanca').val() +'/people/'+ $('#travellers').val() +'/0/'+ detailsuffix;
    		return false;
    	}
    	else{
    		$('#errorDetailpage').show();
    		$('#selDates , #selDateDeparture').css('border-color','#cc0000');
    		return false;
    	}
    });
    

});

	this.imagePreview = function(){		
	xOffset = 10;
	yOffset = 30;

		/* END CONFIG */
		$(".smallserviceimage a , #thumbnails a, .similar_line .singleimage a").hover(function(e){
			this.t = this.title;
			titeltext = this.t;
			this.title = "";	
			imgSrc = $(this).attr('rel');
			var c = (this.t != "") ? "<br/>" + this.t : "";
			
			$("body").append("<p id='preview'><img src='"+ imgSrc +"' alt='Image preview' />"+ c +"</p>");
			
			var bodyWidth = $('body').width();
			var imageWidth = $('#preview').width();
			
			if(e.pageX < (bodyWidth/2)){
				$("#preview").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px").fadeIn("fast");
			}else{
				$("#preview").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX - imageWidth - yOffset) + "px").fadeIn("fast");
			}
		},
		function(){
			this.title = titeltext;	
			$("#preview").remove();
		});	
		$(".smallserviceimage a, #thumbnails a, .similar_line .singleimage a").mousemove(function(e){
			var bodyWidth = $('body').width();
			var imageWidth = $('#preview').width();
			
			if(e.pageX < (bodyWidth/2)){
				$("#preview").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px");
			}else{
				$("#preview").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX - imageWidth - yOffset) + "px");
			}

		});		
		
		$(".smallserviceimage a, #thumbnails a, .similar_line .singleimage a").click(function(e){
			return false;
		});
		
	};

function putdate(input) 
{ 
       var min = new Date(); //Set this to your absolute minimum date
       var dateMin = min;
       return {
    	   minDate: dateMin
       }; 	
}