/**
 * jQuery Lightweight Slideshow
 * 
 * Author: Dan LeFree
 * Author URI: http://dan.lefree.net/
 * 
 */

// Configuration: Set time out interval in seconds
var slideTimeout = 5;
// EOF_Configuration

var showTimerID = 0;

var slidePointer = -1;

var slides = new Array();

function advanceSlide()
{
	if ( ! showTimerID )
	{
		return false;
	}
	
    var lastSlide = slidePointer;
    if ( slidePointer >= (slides.length - 1) ) {
        slidePointer = 0;
    } else {
        slidePointer++;
    }
    var nextSlide = slidePointer;
    $('div#'+slides[lastSlide]).fadeOut();
    $('div#'+slides[nextSlide]).fadeIn();
    startShow();
}


function registerSlide( slideNo )
{
    slides.push( slideNo );
}


function startShow()
{
	showTimerID = setTimeout( 'advanceSlide()', slideTimeout * 1000 );
}


function stopShow()
{
    if ( showTimerID ) {
        clearTimeout(showTimerID);
    }
}

$(document).ready(function(){
	
    if ( $('div.slideshow div.slide').length )
	{
		$('div.slideshow div.slide').css('display', 'none');
		
		$('div.slideshow').css('position', 'relative');
		$('div.slideshow').css('height', '420px');
		$('div.slideshow').css('width', '420px');
		$('div.slideshow').css('text-align', 'center');
		$('div.slideshow').css('overflow', 'none');
		
		$('div.slideshow div.slide').css('position', 'absolute');
		$('div.slideshow div.slide').css('top', 10);
		$('div.slideshow div.slide').css('left', 10);
		
        $('div.slideshow div.slide').each(function() {
            registerSlide( $(this).attr('id') );
        });
        $('div.slide').bind( 'mouseenter', function() {
            stopShow();
        });
        $('div.slide').bind( 'mouseleave', function() {
            startShow();
        });
		
		showTimerID = setTimeout( 'advanceSlide()', 1 );
    }
	
	
	/**
	 * jQuery AreaMap replacement
	 * 
	 * Author: Dan LeFree
	 * Author URI: http://dan.lefree.net/
	 * 
	 */
	/*
    if ( $('a.jqAreaMap').length )
	{
		$('a.jqAreaMap').css('visibility', 'hidden');
		$('a.jqAreaMap').each(function(){
			var thisID = $(this).attr('id');
			var thisMapImage = $('#'+thisID+' img');
			var htmlOutput = '';
			switch(thisID)
			{
				case 'set-series':
					htmlOutput += '<div class="jqAreaMap">';
					htmlOutput += '<img src="'+thisMapImage.attr('src')+'" width="'+thisMapImage.width()+'" height="'+thisMapImage.height()+'" alt="" usemap="#map-'+thisID+'" />';
					htmlOutput += '<map name="map-'+thisID+'">';
					htmlOutput += '<area shape="rect" coords="0,0,202,131" href="/galleries/hobo-eaters/" alt="Hobo Eaters" />';
					htmlOutput += '<area shape="rect" coords="203,0,405,131" href="/galleries/blade-runner-2012/" alt="Blade Runner 2012" />';
					htmlOutput += '<area shape="rect" coords="406,0,606,131" href="/galleries/raising-hell/" alt="Raising Hell" />';
					htmlOutput += '<area shape="rect" coords="607,0,808,131" href="/galleries/the-deathside/" alt="The Deathside" />';
					htmlOutput += '</map>';
					htmlOutput += '</div>';
				break;
			}
			$('#galleries').append(htmlOutput);
			$('#'+thisID).remove();
		});
	}
	*/
	
	
});

