﻿var controlWidth = 150;
var allowMove = true;
var moveWidth = 900;

$(document).ready(function(){
    $("#mycarousel").width($("#mycarousel").children().length*controlWidth);
    //$("#mycarousel").width(10*controlWidth);
    $("#imgBtnLeft").hide();
    $("#imgBtnRight").hide();
    
    if($("#mycarousel").width()>moveWidth) $("#imgBtnLeft").show();
    $("#mycarousel").attr("left","0px");
    
    $("#imgBtnLeft").click(function(){
        if(allowMove){
	        allowMove = false;
	        var arealeft = $("#mycarousel").css("left");
	        arealeft = arealeft.substring(0,arealeft.length-2);
	        arealeft = parseInt(arealeft);
	        //$("#mycarousel").css("left",(arealeft-150)+"px");
	        $("#mycarousel").animate({left:(arealeft-moveWidth)+"px"},800,function(){allowMove = true;});
			
	        if((-arealeft+moveWidth*2)>=$("#mycarousel").css("width").substring(0,$("#mycarousel").css("width").length-2))
	        {
		        $("#imgBtnLeft").hide();
	        }
	        if(arealeft-moveWidth<0)
	        {
		        $("#imgBtnRight").show();
	        }
        }
    });
    
    $("#imgBtnRight").click(function(){
        if(allowMove){
	        allowMove = false;
	        var arealeft = $("#mycarousel").css("left");
	        arealeft = arealeft.substring(0,arealeft.length-2);
	        arealeft = parseInt(arealeft);
	        //$("#mycarousel").css("left",(arealeft+150)+"px");
	        $("#mycarousel").animate({left:(arealeft+moveWidth)+"px"},800,function(){allowMove = true;})
			
	        if((-arealeft-moveWidth*2)<$("#mycarousel").css("width").substring(0,$("#mycarousel").css("width").length-2))
	        {
		        $("#imgBtnLeft").show();
	        }
	        if(arealeft+moveWidth>=0)
	        {
		        $("#imgBtnRight").hide();
	        }
        }
    });
});