var site_domain = $('base').attr('href');

$(document).ready(function() {
	
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	$('.slideshow').cycle({
		cleartype: true,
		timeout: 5000,
		pause: true,
		before: function() {
			$('.caption-container').css('display','none');
		},
		after: function() {
			//$('.caption-container', this).css({opacity: '0.6'}).slideDown();
			$('.caption-container', this).slideDown();
		}
	});
	
	$(".tab").click(function () {
		// switch all tabs off
		$(".active").removeClass("active");
		// switch this tab on
		$(this).addClass("active");
		// slide all content up
		$(".tab_content").hide();
		// slide this content up
		var content_show = $(this).attr("title");
		$("#"+content_show).show();
		
		return false;
	});
	
	//Image and content sliders
	$('#slider').easySlider({
		auto: true,
		continuous: true,
		numeric: true
	});
	
	 //Search form
	$('#search-form').ajaxForm({
		url: site_domain+"/cont_properties_list.php?ajax_loaded=1", // Change the url to the ajax version
		success: function(data) {
			$("#properties-list-pagination-container").html(data);
		}
	});
	
	//Order Form
	$('#order-select').live('change', function() {
	     $('#order-form').ajaxSubmit({
			url: site_domain+"/cont_properties_list.php?ajax_loaded=1", // Change the url to the ajax version
			success: function(data) {
				$("#properties-list-pagination-container").html(data);
			}
		});
	});
	
	//Login form
	$('#login-form').ajaxForm({
		url: site_domain+"/cont_login.php?ajax_loaded=1", // Change the url to the ajax version
		type: 'post',
		success: function(data) {
			if(data == "1") {
				window.location.replace(''+site_domain + 'account&logged=1');
			}
			else {
				$("#login-content-container").html(data);
			}
		}
	});
	
	//Glossary
	$('#glossary-click').live('click', function() {
		 $('#glossary-content').slideToggle();
	  	return false;
	});
	
	//Default input values
	$(".defaultText").focus(function(srcc) {
        if ($(this).val() == $(this)[0].title) {
            $(this).removeClass("defaultTextActive");
            $(this).val("");
        }
    });
   
    $(".defaultText").blur(function() {
        if ($(this).val() == "") {
            $(this).addClass("defaultTextActive");
            $(this).val($(this)[0].title);
        }
    });
    
    $(".defaultText").blur();
    
    //subscribe form
	$('#subscribe-enewsletter').ajaxForm({
		url: "cont_enewsletter.php?ajax_loaded=1", // Change the url to the ajax version
		success: function(data) {
			$("#subscribe-enewsletter-content").html(data);
		}
	}); 
	
	//Login Tabs
	$('.login-click').live('click', function() {
		var id = this.id;
		//Remove all highlights
		$('.login-click').removeClass('selected');
		//Highlight correct tab
		$('#'+id).addClass('selected');
		//Indicate which tab they're logging in through
		$("input#type").val(id);

		$('#login-content').slideToggle('fast', function () {
			//If hidden remove the highlight
			if( $('#login-content').is(":hidden")){
				$('.login-click').removeClass('selected');
			}
		});
		
		return false;
	});
	//IE handle disabled link
	$('.login-click-disabled').live('click', function() {
		return false;
	});
});

function load_news_list(start) {
	$.ajax({
	   type: "GET",
	   url: site_domain+"cont_news_list.php",
	   data: "start="+start+"&ajax_loaded=1",
	   cache: true,  
	   success: function(data){
			$("#news-list-pagination-container").html(data);
	   },
	    error: function () {
	    $('#news-list-pagination-container').empty(); // remove the loading image 
	    $('#news-list-pagination-container').html('<div style="padding:50px 0 50px 0;" class="align-center red">The news list could not be loaded. Please refresh the page and try again</div>');
	  } 
	});
	
	$("#news-list-pagination-container").show();
}

function load_properties_list(start, options) {
	$.ajax({
	   type: "GET",
	   url: site_domain+"cont_properties_list.php",
	   data: "start="+start+"&ajax_loaded=1&options_serialized="+options,
	   cache: true,  
	   success: function(data){
			$("#properties-list-pagination-container").html(data);
	   },
	    error: function () {
	    $('#properties-list-pagination-container').empty(); // remove the loading image 
	    $('#properties-list-pagination-container').html('<div style="padding:50px 0 50px 0;" class="align-center red">The properties list could not be loaded. Please refresh the page and try again</div>');
	  } 
	});
	
	$("#properties-list-pagination-container").show();
}

function load_properties_images(start, id) {
	$.ajax({
	   type: "GET",
	   url: site_domain+"cont_property_images.php",
	   data: "start="+start+"&ajax_loaded=1&id="+id,
	   cache: true,  
	   success: function(data){
			$("#property-images-container").html(data);
	   },
	    error: function () {
	    $('#property-images-container').empty(); // remove the loading image 
	    $('#property-images-container').html('<div style="padding:50px 0 50px 0;" class="align-center red">The property images could not be loaded. Please refresh the page and try again</div>');
	  } 
	});
	
	$("#property-images-container").show();
}


/*
$(document).ready(function() {		
			
	//Execute the slideShow, set 4 seconds for each images
	var slideShowspeed = 5000;
	var class_selector = 'slideshow';
	slideShow(class_selector, slideShowspeed, 1, 1);
	
	$('li#slideshow-controls ul li a').click(function () {
		var goto_li = $("li#slideshow-controls ul li a").index(this);
		timer = gallery(goto_li,class_selector);			
	});

});*/

