function positionPopup(PopupDiv) {
    var Pos = jQuery('#header div.container').position();
	var leftMargin = (jQuery(window).width() - 950) / 2;
    //var popupTop = Pos.top + jQuery('#search').height() + 100;
	var popupTop = jQuery('#header').height(); // 150
    var popupLeft = (950 + leftMargin) - (jQuery(PopupDiv).width() + 66);
	//var popupLeft = (950 + Pos.left) - (430 + 36);
	
    jQuery(PopupDiv).css({
        'position': 'absolute',
        'top': popupTop,
        'left': popupLeft,
        'z-index': 9999
    });

    jQuery('#login, #search, #login_overlay, #search_overlay').expose({
        color: '#000',
        opacity: 0.5,
        onLoad: function() {
            jQuery('#search').css('z-index', 9999);
        },
        onBeforeClose: function() {
            jQuery('#login').css('background-color', '#333');
            jQuery('#search').css('background-color', '#222');
            jQuery('#login_overlay').fadeOut();
            jQuery('#search_overlay').fadeOut();
        }
    });
}

function positionContent() {

    // Position content above scrollable
    var leftPosition = jQuery('#search').position().left - (jQuery('#content').width() - jQuery('#search').width());
    
    jQuery('#content').css({
        'position': 'absolute',
        'left':	leftPosition,
        'top': 160,
        'opacity': 0.9
    });
}



jQuery(function() {

    /*jQuery('#tools').mouseover(function(e) {
        jQuery('#login, #search, #login_overlay, #search_overlay').expose({
            color: '#000',
            opacity: 0.5,
            onLoad: function() {
                jQuery('#search').css('z-index', 9999);
            },
            onBeforeClose: function() {
                jQuery('#login').css('background-color', '#333');
                jQuery('#search').css('background-color', '#222');
                jQuery('#login_overlay').fadeOut();
                jQuery('#search_overlay').fadeOut();
            }
        });
    });*/

    jQuery('#login').click(function(e) {
        jQuery('#login').css('background-color', '#555');
        positionPopup(jQuery('#login_overlay'));

        jQuery('#search_overlay').fadeOut('fast', function() {
            jQuery('#search').css('background-color', '#222');
            jQuery('#login_overlay').fadeIn('fast');
        });

    });


    jQuery('#search').click(function(e) {
        jQuery('#search').css('background-color', '#555');
        positionPopup(jQuery('#search_overlay'));

        jQuery('#login_overlay').fadeOut('fast', function() {
            jQuery('#login').css('background-color', '#333');
            jQuery('#search_overlay').fadeIn('fast');
        });

    });

    // Ensure home slide-boxes fill width
    jQuery('.homeSlide').width( jQuery(document).width() + 20 );
    positionContent();

    // adjust if window is resized
    jQuery(window).resize(function(event) {
        jQuery('.homeSlide').width( jQuery(document).width() + 20);
        positionContent();
    });

    ///////////////
    // Legacy support code
    if(jQuery.browser.msie && parseInt(jQuery.browser.version) <= 7) {
        //alert('Security Alert: Update your browser');

        // Add JS menu handler for IE6
        if(jQuery.browser.msie && parseInt(jQuery.browser.version) <= 6) {
            jQuery('#nav li').mouseover(function(event) {
                jQuery(this).find('ul.sub').show();
            }).mouseout(function(event) {
                jQuery(this).find('ul.sub').hide();
            });

            jQuery('#nav li.hassub').mouseover(function(event) {
                jQuery(this).find('ul.subsub').show();
            }).mouseout(function(event) {
                jQuery(this).find('ul.subsub').hide();
            });
        }

    } else {

        /*
         * Define scrollable styles
         */

        /* root element for scrollable */
        jQuery('.vert_scrollable').css({
                'position': 'relative',
                'overflow': 'hidden',
                'height': '463px'
        });

        /* root element for scrollable items */
        jQuery('.vert_scrollable .items').css({
                'position': 'absolute',
                'height': '20000em'
        });

        jQuery(".vert_scrollable").scrollable({
            vertical: true,
            circular: true,
            speed: 2000
        }).autoscroll({
            autoplay: true,
            autopause: false,
            interval: 8000
        });
    }
});
