	$(document).ready(function(){
	
	var base_url = "/";
		if ($("a.fancy")){
			$('a.fancy').fancybox({
				'height': 400,
				'width': 700
			});
		}
			//$('.emailer, .butt_si_email').click(function() { 
			//	$email = $(this).attr('rel');
			//	$type = $(this).attr('id');
			//	$('#form_box').show();
			//	return false;
			//});
			$('.emailer, .butt_si_email').fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'autoScale'     	: false,
				'type'				: 'iframe',
				'width'				: 500,
				'height'			: 500,
				'scrolling'   		: 'no'
			});
			$('.ajaximg').fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'autoScale'     	: false,
				'type'				: 'iframe',
				'width'				: 950,
				'height'			: 750,
				'scrolling'   		: 'no'
			});
		if ($("#theteam")){
			$("#theteam").accordion({active: false,collapsible: true,autoHeight:false});
		}
		if ($('#searchCounty,#rentalPeriod,#classification,#branchList,#perpage')){
			$('#searchCounty,#rentalPeriod,#classification,#branchList,#perpage').selectmenu({ 'maxHeight' : 400 });
		}
		if ($('#listing,#sortDescending')){
			$('#listing,#sortDescending').selectmenu({
				'width' : 120,
				'maxHeight' : 400
			});
		}
		if ($('#minPrice,#maxPrice,#bedrooms')){
			$('#minPrice,#maxPrice,#bedrooms').selectmenu({
				'width' : 80,
				'maxHeight' : 400
			});
		}
		if ($('#results_refine #searchCounty')){
			$('#results_refine #searchCounty').selectmenu({
				'maxHeight' : 400
			});
		}
		if ($('#ml_address')){
			$('#ml_address').labelify({ text: "label" });
		}
			$('#left ul li .thisbutt').click(function() { 
			
				$on = $(this).attr('rel');
				$li = $(this).parent();
				$(".searcher").hide();
				$("#left ul li").removeClass('on');
				$($li).addClass('on');
				$($on).show();
				if ($on == "#search_map"){
					$('#search_map').html('<iframe width="332" height="311" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="/includes/homepage_map_search.php"></iframe>');
				}
				return false;
				
			});
			$('.right_green ul#searchlist li .thisbutt').click(function() { 
			
				$on = $(this).attr('rel');
				$li = $(this).parent();
				$(".searcher").hide();
				$(".right_green ul#searchlist li").removeClass('on');
				$($li).addClass('on');
				$($on).show();
				if ($on == "#search_map"){
					$('#search_map').html('<iframe width="332" height="311" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="/includes/homepage_map_search.php"></iframe>');
				}
				return false;
				
			});
			if ($('#lettings,#properties,#services')){
				$('#lettings,#properties,#services').scrollable({ circular: true });
			}
			if ($('#image_gallery')){
				$('#image_gallery').scrollable();
			}

			//Larger Image		 
			$('#cont_holder #container #pages #left .gallery #image_gallery a').click(function() { 
			
				$bigimage = $(this).attr('href');
				$("#cont_holder #container #pages #left #main_image img").hide(); //animation
				$.ajax({
					method: "get",url: base_url + "includes/more_detailsimage.php",data: { image: $bigimage},
					beforeSend: function(){$("#cont_holder #container #pages #left #loading").show();}, //show loading just when link is clicked
					complete: function(){ $("#cont_holder #container #pages #left #loading").hide();}, //stop showing loading when the process is complete
					success: function(html){ //so, if data is retrieved, store it in html
					$("#cont_holder #container #pages #left #main_image").html(html); //show the html inside .content div
					$("#cont_holder #container #pages #left #main_image").show(); //animation
					}
				}); 
				return false;
				
			});	
			
			//Change search type
			$('#rentalPeriod').change(function() { 
				$("#prices").fadeOut("fast"); //animation
				$id = $('#rentalPeriod').attr('value');
				//alert($c_city);		
				$.ajax({
					type: "POST",
					url: base_url + "includes/handler_prices.php",
					data: { 
						id : $id
					},
					success: function(content){ //so, if data is retrieved, store it in html	
					$("#prices").html(content);
					$("#prices").fadeIn("Slow"); //animation
					}
				});
			});
					 
			$('#featured ul li a').click(function() { 
			
				$on = $(this).attr('rel');
				$li = $(this).parent();
				$(".featured_box").hide();
				$("#featured ul li").removeClass('on');
				$($li).addClass('on');
				$($on).show();
				return false;
				
			});	
			
			//Mailing List
			$('#ml_submit').click(function(){
				//AJAX the email address ;)
				 var email_address = $('#ml_address').attr("value"); //retrieve title of link so we can compare with php file
				$.ajax({
					type: "post",url: base_url + "includes/handler_email.php",data: "ml_email="+email_address,
					success: function(html){
						if (html == 1){
							$('#ml_form').append('<p>Please enter a valid email address</p>');
						} else {
							$('#ml_box form').fadeOut(function(){
								$("#ml_box").html(html);
								$("#ml_box p").fadeIn();
							});
						}
					}
				 }); //close $.ajax
				
				return false;
			});
					
			//Deal with the type
			$('#type_property').click(function() {
				$("#homepage").hide(); //animation
				$.ajax({
					contentType: "text/html; charset=utf-8",
					type: "get",
					url: base_url + "includes/homepage_property.php",
					data: "",
					beforeSend: function(){$("#loading").show();}, //show loading just when link is clicked
					complete: function(){ $("#loading").hide();}, //stop showing loading when the process is complete
					success: function(data){ //so, if data is retrieved, store it in html
					$("#homepage").show(); //animation
					$("#homepage").html(data); //show the html inside .content div
					}
				}); 
				return false;
			});
			$('#type_services').click(function() {
				$("#homepage").hide(); //animation
				$.ajax({
					contentType: "text/html; charset=utf-8",
					type: "get",
					url: base_url + "includes/homepage_services.php",
					data: "",
					beforeSend: function(){$("#loading").show();}, //show loading just when link is clicked
					complete: function(){ $("#loading").hide();}, //stop showing loading when the process is complete
					success: function(data){ //so, if data is retrieved, store it in html
					$("#homepage").show(); //animation
					$("#homepage").html(data); //show the html inside .content div
					}
				}); 
				return false;
			});
			//Form Submit
			$('#sortDescending,#perpage,#listing').change(function() {
				$('#search_update').submit();
			});
			
			$('.butt_backtotop').click(function(){
				$( 'html, body' ).animate( { scrollTop: 0 }, 'slow' );
				return false;
			});
			
			$('.butt_refinesearch').click(function(){
				$('#results_refine').slideToggle();
				$('#search_update').fadeToggle();
				return false;
			});
			
			$('a.person').hoverbox();
			
			$('.butt_newsearch').click(function(){
				$("#searchNew").append('<h2>New Search</h2><p>Are you sure you would like to reset your search criteria? </p><a class="butt_yes" href="/search/new"><span>Yes</span></a> <a href="/search" class="butt_no" id="searchNo"><span>No</span></a>')
				$("#searchNew").slideToggle();
				return false;
			});
			$('#searchNo').click(function(){
				$("#searchNew").slideToggle();
				return false;
			});
		
		
	});
	$(window).load(function() {
		if ($("#slider")){
			//Homepage Slider
			$('#slider, #links').fadeIn("slow");
			$('#slideshow_loading').fadeOut("slow");
			$('#slider, #links').cycle({ 
				delay: -1000
			});	
		}
	});
