/*
 * jQuery Cycle Lite Plugin
 * http://malsup.com/jquery/cycle/lite/
 * Copyright (c) 2008 M. Alsup
 * Version: 1.0 (06/08/2008)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires: jQuery v1.2.3 or later
 */
        
function slideShow() {
	
	//Set the opacity of all images to 0
	$('#ko_featuredslider .images a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#ko_featuredslider .images a:first').css({opacity: 1.0});
	
	//Set the meta_title background to semi-transparent
	//$('#ko_featuredslider .meta_wrap').css({opacity: 0.7});

	//Resize the width of the meta_title according to the image width
	//$('#ko_featuredslider .meta_wrap').css({width: $('#ko_featuredslider a').find('img').css('width')});
	
	//set first image as active
	$('#ko_featuredslider .images a:first').addClass('show');
	
	//set first number active
	$('#ko_featuredslider .meta_boxes .numberBox:first').addClass('active');
	
	//Get the meta_title of the first image from REL attribute and display it
	$('#ko_featuredslider .meta_title').html($('#ko_featuredslider .images a:first').find('img').attr('alt'))
	.animate({opacity: 1}, 400);
	
	$('#ko_featuredslider .meta_desc').html($('#ko_featuredslider .images a:first').find('img').attr('rel'))
	.animate({opacity: 1}, 400);
	
	//add first link
	$('#ko_featuredslider .meta_learnmore').find('a').attr('href', $('#ko_featuredslider .images a:first').find('img').attr('link'));
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',6000);
	
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var currentImage = ($('#ko_featuredslider .images a.show')?  $('#ko_featuredslider .images a.show') : $('#ko_featuredslider .images a:first'));
	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var nextImage = ((currentImage.next().length) ? ((currentImage.next().hasClass('meta_title'))? $('#ko_featuredslider .images a:first') :currentImage.next()) : $('#ko_featuredslider .images a:first'));	
	
	//get active progress box -FIRST MUST BE SET IN CSS
	var currentNumber = ($('#ko_featuredslider .meta_boxes .active')?  $('#ko_featuredslider .meta_boxes .active') : $('#ko_featuredslider .meta_boxes .numberBox:first'));
	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	if(currentNumber.next().length == ""){
		var nextNumber = $('#ko_featuredslider .meta_boxes .numberBox:first');
	}else{
		var nextNumber = currentNumber.next();
	}
	
	//Get next image meta_title
	var meta_title = nextImage.find('img').attr('alt');
	var meta_desc = nextImage.find('img').attr('rel')
	var meta_link = nextImage.find('img').attr('link');
	
	//Set the fade in effect for the next image, show class has higher z-index
	nextImage.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);

	//Hide the current image
	currentImage.animate({opacity: 0.0}, 1000).removeClass('show');
	
	//changes progress boxes
	nextNumber.addClass("active");
	currentNumber.removeClass("active"); 
	
	//Set the opacity to 0 and height to 1px
	//$('#ko_featuredslider .meta_wrap').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the meta_title, opacity to 0.7 and heigth to 100px, a slide up effect
	//$('#ko_featuredslider .meta_wrap').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
	
	//Display the content
	$('#ko_featuredslider .meta_title').html(meta_title);
	$('#ko_featuredslider .meta_desc').html(meta_desc);
	$('#ko_featuredslider .meta_learnmore').find('a').attr('href', meta_link);
	
	
}

