jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
    return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

$(document).ready(function(){

    if ($('#screen').length > 0){
        $('#screen').serialScroll({
            target:'#sections',
            items:'li',
            prev:'p.prev',
            next:'p.next',
            axis:'xy',
            navigation:'#navigation li a',
            duration:700,
            force:true,
            onBefore:function( e, elem, $pane, $items, pos ){
                e.preventDefault();

                $("#navigation ul li").each(function(){
                    $(this).removeClass("red");
                });
                $("#navigation ul li").eq(pos).addClass("red");


                if( this.blur ){
                    this.blur();
                }
            },
            onAfter:function( elem ){
            
            }
        });
    }

    if ($('.boxgrid.caption').length > 0) {
        $('.boxgrid.caption').each(function(){
            $(this).hover(function(){
                $(".cover", this).stop().animate({
                    top:'80px'
                },{
                    queue:false,
                    duration:160
                });
            }, function() {
                $(".cover", this).stop().animate({
                    top:'160px'
                },{
                    queue:false,
                    duration:160
                });
            });
        });
    }

    if ($("#record_list").length > 0){
        $("#record_list").fixedtableheader();

        $("#record_list tbody tr").hover(
            function(){
                var newPath = $('td.cover img', this).attr('src').replace(new RegExp("small","g"), "medium");
                $('td.cover img', this).attr({
                    src:newPath
                });
            },
            function(){
                var newPath = $('td.cover img', this).attr('src').replace(new RegExp("medium","g"), "small");
                $('td.cover img', this).attr({
                    src:newPath
                });
            }
            );
    }

    if ($('#recordSlider').length > 0){
        setTimeout(function(){
            $('#recordSlider').nivoSlider({
                effect:'fade',
                slices:15,
                pauseTime:5000,
                pauseOnHover:false,
                directionNav:false,
                controlNavThumbs:true,
                controlNavThumbsSearch: '/big/',
                controlNavThumbsReplace: '/small/'
            });
        }, 2000);
    }


    if ($('.dropdown').length > 0){
        
        $('.dropdown').each(function () {

            var id = $(this).attr('id');
            
            var curValue = eval("dropdown.curValues." + id);

            var value = $("dd ul li a span:contains(" + curValue + ")",this).closest('li');

            if (value != null){
                $('dt', this).html(value.html());
            }

            $("dt a", this).click(function(){
                $(".dropdown dd ul").hide();
                $('dd ul', $(this).closest("dl")).toggle();
            });

            $("dd ul li a" , this).click( function() {

                var text = $(this).html();
                var elem = $(this).closest('dl');

                $('dt a' , elem).html(text);
                $('dd ul' , elem).toggle();

                $("dl.dropdown").each(function(){
                    dropdown.current +=  $('dt a span.value', this).html() + '/';
                });

                var url = dropdown.urlPrefix;
                url = url.replace( dropdown.toFind, dropdown.current );

                $(location).attr('href',url);
            });
        });

        $(document).bind('click', function(e) {
            var $clicked = $(e.target);
            if ($clicked.parents().hasClass("dropdown"))
                return false;
        });

    };
});
