
$(document).bind("ready", function(){
	
	$('body').addClass("javascript");	
	
	$('.clickable').css("cursor", "pointer");

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

	$('.clickable').hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});

	if(jQuery.fn.lightBox){
		$('a[rel=lightbox]').lightBox();
	}
	
	jQuery.fn.extend({
		getCurrentAndNext: function(filter){
			if($(this).attr("skip")){
				$(this).removeAttr("skip");
				return "skip";
			}

			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];
		}
	});
	
	$('#images img:not(:first)').css("display", "none");
	$('#images img:first').attr("current", "true");
	
	updateBanner = function(){
		if($('#images').find("img").length == 1) return;
		nextCurrent = $('#images').getCurrentAndNext("img");
		
		current = nextCurrent[0];
		next	= nextCurrent[1];
		
		$(current).fadeOut(2500);
		$(next).fadeIn(2500);
	}
	
	setInterval(updateBanner, 5000);

	$('#slideshow a.image:not(:first)').css("display", "none");
	$('#slideshow a.image:first').attr("current", "true");

	$('#slideshow ul a:first').addClass("selected");
	$('#slideshow ul li:first').attr("current", "true");
	
	updateStats = function(){
		if($('#slideshow').find("a.image").length == 1) return;
		
		nextCurrent = $('#slideshow').getCurrentAndNext("a.image");
		
		if(nextCurrent == "skip") return;

		current = nextCurrent[0];
		next	= nextCurrent[1];
		
		$(current).fadeOut(400);
		$(next).fadeIn(400);

		nextCurrent = $('#slideshow ul').getCurrentAndNext("li");

		current = nextCurrent[0];
		next	= nextCurrent[1];
		
		$(current).find("a").removeClass("selected");
		$(next).find("a").addClass("selected");
		
	}

	$('#slideshow li a').bind("click", function(){

		$('#slideshow').attr("skip", "true");

		index = $(this).parent().parent().find("li").index($(this).parent());
		
		$('#slideshow a.image[current]').removeAttr("current").fadeOut(0);
		$('#slideshow a.image').eq(index).attr("current", "true").fadeIn(0);

		$('#slideshow ul a.selected').removeClass("selected");
		$(this).addClass("selected");

		$('#slideshow ul li[current]').removeAttr("current");
		$(this).parent().attr("current", "true");

		return false;
	});
	
	setInterval(updateStats, 3000);
	
	//switch testimonials
	
	$('.testimonial .testimonialswitch:not(:first)').css("display", "none");
	$('.testimonial .testimonialswitch:first').attr("current", "true");
	
	updateTestimonial = function(){
		nextCurrent = $('.testimonial').getCurrentAndNext(".testimonialswitch");
		
		current = nextCurrent[0];
		next	= nextCurrent[1];
		
	    $(current).fadeOut(0);
		$(next).fadeIn(2500);
	}
	
	setInterval(updateTestimonial, 5000);

});



