﻿$(document).ready(function(){
	var obj = $("#slider ul"); 
    var s = $("#slider ul li").length;
    var w = 230;
    var move=w*4;
    $(obj).width(s*w);
    if($.browser.msie){$("#slider ul li:first").css('margin-right','1px');}
    var back=150;
    var objWidth=s*w;
	$("#nextBtn").click(function(){
	stop();
	    if ((objWidth + parseInt(obj.css("right")))/w > 4)
	    {   
	    $(obj).animate({right: "+="+back}, 200);
	        $(obj).animate({right: "-="+(move+back)}, 'normal',function(){
	        
		        if ((objWidth + parseInt(obj.css("right")))/w <= 4)
                    $("#nextBtn").css('background-position','0px -192px');
 
                 $("#prevBtn").removeAttr("style");   

	        });
        }
	});
    $("#prevBtn").click(function(){
    stop();
        if(parseInt($(obj).css("right")) < 0)
        {
            $(obj).animate({right: "-="+back}, 200);
	        $(obj).animate({right: "+="+(move+back)}, 'normal',function(){
	        
                if (parseInt(obj.css("right")) == 0)
                $("#prevBtn").css('background-position',' 0px -240px');  

                $("#nextBtn").removeAttr("style");    
	        });
	    }
	});
	
    $("#slider .item").mouseenter(function(){
        $(this).animate({ backgroundColor: "#EAEFF2" }, 100);
        $(this).animate({ backgroundColor: "#ffffff" }, 800);
        var img=$(this).find('img');
        img.css("position","relative");
        img.animate({top: "+=10"}, 180);
        img.animate({top: "-=10"}, 200,function(){img.css("position","");});
        
        var title=$(this).find('strong');
        title.animate({paddingRight: "+=10"}, 150);
        title.animate({paddingRight: "-=10"}, 250);
         //title.find('span').css('color','#ffffff');
        var more=$(this).find('.more');
        more.animate({marginRight:"+=10" , marginLeft:"+=10"}, 250);
        more.animate({marginRight:"-=10" , marginLeft:"-=10"}, 190);

    });
    $("#slider .item").mouseleave(function(){
 //$(this).animate({ backgroundColor: "#ffffff" }, 800);
        });
    var  intervalID = setInterval( slide, 8000 );
    
    
    function slide()
    {
        if ((objWidth + parseInt(obj.css("right")))/w > 4)
	    {   
	    $(obj).animate({right: "+="+back}, 200);
	        $(obj).animate({right: "-="+(move+back)}, 'slow',function(){
	        
		        if ((objWidth + parseInt(obj.css("right")))/w <= 4)
                    $("#nextBtn").css('background-position','0px -192px');
 
                 $("#prevBtn").removeAttr("style");   

	        });
        }
        else
        {
            $(obj).animate({right: "0"}, s*100,function(){
            $("#prevBtn").css('background-position',' 0px -240px');
            $("#nextBtn").removeAttr("style");   

	        });
        }
    }
    
    
    
    function stop() 
    {
        if(intervalID)
        clearInterval(intervalID);
    }
$('#slider img').each(function(){
        if($(this).width() > parseInt($(this).css('max-width')))
            $(this).width($(this).css('max-width'));
        
        if($(this).width() > parseInt($(this).css('max-height')))
            $(this).height($(this).css('max-height'));
    });
});

