$(document).ready(function() {    
    var oWidth = $('img.resize').width();
    var oHeight = $('img.resize').height();
    var mpx = (oWidth/oHeight);
    
    var config = {
        toolbar: [
            ['Bold','Italic','Underline','Link','Unlink','Image','Smiley'],
            ['TextColor','BBColor']
        ],
        skin: 'office2003',
        resize_enabled: false,
        docType: '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
        keystrokes: [
            [ CKEDITOR.CTRL + 66, 'bold' ],
            [ CKEDITOR.CTRL + 73, 'italic' ],
            [ CKEDITOR.CTRL + 85, 'underline' ],
        ]
    };
    
    $(function() {
        $("input.screen, textarea.mess").focusFields(null,null,"#d6ece9",null);
    }),
    $('ul#mainmenu li.mainitem').hover(function() {
        $(this).addClass('active');
        $('ul.submenu',this).stop(true,true).addClass('showsub').slideDown('slow');
    },
    function() {
        $(this).removeClass('active');
        $('ul.submenu',this).stop(false,true).removeClass('showsub').slideUp('slow');
    }),
    $('div#header').innerfade({
        speed: 'slow',
        timeout: 5000
    }),
    $('ul.reportlist').bxGallery({
        maxheight: 800,
        thumbwidth: 75,
        thumbplacement: 'top'
    }),
    $('input.searchfield').click(function() {
        $(this).val("");
    }),
    $('textarea#message').ckeditor(config),
    $('textarea.admininput').ckeditor(),
    $('img.resize').hover(function() {
        if($(this).width() > $(this).height()) {
            $(this)
                .stop()
                .animate({
                    width:(oWidth*mpx)+'px',
                    height:(oHeight*mpx)+'px'
                },1000);
        }
    },
    function() {
        if($(this).width() > $(this).height()) {
            $(this)
                .stop()
                .animate({
                    width: oWidth+'px',
                    height: oHeight+'px'
                },1000);
        }
    });
});

function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {
       var anchor = anchors[i];
        if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
            anchor.target = "_blank";
        }
    }
}
window.onload = externalLinks;
