
var base_scroll = getScrollHeight();

            var padding = 250;

            var in_transition = false;

            var entry_timer = cur_select = prev_scroll_pos = 0;

                                                          

            $(document).ready(function() {

                $('#logo').css('cursor','pointer').click(function(){

                    $('html, body').animate({scrollTop:0}, 500);

                });

					

                setTimer();

                checkEntryPosition();

                $(".project_link").live("click",function() {

                    $(".project_link").removeClass("active");

                    cur_select = $(this).attr("id").replace("menu_","entry_");

                    snapToEntry(parseInt(document.getElementById(cur_select).offsetTop));

                    $(this).addClass("active");

                    return false;

                });

                                                            

                $(".project_next a").live("click", function() {

                    snapToEntry("next");

                    return false;

                });

                                                            

                $("#goodicons img").each(function (i) {

                    var $item = $(this); 

                    setTimeout(function() { 

                        $item.animate({opacity: "1"}, 600);

                    }, 600*i);

                });

                                                            

                $(document).scroll(function() {

                    var entry_top = parseInt(document.getElementById(cur_select).offsetTop);

                    var win_pos = $(window).scrollTop();

                    parseInt(win_pos);

                    var hit_pos = parseInt(entry_top - $("#head_bar").height());

                    var diff = -(win_pos-entry_top)-$("#head_bar").height();

                    if(win_pos >= hit_pos && win_pos < entry_top) {

                        $("#head_bar").css("top",diff);

                        if(prev_scroll_pos > win_pos) {

                            $("#head_title").html($("#"+$("#"+cur_select).prev().prev().prev().attr("id")+" .project_title a").html());

                        }

                                                                    

                    } else if(win_pos >= entry_top) {

                        $("#head_title").html($("#"+cur_select+" .project_title a").html());

                        $("#head_bar").css("top",0);

                    }

                                                                

                    if(win_pos > "1100") {

                        $(".val_text").each(function (i) {

                            var $item = $(this); 

                            setTimeout(function() { 

                                $item.animate({opacity: "1"}, 600);

                            }, 600*i);

                        });

                    }

                                                                

                    if(win_pos > "6454") {

                        $("#eye").css("backgroundPosition", "0 -76px");

                    }

                                                                

                    if(win_pos > "6643") {

                        $("#compass_arrow").css("backgroundPosition", "0 -167px");

                    }

                                                                

                    if(win_pos > "6900") {

                        $("#sunnyboy").css("backgroundPosition", "0 -160px");

                    }

                                                                

                    if(win_pos > "7050") {

                        $("#connection").css("backgroundPosition", "0 -109px");

                    }

                                                                

                    if(win_pos > "7252") {

                        $("#talk").css("backgroundPosition", "0 -123px");

                    }

                                                                

                    if(win_pos > "7300") {

                        $("#lasticon").css("backgroundPosition", "0 -130px");

                    }

                                                                

                    if(win_pos > "9947") {

                        $("#pepsi_icons img").each(function (i) {

                            var $item = $(this); 

                            setTimeout(function() { 

                                $item.animate({opacity: "1"}, 600);

                            }, 600*i);

                        });

                    }

                    var this_prev = $("#"+cur_select).prev().prev().prev();           

                    prev_scroll_pos = win_pos;

                });

            });

                                                        

            function checkEntryPosition() {

                if(!in_transition) {

                    $(".entry").each(function() {

                        var this_id = $(this).attr("id");

                        var nav_id = this_id.replace("entry_","menu_");

                        var entry_top = parseInt(document.getElementById(this_id).offsetTop);

                        var scroll_pos = parseInt(getScrollHeight()-(base_scroll/2));

                                                                    

                        if(scroll_pos >= entry_top && scroll_pos < (entry_top+$(this).height())) {

                            if(!$("#"+nav_id).hasClass("active")) {

                                $("#"+nav_id).addClass("active");

                                cur_select = this_id;

                            }

                                                                        

                        } else {

                            $("#"+nav_id).removeClass("active");

                        }

                                                                    

                    });

                }

            }

                                                        

            $(document).bind("scrollComplete", function(e) {

                in_transition = false;

            });

                                                        

            function snapToEntry(entry_top) {

                clearTimeout(scroll);

                if(entry_top == "next") {

                    var upnext = false;

                    $(".entry").each(function() {

                        if($(this).attr("id") == cur_select && cur_select != $(".entry:last").attr("id")) upnext = true;

                        else if(upnext) {

                            cur_select = $(this).attr("id");

                            return false;

                        }

                    });

                    if(!upnext) cur_select = $(".entry:first").attr("id");

                    entry_top = parseInt(document.getElementById(cur_select).offsetTop);

                    $(".project_link").removeClass("active");

                    $("#"+cur_select.replace("entry_","menu_")).addClass("active");

                }

                in_transition = true;

                fireScroll(entry_top+1,(getScrollHeight()-base_scroll),0);

            }

                                                        

            function setTimer() {

                entry_timer = setInterval("checkEntryPosition()",10);

            }

                                                        

            function fireScroll(targetYPos,y,t) {

                var speed = 10;

                var diff = targetYPos - y;

                var steps = diff/(speed*speed);

                t += (t+steps)/diff;

                newY = (t==1) ? y+diff : y + (diff * (-Math.pow(2, -20 * t/1) + 1));

                if(t) window.scrollTo(0, newY);

                                                        

                if(t >= 1 || lastT == t || !t) {

                    clearTimeout(scroll);

                    window.scrollTo(0, targetYPos)

                    $(document).trigger("scrollComplete");

                } else {

                    scroll=setTimeout("fireScroll("+targetYPos+","+y+","+t+")",1);

                }

                                                        

                lastT = t;

                                                        

                return false;

            }

