(function($) {
	$(document).ready( function() {
	// SETUP
	var show_navigation = true;
	var navigation_position = 'bottom';
	var slide_autoplay = true;
	var slide_autoplay_delay = 5300;
	var slide_speed = 500;
	var current_slide = 0;
	
	// CODE START
	var slider_id = 'sc_slider';
	var slider_navigation_id = 'sc_slider_navigation';
	var total_images = $('#' + slider_id + ' ul li').length;
	var total_slides = total_images/3;
    var myInterval;
    var myInterval_off = false;
    
	// Navigation
	if (total_slides > 1 && show_navigation) {
		if (navigation_position == 'bottom') {
			$('#sc_slider').append('<ul id="' + slider_navigation_id + '">');
			for (var i=0; i<total_slides; i++) {
				$('ul#' + slider_navigation_id).append('<li></li>');
			}
			$('#sc_slider').append('</ul><div class="sc_clear"></div>');
		} else {
			$('#sc_slider').prepend('</ul><div class="sc_clear"></div>');
			$('#sc_slider').prepend('<ul id="' + slider_navigation_id + '">');
			for (var i=0; i<total_slides; i++) {
				$('ul#' + slider_navigation_id).prepend('<li></li>');
			}
		}
		
		$('ul#' + slider_navigation_id + ' li').click(function() {
			clearInterval(myInterval);
            myInterval_off = true;
			var current_slide = $(this).prevAll().length;
			$('ul#' + slider_navigation_id + ' li').css({backgroundPosition: "0 -11px"});
			$(this).css({backgroundPosition: "0 0"});
			$('#sc_slider_posts').stop().animate({right: [960*current_slide, 'swing' ]}, slide_speed);
		});
	}
	
	// Autoplay function
	function slide_autoplay_function () {
		if (current_slide >= total_slides -1) {
			current_slide = 0;
		} else {
			current_slide++;
		}
		$('#sc_slider_posts').animate({right: [960*current_slide, 'swing' ]}, slide_speed);
		$('ul#' + slider_navigation_id + ' li').css({backgroundPosition: "0 -11px"});
		$('ul#' + slider_navigation_id + ' li').eq(current_slide).css({backgroundPosition: "0 0"});
	}
	
	// Autoplay condition
	if (slide_autoplay && total_slides > 1) {
		myInterval = setInterval(slide_autoplay_function, slide_autoplay_delay);
	}
	
	// On hover stop
    $('#' + slider_id).hover(function() {
    	clearInterval(myInterval);
    },
    function() {
		if (!myInterval_off) {
        	myInterval = setInterval(slide_autoplay_function, slide_autoplay_delay);
        }
    });
	
	// Initialize
	$('ul#' + slider_navigation_id + ' li').eq(current_slide).css({backgroundPosition: "0 0"});
	$('#sc_slider_posts').stop().css({right: 960*current_slide});
	});
})(jQuery);
