//Fire up the script

var lastID = 0;
var height = 290;

$(window).load(function(){
	//If the the form is not an object, don't do anything
	ContactForm();
	
	if (!document.getElementById('previewBox')) return;
	ListingsPreviews();
	
	$('.scrollItem').css('background-image', 'url("")');
	$('.loading').css('background-image', 'url("")');
});

function ContactForm() {
	if ($('#showform').html() != "true") {
		$('#contactForm').hide();
		$('#contactLink').show();
	}
	$('#contactLink a').click(function() {
		$('#contactLink').hide();
		$('#contactForm').show();
		return false;
	});
	$('#contactHide').click(function() {
		$('#contactForm').hide();
		$('#contactLink').show();
		return false;
	});
}


function ListingsPreviews() {
	$('#thumbHolder > a').each(function() {
		$(this).click(swapDown);
	});
	try {
		$(function() {
			$('#previewBox a').lightBox();
		});
	} catch(err) {}
}
function swapDown() {
	var id = $(this).attr('id');
	if (id == lastID) return false;
	
	
	$('.scrollItem').css('float', 'none');
	$('.scrollItem').css('position', 'absolute');
	
	$('.scrollItem').css('top', '-'+ height +'px');
	$('#scroller'+ lastID).css('top', '0px');
	
	$('#scroller'+ lastID).css('z-index', '-1');
	$('#scroller'+ lastID).animate({top: ''+ height +'px'}, 700, function() {
		$(this).css('top', '-'+ height +'px');
		$('#scroller'+ lastID).css('z-index', '0');
		$(this).show();
	});
	
	$('#previewScroller').css('top', '0px');
	$('#previewScroller').css('left', '0px');
	
	$('#scroller'+ id).animate({top: '0'}, 700);
	
	
	
	lastID = id;

	return false;
}


