﻿$(function() {
    //$("#sliderContent").width($("#sliderContent img").totalWidth());
    $("#sliderContent").css("left", $("#sliderContainer").width() - $("#sliderContent").width());
    $("#leftArrow").click(function() {
        MoveSliderLeft();
    });
    $("#rightArrow").click(function() {
        MoveSliderRight();
    });
});

function MoveSliderLeft() {
    var step = 400;
    MoveSlider(step);
}

function MoveSliderRight() {
    var step = -400;
    MoveSlider(step);
}

function MoveSlider(step) {
    var speed = 700;
    var content = $("#sliderContent")[0];
    var container = $("#sliderContainer")[0];
    var l = content.style.left;
    var l1 = parseInt(l);
    var newLeft = l1 + step;
    if (newLeft > 0) {
        newLeft = 0;
    }
   
    if (newLeft < container.clientWidth - content.clientWidth) {
        newLeft = container.clientWidth - content.clientWidth;
    }

    $("#sliderContent").animate({ left: newLeft }, speed, "linear");
}

$.fn.totalWidth = function() {
    var totalWidth = 0;
    this.each(function() {
        totalWidth += $(this).outerWidth(true);
    });

    return totalWidth;
}

