// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function linkToProperty(id, page)
{
	location.href = '/featured/view/'+id+'?page='+page+'&'+Form.serializeElements([$('status'),$('beds'),$('baths'),$('sort')]);
}


function showPropertyPhoto(imgURL)
{
	
	

	new Effect.Opacity('property_photo_detail', { from: 1.0, to: 0.0, duration: 0.2, queue: 'end', afterFinish: function(effect) { $(effect.element.id).src=imgURL; 
	
	image = document.getElementById("property_photo_detail");
	
	if (image){ 
	
		if (image.complete) {
			new Effect.Opacity('property_photo_detail', { from: 0.0, to: 1, duration: 0.2 }, {queue: 'end'});
			new Effect.Opacity('photo-loading', { from: 1.0, to: 0.0, duration: 0.2 }, {queue: 'end'});
		} else {
			
			image.onload = function() {
				new Effect.Opacity('property_photo_detail', { from: 0.0, to: 1, duration: 0.2 }, {queue: 'end'});
				new Effect.Opacity('photo-loading', { from: 1.0, to: 0.0, duration: 0.2 }, {queue: 'end'});
			}
		}
	} else {
		new Effect.Opacity('property_photo_detail', { from: 0.0, to: 1, duration: 0.2 }, {queue: 'end'});
		new Effect.Opacity('photo-loading', { from: 1.0, to: 0.0, duration: 0.2 }, {queue: 'end'});
	}
	
	}} );
	new Effect.Opacity('photo-loading', { from: 0.0, to: 1, duration: 0.2 }, {queue: 'end'});	
	
	return false;
}

scroll_offset = 0;

function scrollThumbsBack() 
{
	if (scroll_offset + 101 <= 0) 
	{
		scroll_offset += 101;
		new Effect.Move('photo-scroll-area', {
	  		x: scroll_offset, y: 0, mode: 'absolute', duration: 0.3,
	  		transition: Effect.Transitions.sinoidal
		});
	}
}

function scrollThumbsForward() 
{
	
	width = $('photo-scroll-area').getWidth();
	if ((width - Math.abs(scroll_offset)) > 404) 
	{
		scroll_offset -= 101;
		new Effect.Move('photo-scroll-area', {
	  		x: scroll_offset, y: 0, mode: 'absolute', duration: 0.3,
	  		transition: Effect.Transitions.sinoidal
		});
	}

}

function validateContact() 
{

	valid = true;
	
	if (!$('firstname').present())
		valid = false;
		
	if (!$('lastname').present())
		valid = false;
		
	if (!$('address').present())
		valid = false;

	if (!$('city').present())
		valid = false;
		
	if (!$('zipcode').present())
		valid = false;
		
	if (!$('phone').present())
		valid = false
		
	if (!$('email').present())
		valid = false;
	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if (reg.test($('email').value) == false)
		valid = false;
		
	if(!valid) 
	{
		$('form-message').update("Please fill in all required fields").show();
		
	}

	return valid; 

}
