/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/


var isplaying = true;
var imageHolderList = new Array("imageHolder1","imageHolder2","imageHolder3","imageHolder4");
var img = [];

jQuery(function() {
	jQuery('#slideshow img').each(function(i){
		img[i] = [this.src, this.alt];
	});
});
function slideSwitch() {
	if (isplaying){
		var active = jQuery('#slideshow DIV.active');
		var activeList = jQuery('li.active');
		var activeButton = activeList.find('> a');
		
		if ( active.length == 0 ) {
			active = jQuery('#slideshow DIV:last');
		}
		if (activeList.length==0){
			activeList = jQuery('li:last');
			activeButton = activeList.find('> a');
		}

		// use this to pull the divs in the order they appear in the markup
		var next =  active.next().length ? active.next() : jQuery('#slideshow DIV:first');	
		var nextList = 	activeList.next().length ? activeList.next() : jQuery('#rotationbuttons li:first');
		var nextButton = nextList.find('> a');
		active.removeClass('active last-active');
		next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				
			});
		activeList.removeClass('active');	
		activeButton.removeClass('active');
		nextList.addClass('active');
		nextButton.addClass('active');
		
		updateTitle(next);
		
	}
}

function goToImage(index) {
	var active = jQuery('#slideshow DIV.active');
	

	if ( active.length == 0 ) active = jQuery('#slideshow DIV:last');

	// use this to pull the divs in the order they appear in the markup
	var next =  jQuery('#'+ imageHolderList[index]);
	
	active.addClass('last-active');
	active.removeClass('active last-active');
	next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			
		});

	updateTitle(next);
}

function updateTitle(slide) {

	if ( jQuery(slide).hasClass('event') ) {
		jQuery('#cslider_title').html( 'Featured Event' );
	} else if ( jQuery(slide).hasClass('product') ) {
		jQuery('#cslider_title').html( 'Featured Product' );
	} else {
		jQuery('#cslider_title').html( 'Featured Client' );
	}
}

jQuery(function() {

	jQuery('.buttonlist a').click(function(event){
			event.preventDefault();
			jQuery('.buttonlist a').removeClass('active');
			jQuery(this).addClass('active');
			isplaying = false;
			var imgToLoad = jQuery(this).attr('href');
			imgToLoad = imgToLoad.split('#');
			imgToLoad = parseInt(imgToLoad[1].substr(3)) - 1;
			goToImage(imgToLoad);			
	});	
	
	jQuery('#slideshow a').click(function(event){
		event.preventDefault();
		isplaying = false;
	});
	
	setInterval( "slideSwitch()", 5000 );
});

