$(document).ready(function() 
{
	if($("a[rel=gallery]").length)
	{
		$("a[rel=gallery]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	}
	$("#frm-cnt").submit
	(
		function()
		{
			$("#msg-status").html('');
			$("#msg-status").html('<p><span class="msg-stat">Sending Message, Please wait.</span></p>');
			var str = $(this).serialize();
			$.ajax(
			{
				type: "POST",
				url: "sendmail.php",
				data: str,
				success: 
				function(msgStatus)
				{
					$("#msg-status").ajaxComplete(function(event, request, settings)
					{
						$(this).html(msgStatus);
					});
				}
			});
			$("#securecode").attr("src", "securecode.php?" +  Math.floor(Math.random()*100));
			return false;
		}
	);
	
	if($('#automotive').length){loadgallery('automotive', 'automotive', 0);}
	if($('#residential').length){loadgallery('residential', 'residential', 0);}
});

function loadgallery(strID, strDir, intStart)
{
	$.ajax(
	{
		type: "GET",
		url: "gallery.php",
		data: "dir="+strDir+"&s="+intStart,
		success: 
		function(strHTML)
		{
			$('#'+strID).ajaxComplete(function(event, request, settings)
			{
				$(this).html(strHTML);
				strIDA = '#'+strID+' a';
				$('.next',this).click(function(){$('#'+strID+' li').fadeIn("slow");loadgallery(strID, strDir, $(this).attr('rel'));});
				$('.previous',this).click(function(){$('#'+strID+' li').fadeIn("slow");loadgallery(strID, strDir, $(this).attr('rel'));});
				$('#'+strID+' ul li').slideDown("slow");
				if($("a[rel=gallery]").length)
				{
					$("a[rel=gallery]").fancybox({
						'transitionIn'		: 'none',
						'transitionOut'		: 'none',
						'titlePosition' 	: 'over',
						'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
							return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
						}
					});
				}
			});
		}
	});
}
