/*
Copyright 2008-2010 shavemagazine.com
Author: Abe Sabbagh
*/
function slideSwitch(direction, specific) {
    var $active = $('#slideshow_inner div.active');
	if (direction == 'specific'){
		var $next =  $('#slideshow_inner div#' + specific);
		if($active.attr('id') == $next.attr('id')) return;
	}else if (direction == 'prev'){
		var $next =  $active.next().length ? $active.next() : $('#slideshow_inner div.slide:first');
	}else{
		var $next =  $active.prev().length ? $active.prev() : $('#slideshow_inner div.slide:last');
	}
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 400, function() {
			if(jQuery.browser.msie){
				this.style.removeAttribute('filter');
			}
            $active.removeClass('active last-active');
		});
}
function set_slideshow_buttons_background(button, hover) {
	var temp = button.attr("class").substring(5,6);
	var height = (hover)? '19': '0';
	
	if( temp == '1' ) button.css( {backgroundPosition: "-1px "+height+"px"} );
	else if( temp == '2' ) button.css( {backgroundPosition: "-25px "+height+"px"} );
	else if( temp == '3' ) button.css( {backgroundPosition: "-50px "+height+"px"} );
	else if( temp == '4' ) button.css( {backgroundPosition: "-75px "+height+"px"} );
	else if( temp == '5' ) button.css( {backgroundPosition: "-100px "+height+"px"} );
	else if( temp == '6' ) button.css( {backgroundPosition: "-125px "+height+"px"} );
	else if( temp == '7' ) button.css( {backgroundPosition: "-150px "+height+"px"} );
}
$(function() {
	$(document).ready(function(){
		set_slideshow_buttons_background($('.slide1_button'), false);
		set_slideshow_buttons_background($('.slide2_button'), false);
		set_slideshow_buttons_background($('.slide3_button'), false);
		set_slideshow_buttons_background($('.slide4_button'), false);
		set_slideshow_buttons_background($('.slide5_button'), false);
		set_slideshow_buttons_background($('.slide6_button'), false);
		set_slideshow_buttons_background($('.slide7_button'), false);
		$('#next').css( {backgroundPosition: "-500px 0px"} );
		$('#prev').css( {backgroundPosition: "-460px 0px"} );
		slideInterval = setInterval( "slideSwitch()", 7000 );
	});
	$(".slide1_button, .slide2_button, .slide3_button, .slide4_button, .slide5_button, .slide6_button, .slide7_button").click(function(){
		slideSwitch('specific', $(this).attr("class").substring(0,6) );
		clearInterval(slideInterval);
		slideInterval = setInterval( "slideSwitch()", 7000 );
	});
	$('.slide_button')
		.mouseover(function(){ set_slideshow_buttons_background($(this), true); })
		.mouseout(function(){ set_slideshow_buttons_background($(this), false); })
	$('#next')
		.click(function(){
			slideSwitch();
			clearInterval(slideInterval);
			slideInterval = setInterval( "slideSwitch()", 7000 );
		})
		.mouseover(function(){ $(this).css( {backgroundPosition: "-500px 19px"} ); })
		.mouseout(function(){ $(this).css( {backgroundPosition: "-500px 0px"} ); })
	$('#prev')
		.click(function(){
			slideSwitch('prev');
			clearInterval(slideInterval);
			slideInterval = setInterval( "slideSwitch()", 7000 );
		})
		.mouseover(function(){ $(this).css( {backgroundPosition: "-460px 19px"} ); })
		.mouseout(function(){ $(this).css( {backgroundPosition: "-460px 0px"} ); })
});
