$(function() {
var hightLi;
hightLi = 0;
countLi = 0;
$("#strip ul li").each(function() {  
    countLi++;
    hightLi = hightLi + ($(this).height() + 2.5);
    //alert($(this).height() + 3);
});
var strip_height = hightLi + ($("#strip .numbers").length * 80) + (64);
last = parseInt("-" + strip_height) + 504;
        var direction = 0;
        $(".yearSelect a").click(function(e) {
            
            $(".yearSelect a").attr("class", "");
            $(this).attr("class", "active");
            if($(this).text() == "Oldest") {
                var year = 1930;
                var year2 = 1970;
            } else {
                var year = parseInt($(this).text().split("-")[0]);
                var year2 = parseInt($(this).text().split("-")[1]);
            }
            var offset = 0;
            var exit = 0;
            var hasBeginYear = 0;
            var specialcount = 0;
            var remember_last = 0;
            $("#strip").children().each(function(y) {
        
                if( this.className == "year" ) {
                    
                    loopYear = parseInt($(this).children(".numbers").text())
                    if (loopYear == year) {
                        hasBeginYear = 1;                        
                        remember_last = 0;
                        return;
                    } else if(loopYear > year && hasBeginYear != 1) 
                    {
                        specialcount = 0;
                        $(this).children('ul li').each( function(e) {
                        
                        
                            if (this.className == "numbers" || this.className == "list" ) {
                                specialcount -= $(this).height();
                            } 
                        });
                        specialcount -= 40;
                        
                        if (hasBeginYear != 1) {
                            remember_last = specialcount
                        }
                        
                        offset += specialcount
                        return;
                    } else
                    {
                        exit++;
                    }
                }
            });
            offset = offset - remember_last;
            
            if(offset < last) {
                offset = last;
            }
            
            $("#strip").css({ marginTop: offset + "px" });
            });
        });
        function slide( speed ) {
            var margin = parseInt($("#strip").css("marginTop"));
            if (speed) {
                $("#strip").animate({ marginTop: margin + ( 100 * direction ) + "px" }, speed );
            } else {
                var off = margin + 100 * direction;
                
                if (off >= 0) {
                    off = 0;
                    $("#strip").animate({ marginTop: off + "px" }, { duration: 1500, easing: "linear", queue: false });
                    return;
                } else if (off < last ) {
                    off = last;
                    $("#strip").animate({ marginTop: off + "px" }, { duration: 1500, easing: "linear", queue: false });
                    return;
                } else 
                    $("#strip").animate({ marginTop: 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_height_years = 0;
            $("#strip .year .image").each( function(e) {
                strip_height_years += 104;
            });
            
            strip_height = 0;
            $("#strip ul li").each(function (e) { 
                strip_height += $(this).height();
            });
            
            strip_height += strip_height_years;
            $("#strip").height(strip_height);
            // --- scroll left
            $(".toparrow").mouseover(function(e) {
                $("#strip").stop();
                direction = 1;
                slide();
            });
            $(".toparrow").mousemove(function(e) { });
            $(".toparrow").mouseout(function() { $("#strip").stop(); });
            // --- scroll right
            $(".bottomarrow").mouseover(function(e) {
                $("#strip").stop();
                direction = -1;
                slide();
            });
            $(".bottomarrow").mousemove(function(e) { });
            $(".bottomarrow").mouseout(function(e) { $("#strip").stop(); });
            // --- year groups
            $(".years a").click(function(e) {
                var year = $(this).text().split("-")[0];
                
            });
        });