/********************************************************************************\
	Golfweek global namespace object.
\********************************************************************************/
var GW = {};

/********************************************************************************\
	Pre-exising JS
\********************************************************************************/
var axel = Math.random() + "";
var ord = axel * 1000000000000000000;
var sgi_ord = Math.random()*10000000000000000;
var sgi_tile = 1;

function popUp(URL) {
   day = new Date();
   id = day.getTime();
   eval("page" + id + " = window.open(URL, '" + id +"', 'toolbar=0,scrollbars=0,status=1,menubar=0,resizable=0,width=735,height=590,left=50,top=50');");
}

function popUp2(URL) {
   day = new Date();
   id = day.getTime();
   eval("page" + id + " = window.open(URL, '" + id +"', 'toolbar=0,scrollbars=1,status=0,menubar=0,resizable=0,width=500,height=600,left=150,top=150');");
}

function popUp3(URL) {
   day = new Date();
   id = day.getTime();
   eval("page" + id + " = window.open(URL, '" + id +"', 'toolbar=0,scrollbars=1,status=0,menubar=0,resizable=0,width=800,height=735,left=150,top=150');");
}



//** Tab Content script- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Last updated: Nov 8th, 06

var enabletabpersistence=1 //enable tab persistence via session only cookies, so selected tab is remembered?

////NO NEED TO EDIT BELOW////////////////////////
var tabcontentIDs=new Object()

function expandcontent(linkobj){
var ulid=linkobj.parentNode.parentNode.id //id of UL element
var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents
for (var i=0; i<ullist.length; i++){
ullist[i].className=""  //deselect all tabs
if (typeof tabcontentIDs[ulid][i]!="undefined"){ //if tab content within this array index exists (exception: More tabs than there are tab contents)
	//hide all tab contents
	document.getElementById(tabcontentIDs[ulid][i]).style.display="block";
	document.getElementById(tabcontentIDs[ulid][i]).style.height="1px"; 
	document.getElementById(tabcontentIDs[ulid][i]).style.width="1px";
	document.getElementById(tabcontentIDs[ulid][i]).style.position="absolute";
	document.getElementById(tabcontentIDs[ulid][i]).style.overflow="hidden";
}
	
}
linkobj.parentNode.className="selected"  //highlight currently clicked on tab
document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content
document.getElementById(linkobj.getAttribute("rel")).style.height="auto" //expand corresponding tab content
document.getElementById(linkobj.getAttribute("rel")).style.width="100%" //expand corresponding tab content
document.getElementById(linkobj.getAttribute("rel")).style.position="relative" //expand corresponding tab content
saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))
}

function expandtab(tabcontentid, tabnumber){ //interface for selecting a tab (plus expand corresponding content)
var thetab=document.getElementById(tabcontentid).getElementsByTagName("a")[tabnumber]
if (thetab.getAttribute("rel"))
expandcontent(thetab)
}

function savetabcontentids(ulid, relattribute){// save ids of tab content divs
if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet
tabcontentIDs[ulid]=new Array()
tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute
}

function saveselectedtabcontentid(ulid, selectedtabid){ //set id of clicked on tab as selected tab id & enter into cookie
if (enabletabpersistence==1) //if persistence feature turned on
setCookie(ulid, selectedtabid)
}

function getullistlinkbyId(ulid, tabcontentid){ //returns a tab link based on the ID of the associated tab content
var ullist=document.getElementById(ulid).getElementsByTagName("li")
for (var i=0; i<ullist.length; i++){
if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel")==tabcontentid){
return ullist[i].getElementsByTagName("a")[0]
break
}
}
}

function initializetabcontent(){
for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off
setCookie(arguments[i], "")
var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
var ulobj=document.getElementById(arguments[i])
var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
for (var x=0; x<ulist.length; x++){ //loop through each LI element
var ulistlink=ulist[x].getElementsByTagName("a")[0]
if (ulistlink.getAttribute("rel")){
savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
ulistlink.onclick=function(){
expandcontent(this)
return false
}
if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
expandcontent(ulistlink) //auto load currenly selected tab content
}
} //end inner for loop
if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value
var culistlink=getullistlinkbyId(arguments[i], clickedontab)
if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value
expandcontent(culistlink) //auto load currenly selected tab content
else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)
expandcontent(ulist[0].getElementsByTagName("a")[0]) //just auto load first tab instead
}
} //end outer for loop
}


function getCookie(Name){ 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

function setCookie(name, value){
document.cookie = name+"="+value //cookie value is domain wide (path=/)
}


/********************************************************************************\
	Onload
\********************************************************************************/
GW.load= function(){    
   GW.refreshTimer = setInterval('GW.refresh()', 45*1000); //45 sec (5 min : 5*60*1000 )
}

/********************************************************************************\
	Refresh App (set on timer: GW.refreshTimer)
\********************************************************************************/
GW.refresh = function(){    
    if(typeof GW.ad=="undefined"||!GW.ad){
        GW.ad = function(id, ord, width, height, file){
            if (document.all){ //ie (would always show frameborder otherwise)
                this.iframe = document.createElement('<iframe frameborder="0" scrolling="no"></iframe>');
            } else { // everything else
                this.iframe = document.createElement('iframe');
            }
            this.iframe.setAttribute('frameborder', '0');
            this.iframe.setAttribute('scrolling', 'no');
            this.iframe.setAttribute('height', height);
            this.iframe.setAttribute('width', width);
            this.file = file;
            this.node = document.getElementById(id);
            
            this.refresh = function(ord){
                if(typeof this.node=="undefined"||!this.node) {
                    return false; }
                                    
                //remove contents
                var len = this.node.childNodes.length;
                for( var i=len - 1; i > -1; i-- ){
                    this.node.removeChild(this.node.childNodes[i]);
                }                
                //load frame with new ord
                var src = 'http://ads.golfweek.com/homepage/' + this.file + '?ord=' + ord + '';
                this.iframe.setAttribute('src', src);
                this.node.appendChild(this.iframe);
                return true;
            }            
            return this.refresh(ord);            
        }
        GW.ads = [];
        var ord = (Math.random() + "") * 1000000000000000000;
                        
        //create new golfweek ads
        GW.ads[0] = new GW.ad('header-ad', ord, '728', '90', 'ad-head.asp');
        GW.ads[1] = new GW.ad('ad-right', ord, '160', '1216', 'ad-right.asp');
        GW.ads[2] = new GW.ad('ad-mid', ord, '300', '250', 'ad-mid.asp');                
    } else {        
        //already generated iframes
        //create new ord and reload        
        var ord = (Math.random() + "") * 1000000000000000000;
        for(var i=GW.ads.length-1; i>=0; i--){            
            GW.ads[i].refresh(ord);
        }     
    }    
} //end GW.refresh



