$(function() {

	if($('#banners').length)
		$('#banners').cycle({fx: 'fade', speed: 3000, speedOut: 2000, speedIn: 1000});

	initClearDefaultValue();
	
	rollovers();
	
	if($("a[rel='lightbox']").length)
		$("a[rel='lightbox']").lightBox();

	$('tr.listing_tr td').mouseenter(function() { $(this).parents("tr:first").find("td").css("background","#e3e3e3"); });
	
	$('tr.listing_tr td').mouseleave(function() { $(this).parents("tr:first").find("td").css("background","#fff"); });

});

function initClearDefaultValue() {
	var defaultColour = "000000";
	var activeColour = "000000";

	$('.clearDefaultValue').focus(function() {
		el = $(this);

		if(el.val() == el[0].defaultValue) {
			el.val("");
			el.css("color","#"+activeColour);
		}
	});
	
	$('.clearDefaultValue').blur(function() {
		el = $(this);

		if(el.val() == "") {
			//el.val(el[0].defaultValue);
			el.css("color","#"+defaultColour);
		}
	});
}

function validateEmail() {
	emailVal = $('input[name="cm-drzjt-drzjt"]').val();
	
	if(emailVal.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	
	alert("Your email address seems invalid. Please re-enter it.");

	return false;
}

function rollovers()
{
	$(".rollover").hover(
		function () {
			imgSrc = $(this).attr("src");
			if(imgSrc == undefined)
			{
				imgSrc = $(this).css("background-image");
				newImgSrc = imgSrc.replace("_0","_1");
				$(this).css("background-image",newImgSrc);
			}
			else
			{
				newImgSrc = imgSrc.replace("_0","_1");
				$(this).attr("src",newImgSrc);
			}
		}, 
		function () {
			imgSrc = $(this).attr("src");
			if(imgSrc == undefined)
			{
				imgSrc = $(this).css("background-image");
				newImgSrc = imgSrc.replace("_1","_0");
				$(this).css("background-image",newImgSrc);
			}
			else
			{
				if(!$(this).hasClass("no_rollover"))
				{
					newImgSrc = imgSrc.replace("_1","_0");
					$(this).attr("src",newImgSrc);
				}
			}
		}
	);
}

function showImg(img)
{
	var div = $('div#lrg_photo');
	var divImg = div.find("img");
	
	var imgStr = '<img src="' + img + '" style="display:none;" />';
	
	newImg = $(imgStr).insertAfter(divImg);

	divImg.fadeOut(300, function() { divImg.remove();});
	newImg.fadeIn(300);
}

function printVersion(id, type)
{
	var url = "print.php?id=" + id + "&type=" + type;
	
	window.open (url,"Print","location=0,status=0,scrollbars=1,width=700,height=570"); 
}
