
$(document).ready(function() {
	//featured image rotator
	//theRotator();
	if ($('#rotator').length) {
		$('#rotator').jqFancyTransitions({ 
			width: 271,
			height: 180,
			effect: 'curtain',
			titleOpacity: 0.5,
			position: 'alternate',
			delay: 3000
		});
	}

   // Match all link elements with href attributes within the content div
   $('#shedulepic img').qtip(
   {
      content: 'No properties scheduled for viewing yet. Add properties to your viewing list to continue.', // Give it some content, in this case a simple string
	  position: {
				 corner: {
					         target: 'bottomLeft',
					         tooltip: 'topRight'
						}

	  },
	  hide: {
            fixed: true // Make it fixed so it can be hovered over
         },
	  style: {
            border: {
               width: 0, 
               radius: 4,
			   color: '#517B91'
            }, 
            tip: true,
			background: '#ffffff',
			color: 'black'	

			}

   });

	$('#gallery a').lightBox();

	if($("#sizetype").val() == 'SQF'){
		select_value = $("#sizetypevalue").val();
		$('#search_size').children().remove().end();	
			var obj = { '':'Any', '>20':'>215', '>40':'>430', '>60':'>645', '>80':'>861', '>100':'>1076' , '>150':'>1614' , '>200':'>2152' , '>250':'>2690', '>300':'>3229'};
			var off_obj = { '':'Any', '>40':'>430', '>80':'>861', '>100':'>1076', '>150':'>1614', '>200':'>2152' , '>250':'>2690' , '>300':'>3229' , '>400':'>4305', '>600':'>6458', '>800':'>8611'};
			$.each(obj, function(i, val){ 
				if(select_value == i){
					$('#search_size').append('<option SELECTED  value="'+i+'">'+val+'</option>');
				}else{
					$('#search_size').append('<option value="'+i+'">'+val+'</option>');
				}
			});
			$.each(off_obj, function(i, val){ 
				if(select_value == i){
					$('#search_offsize').append('<option SELECTED  value="'+i+'">'+val+'</option>');
				}else{
					$('#search_offsize').append('<option value="'+i+'">'+val+'</option>');
				}
			});			
	}else{
		select_value = $("#sizetypevalue").val();
		$('#search_size').children().remove().end();	
			var obj = { '':'Any', '>20':'>20', '>40':'>40', '>60':'>60', '>80':'>80', '>100':'>100' , '>150':'>150' , '>200':'>200' , '>250':'>250', '>300':'>300'};
			var off_obj = { '':'Any', '>40':'>40', '>80':'>80', '>100':'>100', '>150':'>150', '>200':'>200' , '>250':'>250' , '>300':'>300' , '>400':'>400', '>600':'>600', '>800':'>800'};
			$.each(obj, function(i, val){ 
				if(select_value == i){
					$('#search_size').append('<option SELECTED  value="'+i+'">'+val+'</option>');
				}else{
					$('#search_size').append('<option value="'+i+'">'+val+'</option>');
				}
			});	
			$.each(off_obj, function(i, val){ 
				if(select_value == i){
					$('#search_offsize').append('<option SELECTED  value="'+i+'">'+val+'</option>');
				}else{
					$('#search_offsize').append('<option value="'+i+'">'+val+'</option>');
				}
			});				
	}

		
		$('#search_size1').children().remove().end();	
			var obj = { '':'Any', '>20':'>20', '>40':'>40', '>60':'>60', '>80':'>80', '>100':'>100' , '>150':'>150' , '>200':'>200' , '>250':'>250', '>300':'>300'};
			var off_obj = { '':'Any', '>40':'>40', '>80':'>80', '>100':'>100', '>150':'>150', '>200':'>200' , '>250':'>250' , '>300':'>300' , '>400':'>400', '>600':'>600', '>800':'>800'};
			$.each(obj, function(i, val){ 
				if(select_value == i){
					$('#search_size1').append('<option SELECTED  value="'+i+'">'+val+'</option>');
				}else{
					$('#search_size1').append('<option value="'+i+'">'+val+'</option>');
				}
			});	



	


	$("#housesize").change(function(){
		sizevalue = $(this).val();
		if(sizevalue == 'SQF'){
			$('#search_size').children().remove().end();	
			var obj = { '':'Any', '>20':'>215', '>40':'>430', '>60':'>645', '>80':'>861', '>100':'>1076' , '>150':'>1614' , '>200':'>2152' , '>250':'>2690', '>300':'>3229'};
			$.each(obj, function(i, val){ 
				$('#search_size').append('<option  value="'+i+'">'+val+'</option>');
			});	
		}else{
			$('#search_size').children().remove().end();
			var obj = { '':'Any', '>20':'>20', '>40':'>40', '>60':'>60', '>80':'>80', '>100':'>100' , '>150':'>150' , '>200':'>200' , '>250':'>250', '>300':'>300'};
			$.each(obj, function(i, val){ 
				$('#search_size').append('<option  value="'+i+'">'+val+'</option>');
			});
			
		}
	});
	
	
		$("#officesize").change(function(){
		sizevalue = $(this).val();
		if(sizevalue == 'SQF'){
			$('#search_offsize').children().remove().end();	
			var obj = { '':'Any', '>40':'>430', '>80':'>861', '>100':'>1076', '>150':'>1614', '>200':'>2152' , '>250':'>2690' , '>300':'>3229' , '>400':'>4305', '>600':'>6458', '>800':'>8611'};
			$.each(obj, function(i, val){ 
				$('#search_offsize').append('<option  value="'+i+'">'+val+'</option>');
			});	
		}else{
			$('#search_offsize').children().remove().end();
			var obj = { '':'Any', '>40':'>40', '>80':'>80', '>100':'>100', '>150':'>150', '>200':'>200' , '>250':'>250' , '>300':'>300' , '>400':'>400', '>600':'>600', '>800':'>800'};
			$.each(obj, function(i, val){ 
				$('#search_offsize').append('<option  value="'+i+'">'+val+'</option>');
			});
			
		}
	});
	
	$("#property_type").change(function() {
		var src = $("option:selected", this).val();
		//House / Apartment
		//Office Space / Commercial
		if(src == 'House / Apartment'){
			$("#house_apartment").attr("class","visible");
			$("#office_space").attr("class","hidden");
			
			$("#commercial_table").attr("class","hidden");
			$("#residential_table").attr("class","visible");
			
			
		}else if(src == 'Office Space / Commercial')
		{
			$("#house_apartment").attr("class","hidden");
			$("#office_space").attr("class","visible");
			
			$("#commercial_table").attr("class","visible");
			$("#residential_table").attr("class","hidden");
		}

	});
	
    // Initialise the first and second carousel by class selector.
	// Note that they use both the same configuration options (none in this case).
	function mycarousel_initCallback() {
		$("ul").show();
	}
	
	jQuery('.carousel').jcarousel({
	visible:3, 
	initCallback: mycarousel_initCallback
	});
	
	
	
	
	
	
	$("#thumb.thumbs").click(function() {
		//alert($(this).attr('rel'));		
		$(".mainimage",$(this).parents("#photobar").eq(0)).attr("src",$(this).attr('rel'));
		
	});
	
	
	
		$("[id=listing]").mouseover(function() {
		
			$(this).removeClass("off");	
			$(this).addClass("on");
			
			//$(this).children("div#searchresults").children("div").children("div#infobar").hide();
			$(this).children("div#propertyresults").children("div").children("#infobar").children("div[class=regular]").addClass("regularhover");
			$(this).children("div#propertyresults").children("div").children("#infobar").children("div[class=prop]").attr("class","prophover");
			$(this).children("div#propertyfooter").attr("id","propertyfooterhovered");
			
			$tools = '#tools' +$(this).attr('rel');
			$full = '#full' +$(this).attr('rel');
			$($tools).show();
			$($full).addClass("bolder");
			
		});
		
		$("[id=listing]").mouseout(function() {
			
			$(this).removeClass("on");	
			$(this).addClass("off");
			$(this).children("div#propertyresults").children("div").children("#infobar").children("div[class*=regular]").removeClass("regularhover");
			$(this).children("div#propertyresults").children("div").children("#infobar").children("div[class=prophover]").attr("class","prop");
			$(this).children("div#propertyfooterhovered").attr("id","propertyfooter");
			
			$(this).removeClass("listingborder");	
			$(this).addClass("lightborder");
			$tools = '#tools' +$(this).attr('rel');
			$full = '#full' +$(this).attr('rel');
			$($tools).hide();
			$($full).removeClass("bolder");
		});
	
		$('#privacy_policy').click(function() {
				window.open("/privacy/privacy.html","Privacy Policy",'width=500,height=600,scrollbars=yes,left=450,top=100,resizable=no');
				return false;
		});
	
		var options = { 
	    target:     '#inquiry_result', 
	    success:    function() { 
	       
		   //reload captcha
		   var randomnumber=Math.floor(Math.random()*10000)
		   $("#pixel").attr("src","/pixel.php?" + randomnumber);
		   //remove current values on text fields
		   document.getElementById("name").value = '';
		   document.getElementById("email").value = '';
		   document.getElementById("inquiry").value = '';
		   document.getElementById("security_code").value = '';
	    } 
		}; 
	 
		// pass options to ajaxForm 
		$('#inquiryForm').ajaxForm(options);
	
		$("#advanced").click(function() {
			$("div#advancedtoggle").slideToggle();
			if(document.getElementById('search_advanced').value < 1)
			{
				document.getElementById('search_advanced').value = 1;
				document.getElementById('search_off_advanced').value = 1;
			}
			else
			{
				document.getElementById('search_advanced').value = 0;
				document.getElementById('search_off_advanced').value = 0;
			}
			
		});
		

		$("#captchareload").click(function() {
			var randomnumber=Math.floor(Math.random()*10000)
			$("#pixel").attr("src","/pixel.php?" + randomnumber);
		});


		var $current = "";
		$("[id*=button_]").click(function() {			
			$bg = "url(/images/button_" + $(this).parent().attr('rel')  + "_back.gif)";		
			$("[id*=button_]").each(function() {
				$bgoff = "url(/images/button_" + $(this).attr('rel')  + "_back_off.gif)";		
				$(this).css("background-image",$bgoff);
			});
			$(this).parent().css("background-image",$bg);
			switch ($(this).parent().attr("rel")) {
				case "buy":
					if ($current !== "buy") {
						$current = "buy";
						$("#form_office").hide();
						$("#form_buy").show();
					}
					$("#searchbar_action").val("buy");
				break;
				case "rent":
					if ($current !== "rent") {
						$current = "rent";
						$("#form_office").hide();
						$("#form_buy").show();										
					}
					$("#searchbar_action").val("rent");
				break;
				case "office":
					if ($current !== "office") {
						$current = "office";
						$("#form_buy").hide();
						$("#form_office").show();
					}
				break;
			}

			return false;
		});
	});
	
	function findValue(li) {
		alert('tes');
	if( li == null ) return alert("No match!");

		// if coming from an AJAX call, let's use the CityId as the value
		if( !!li.extra ) var sValue = li.extra[0];

		// otherwise, let's just display the value in the text box
		else var sValue = li.selectValue;

		window.location = sValue;
	}

	function selectItem(li) {
		findValue(li);
	}
	
	$(document).ready(function() {		
		var options = {width:300, matchContains: true,onFindValue:findValue,
				onItemSelect:selectItem}
		$("[id=search_for]").autocomplete(locations,options);
	});

function propertyscheduler($propertyid,$action) {
	var classId = "#"+$propertyid;
	switch ($action) {
		case "add": 
			$url = '/ajax/ajax_propertyscheduler.php?propertyid=' + $propertyid + "&action=add";
			//$('#scheduler').attr("propcount")
			$('#schedulertoggle').attr("class","visible");
			$('#shedulepic').attr("class","hidden");
			// Call the ajax to handle the cookie, load html to box and alert the output
			$.ajax({
			  url: $url,
			  success: function(data) {
				//$('.result').html(data);
				$('#propertyscheduler').load('/include/html.propertyscheduler.inc.php');
				
				if (!$('#propsched[rel=' + $propertyid + ']').attr("checked")) {
					$('#propsched[rel=' + $propertyid + ']').attr("checked","true");
				}
				$(classId).html("Schedule Viewing Now");
				$(classId).wrapInner("<a href=\"/schedule/\"></a>");
				alert(data);
				$('#time_sched').load('/schedule/html.schedule.inc.php');
			  }
			});
		break;
		case "remove":
			$url = '/ajax/ajax_propertyscheduler.php?propertyid=' + $propertyid + "&action=remove";
			if($('#scheduler').attr("propcount") < 2){ $('#schedulertoggle').attr("class","hidden"); 
				$('#shedulepic').attr("class","visible");
			}
			// Call the ajax to handle the cookie, load html to box and alert the output
			$.ajax({
			  url: $url,
			  success: function(data) {
				//$('.result').html(data);
				$('#propertyscheduler').load('/include/html.propertyscheduler.inc.php');
				if ($('#propsched[rel=' + $propertyid + ']').attr("checked")) {
					$('#propsched[rel=' + $propertyid + ']').attr("checked","");
				}
				alert(data);
			  }
			});
		break;
	}
	return false;
}

$(document).ready(function() {
	
	$("input#propsched").click(function() {
		$ischecked = $(this).attr("checked");
		$propertyid = $(this).attr("rel");
		if ($ischecked) {
			$action = "add";
		} else {
			$action = "remove";
		}
		propertyscheduler($propertyid,$action); 
		
	});
	
	if($('#scheduler').attr("propcount") < 1){ $('#schedulertoggle').attr("class","hidden"); }else{
		$('#schedulertoggle').attr("class","visible");
		$('#shedulepic').attr("class","hidden");
	}
	
});



function googleTranslateElementInit() {
			  new google.translate.TranslateElement({
			    pageLanguage: 'en'
			  }, 'google_translate_element');
}

$(document).ready(function() {
	$('#searchbarbutton_buy').click(function(){
		$('#shortterm').attr("class","hidden");
	});
	$('#searchbarbutton_rent').click(function(){
		$('#shortterm').attr("class","visible");
	});
	

	if($('#shortterm').attr("action") != 'rent'){
		$('#shortterm').attr("class","hidden");
	}
	
	$('#action').change(function(){
		if($(this).attr('value') == 'rent'){
			$('#shortterm_off').attr('class','visible');
		}else{
			$('#shortterm_off').attr('class','hidden');
		}
	});
	
	if($('#action').attr("value") != 'rent'){
		$('#shortterm_off').attr("class","hidden");
	}
});

$(document).ready(function(){
	$('[id=search_for]').hint();
	
	$('[id=search_for]').keyup(function(event) {
		if (event.keyCode == '27') {
			$('[id=search_for]').attr("value","");
			$('[id=search_for]').blur();
		}
	});
	
	$('#prop_view_tab').click(function(){
		$('[id=innercontainer]').load('/includes/html.searchbar.inc.php');
	});
	
});



$(document).ready(function() {
	$('#filter_btn').click(function(){
		curr_val = $('#filter_btn').attr("url");
		new_val = '';
		$('input[id=filter_field]:checked').each(function() {
			if(new_val == ''){ new_val = curr_val; }
			value = $(this).val();
			name = $(this).attr("name");
			new_val = new_val + "&" + name + "=" + value; 
	     });
		 if(new_val != ''){
			window.location = '?'+new_val;
		 }else{
			window.location = '?'+curr_val;
		 }
	 });
	 
	 $('[id=filterspan]').click(function(){
		if($(this).children('input[id=filter_field]').attr("checked")){
			$(this).children('input[id=filter_field]').attr("checked","");
		}else{
			$(this).children('input[id=filter_field]').attr("checked","checked");
		}
	 
	 });
	 $('input[id=filter_field]').click(function(){
			if($(this).attr("checked")){
				$(this).attr("checked","");
			}else{
				$(this).attr("checked","checked");
			}
	 });

});


	

