$(document).ready(function() { 
	
	if ($.jqURL.get('search') == "type") {
		//$("#typeSelect option[" + searchValue + "]").attr("selected", true);
		$('#typeSelect').val($.jqURL.get('value'));
	}
	
	if ($.jqURL.get('search') == "region") {
		//$("#regionSelect option[" + searchValue + "]").attr("selected", true);
		$('#regionSelect').val($.jqURL.get('value'));
	}
		
   $("#btnTypeSearch").click(function() {	   
	   var selection =  $('#typeSelect').val();	   
	   window.location = "http://www.coralbeachrealty.net/listings.php?search=type&value=" + selection;		
   });
   
   $("#btnRegionSearch").click(function() {
	   var selection =  $('#regionSelect').val();	   
	   window.location = "http://www.coralbeachrealty.net/listings.php?search=region&value=" + selection;	
   });   
   
   //gallerys
   $(".galleryPrev").click(function() {
		
		var code = $(this).attr("code");
		var currentPhoto =  parseInt($("#gallery" + code).attr("currentPhoto"));
		var nextPhoto = 0;
		
		$("#photo" + currentPhoto + code).addClass("hidden");
		
		if (currentPhoto <= 1) {
			nextPhoto = 10;
			currentPhoto = 10;
		} else {			
			nextPhoto = currentPhoto - 1;
			currentPhoto--;
		}

		$("#photo" + nextPhoto + code).removeClass("hidden");			
		
		$("#gallery" + code).attr("currentPhoto", currentPhoto);
	});
	
    $(".galleryNext").click(function() {
		var code = $(this).attr("code");
		var currentPhoto = parseInt($("#gallery" + code).attr("currentPhoto"));
		var nextPhoto = 0;
		
		$("#photo" + currentPhoto + code).addClass("hidden");
		
		if (currentPhoto >= 10) {
			nextPhoto = 1;
			currentPhoto = 1;
		} else {			
			nextPhoto = currentPhoto + 1;
			currentPhoto++;
		}

		$("#photo" + nextPhoto + code).removeClass("hidden");			
		
		$("#gallery" + code).attr("currentPhoto", currentPhoto);		
	});
   
 });

 
function contactFormPopup(code,agent) {	
	var url = "contactForm.php?code=" + code + "&agent=" + agent + "";
	window.open(url,"Contact_Form","width=500,height=500");	
}
