/*
Auto center window script- Eric King (http://redrival.com/eak/index.shtml)
Permission granted to Dynamic Drive to feature script in archive
For full source, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
*/

var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
}

//------------------ Site-wide Document ready script
$(function() {

    // Add global var indicating if browser is IE 5.5 or IE 6, or neither.
    GEOORBIS.globals.is_IE556 = false;
    if ($.browser.msie) {
        var arVersion = navigator.appVersion.split("MSIE");
        var version = parseFloat(arVersion[1]);

        if ((version >= 5.5) && (version < 7))
            GEOORBIS.globals.is_IE556 = true;
    }
    
    // Fix PNG display in IE 5.5 and IE 6.
    GEOORBIS.util.image.fixPNG('http://images.geoorbis.com/site/spacer.gif');

    GEOORBIS.globals.textFields = [];
    $('input.text_field').each(function() {
        $(this).parent().get()[0].id = String(GEOORBIS.globals.textFields.length);

        GEOORBIS.globals.textFields.push(new Object());
        GEOORBIS.globals.textFields[GEOORBIS.globals.textFields.length-1].entered = false;
        GEOORBIS.globals.textFields[GEOORBIS.globals.textFields.length-1].defaultVal = this.value;

        $(this).focus(function() {
            var index = Number($(this).parent().get()[0].id);
            if (!(GEOORBIS.globals.textFields[index].entered)) {
                GEOORBIS.globals.textFields[index].entered = true;
                this.value = "";
            }
        }).blur(function() {
            var index = Number($(this).parent().get()[0].id);
            if (!this.value) {
                this.value = GEOORBIS.globals.textFields[index].defaultVal;
                GEOORBIS.globals.textFields[index].entered = false;
            }
        });
    });

    // Fix line extension in the main content area.
    var mHeight = $('#main').get()[0].offsetHeight - 6;
    $('#main .line').css('height', (mHeight - 459) + 'px');
		
    //------------------- Add global behaviours
    // 1. Header navigation links.
        
    $('#headerMain .navigation a').each(function() {
        var s = $(this).parent().attr("id");
        s = s.substring(4, s.length);
        if (s != $(document.body).attr("id")) {
            $(this).hover(function() {
                var bgout, pos, bgover;
                bgout = $(this).parent().css('backgroundImage');
                pos = bgout.lastIndexOf('.');
                bgover = bgout.substring(0, pos) + '_f2' + bgout.substring(pos, bgout.length);
                $(this).parent().css('backgroundImage', bgover);
                return true;
            }, function() {
                $(this).parent().css('backgroundImage', $(this).parent().css('backgroundImage').replace(/_f2/, ''));
                return true;
            });
        }
        s = null;
    });
});