$(document).ready(function() {

$(".is_paging a:first").addClass("firstslide");
$(".is_paging a:last").addClass("lastslide");
$is_active = $(".is_paging a:first");
$is_active_slide = $(".is_slide_reel div:first");
$is_active_slide.children().css('opacity','1');

$(".is_paging a:first").addClass("active");
$is_active_slide.addClass("active");

//Get size of the slide, how many slides there are, then determin the size of the slide reel.
var slideWidth = $(".is_window").width();
var slideSum = $(".is_slide_reel div").size();
var slideReelWidth = slideWidth * slideSum;

//Adjust the slide reel to its new size
$(".is_slide_reel").css({'width' : slideReelWidth});

//Paging  and Slider Function
is_rotate = function(){
	var activeslide = $is_active.attr("rel");
    var is_triggerID = $is_active.attr("rel") - 1; //Get number of times to slide
    var slide_reelPosition = is_triggerID * slideWidth; //Determines the distance the slide reel needs to slide

    $(".is_paging a").removeClass('active'); //Remove all active class
    $is_active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
	
	$(".is_slide_reel div").removeClass('active'); //Remove all active class
    $is_active_slide.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

    //Slider Animation
    $(".is_slide_reel").animate({
        left: [-slide_reelPosition, 'swing']
    }, 1200 );
	$(".is_slide_reel div").each(function (){
		if ( $(this).hasClass('active')){
			 $(this).children("span").delay(800).animate({opacity: 1}, 300, 'swing');
			 $(this).children("img").delay(1000).animate({opacity: 1}, 500, 'swing');
		} else {
			$(this).children("span").animate({opacity: 0}, 200, 'swing');
			$(this).children("img").animate({opacity: 0}, 200, 'swing');
			}
	});
	return false;
}; 

//Rotation  and Timing Event
is_rotateSwitch = function(){
    is_play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
        $is_active = $('.is_paging a.active').next(); //Move to the next paging
        if ( $is_active.length === 0) { //If paging reaches the end...
            $is_active = $('.is_paging a:first'); //go back to first
        }
		$is_active_slide = $('.is_slide_reel div.active').next(); //Move to the next paging
        if ( $is_active_slide.length === 0) { //If paging reaches the end...
            $is_active_slide = $('.is_slide_reel div:first'); //go back to first
        }
        is_rotate(); //Trigger the paging and slider function
    }, 10000); //Timer speed in milliseconds (7 seconds)
};

is_rotateSwitch(); //Run function on launch

is_fx = function(){
	is_fx_time = setInterval(function(){
		$on = 0;
		$(".is_slide_reel div").each(function (){
			if ( $on = 0 ){
			 	$(".is_slide_reel div").hasClass('active').children("img").animate({ width: "+20"}, 100, 'swing');
			 	on = 1;
			} else {
				$(".is_slide_reel div").hasClass('active').children("img").animate({ top: "-20"}, 100, 'swing');
				on = 0;
			};
		});
	});
};

is_fx();

//On Hover
$(".indexslide").hover(function() {
    clearInterval(is_play); //Stop the rotation
}, function() {
    is_rotateSwitch(); //Resume rotation timer
});	

//On Click
$(".is_paging a").click(function() {
    $is_active = $(this); //Activate the clicked paging
	$(".is_slide_reel div").each(function(index) {
       	if ( $is_active.attr("rel") == 1) {
			$is_active_slide = $("div#is1");
		}
		if ( $is_active.attr("rel") == 2) {
			$is_active_slide = $("div#is2");
		}
		if ( $is_active.attr("rel") == 3) {
			$is_active_slide = $("div#is3");
		}
		if ( $is_active.attr("rel") == 4) {
			$is_active_slide = $("div#is4");
		}
    });
    //Reset Timer
    clearInterval(is_play); //Stop the rotation
    is_rotate(); //Trigger rotation immediately
    is_rotateSwitch(); // Resume rotation timer
    return false; //Prevent browser jump to link anchor
});
	
$("#button_left").click(function() {
	if ($is_active.hasClass("firstslide")) {
		$is_active = $('.is_paging a:last');
		$is_active_slide = $('.is_slide_reel div:last');
		//Reset Timer
    	clearInterval(is_play); //Stop the rotation
    	is_rotate(); //Trigger rotation immediately
    	is_rotateSwitch(); // Resume rotation timer
    	return false; //Prevent browser jump to link anchor
	} else {
    	$is_active = $('.is_paging a.active').prev();
		$is_active_slide = $('.is_slide_reel div.active').prev();
    	//Reset Timer
    	clearInterval(is_play); //Stop the rotation
    	is_rotate(); //Trigger rotation immediately
    	is_rotateSwitch(); // Resume rotation timer
    	return false; //Prevent browser jump to link anchor
	}
});

$("#button_right").click(function() {
	if ($is_active.hasClass("lastslide")) {
		$is_active = $('.is_paging a:first');
		$is_active_slide = $('.is_slide_reel div:first');
		//Reset Timer
    	clearInterval(is_play); //Stop the rotation
    	is_rotate(); //Trigger rotation immediately
    	is_rotateSwitch(); // Resume rotation timer
    	return false; //Prevent browser jump to link anchor
	} else {
    	$is_active = $('.is_paging a.active').next();
		$is_active_slide = $('.is_slide_reel div.active').next();
    	//Reset Timer
    	clearInterval(is_play); //Stop the rotation
    	is_rotate(); //Trigger rotation immediately
    	is_rotateSwitch(); // Resume rotation timer
    	return false; //Prevent browser jump to link anchor
	}
});
	
	
});

$(".is_button img").hover(function(){$(this).toggleClass('hover',300)});


