;(function($){ 
	
	$.fn.slideShow = function(settings)
	{
		var config = {
		'timeOut': 6000,
		'speed': 'normal'
		};
		
		if (settings) {
		$.extend(config, settings);
		};

		this.each(function()
		{
			var $elem = $(this);
			$elem.children(':gt(0)').hide();
			setInterval(function() {
			$elem.children().eq(0).fadeOut(config.speed).next().fadeIn(config.speed).end().appendTo($elem);
			}, config.timeOut);
		});

		return this;
	};
})(jQuery);


$(document).ready(function()
	{

	$('div#slideshow').slideShow({ 'timeOut': 6000, 'speed': 100 });
	$('div#testies').slideShow({ 'timeOut': 6000, 'speed': 100 });

	// grab the hidden form values
	var theminpriceval = $('input#minprice').val();
	var themaxpriceval = $('input#maxprice').val();
	var thebedval = $('input#beds').val();
	var thewhereval = $('input#wheres').val();
	var theavailminval = $('input#availablemin').val();
	var theavailmaxval = $('input#availablemax').val();

	// set the visual values
	


	// set the sentence
	$("span#textminprice").text(theminpriceval);
	$("span#textmaxprice").text(themaxpriceval);
	//$('span#textwhens').text(thewhentext);
	$('span#textwheres').text(thewhereval);
	$('span#textbeds').text(thebedval);



	$('div.option div').hover(function(){
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});



	$('#bed_choice div').click(function(){
	
		if($(this).hasClass("checked"))
        {
        	// do nothing
		}
		else
		{
			$(this).siblings().removeClass("checked");
			$(this).addClass("checked");
			
			var bedval = $(this).find("span").html();
      		$("input#beds").val(bedval);
      		$("span#textbeds").text(bedval);
			
		}
        
	});	
	
	
	$('#where_choice div').click(function(){
	
		if($(this).hasClass("checked"))
        {
        	// do nothing
		}
		else
		{
			$(this).siblings().removeClass("checked");
			$(this).addClass("checked");
			
			var whereval = $(this).find("span").html();
      		$("input#wheres").val(whereval);
      		$("span#textwheres").text(whereval);
			
		}
        
	});	
	
	
	$('#when_choice div').click(function(){
	
		if($(this).hasClass("checked"))
        {
        	// do nothing
		}
		else
		{
			$(this).siblings().removeClass("checked");
			$(this).addClass("checked");
			
			var whentext = $(this).find("span").html();
			$("span#textwhens").text(whentext);
		}
        
	});	

	$('#when_choice div#when1').click(function(){
	
		$("input#availablemin").val('');
		$("input#availablemax").val('');
        
	});

	$('#when_choice div#when2').click(function(){

		$("input#availablemin").val('01/07/2010');
		$("input#availablemax").val('30/09/2010');
        
	});	


	$("#slider-range").slider({
		range: true,
		min: 45,
		max: 120,
		step: 5,
		values: [theminpriceval, themaxpriceval],
		slide: function(event, ui) {
		
			// actual value for form
			$("input#minprice").val(ui.values[0]);
			$("input#maxprice").val(ui.values[1]);
			
			// results paragraph
			$("span#textminprice").text(ui.values[0]);
			$("span#textmaxprice").text(ui.values[1]);
			
		}
	});

	
	if ($("a[rel^='prettyPhoto']").length) 
	{
		$("a[rel^='prettyPhoto']").prettyPhoto(
		{
			animationSpeed: 'normal', /* fast/slow/normal */
			padding: 40, /* padding for each side of the picture */
			opacity: 0.35, /* Value betwee 0 and 1 */
			showTitle: false, /* true/false */
			allowresize: true, /* true/false */
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
			hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
			modal: true, /* If set to true, only the close button will close the window */
			changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
			callback: function(){} /* Called when prettyPhoto is closed */
		});
	}
	
	// initial min/max values
	//$("#minprice").val($("#slider-range").slider("values", 0));
	//$("#maxprice").val($("#slider-range").slider("values", 1));




});