var fpmusic = new function()
{
    this.init = function(e)
    {
        var self = this;
        var delay = 2500;

        $('#news .MaiN').css({display:'none'}).fadeIn(delay);
        $('#recordlabel .MaiN').css({display:'none'}).fadeIn(delay);
        $('#artists .MaiN').css({display:'none'}).fadeIn(delay);
        $('#shop .MaiN').css({display:'none'}).fadeIn(delay);
        $('#management .MaiN').css({display:'none'}).fadeIn(delay);
        $('#publishing .MaiN').css({display:'none'}).fadeIn(delay);
        $('#sync .MaiN').css({display:'none'}).fadeIn(delay);
        $('#contact .MaiN').css({display:'none'}).fadeIn(delay);
        $('img.fprinfo').bind('mouseenter', this.showInfo);
        $('a.infobox').bind('mouseleave', this.hideInfo);
        $('a.infobox').click(this.infoBoxClick);

        if ($('div#authors').size() > 0) {
            var authorsTop = $(window).height() - $('div#authors').height() - 10;
            var tableBottom = $('.MaiN').position().top + $('.MaiN').outerHeight() + 10;
            if (authorsTop < tableBottom) {
                authorsTop = tableBottom + 10;
            }
            $('div#authors').css({top:authorsTop});
        }

        if ($('div.content').height() < $(window).height()) {
            var pageHeight = $(window).height() - $('#wp').offset().top;
            $('div.content').css({height:pageHeight});
        }
        $(window).resize(self.onResize);
    };

    this.infoBoxClick = function(e)
    {
        var $t = $(e.target);
        if ($t.attr('href') == '#') {
            e.stopPropagation();
            e.preventDefault();
        }
    };

    this.hideInfo = function(e)
    {
        e.stopPropagation();
        e.preventDefault();
        if ($(e.target).hasClass('infobox')) {
            $(e.target).hide();            
        }
        else {
            $(e.target).parent().hide();
        }
    };

    this.showInfo = function(e)
    {
        e.stopPropagation();
        e.preventDefault();
        var $t = $(e.target).prev('a.infobox');
        $t.css({display:'inline-block'});
        if ($t.attr('href') == '#') {
            $t.css({cursor:'default'});
        }
    };

    this.onResize = function(e)
    {
        if ($('div#authors').size() > 0) {
            var authorsTop = $(window).height() - $('div#authors').height() - 10;
            var tableBottom = $('.MaiN').position().top + $('.MaiN').outerHeight() + 10;
            if (authorsTop < tableBottom) {
                authorsTop = tableBottom + 10;
            }
            $('div#authors').animate({top:authorsTop}, {queue:false,duration:200});
        }

        if ($('div.content').height() < $(window).height()) {
            var pageHeight = $(window).height() - $('#wp').offset().top;
            $('div.content').css({height:pageHeight});
        }
    };
};
$(function() {fpmusic.init();});
