(function($){

    $(function(){

        resizeContent();
        $(window).resize(function(){
            resizeContent();
            //$.scrollTo(0, 1000);
        });

        if (location.search.length > 0)
        {
            var id = location.search.split("?id=")[1];
            $.scrollTo($('#' + id).parents("li"), 1000, { margin: true });
        }


        $("div.next:not(:last)").click(function(){
           
           $.scrollTo($(this).parents("li").next(), 1000, { margin: true });

        });

        $("div.next:last").click(function(){

           $.scrollTo(0, 1000);

        });

        $("div.previous:not(:first)").click(function(){
           
           $.scrollTo($(this).parents("li").prev(), 1000, { margin: true });
           
        });

        $("div.previous:first").click(function(){

           $.scrollTo($(this).parents("li").siblings().last(), 1000, { margin: true });

        });

        $("#clients a").click(function()
        {
            var id = $(this).attr('rel');
            $.scrollTo($('#' + id).parents("li"), 1000, { margin: true });
            return false;
        });

    });

    var resizeContent = function()
    {
        var width = $(window).width();
        var items = $("#boxes > li").width(width - 100);
        $("div.content").width(items.length * width);
    }

})(jQuery);


