$(document).ready(function() {
	
	$("#ctl00_cphQuickSearch_ucBoxQuickSearch_tbArrival").datepicker({minDate: 1,maxDate: new Date('12/31/2011 12:00:00 AM')});
	
	$('#fadeshow1').cycle();
	
	$('#popular-searches').cycle();
	
	//quick search form - homepage
	$(".toggleSearch").click(function(){
		if($("#divHomeSearch").hasClass('hidden')) {
			$("#divHomeSearch").removeClass('hidden');
		} else {
			$("#divHomeSearch").addClass('hidden');
		}
		return false;
	})
	
	
	//When page loads…
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {
		
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		if(activeTab == '#tab2') {
			goMap();
		}
		return false;
	});
	
	
	
	// fancybox
	$("a.fancy-image").fancybox();
	
	
	$("form.rentalSearchForm").submit(function() {
		s=s_gi(s_account);
		s.linkTrackVars = 'events,prop9,eVar12,eVar8,prop5,prop4,eVar7,prop6,eVar9';
		s.linkTrackEvents = 'event10';
		s.events = 'event10';
		if($('#unit-type option:selected').html() != null){
			s.prop9 = $('#unit-type option:selected').html().toLowerCase();
			s.eVar12 = s.prop9;
		}
		
		if($('#unit-bd option:selected').html() != null){
			s.prop5 = $('#unit-bd option:selected').html().toLowerCase();
			s.eVar8 = s.prop5;
		}
		if($('.propview:checked').val() != undefined){
			var db = [];
			$.each($('.propview:checked'), function() {
				db.push($(this).val().toLowerCase()); 
			});
			s.prop4 = db;
			s.eVar7 = s.prop4;
			
		}
		if($('.amen:checked').val() != undefined){
			var db = [];
			$.each($('.amen:checked'), function() {
				db.push($(this).val().toLowerCase()); 
			});
			s.prop6 = db;
			s.eVar9 = s.prop6;
			
		}
		s.tl(this, 'o', 'successfull search');
		$.post('/phpScripts/search.php', $(this).serialize(), function(x) {
			window.location = "/rentals/results/";
		})
		return false;
	})
	
	$(".popSearch").click(function() {
		var url = $(this).attr('href') + '&searchRequest=1';
		$.post(url, function(x) {
			window.location = '/rentals/results/';
		})
		return false;
	})
	
});
