﻿$(document).ready(function() {
        initRotator();
});

function initRotator() {
    slider();
    $("*[class^='homeContent']").width(942);
    //Add in if more than two items
    $("#homeContentWrapper").width($(".homeContent").width() * $(".homeContent").length);
    $(".homeImage").hover(function() { $("#homeControls").show() }, function() { $("#homeControls").hide() });
}

var currentVal;

function slider() {

    currentVal = 1;
    var speed = 7000;
    var run = setInterval('rotate()', speed);

    var item_width = $('.homeContent').outerWidth();
    var left_value = item_width * (-1);

    $('.homeContent:first').before($('.homeContent:last'));
    $('#homeContentWrapper').css({ 'left': left_value });

    $('#homePrev').click(function() {
    	var left_indent = parseInt($('#homeContentWrapper').css('left')) + item_width;
    	$('#homeContentWrapper:not(:animated)').animate({ 'left': left_indent }, 1700, function() {
    		$('.homeContent:first').before($('.homeContent:last'));
    		$('#homeContentWrapper').css({ 'left': left_value });
    		clearInterval(run);
    		run = setInterval('rotate()', speed);
    	});
    });

    $('#homeNext').click(function() {
        var left_indent = parseInt($('#homeContentWrapper').css('left')) - item_width;
        $('#homeContentWrapper:not(:animated)').animate({ 'left': left_indent }, 1700, function() {
            $('.homeContent:last').after($('.homeContent:first'));
            $('#homeContentWrapper').css({ 'left': left_value });
            clearInterval(run);
            run = setInterval('rotate()', speed);
        });
    });
    
}

function rotate() {
    $('#homeNext').click();
}
