/*
 * jQuery Timer Plugin
 * http://www.evanbot.com/article/jquery-timer-plugin/23
 *
 * @version      1.0
 * @copyright    2009 Evan Byrne (http://www.evanbot.com)
 */ 

jQuery.timer = function(time,func,callback){
    var a = {timer:setTimeout(func,time),callback:null}
    if(typeof(callback) == 'function'){a.callback = callback;}
    return a;
};

jQuery.clearTimer = function(a){
    clearTimeout(a.timer);
    if(typeof(a.callback) == 'function'){a.callback();};
    return this;
};

function homeSlideShow() {

//Set the opacity of all images to 0
$('#homeTopSectionIMG div#images div').css({opacity: 0.0});

//Get the first image and display it (set it to full opacity)
$('#homeTopSectionIMG div#images div:first').css({opacity: 1.0});

// set the link
$('#homeTopSectionIMG a#highlightlink').attr('href', $('#homeTopSectionIMG div#images div:first h3 a').attr('href'));

//Get the caption of the first image from REL attribute and display it
$('#homeTopSectionIMG .content').html($('#homeTopSectionIMG div#images div:first').html()).animate({opacity: 1}, 400);

// add show class to first image
$('#homeTopSectionIMG div#images div:first').addClass('show');

//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
setInterval('homeGallery()',10000);

}

function homeGallery() {

//if no IMGs have the show class, grab the first image
var current = ($('#homeTopSectionIMG div#images div.show') ?  $('#homeTopSectionIMG div#images div.show') : $('#homeTopSectionIMG div#images div:first'));
    
//Get next image, if it reached the end of the slideshow, rotate it back to the first image
var next = ((current.next().length) ? ((current.next().hasClass('caption')) ? $('#homeTopSectionIMG div#images div:first') : current.next()) : $('#homeTopSectionIMG div#images div:first'));    
    
// set the link
$('#homeTopSectionIMG a#highlightlink').attr('href', next.find('h3 a').attr('href'));
    
//Get next image caption
var caption = next.html();    
    
//Set the fade in effect for the next image, show class has higher z-index
next.css({opacity: 0.0})
.addClass('show')
.animate({opacity: 1.0}, 2000);

//Hide the current image
current.animate({opacity: 0.0}, 2000)
.removeClass('show');
    
//Set the opacity to 0 and height to 1px

$('#homeTopSectionIMG .caption').animate({opacity: 0.0}, { queue:false, duration:1000 }).animate({height: '1px'}, { queue:true, duration:1000 });    

//Animate the caption, opacity to 1 and heigth to 100px, a slide up effect
$('#homeTopSectionIMG .content').animate({opacity: 0.0},100);
$('#homeTopSectionIMG .caption').animate({opacity: 1},100 ).animate({height: '210px'},1000);

//delay.
    
myTimer = $.timer(2000,function(){
  $('#homeTopSectionIMG .content').animate({opacity: 1},200);
  $('#homeTopSectionIMG .content').html(caption);        
});

}
