
// Google analytics stuff
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
try{
var pageTracker = _gat._getTracker("UA-311157-45");
pageTracker._trackPageview();
} catch(err) {}

var undefined;

var images = new Object;

function checkLogin(){if(self.location.search.indexOf("failed")==1){document.getElementById("login-error").style.display = "block"}}

function Preload_Image(_path) {

    if ( document.images ) {

        var _file; var _name; var _x;

        _x = _path.lastIndexOf("/");

        if ( (_x > -1) && (_x < _path.length) ) {

            _file = _path.substring(_x + 1, _path.length);

        } else {

            _file = _path;

        }


        _x = _file.lastIndexOf(".");

        if ( (_x > -1) && (_x < _file.length) ) {

            _name = _file.substring(0, _x);

        } else {

            _name = _file;

        }

        var _offset = images.length;

        images[ _name ] = new Image;
        images[ _name ].src = _path;

        return( _name );

    }

}


function Preload_Images() {

    if ( document.images ) {

        for (var _i = 0; _i < arguments.length; _i++) {
        
            Preload_Image(arguments[_i]);
         
        }

    }

}

function Change_Image(_img_name, _obj_name, _text) {

    if ( document.images && (document.images[ _img_name ] != undefined) &&
         (document.images[ _img_name ] != null) && 
         (images[ _obj_name ] != undefined) && (images[ _obj_name ] != null) &&
         (images[ _obj_name ].src != undefined) && (images[ _obj_name ].src != null) ) {

        document.images[ _img_name ].src = images[ _obj_name ].src;

    }
    
    if ( _text != null ) {
    
        window.status = _text;
        
    } else {
    
        window.status = '';
        
    }

}

function Hide_Div(_div_name) {

  var _div = document.getElementById(_div_name);
  
  if ( _div != null ) {
    _div.style.display = "none";
  }

}

function Show_Div(_div_id) {

  var _div = document.getElementById(_div_id);
  
  if ( _div != null ) {
    _div.style.display = "block";  
  }

}

function Set_Opacity(_elem_id, _amount) {
	
  var _elem = document.getElementById(_elem_id);
  
  if ( _elem != null ) {
    _elem.style.opacity = _amount;
    _elem.style.filter = 'alpha(opacity=' + _amount*100 + ')';
  }	
}


function Dropdown(_menuId, _dropdownId, _keepVis) {

    this.menuId                 = _menuId; 
    this.menuElement            = document.getElementById(_menuId);
    
    this.dropdownId             = _dropdownId;
    this.dropdownElement        = document.getElementById(_dropdownId);
    
    this.keepVisible            = _keepVis;
    this.currentlyInMenu        = false;
    this.currentlyInDropdown    = false;
    this.interval               = null;
    
    if ( _keepVis && this.dropdownElement.style.visibility != 'visible' ) {
        this.dropdownElement.style.visibility = 'visible';
    }
    
}

_dropdownObjs = new Array();

function initialiseMenus() {

    for (var _i = 0; _i < arguments.length; _i = _i + 3) {
        
        _dropdownObjs[_dropdownObjs.length] = new Dropdown(arguments[_i], arguments[_i+1], arguments[_i+2]);
         
    }  

}

function getByMenuId(_checkId) {
    
    var ret = null;
    
    for (var _i = 0; _i < _dropdownObjs.length; _i++) {
        
        if ( _dropdownObjs[_i].menuId == _checkId ) {
            ret = _dropdownObjs[_i]; break;
        }
        
    }
    
    return ret;
    
}

function getByDropdownId(_checkId) {
    
    var ret = null;
    
    for (var _i = 0; _i < _dropdownObjs.length; _i++) {
        
        if ( _dropdownObjs[_i].dropdownId == _checkId ) {
            ret = _dropdownObjs[_i]; break;
        }
        
    }
    
    return ret;
    
}

    // this could work better by passing functions to apply to matching/non-matching things in 'getMenuById'

function enteredMenu(_menu_name) {     

    _menuObj = getByMenuId(_menu_name);
    
    if ( _menuObj == null ) {
        return;   
    }

    for (var _i = 0; _i < _dropdownObjs.length; _i++) {
     
        _menuTest = _dropdownObjs[_i];
        
        if ( _menuTest != _menuObj && _menuTest.keepVisible ) {        
       
           if ( _menuTest.dropdownElement.style.visibility != 'hidden' ) {
               _menuTest.dropdownElement.style.visibility = 'hidden';  
           }
                       
        }
        
    }

    _menuObj.currentlyInMenu = true;   

    if ( _menuObj.dropdownElement.style.visibility != 'visible' ) {
        _menuObj.dropdownElement.style.visibility = 'visible';  
    }
    
    if ( _menuObj.interval != null ) {
        window.clearInterval( _menuObj.interval );
    }

}

function leftMenu(_menu_name) {
    
    _menuObj = getByMenuId(_menu_name);

    if ( _menuObj == null ) {
        return;    
    }
    
    if ( !_menuObj.keepVisible ) {

        _menuObj.currentlyInMenu = false;
    
        _menuObj.interval = window.setInterval("tryToHideDropdown('" + _menuObj.dropdownId + "');", 200);
    
    }
    
}


function enteredDropdown(_dropdown_name) {

    _menuObj = getByDropdownId(_dropdown_name);

    if ( _menuObj == null ) {
        return;    
    }
    
    if ( !_menuObj.keepVisible ) {

        _menuObj.currentlyInDropdown = true;

        if ( _menuObj.interval != null ) {
    
            window.clearInterval( _menuObj.interval );

        }
    
    }

}

function leftDropdown(_dropdown_name) {

    _menuObj = getByDropdownId(_dropdown_name);

    if ( _menuObj == null ) {
        return;    
    }
    
    if ( !_menuObj.keepVisible ) {
        
        _menuObj.currentlyInDropdown = false;

        _menuObj.interval = window.setInterval("tryToHideDropdown('" + _menuObj.dropdownId + "');", 75);

    }

}

function tryToHideDropdown(_dropdown_name) {

    _menuObj = getByDropdownId(_dropdown_name);

    if ( _menuObj == null ) {
        return;    
    }

    if ( !_menuObj.keepVisible && !_menuObj.currentlyInMenu && !_menuObj.currentlyInDropdown ) {

        if ( _menuObj.dropdownElement.style.visibility != 'hidden' ) {

            _menuObj.dropdownElement.style.visibility = 'hidden';

        }

        window.clearInterval( _menuObj.interval );

    }

    for (var _i = 0; _i < _dropdownObjs.length; _i++) {
     
        _menuTest = _dropdownObjs[_i];
        
        if ( (_menuTest != _menuObj) && _menuTest.keepVisible ) {        
       
           if ( _menuTest.dropdownElement.style.visibility != 'visible' ) {
               _menuTest.dropdownElement.style.visibility = 'visible';  
           }
                                  
        }
        
    }

}

