//document

/*** 
    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 .slide-item.active');

    if ( $active.length == 0 ) $active = $('#slideshow .slide-item:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow .slide-item:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 2000, function() {
            $active.removeClass('active last-active');
            $active.find('p').css({width: '300px'}).removeFE(false);
            $next.find('p').css({width: '300px'}).removeFE(false);
            $next.find('p').css({width: '300px'}).FontEffect();
            
        });
    
}


/* dynamic */
function dynamic_init(self){
	if (self.children('p').css('display') == 'block'){
		self.children('p').slideUp();
		self.css('background-position', '-20px -28px');
	}
	else{
		self.children('p').slideDown();
		self.css('background-position', '-40px 0');
	}
}


/* tour */
function side_list_init(index, side_list){
	side_list.find('a').removeClass('current');
	side_list.find('a').eq(index).addClass('current');
	$('#content').children('a').hide();
	$('#content').children('a').eq(index).fadeIn();
}

 function getIndex(url) {  
	var str= 1
	if(url.indexOf('#') != -1) {  
		str = url.substr(url.indexOf('#') + 5);
		if (str.substr(0,1) == 0){
			str = str.substr(1);
		}
	}  
	return str;
}  

$(document).ready(function() {
	//init
	/*
	if ($('body.tour').length){
		side_list_init(getIndex(location.href) - 1, $('.side-list'));
	}
	*/
	
	var dynamic_list = $('.dynamic-list');
	if (dynamic_list.length){
		dynamic_list.children('li').click(function(){
			dynamic_init($(this));
		});
	}
	
	/*
	var side_list = $('.side-list');
	if (side_list.length){
		side_list.find('a').each(function(i){
			$(this).click(function(){
				side_list_init(i, side_list);
				//return false;
			})
		})
	}
	*/
	
	if ($('#navigation').length){
		$('#navigation > ul > li').hover(function(){
			$(this).addClass('hover')
		}, function(){
			$(this).removeClass('hover');
		})
	}
	
	//activate slideshow (comments it to deactivate)
	setInterval(slideSwitch, 6000 );
	
		
	$('#slideshow .slide-item p').FontEffect({ shadow:true, outline:true })

	
});

