if (document.getElementById) { // modern check


/**

Unobtrusive popup script
(todo:  convert to JSON

Sample usage 1:   <a href="foo.html" target="someWindowName" class="popup">popup using defaults</a>
Sample usage 2:   <a href="foo.html" target="someWindowName" class="popup pup-w200_h100">custom-sized popup, otherwise using defaults</a>
Sample usage 3:   <a href="foo.html" target="someWindowName" class="popup pup-w200_h100_scrollbars_toolbar">a more-customized popup</a>
	- including a standard JS popup option counts as option=1 (i.e. option=yes)

Target attribute sets custom name for new window, allowing you to target windows if needed.

	STD. POPUP OPTIONS:
	  status  	The status bar at the bottom of the window.
	  toolbar 	The standard browser toolbar, with buttons such as Back and Forward.
	  location 	The Location entry field where you enter the URL.
	  menubar 	The menu bar of the window
	  directories 	The standard browser directory buttons, such as What's New and What's Cool
	  resizable 	Allow/Disallow the user to resize the window.
	  scrollbars 	Enable the scrollbars if the document is bigger than the window

Sample usage 4 - everything on it:

<a href="foo.html" target="fancyPants" class="popup pup-w801_h625__resizable_status_scrollbars_toolbar_menu_bar_directories_location">all-customized popup</a>

*/



/*
	CONFIGS =================================
*/

	// config:  pop-up defaults
	var popClass = "popup";
	var popName	= "popWin";
	var popPrefix = "pup-";
	var popW	= 400;
	var popH	= 300;
	

/*
	END config ----------------------
*/




/*
	UTILITIES =================================
*/

	/**
	 * addEvent
	 * Non-destructively attach a function to any event.
	 * @example	addEvent(window, 'load', functionName);
	*/
	if (typeof addEvent == 'undefined') {
		function addEvent(obj, evType, fn) {
			if (obj.addEventListener){
				obj.addEventListener(evType, fn, true);
				return true;
			} else if (obj.attachEvent){
				var r = obj.attachEvent("on"+evType, fn);
				return r;
			} else {
				return false;
			}
		}
	}
	
/*
	END Utilities -----------
*/


/*
	FUNCTIONS ============================
*/

	/**
	 * popupHandler();
	 * Pop-up window launch handler. Keys off of specified CSS class.
	*/
	function popupHandler() { 
		var cl=popClass.length;
		var a=document.getElementsByTagName("a");
		for(var i=0; i<a.length; i++) { 
			var ca=document.getAttribute?a[i].getAttribute("class").split(" "):a[i].className.split(" ");
			if(ca[0]===popClass) { 
				a[i].onclick=function () { 
					var w = popW;  var h = popH; var s='';
					var ca2=document.getAttribute ? this.getAttribute("class").split(" ") : this.className.split(" ");
					for (var i=0; i<ca2.length; i++) {
						if (ca2[i].substring(0,popPrefix.length) === popPrefix) {
							var aaa = ca2[i].substring(popPrefix.length,ca2[1].length);
							c = aaa.split("_");
							for (var z=0; z<c.length; z++) {
								if (c[z].substring(0,1)=='w') { w = c[z].substring(1,c[z].length); }
								else if (c[z].substring(0,1)=='h') { h = c[z].substring(1,c[z].length); }
								else { s += c[z] +"=1,"; }
							}					
						}
					}
					var t=this.getAttribute("target")?this.getAttribute("target"):popName;
					popUp(this.getAttribute("href"),t,w,h,s);
					return false;
				}
			}
		}
	}
	
	/**
	* popUp();
	* Pop-up window launcher.
	*/
	function popUp(winURL,t,w,h,s){
		var specs="width="+w+",height="+h+",";
		if (s && s!='') { specs += s; }
		var scrX=Math.round((screen.width/2)-(w/2));
		var scrY=Math.round((screen.height/2)-(h/2));
		if(scrY>100){ scrY=scrY-40; }
		specs+='top='+scrY+',left='+scrX;
		var win=window.open(winURL,t,specs);
		win.focus();
	}

	
/*
	END Function -----------
*/
	
	
	
	
//	ONLOAD INITS ==================================

	addEvent(window,'load',popupHandler);

// -------------------------------
} // close modern check




/*  addEvent
		Example:
		 addEvent(window, 'load', my_function);

		Or:
		 addEvent(window, 'load', function() {
			document.getElementById('myfield').focus()
		 });

	*/


	if (typeof addEvent == 'undefined') {
		function addEvent(obj, evType, fn){
			if (obj.addEventListener){
				obj.addEventListener(evType, fn, true);
				return true;
			} else if (obj.attachEvent){
				var r = obj.attachEvent("on"+evType, fn);
				return r;
			} else {
				return false;
			}
		}
	}
	
addEvent(window, 'load', homeMargin);
addEvent(window, 'load', borderChildOff);
addEvent(window, 'load', leftNavLast);
addEvent(window, 'load', calendarDisplay);
addEvent(window, 'load', hoverProduction);
addEvent(window, 'load', giftBorderOff);
addEvent(window, 'load', giftBrowseBorderOff);
addEvent(window, 'load', navHover);
addEvent(window, 'load', macCheck);
addEvent(window, 'load', safariWinCheck);
addEvent(window, 'load', giftMessage);




function homeMargin() {
    if(!document.getElementById("single_col_home")) {
        return false;
    }
    var grabHome  = document.getElementById("single_col_home");
    grabHome.parentNode.parentNode.parentNode.className = "home_page";    // on home page set padding differently for wrapper
}


function borderChildOff() {
    if (!document.getElementById("season_tickets")) return false;
    var grabParent  = document.getElementById("season_tickets");
    var paras = grabParent.getElementsByTagName("p");
    for (var i = 0; i < paras.length; i++) {  
        var elem = paras[0].className = "first";   
    }
}



function leftNavLast() {    // finds last item in dynamic left nav and applies correct class (border none)
    if (!document.getElementById("gift_nav")) return false;
    var grabNav  = document.getElementById("gift_nav");
    var listItems = grabNav.getElementsByTagName("li");
    for (var i = 0; i < listItems.length; i++) {  
        var elem = listItems[listItems.length-1];
        var lastElem = elem.className = "last";
    }
    var listTags = grabNav.getElementsByTagName("a");
    for (var i = 0; i < listTags.length; i++) { 
        var listParent = listTags[i];           // store all anchor tags
        var listHref = listTags[i].href;        // find anchor href in tags
        var urlLocale = window.location.href;   // find url locale      
        if (urlLocale == listHref) {
            listParent.className = "on";        // if locale and anchor href match, set anchor tag to class 'on'
            break;
        }
    }
    
}




function giftBorderOff() {    // turns first element of every 4th item for three rows length to border off class
    if (!document.getElementById("gift_bottom")) return false;
    var grabNav  = document.getElementById("gift_bottom");
    var listItems = grabNav.getElementsByTagName("div");
    for (var i = 0; i < listItems.length; i++) { 
        if (i % 44 == 0) {   // this accounts for nested divs
        listItems[i].className = "gift_item first";
        }      
    }
}

function giftBrowseBorderOff() {    // turns first element of every 4th item for three rows length to border off class
    if (!document.getElementById("browse_wrapper")) return false;
    var grabNav  = document.getElementById("browse_wrapper");
    var listItems = grabNav.getElementsByTagName("div");
    for (var i = 0; i < listItems.length; i++) { 
        if (i % 2 == 0) {
        listItems[i].className = "browse_item first";
        }      
    }
}


function giftMessage() {
    if(!document.getElementById("gift_message")) {
        return false;
    }
    var findMessage  = document.getElementById("gift_message");
    findMessage.style.display = "none";     // turn off gift messaging by default
}

function messageYes() {
    if(!document.getElementById("gift_message")) {
        return false;
    }
    var clickMessage  = document.getElementById("gift_message");
    clickMessage.style.display = "block";   // turn on gift message on link click
}




function calendarDisplay () {
    if(!document.getElementById("event_calendar")) {
        return false;
    }
    if(!document.getElementById("production_info")) {
        return false;
    }
    var grabCal = document.getElementById("event_calendar");
    var calLinks = grabCal.getElementsByTagName("a");
    for (var i=0; i < calLinks.length; i++) { 
        calLinks[i].onmouseover = function() {
        allProdOff(); // turn all production divs off by default 
        var relLinks = this.getAttribute("rel");     
        if(!document.getElementById('performancePop_' + relLinks)) {
            return false;
        }
        var grabProd = document.getElementById('performancePop_' + relLinks);
        grabProd.className = "on";                
        var xpos = this.offsetLeft; // find position of link
        var ypos = this.offsetTop;                
        if (xpos > (document.getElementById("event_calendar").offsetWidth / 2)) {
            xpos = xpos - ((grabProd.offsetWidth + 20) + this.offsetWidth);
        }                
        grabProd.style.position = "absolute";
        grabProd.style.left = xpos + 10 + this.offsetWidth + "px";
        grabProd.style.top = ypos + "px";  
        return false;   
        }      
    }
}

 function allProdOff () {
    var prodParent = document.getElementById("production_info");
    for (var i=0; i < prodParent.childNodes.length; i++) {
        if (prodParent.childNodes[i].nodeName == "DIV") {
            prodParent.childNodes[i].className = "off";
        }
    }
 }
 

 function hoverProduction () {
    if(!document.getElementById("subs_productions")) {
        return false;
    }
    if(!document.getElementById("subs_season_info")) {
        return false;
    }
    var grabProds = document.getElementById("subs_productions");
    var prodLinks = grabProds.getElementsByTagName("a");
    for (var i=0; i < prodLinks.length; i++) { 
        prodLinks[i].onmouseover = function() {
        allLinkProdOff(); // turn all production divs off by default 
        var relLinks = this.getAttribute("rel");     
        if(!document.getElementById('Production_' + relLinks)) {
            return false;
        }
        var grabProd = document.getElementById('Production_' + relLinks);
        grabProd.className = "on";                
        var xpos = this.offsetLeft; // find position of link
        var ypos = this.offsetTop;                                
        grabProd.style.position = "absolute";
        // this.style.paddingRight = "10px";
        grabProd.style.left = xpos + 10 + this.offsetWidth + "px";
        grabProd.style.top = ypos + "px";  
        return false;    
        }      
        prodLinks[i].onmouseout = function() {
         allLinkProdOff(); // turn off diplay on mouseout
        }
    }
}

 function allLinkProdOff () {
    var prodParent = document.getElementById("subs_season_info");
    for (var i=0; i < prodParent.childNodes.length; i++) {
        if (prodParent.childNodes[i].nodeName == "DIV") {
            prodParent.childNodes[i].className = "off";
        }
    }
 }



function navHover() {
	if(!document.getElementById("main_nav")) {
        return false;
    }
	var	navRoot = document.getElementById("main_nav");
	for (i=0; i<navRoot.childNodes.length; i++) {
	    node = navRoot.childNodes[i];
	    if (node.nodeName=="LI") {
		    node.onmouseover=function() {
			    this.className=" over";
		    }
		    node.onmouseout=function() {
			    this.className=" out";
		    }
	    }
    }
}
	
function macCheck() {                            // mac only rules
    if (navigator.userAgent.toLowerCase().indexOf('mac') != -1) {
	    if(!document.getElementById("main_nav")) {
            return false;
        }
	    var	navRoot = document.getElementById("main_nav");
	    for (i=0; i<navRoot.childNodes.length; i++) {
	        node = navRoot.childNodes[i];
	        if (node.nodeName=="LI") {
		        node.style.margin = "0px 9px";      // margin for nav items different, due to mac font aliasing
	            node.onmouseover=function() {
		            this.className="";
	            }
	            node.onmouseout=function() {
		            this.className="";               // no class name for rollover / out, mac bug with hover color inheritance
	            }
		    }
	    }
    }
}

function safariWinCheck() {                            // safari windows only rules
    if (navigator.userAgent.toLowerCase().indexOf('windows') > -1 && navigator.userAgent.toLowerCase().indexOf('webkit') > -1) {
	    if(!document.getElementById("main_nav")) {
            return false;
        }
	    var	navRoot = document.getElementById("main_nav");
	    for (i=0; i<navRoot.childNodes.length; i++) {
	        node = navRoot.childNodes[i];
	        if (node.nodeName=="LI") {
		        node.style.margin = "0px 9px";      // margin for nav items different, due to webkit font aliasing
	            node.onmouseover=function() {
		            this.className="";
	            }
	            node.onmouseout=function() {
		            this.className="";               // no class name for rollover / out, webkit bug with hover color inheritance
	            }
		    }
	    }
    }
}

