// 	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

var IE = (document.all) ? 1 : 0;
var DOM = (document.getElementById) ? 1 : 0;
var NS4 = (document.layers) ? 1 : 0;
var MAC = ((navigator.appVersion.indexOf("PPC") >0) || (navigator.appVersion.indexOf("Mac") >0)) ? 1 : 0;
var ua = '$User_Agent';
var OPERA = (ua.indexOf("Opera") > 0) ? 1 : 0;

var Browser = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) { if (dataString.indexOf(data[i].subString) != -1) return data[i].identity; }
			else if (dataProp) return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb" },
		{ string: navigator.vendor, subString: "Apple", identity: "Safari" },
		{ prop: window.opera, identity: "Opera" },
		{ string: navigator.vendor, subString: "iCab", identity: "iCab" },
		{ string: navigator.vendor, subString: "KDE", identity: "Konqueror" },
		{ string: navigator.userAgent, subString: "Firefox", identity: "Firefox" },
		{ string: navigator.vendor, subString: "Camino", identity: "Camino" },
		{ string: navigator.userAgent, subString: "Netscape", identity: "Netscape" },
		{ string: navigator.userAgent, subString: "IE", identity: "Explorer", versionSearch: "MSIE" },
		{ string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv" },
		{ string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla" }
	],
	dataOS : [
		{ string: navigator.platform, subString: "Win", identity: "Windows" },
		{ string: navigator.platform, subString: "Mac", identity: "Mac" },
		{ string: navigator.platform, subString: "Linux", identity: "Linux" }
	]

};
Browser.init();



// Video Player detection variables
var agt = navigator.userAgent.toLowerCase();
var cnnSiteWideCurrDate = new Date();
var cnnHasOpenPopup = 0;

// *****************************************************************************
// 1.0 UTILITY FUNCTIONS
// *****************************************************************************

	//function $(e) { return document.getElementById(e); }
	function show(e) { e.style.display = "block"; }
	function hide(e) { e.style.display = "none"; }
	function rand(lo,hi) { return Math.floor(Math.random()*(hi-lo+1))+lo; }
	function find(srch,str) { if (str.indexOf(srch)>=0) return true; else return false; }

	// Get all cookies into array
	var cookie = new Array();
	var tmpArray = document.cookie.replace(/;\s+/g,';').split(';');
	for (var i = 0; i < tmpArray.length; i++) {
		var a = unescape(tmpArray[i]);
		var x = a.indexOf('=');
		if ( x != -1) cookie[a.substring(0, x)] = a.substring(x+1, a.length);
	}

	// set_cookie
	function set_cookie ( name, value, hours, path, domain, secure ) {
		if ( hours ) var numHours = ( new Date((new Date()).getTime()+hours*3600000) ).toGMTString();
		document.cookie = name+'='+escape(value)+((numHours)?(';expires='+numHours):'')+((path)?';path='+path:'')
			+((domain)?';domain='+domain:'')+((secure && (secure == true))?'; secure':'');
	}

	// read_cookie
	function readCookie ( name ) { return cookie[name]; }

	// kill cookie
	function kill_cookie ( name, path, domain ) {
		if ( cookie[name] ) document.cookie = name+'='+theValue+'; expires=Fri, 13-Apr-1970 00:00:00 GMT'
			+((path)?';path='+path:'')+((domain)?';domain='+domain:'');
	}

	// getElementsByClass
	function getElementsByClass(searchClass,tag,node) {
		var classElements = new Array();
		if ( node == null ) node = document;
		if ( tag == null ) tag = '*';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
		for (i = 0, j = 0; i < elsLen; i++) {
			if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; }
		}
		return classElements;
	}

	// getElementByClass
	function getElementByClass(searchClass,tag,node) {
		var classElements = new Array();
		if ( node == null ) node = document;
		if ( tag == null ) tag = '*';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
		for (i = 0, j = 0; i < elsLen; i++) {
			if ( pattern.test(els[i].className) ) { return els[i]; }
		}
		return false;
	}

	// get Param: returns URL query parameter of 'name'
	function getParam( name ) {
		var regexS = "[\\?&]"+name+"=([^&#]*)";
		var regex = new RegExp( regexS );
		var tmpURL = window.location.href;
		var results = regex.exec( tmpURL );
		if( results == null ) { return ""; } else { return results[1]; }
	}

	// MousePosition
	function MousePosition(e) {
		var posx = posy = 0;
		if (!e) var e = window.event;
		if (e.pageX || e.pageY) { posx = e.pageX; posy = e.pageY; }
		else if (e.clientX || e.clientY) 	{
			posx = e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;
			posy = e.clientY+document.body.scrollTop+document.documentElement.scrollTop;
		}
		return [posx, posy];
	}

	// findPos
	function findPos(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
	}

// 2.0 FORM INTERATION
// 	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

	// LOGIN BOX OBJECT
	var networkRow = new Object();
	networkRow.userField = function( action, input ){
		if( action == 'focus' ){ input.className = 'userActive'; }
		else if ( action == 'blur' && ! input.value.length ) { input.className = 'userInactive'; }
	}
	networkRow.passwordField = function( action, input ){
		if( action == 'focus' ){ input.className = 'passActive'; }
		else if ( action == 'blur' && ! input.value.length ){ input.className = 'passInactive'; }
		return;
	}


// 3.0 NAVIGATION
// 	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-


	// CNN_openPopup
	function CNN_openPopup( url, name, widgets, openerUrl ) {
		var host = location.hostname;
		try { window.top.name = "opener"; } catch (e) {}
		var popupWin = window.open( url, name, widgets );
		if(popupWin) {cnnHasOpenPopup = 1;}
		if ( popupWin && popupWin.opener ) {
			if ( openerUrl ) { popupWin.opener.location = openerUrl; }
		}
		if ( popupWin) { popupWin.focus(); }
	}

	// LaunchVideo
	function LaunchVideo( videoPath ) {
		var videoDate = "";
		var cnnVideoDatePathRegExp = /(\d{4})\/(\d{2})\/(\d{2})/;
		var cnnVideoDatePathArray = cnnVideoDatePathRegExp.exec( videoPath );
		if ( cnnVideoDatePathArray ) {
			var originalDate = new Date( parseInt( cnnVideoDatePathArray[1] ), parseInt( cnnVideoDatePathArray[2] ) - 1, parseInt( cnnVideoDatePathArray[3] ) );
			var expireDate = new Date( originalDate.getTime()+( 7 * 24 * 60 * 60 * 1000 ) );
			var expireYear = new String( expireDate.getFullYear() );
			var expireMonth = new String( expireDate.getMonth()+1 );
			var expireDay = new String( expireDate.getDate() );
			if ( expireMonth.length < 2 ) { expireMonth = '0'+expireMonth; }
			if ( expireDay.length < 2 ) { expireDay = '0'+expireDay; }
			videoDate = expireYear+'/'+expireMonth+'/'+expireDay;
		}
		cnnVideo( 'play', '/video'+videoPath.substring( 0, ( videoPath.length - 1 ) ), videoDate );
	}

	function detectWindowsMedia() {
		pluginFound = detectPlugin( 'Windows Media' );
		if ( !pluginFound && detectWMPSupport() ) { pluginFound = true; }
		return pluginFound;
	}

	function detectWMPSupport(){
		var wmp64 = "MediaPlayer.MediaPlayer.1";
		var wmp7 = "WMPlayer.OCX.7";
		if((window.ActiveXObject && navigator.userAgent.indexOf('Windows') != -1) || window.GeckoActiveXObject) {
			if(createActiveXObject(wmp7)) return true;
			else {
				if(createActiveXObject(wmp64)) return true;
				else return false;
			}
		} else return false;
	}

	function createActiveXObject(id){
	  var error;
	  var control = null;
	  try {
		if (window.ActiveXObject) control = new ActiveXObject(id);
		else if (window.GeckoActiveXObject) control = new GeckoActiveXObject(id);
	  }
	  catch (error){;}
	  return control;
	}

	function detectPlugin() {
		var daPlugins = arguments;
		var pluginFound = false;
		if ( navigator.plugins && navigator.plugins.length > 0 ) {
			var pluginsArrayLength = navigator.plugins.length;
			for ( var pluginsArrayCounter = 0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
				var numFound = 0;
				for ( var namesCounter = 0; namesCounter < daPlugins.length; namesCounter++ ) {
					if ( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) ||
						(navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
						numFound++;
					}
				}
				if ( numFound == daPlugins.length ) { pluginFound = true; break; }
			}
		}
		return pluginFound;
	}

	function cnnVideo( mode, arg, expiration ) {
		var playerURL	 = '/video/player/player.html';
		var detectURL	 = '/video/player/detect.exclude.html';
		var noplugURL	 = '/video/player/pages/detection/noplugin.html';
		var expireURL	 = '/video/player/player.html';
		var openURL		 = detectURL;
		var cnnVideoArgs = '';
		if ( detectWindowsMedia() ) {
			var cnnPassedDetection = new String(cookie['cnnVidPlug']).toLowerCase();
			if ( cnnPassedDetection == "activex" || cnnPassedDetection == "native" ) { openURL = playerURL; }
		} else {
			openURL = noplugURL;
		}
		switch ( mode ) {
			case 'play':
				var cnnExpireDate = new Date( new Date().getTime() - 24*60*60*1000 );
				var dateStringRegExp = /^(\d{4})\/(\d{2})\/(\d{2})$/;
				var dateStringArray = dateStringRegExp.exec( expiration );

				if ( dateStringArray && expiration) {
					cnnExpireDate = new Date( dateStringArray[1], dateStringArray[2] - 1, dateStringArray[3] );
				} else {
					cnnExpireDate = cnnSiteWideCurrDate;
				}
				if ( cnnExpireDate.getTime() < cnnSiteWideCurrDate.getTime() ) {
					if ( cnnPassedDetection == "activex" || cnnPassedDetection == "native" ) { openURL = expireURL; }
					else { openURL = detectURL; }
					cnnVideoArgs = 'url=/video/player/static/404';
				} else { cnnVideoArgs = 'url='+arg; }
				break;
			case 'browse': cnnVideoArgs = 'section='+arg; break;
			default: cnnVideoArgs = 'section=/ALL'; break;
		}
		if(openURL.indexOf('http://')==-1) { openURL='http://www.pgatour.com'+openURL; }
		CNN_openPopup( openURL+'?'+cnnVideoArgs, 'CNNVideoPlayer', 'scrollbars=no,resizable=no,width=770,height=570' );
	}
	
	// LIVE@ Window Launcher
	function openLiveAt(args) {
		var playerURL	 = '/video/liveat/';
		var noplugURL	 = '/video/liveat/noplugin.html';
		var detectURL	 = '/video/liveat/detect.exclude.html';
		var openURL		 = playerURL; //detectURL;
		var cnnVideoArgs = '';
		
		/** ADS VARIABLES FOR PREROLL **/		
		var adEmasCookie = cookie['adDEmas'];
		NGUserIDCookieValue = NGUserIDCookie; // set by ads.pgatour.com
		if (NGUserIDCookieValue == null) { NGUserIDCookie = false; }
		args += "&NGUserID="+escape(NGUserIDCookieValue)+"&adDEmas="+escape(adEmasCookie);		

/*
		if ( detectWindowsMedia() ) {
			var cnnPassedDetection = new String(cookie['cnnVidPlug']).toLowerCase();
			if ( cnnPassedDetection == "activex" || cnnPassedDetection == "native" ) { openURL = playerURL; }
		} 
		else { openURL = noplugURL; }
*/		
		CNN_openPopup(openURL+'?'+ args,'900x683','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=900,height=683');
	}

	// gallery_popup
	function gallery_popup(galleryURL) {
		CNN_openPopup(galleryURL, 'gallery_popup', 'scrollbars=no,resizable=no,width=580,height=500');
	}

// 5.0 OMNITURE HELPER FUNCTIONS
// 	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-

		function populateImpressionVars(linkid){
			var pageName = "Presidents Cup Homepage";
			var tabName, teamName;
			tabName = $(linkid).innerHTML;
			teamName = (linkid.indexOf('US') > 0) ? "US Team" : "International Team";		
			_report = pageName + " : " + teamName + " [ " + tabName + " ]";
			/*omniture request*/ 
			s.tl(this,'o',_report);
		}

		
		
// HIGHLIGHT NAVIGATION ---------------------	
function extractPageName(hrefString)
	{
	        var arr = hrefString.split('/');
	        return  (arr.length<2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase();               
	}
	
	function setActiveMenu(arr, crtPage)
	{
	        for (var i=0; i<arr.length; i++)
	        {
	                if(extractPageName(arr[i].href) == crtPage)
	                {
	                        if (arr[i].parentNode.tagName != "DIV")
	                        {
	                                arr[i].className = "active";
	                                arr[i].parentNode.className = "active";
	                        }
	                }
	        }
	}
	
	function setPage()
	{
	        hrefString = document.location.href ? document.location.href : document.location;
	
	        if (document.getElementById("tourWGCNavigation")!=null)
	                setActiveMenu(document.getElementById("tourWGCNavigation").getElementsByTagName("a"), extractPageName(hrefString));
	}
// SON OF SUCKERFISH NAVIGATION ---------------------		
sfHover = function() {
	if (document.getElementById("tourWGCNavigation")) {
		var sfEls = document.getElementById("tourWGCNavigation").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);	



TextResizeDetector = function() {
    var el  = null;
	var iIntervalDelay  = 200;
	var iInterval = null;
	var iCurrSize = -1;
	var iBase = -1;
 	var aListeners = [];
 	var createControlElement = function() {
	 	el = document.createElement('span');
		el.id='textResizeControl';
		el.innerHTML='&nbsp;';
		el.style.position="absolute";
		el.style.left="-9999px";
		var elC = document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID);
		// insert before firstChild
		if (elC)
			elC.insertBefore(el,elC.firstChild);
		iBase = iCurrSize = TextResizeDetector.getSize();
 	};

 	function _stopDetector() {
		window.clearInterval(iInterval);
		iInterval=null;
	};
	function _startDetector() {
		if (!iInterval) {
			iInterval = window.setInterval('TextResizeDetector.detect()',iIntervalDelay);
		}
	};

 	 function _detect() {
 		var iNewSize = TextResizeDetector.getSize();

 		if(iNewSize!== iCurrSize) {
			for (var 	i=0;i <aListeners.length;i++) {
				aListnr = aListeners[i];
				var oArgs = {  iBase: iBase,iDelta:((iCurrSize!=-1) ? iNewSize - iCurrSize + 'px' : "0px"),iSize:iCurrSize = iNewSize};
				if (!aListnr.obj) {
					aListnr.fn('textSizeChanged',[oArgs]);
				}
				else  {
					aListnr.fn.apply(aListnr.obj,['textSizeChanged',[oArgs]]);
				}
			}

 		}
 		return iCurrSize;
 	};
	var onAvailable = function() {
		if (!TextResizeDetector.onAvailableCount_i ) {
			TextResizeDetector.onAvailableCount_i =0;
		}

		if (document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID)) {
			TextResizeDetector.init();
			if (TextResizeDetector.USER_INIT_FUNC){
				TextResizeDetector.USER_INIT_FUNC();
			}
			TextResizeDetector.onAvailableCount_i = null;
		}
		else {
			if (TextResizeDetector.onAvailableCount_i<600) {
	  	 	    TextResizeDetector.onAvailableCount_i++;
				setTimeout(onAvailable,200)
			}
		}
	};
	setTimeout(onAvailable,500);

 	return {

		 	init: function() {

		 		createControlElement();
				_startDetector();
 			},

 			addEventListener:function(fn,obj,bScope) {
				aListeners[aListeners.length] = {
					fn: fn,
					obj: obj
				}
				return iBase;
			},

 			detect:function() {
 				return _detect();
 			},

 			getSize:function() {
	 				var iSize;
			 		return el.offsetHeight;


 			},

 			stopDetector:function() {
				return _stopDetector();
			},

 			startDetector:function() {
				return _startDetector();
			}
 	}
 }();


TextResizeDetector.TARGET_ELEMENT_ID = 'doc';
TextResizeDetector.USER_INIT_FUNC = function() {
	var iBase = TextResizeDetector.addEventListener(setTall, null);
};

// Rotating T1 Code
// 	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
// 

// 1/8/2009 - John Jimenez
// RE: Request from Tia Likely to investigate why the Pause, Next, & Previous
//     functions stopped working.

function start_slideshow(firstFrame, lastFrame, delay) {
	// Store The First, Last & Delay into globals for ease of use
	// Force the blnT1Rotate flag to true
	// set strSlideShowString to the string that will be eval()ed by setTimeout
	t1Delay = delay;
	t1FirstFrame = firstFrame;
	t1CurrentFrame = firstFrame;
	t1LastFrame = lastFrame;
	blnT1Rotate = true;
	PlaySlide();
}

// Switches the slides visually
function switch_slide(hideFrame, showFrame, delay) {
	// Check the Flag. True means Rotate; False, not so much.
	if (blnT1Rotate) {
		clearTimeout(tour_slideshow);
		// Fade out current frame
		Effect.Fade('tourWGCT1Slide' + hideFrame);
		// Switch the frames around (copy/pasted from old code, formated & variables changed)
		if (showFrame > t1LastFrame) {
			showFrame = t1FirstFrame;
		} else if (showFrame < t1FirstFrame) {
			showFrame = t1LastFrame;
		}
		t1CurrentFrame = showFrame;
		setTimeout("Effect.Appear('tourWGCT1Slide" + showFrame + "');", 850);
		PlaySlide();
	}

	//slideshow_debug_status();
}

// Starts the timer for the next slide
function PlaySlide() {
	blnT1Rotate = true;
	strSlideShowString = 'switch_slide('+t1CurrentFrame+','+(t1CurrentFrame+1)+','+t1Delay+');';
	tour_slideshow = setTimeout(strSlideShowString, t1Delay + 850);
}

// Toggle, Next, & Previous will only work if start_slideshow was called.
function ToggleSlideShow() {
	if (t1CurrentFrame) {
		if (blnT1Rotate && tour_slideshow) {
			blnT1Rotate = false;
			clearTimeout(tour_slideshow);
		} else {
			PlaySlide();
		}
	}
}

function NextSlide() {
	if (t1CurrentFrame) {
		blnT1Rotate = true;
		clearTimeout(tour_slideshow);
		switch_slide(t1CurrentFrame, t1CurrentFrame+1, t1Delay);
	}
}

function PreviousSlide() {
	if (t1CurrentFrame) {
		blnT1Rotate = true;
		clearTimeout(tour_slideshow);
		switch_slide(t1CurrentFrame, t1CurrentFrame-1, t1Delay);
	}
}

function slideshow_debug_status(){
	var statMsg = 'Current Slide:'+t1CurrentFrame;
	window.status = statMsg;
}

function slideshow_debug() {
	var msg = 'SlideShow Debug\n\n';
	msg += 'strSlideShowString = '+strSlideShowString+'\n';
	msg += 't1CurrentFrame = '+t1CurrentFrame+'\n';
	msg += 't1Delay = '+t1Delay+'\n';
	msg += 't1FirstFrame = '+t1FirstFrame+'\n';
	msg += 't1LastFrame = '+t1LastFrame+'\n';
	msg += 'blnT1Rotate = '+blnT1Rotate+'\n';
	alert(msg);
}


// Photo Gallery Code
//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-
//
function tourShowPhotogallery(_GalleryObj, _link) {
	if (!_GalleryObj || !_link) { return; }
	 $("tourPhotoGalleryFlashIF").src = _link;
}

// Video List Sorting
function initVideoArchive() {
	var oDocContainerRef;
	var oListVideoGroupIds;
	var oListVideoGroupsDocRef;
	
	oDocContainerRef = document.getElementById("hDocContainer")
	oListVideoGroupIds = sVideoGroups.split('|');
	oListVideoGroupIds.sort(function(a,b){return b - a});
	oListVideoGroupsDocRef = new Array();
	for (var i=0; i<oListVideoGroupIds.length; i++) {
		if (oListVideoGroupIds[i]) {
			oDocContainerRef.appendChild(document.getElementById(oListVideoGroupIds[i]).cloneNode(true));
		}
  }
}

// Open LiveAt Player for WGC
function openLiveAtPlayer(playerURL)	{ // LIVE@ Window Launcher - 2.0
		CNN_openPopup(playerURL,'1000x700','status=no,toolbar=no,resizable=no,scrollbars=no,menubar=no,location=no,width=1000,height=700');
}