$(document).ready(function(){

    $("select.niceSelect").niceSelect(); 

    var name, value;
    $('#header .mainmenu li a').each(function(){
        name = $(this).parent().attr('id').substring(9);
        value = $(this).text();
        
        $(this).addClass('hidden');
        $(this).attr('style', 'background-image: url(/mmediaprocess.php/Prb::mainmenu/repository/layout/'+name+'.png?_='+escape(value)+');');
    });
    
    $('#mainmenu li').mouseover(function(){
        $(this).addClass('hover');
        $(this).find('ul').show();
    }).not( $("#mainmenu li li") ).mouseout(function(){
        $(this).removeClass('hover');
        $(this).find('ul').hide();
    });
    
    $('.main li a').mouseover(function(){
        $(this).parent().parent().find('li[class=active]').removeClass('active');
        $(this).parent().addClass('active');
        $(this).parent().parent().parent().find('.sub').hide();
        $( '#' + $(this).parent().attr('id').substring(5) ).show();
    });
    
    $('.small-font').click(function(){
        $('#content .content').css({
            'fontSize'   : '11px',
            'lineHeight' : '13px'
        });
        return false;
    });
    $('.medium-font').click(function(){
        $('#content .content').css({
            'fontSize'   : '15px',
            'lineHeight' : '17px'
        });
        return false;
    });
    $('.larg-font').click(function(){
        $('#content .content').css({
            'fontSize'   : '19px',
            'lineHeight' : '21px'
        });
        return false;
    });
    
    var html, src, innerWidth, innerHeight;
    $('img.image-resize').each(function(){
        
        html = $('<div />').addClass('image-resize');
        $(this).wrap(html);
        
        html = $("<div />").addClass("resize").attr('style', 'display: none');
        $(this).before(html);
        
        src = $(this).attr('src').replace(/([0-9]+)x([0-9]+)/i, function(xy,x,y){ return x*2 + 'x' + y*2 });
        html = $('<img />').attr('src', src);
        $(this).prev().append(html);
        
        $(this).attr('class', 's');
        
    });
    
    $('.image-resize img[class="s"]').live('mouseover', function(){
        innerWidth  = $(this).innerWidth();
        innerHeight = $(this).innerHeight();

        $(this).parent().find('.resize').css({
            left    : '-6px',
            top     : '-6px',
            display : 'block',
            opacity : 0
        });
        $(this).parent().find('.resize img').css({
            width   : innerWidth  + "px",
            height  : innerHeight + "px"
        });
        $(this).parent().find('.resize img').animate({
            width   : 2 * innerWidth  + "px",
            height  : 2 * innerHeight + "px"
        });
        $(this).parent().find('.resize').animate({
            left    : "-" + innerWidth/2  + "px",
            top     : "-" + innerHeight/2 + "px",
            opacity : 1
        });

        $(this).parent().find('.resize').mouseout(function(){
            $(this).fadeOut('slow');
        });
        
    });
    
    $('select').mousedown(function(){ 
        $(this).addClass("resetWidth"); 
        if ($(this).width() < 370) {
            $(this).width(370);
        }
    }).blur(function(){ 
        $(this).removeClass("resetWidth");
    }).change(function(){ 
        $(this).removeClass("resetWidth"); 
    });


});