// Putting search labels into the field.
// Just realised this isnt needed.
$(document).ready(function() {
	var name = $('label[for="prop_name"]').text();
	
	$('label[for="prop_name"]').hide();
	
	$('input[name="prop_name"]').val(name);
	
	$('input[name="prop_name"]').focus(function(){
		var current_val = $(this).val();
		if (current_val == "Property Name") {
			$(this).val("");
		}
	});

	$('input[name="prop_name"]').blur(function(){	
		var current_val = $('input[name="prop_name"]').val();
		var default_val = "Property Name"
		if (current_val == "") {
			$(this).val(default_val);
		}
	});
	
	// OLD WAY, NOT USED Hide here, so you get to see the content with no javascript
	/*$('#home_extra').css({'display':'none'});
	
	$('#home_more').click(function(){
		$('#home_extra').show();
		$('#home_more').hide();
	});
	
	$('#home_close').click(function(){
		$('#home_extra').hide();
		$('#home_more').show();
	});	*/
	
	// Drop a button in to open divs
	$("#main_contant_home p").first().append(' <a id="home_more" href="javascript:;">More &raquo;</a>');
	$("#main_contant_home p").last().append(' <a id="home_close" href="javascript:;">Close</a>');
	
	//Hide all but first para on homepage.
	$("#main_contant_home p:not(:first)").hide();
	
	// Make buttons work
	$('#home_more').click(function(){
		$("#main_contant_home p:not(:first)").show();
		$('#home_more').hide();
	});
	
	$('#home_close').click(function(){
		$("#main_contant_home p:not(:first)").hide();
		$('#home_more').show();
	});	
	
	// Hide stuff for advanced search
	
	$('#advancedSearch').css({'display':'none'}); 	
	
	$("#advanced_link").toggle(
	  function () { 		
		$('#advancedSearch').slideDown("fast"); 
	  }, 
	  function () {
		$('#advancedSearch').slideUp("fast"); 
	  }
	);

  	var $bigList = $('.navbar_locations'), group;
  		while((group = $bigList.find('li:lt(8)').remove()).length){
    	$('<ul/>').append(group).appendTo('li.locations');
  	}
	
  	var $bigList = $('.navbar_holiday_ideas'), group;
  		while((group = $bigList.find('li:lt(8)').remove()).length){
    	$('<ul/>').append(group).appendTo('li.holiday_ideas');
  	}	
	
  	var $bigList = $('.navbar_home'), group;
  		while((group = $bigList.find('li:lt(8)').remove()).length){
    	$('<ul/>').append(group).appendTo('li.home');
  	}		
	
  	var $bigList = $('.navbar_out_and_about'), group;
  		while((group = $bigList.find('li:lt(8)').remove()).length){
    	$('<ul/>').append(group).appendTo('li.out_and_about');
  	}	
	
  	var $bigList = $('.navbar_owners'), group;
  		while((group = $bigList.find('li:lt(8)').remove()).length){
    	$('<ul/>').append(group).appendTo('li.owners');
  	}	
	
  	var $bigList = $('.navbar_contact_us'), group;
  		while((group = $bigList.find('li:lt(8)').remove()).length){
    	$('<ul/>').append(group).appendTo('li.contact_us');
  	}			
	
	
	/****/
	var i = 1;
	$('li.locations ul').each(function(index) {
		$(this).addClass("group" + i);
		i++;
	})
	
	$('li.locations ul').wrapAll("<div class=\"dropdown_bg\"></div>");
	/****/
	var i = 1;
	$('li.holiday_ideas ul').each(function(index) {
		$(this).addClass("group" + i);
		i++;
	})
	
	$('li.holiday_ideas ul').wrapAll("<div class=\"dropdown_bg\"></div>");	
	/****/
	var i = 1;
	$('li.home ul').each(function(index) {
		$(this).addClass("group" + i);
		i++;
	})
	
	$('li.home ul').wrapAll("<div class=\"dropdown_bg\"></div>");	
	/****/	
	
	/****/
	var i = 1;
	$('li.out_and_about ul').each(function(index) {
		$(this).addClass("group" + i);
		i++;
	})
	
	$('li.out_and_about ul').wrapAll("<div class=\"dropdown_bg\"></div>");	
	/****/
	var i = 1;
	$('li.owners ul').each(function(index) {
		$(this).addClass("group" + i);
		i++;
	})
	
	$('li.owners ul').wrapAll("<div class=\"dropdown_bg\"></div>");	
	/****/
	var i = 1;
	$('li.contact_us ul').each(function(index) {
		$(this).addClass("group" + i);
		i++;
	})
	
	$('li.contact_us ul').wrapAll("<div class=\"dropdown_bg\"></div>");		
			
	// Make fluid width dropdowns
	var colwidth = $('.navbar_horizontal_navigation li ul.group2').width();

	$('.navbar_horizontal_navigation li').hover(function(){
		var listclass = $(this).attr('class').split(' ').slice(-1);
		var searchclass = "." + listclass + ' .dropdown_bg ul';
		var cols = ($(searchclass).length);
		cols--;
		var listwidth = $(searchclass).width();
		if(cols > 2) {
			var totalwidth = (colwidth * cols) + 75;
		}
		else {
			var totalwidth = (colwidth * cols) + 50;
		}
		$("." + listclass + ' .dropdown_bg').css('width',totalwidth);
	});
	
	$('ul.navbar_horizontal_navigation').addClass('grid');
	$('ul.navbar_horizontal_navigation').addClass('grid_12');
	$('ul.navbar_general_info li:eq(0)').addClass('header_item');	
	$('ul.navbar_our_props li:eq(0)').addClass('header_item');	

	$(".line_two .new_search").toggle(
	  function () { 		
		$('#search_container').slideDown("fast"); 
	  }, 
	  function () {
		$('#search_container').slideUp("fast"); 
	  }
	);	
	
	$('#news_select').change(function(){
		var selected_item = $(this).attr('value');
		if(selected_item == 'date') {
			$('.month_picker').show();
			$('.group_picker').hide();
		}
		else if(selected_item == 'category'){
			$('.month_picker').hide();
			$('.group_picker').show();			
		}
		
	});
	
	// Search form stuff.
	$('#property_select').change(function(){
		$('#location_select').val('');
	});
	
	$('#location_select').change(function(){
		$('#property_select').val('');
	});
	
});


