/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
(function() {
    if (!window.PGATOUR) {
        window['PGATOUR'] = {};
    }
	
    function isCompatible(_other) {
        if (_other === false
            || !Array.prototype.push
            || !Object.hasOwnProperty
            || !document.createElement
            || !document.getElementsByTagName
            ) {
            return false;
        }
        return true;
    }
    window['PGATOUR']['isCompatible'] = isCompatible;

    function $() {
        var elements = new Array();
		
        // Find all elements supplied as arguments
        for (var i = 0; i < arguments.length; i++) {
            var element = arguments[i];
			
            // If the argument is a string assume it's an id
            if (typeof element == 'string') {
                element = document.getElementById(element);
            }
			
            // If only one argument was supplied, return the element immediately
            if (arguments.length == 1) {
                return element;
            }
			
            // Otherwise add it to the arrary;
            elements.push(element);
        }
		
        // Return the array of multiple requested elements
        return elements;
    };
    window['PGATOUR']['$'] = $;

    function addEvent(_node, _type, _listener) {
        // Check compatibility using the earlier method
        // to ensure graceful degradation
        if (!isCompatible()) {
            return false;
        }
		
        if (!(node = $(_node))) {
            return false;
        }
		
        if (node.addEventListener) {
            // W3C Method
            node.addEventListener(_type, _listener, false);
            return true;
        }
        else if (node.attachEvent) {
            // MSIE method
            node['e' + _type + _listener] = _listener;
            node[_type + _listener] = function() {
                node['e' + _type + _listener](window.event);
            }
            node.attachEvent('on' + _type, node[_type + _listener]);
            return true;
			
        }
		
        // Didn't have either so return false
        return false;
    };
    window['PGATOUR']['addEvent'] = addEvent;

    function removeEvent(_node, _type, _listener) {
        if (!(node = $(_node))) {
            return false;
        }
		
        if (node.removeEventListner) {
            node.removeEventListener(_type, _listener, false);
            return true;
        }
        else if (node.detachEvent) {
            // MSIE method
            node.detachEvent('on' + _type, _node[_type + _listener]);
            node[_type + _listener] = null;
            return true;
        }
		
        // Didn't have either so return false
        return false;
    };
    window['PGATOUR']['removeEvent'] = removeEvent;

    function getElementsByClassName(_className, _tag, _parent) {};
    window['PGATOUR']['getElementsByClassName'] = getElementsByClassName;

    function toggleDisplay(_node, _value) {};
    window['PGATOUR']['toggleDisplay'] = toggleDisplay;

    function insertAfter(_node, _referenceNode) {};
    window['PGATOUR']['insertAfter'] = insertAfter;

    function removeChildren(_parent) {};
    window['PGATOUR']['removeChildren'] = removeChildren;

    function prependChild(_parent, _newChild) {};
    window['PGATOUR']['prependChild'] = prependChild;
	
    function getBrowserWindowSize() {
        var de = document.documentElement;
        return {
            'width' : (
                window.innerWidth
                || (de && de.clientWidth)
                || document.body.clientWidth
                ),
            'height' : (
                window.innerHeight
                || (de && de.clientHeight)
                || document.body.clientHeight
                )
        }
    };
    window['PGATOUR']['getBrowserWindowSize'] = getBrowserWindowSize;
	
    function getGlobalHost() {
        var host_;
                      
        if (location.hostname.match(/dev[0-9]\.turner/)) {
            host_ = 'jcmsdev8.turner.com:93';
        }
        else if (location.hostname.match(/auth[0-9]\.turner/)) {
            host_ = 'tsiauth-l1.turner.com';
        }
        else if (location.hostname.match(/ref[0-9]\.turner/)) {
            host_ = 'jcmsref1.turner.com:93';
        }
        else if (location.hostname.match(/prod[0-9]\.turner/) || location.hostname.match(/preview\.turner/)) {
            host_ = 'pgatourpreview.turner.com';
        }
        else if (location.hostname.match(/beta\.pgatour/)) {
            host_ = 'beta.pgatour.com';
        }
        else if (location.hostname.match(/jcmswebdev\.pgatour/)) {
            host_ = 'jcmswebdev.pgatour.com:93';
        }
        else if (location.hostname.match(/jcmsref\.pgatour/)) {
            host_ = 'jcmsref.pgatour.com:93';
        }
        else if (location.hostname.match(/preview\.pgatour/)) {
            host_ = 'pgatourpreview.pgatour.com:93';
        }
		else if (location.hostname.match()) {}
        else {
			 host_ = 'i.cdn.turner.com/pgatour';
        }

        return host_;
    }
	window['PGATOUR']['getGlobalHost'] = getGlobalHost;

})();
