$(document).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");
	});
	
	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];
		}
	});
	
	$('#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, 10000);


	
	$('#slideshow').after('<div id="slideshownav">').cycle({ 
    	fx:     'scrollHorz',
	    //easing: 'bounceout',
		timeout: 0,
		speed: 500,
		next:   '#slideshownext', 
		prev:   '#slideshowprev',
		pager:  '#slideshownav', 
		pagerAnchorBuilder: function(idx, slide) { 
			return '<img src="' + slide.src.replace('main.', 'tiny.') + '" width="64" height="64" />'; 
		} 
	});

});
