
$(document).bind("ready", function(){
				   
	$('body').addClass("javascript");	
	
	$('a[rel=lightbox]').lightBox();

	$('.clickable').css("cursor", "pointer");
	$('.clickable').bind("click", function(){
		window.location = $(this).find("a:first").attr("href");
	});

	$('input[name=q], #newsletter input[type=text]').each(function(){
		$(this).attr("revert", $(this).attr("title"));
		
		$(this).bind("focus", function(){
			if($(this).val() == $(this).attr("revert")){
				$(this).val("");
			}
			
			$(this).addClass("filled");
		});
		
		$(this).bind("blur", function(){
			if($(this).val() == ""){
				$(this).val($(this).attr("revert")).removeClass("filled");
			}
		});
	});
	
	$('#newsletter').bind("submit", function(){
		$.ajax({
			type: "POST",
			url: $(this).attr("action"),
			data: $(this).serialize(),
			dataType: 'html',
			success: function(data){
				$('#newsletter').parent().find(" > *").fadeOut(200, function(){
					$('#newsletter').parent().find("p").html("Thank you for signing up for our email newsletter, we will be in touch soon!");
					$('#newsletter').parent().find(" > *").not("form").fadeIn(200);
				});
			}
		});
		
		event.preventDefault();
		event.stopPropagation();
		
		return false;
	});
	
	jQuery.fn.extend({
		getCurrentAndNext: function(filter){
			current = $(this).find(filter + "[current]");
			
			len  = $(this).find(filter + "[current]").next(filter).length;
			if(len >= 1){
				next = $(this).find(filter + "[current]").next(filter);
			}else{
				next = $(this).find(filter + ":first");
			}
			
			$(current).removeAttr("current");
			$(next).attr("current", "true");
			
			return [current, next];
		}
	});
	
	$('#header img:not(:first)').css("display", "none");
	$('#header img:first').attr("current", "true");
	
	updateBanner = function(){
		nextCurrent = $('#header').getCurrentAndNext("img");
		
		current = nextCurrent[0];
		next	= nextCurrent[1];
		
		$(current).fadeOut(400);
		$(next).fadeIn(400);
	}
	
	setInterval(updateBanner, 5000);
	
	
});
