// JavaScript Document

$(document).ready(init);

function init(){
	// global
	defeatSpam3000();
	
	$('#loginButton').click(function() {$('#loginFormDiv').slideDown('fast'), $('#loginButton').hide()});
	$('.showWorkDescription').click(function() {$('.workDescription').toggle('fast')});
	$('.showeventdetails').show();
	$('.eventdetails').hide();
	$('.showeventdetails').click(function() {$(this).parent().next('div').toggle('fast')});
	
	slideSwitch();
	var playSlideshow = setInterval( 'slideSwitch()', 8000 );

//	$('#slideshow DIV').hover(
//	
//	function() {
//	clearInterval(playSlideshow);
//	},
//	function() {
//	playSlideshow = setInterval( 'slideSwitch()', 8000 );
//	slideSwitch();
//	});
}



function defeatSpam3000(){
	$('.nospam').each(function(){
		var emailText    = $(this).text();
		var emailAddress = emailText.replace(/ \[at\] /,'@');
		$(this).replaceWith($.create('a',{'class':'maillink','href':'mailto:'+emailAddress},emailAddress));
	});
}




/*** 
    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 :)
***/


function slideSwitch() {
    var $active = $('#slideshow DIV.active');
    
    var slides = $('#slideshow DIV');
    var rndNum = Math.floor(Math.random() * slides.length );

    if ( $active.length == 0 ){
    	$active =  $($('#slideshow DIV')[rndNum]);
    }

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $($('#slideshow DIV')[rndNum]);

    // uncomment below to pull the divs randomly
    var $sibs  = $active.siblings();
    var rndNum = Math.floor(Math.random() * $sibs.length );
    var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');
	//$('.workDescription').hide('slow');
    $next.css({opacity: 0.0, display: 'block'})
        .addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}


