/* Author: 

*/

// When the document has been loaded
$(document).ready(function()
{
	Cufon.replace('h2, h3, h4, header nav li, .arrow-small, #search-form p, #sub-nav', {hover: true});
	
	$("a[rel=external]").click(function()
	{
		window.open($(this).attr("href"));
		return false;
	});
	
	// This is the code for controlling the underlying movie that fades in and out
	$('#slideshow ul').innerfade(
	{
		speed: 'slow',
		timeout: 7000,
		type: 'sequence',
		containerheight: '265px'
	});
	
	// Homepage search
	$("#search-form div a").click(function()
	{
		loc = $("#location").val();
		if (loc != '')
		{
			url = siteurl + "/location/" + loc;
			$("#test-form").attr("action", url).submit();
		}
		
		return false;
	});
	
	// Property Gallery
	var arrImgs 	= new Array();
	var currImg		= 0;
	var totalImgs	= 0;
	
	if ($("#img-ids").length > 0)
	{
		str 	= $("#img-ids").val();
		arrImgs	= str.split(',');
	}
	
	if ($("#large li").length > 0)
	{
		totalImgs = $("#large li").size();
	}
	
	/*
	$('#thumbs').jcarousel(
	{
		vertical: true,
		scroll: 1
	});
	*/
	
	var items 	= $("#thumbs li").size();
	var count 	= 4;
	
	$(".jcarousel-prev").click(function()
	{
		if (count >= items)
		{
			$("#thumbs").animate(
			{
				top: '+=89'
			}, 500);
			
			count--;
		}
	});
	
	$(".jcarousel-next").click(function()
	{
		if (count < items)
		{
			$("#thumbs").animate(
			{
				top: '-=89'
			}, 500);
			
			count++;
		}
	});
	
	$("#thumbs a").click(function()
	{
		imgID 	= $(this).attr('rel');
		currImg	= $(this).attr('id');
		$("#large li").fadeOut('fast');
		$("#img-"+imgID).fadeIn('fast');
		return false;
	});
	
	$("#prev").click(function()
	{
		if ((currImg - 1) >= 0)
		{
			currImg--;
			prevID = arrImgs[currImg];
			$("#large li").fadeOut('fast');
			$("#img-"+prevID).fadeIn('fast');
		}
		return false;
	});
	
	$("#next").click(function()
	{
		if ((currImg + 1) < totalImgs)
		{
			currImg++;
			nextID = arrImgs[currImg];
			$("#large li").fadeOut('fast');
			$("#img-"+nextID).fadeIn('fast');
		}
		return false;
	});
});
