var strip_width = 10000;
        var direction = 0;
        
        function slide( speed ) {
            var margin = parseInt($("#strip").css("marginLeft"));
            if (speed) {
                $("#strip").animate({ marginLeft: margin + (136*direction) + "px" }, speed );
            } else {
                var off = margin + 136 * direction;
                //alert(off);
                if (off >= 0) {
                    off = 0;
                    $("#strip").animate({ marginLeft: off + "px" }, { duration: 1500, easing: "linear", queue: false });
                    return;
                } else if (off < 900 - strip_width ) {
                    off = 900 - strip_width;
                    
                    $("#strip").animate({ marginLeft: off + "px" }, { duration: 1500, easing: "linear", queue: false });
                    return;
                } else 
                    $("#strip").animate({ marginLeft: off + "px" }, { duration: 1500, easing: "linear", complete: slide, queue: false });
            }
        }
        
        
        $(function() {
            $("#strip .year").each(function() {
                var year = $(this).children(".bottom").text();
                var imgs = [];
                for(var i = Math.min(year.length - 1, 3); i >= 0; i--)
                    imgs.push("<img src='images/num_" + year.substr(i, 1) + ".gif' alt='' />");
                $(this).children(".vertical").html(imgs.join(" "));
            });
            strip_width = 136 * $("#strip a.show").length + ($("#strip .year").length * 105);
            
            if (jQuery.browser.msie = 6) {
                strip_width = strip_width + 135;
            }
        
            $("#strip").width(strip_width);
            strip_speed = strip_width * 1000.0 / 200.0;

            // --- scroll left
            $(".leftarrow").mouseover(function(e) {
                $("#strip").stop();
                this.src = "images/history_left_new.png";
                direction = 1;
                slide();
                $(this).ifixpng();
            });
            
            $(".leftarrow").mousedown(function(e) 
            {
                $("#strip").stop();
                var margin = parseInt($("#strip").css("marginLeft"));
                if(margin < -700) 
                {
                    margin = margin + 700;
                    $("#strip").css({ marginLeft: margin + "px" });
                } else 
                {
                    $("#strip").css({ marginLeft: 0 + "px" });
                }
            });    
            
            $(".leftarrow").mouseup(function(e) {
                slide();
            });
            
            $(".leftarrow").mousemove(function(e) { });
            $(".leftarrow").mouseout(function(e) { 
                $("#strip").stop(); 
                this.src = "images/history_left_new_hover.png";
                $(this).ifixpng();
            });
            // --- scroll right
            $(".rightarrow").mouseover(function(e) {
                this.src = "images/history_right_new.png";
                $("#strip").stop();
                direction = -1;
                slide();
                $(this).ifixpng();
            });
            $(".rightarrow").mousemove(function(e) { });
            $(".rightarrow").mouseout(function(e) { 
                $("#strip").stop(); 
                this.src = "images/history_right_new_hover.png";
                $(this).ifixpng();
            });
            // --- year groups
            
            $(".rightarrow").mousedown(function(e) 
            {
                $("#strip").stop();
                var margin = parseInt($("#strip").css("marginLeft"));
                end = parseInt( "-" + ($("#strip").width())) ;
                endMin = end + 1600;
                if(margin > endMin) 
                {
                    margin = margin - 700;
                    $("#strip").css({ marginLeft: margin + "px" });
                } else 
                {
                    $("#strip").css({ marginLeft: (endMin - 700) + "px" });
                }
            });    
            
            $(".rightarrow").mouseup(function(e) {
                slide();
            });
                
            
            $("#years a").click(function(e) {    
                if(this.id == "oldest" ) {
                    var year = 1930;
                } else {
                    var year = parseInt($(this).text().split("-")[0]);
                }
                
                $("#years a").attr("class", "");
                $(this).attr("class", "active");
                    
                var offset = 0;
                var exit = 0;
                var hasBeginYear = 0;
                var loopYear = 0
                var lastOffsetYear = 0;
                var olderYear = 1;
                var countOlderYears = 0;
                var oountOlderProductions = 0;
                var older = 0;
                $("#strip").children().each(function(y) {
                    
                    if( this.className == "year" ) 
                    {    
                        loopYear = parseInt($(this).children(".bottom").text());
                        if (loopYear == year) {
                            hasBeginYear = 1;
                            return;
                        } else if( loopYear > year && hasBeginYear != 1) {
                            offset2 = 0;
                            offset += 105;
                            return;
                        } else
                        {
                            olderYear = 0;
                            countOlderYears += 105 
                            exit++;
                        }
                    } else {
                        if (exit < 1  && hasBeginYear != 1 && loopYear > year ) {
                            offset += 136;
                            offset2 += 136;
                        } else {
                            oountOlderProductions +=136
                        }
                    }
                });
                
                older = oountOlderProductions + countOlderYears;
                if(olderYear) 
                {
                    offset = offset - 764;
                }
                if(older > 0 && older < 764) {
                    offset = offset - (764 - older);
                }
                
                $("#strip").css({ marginLeft: "-" + offset + "px" });
            });
        });

    $(document).ready(function(){
        
            
        var margin = parseInt($("#strip").css("marginLeft"));
        var thisYear = $('.full .year').text();
        var year = "";
        var exit = 0;
        var offset = 0;
        
        $('#years a').each(function(y) {
            var year = parseInt($(this).text().split("-")[1]);
            var year2 = parseInt($(this).text().split("-")[0]);
            
            if (year <= thisYear && year2 > thisYear) {
                $(this).attr("class", "active");
            } else {
                $("this").attr("class", "");
            }
        });
    
        $("#strip").children().each(function(y) {
            year = $(this).children(".bottom").text();
            if( this.className == "year" ) {
                if (parseInt($(this).children(".bottom").text()) > thisYear) {
                    offset += 105;
                    return;
                } else {
                    exit++;
                }
            } else {
                if (exit < 1) {
                    offset += 136;
                }
            }
        });
        var lastPiece = strip_width - offset;
        if(lastPiece < 900) {
            offset = strip_width - 900;
        } 
        $("#strip").css({ marginLeft: "-" + offset + "px" });
    });


/*
    images/num_0.gif
    images/num_1.gif
    images/num_2.gif
    images/num_3.gif
    images/num_4.gif
    images/num_5.gif
    images/num_6.gif
    images/num_7.gif
    images/num_8.gif
    images/num_9.gif
*/