$(document).ready(function() {
    $('#customer-login .content').hide('fast', function() {
        $('#customer-login .customer-button').css('margin-top', '0px');
    });
    var width = $("#projects .content li").width();
    var sum = $("#projects .content li").size();
    var reelwidth = width * sum;

    $("#projects .content ul").css({'width' : reelwidth});
    
    rotate = function(){
        var triggerID = $active.attr("rel") - 1;
        var reelPosition = triggerID * width;
        $("#projects .paging a").removeClass('active');
        $active.addClass('active');

        $("#projects .content ul").animate({
            left: -reelPosition
        }, 500 );
    };
    rotateSwitch = function(){
        play = setInterval(function(){ 
            $active = $('#projects .paging a.active').next();
            if ( $active.length === 0) {
                $active = $('#projects .paging a:first');
            }
            rotate();
        }, 7000);
    };

    rotateSwitch();

    $("#projects .content li").hover(function() {
        clearInterval(play);
    }, function() {
        rotateSwitch();
    });

    $("#projects .paging a").click(function() {
        $active = $(this);
        clearInterval(play);
        rotate();
        rotateSwitch();
        return false;
    });

    $('#slide ul').attr('class', 1);

    rotatebg = function(){
        var current = $('#slide ul').attr('class');
        if (!current) {
            $('#slide ul').attr('class', 1);
        }
        if (current < 13) {
            if (current == 12) {
                current = 1;
            }else {
                current = parseInt(current)+1;
            }
            $('#slide ul').attr('class', current);
        }
        $('#slide .first').fadeOut('slow',
        function() {
           $('#slide .first').css('background-image', 'url(/themed/koverweb/img/headers/'+current+'.png)');
           $('#slide .first').fadeIn('slow');
        });
    };
    rotatebackground = function(){
        playbg = setInterval(function(){
            rotatebg();
        }, 5000);
    };
    rotatebackground();

    $('#menu .main li').hover(function() {
        $(this).find('.submenu').show();
    },
        function() {
           $(this).find('.submenu').hide();
    });
    $('#customer-login .customer-button a').click(function(e){
        if ($('#customer-login .content').css('display') == 'none') {
            $('#customer-login .content').slideDown(function() {
                $('#customer-login .customer-button').css('margin-top', '-7px');
            });
        }else {
            $('#customer-login .content').slideUp(function() {
                $('#customer-login .customer-button').css('margin-top', '0px');
            });
        }
        e.preventDefault();
        return false;
    });

});
