var BUTTON_OFFSET_SMALL = 16;

//Global page object - called by all appropriate child pages
var page = {
		init:function(){
			
			page.safari();
			page.sIFR();
			
			if(typeof(pagechild) == 'object' && pagechild.init){
				pagechild.init();
			}
			
			page.formDHTML();
		},
		
		//safari specific stylesheet add
		safari:function(){
			if (/AppleWebKit/.test(navigator.userAgent)){
				document.write('<link type="text/css" href="/css/safari.css" />');
			}
		},
		
		//Global sIFR calls
		sIFR:function(parameters){
			if(typeof sIFR == "function"){
				//sIFR.replaceElement("li.home-subnav a.sifr", named({sFlashSrc: "/flash/sifr/FranklinGothicHeavyItalic.swf", sColor: "#FFFFFF", sWmode: "transparent"}));
				sIFR.replaceElement("h2.common",
									named({sFlashSrc: "/flash/sifr/FranklinGothicHeavyItalic.swf", sColor: "#E66505", sWmode: "transparent"}));
				
				sIFR.replaceElement("h2.genre-feature-header",
									named({sFlashSrc: "/flash/sifr/FranklinGothicHeavyItalic.swf", sColor: "#C0D0DC", sWmode: "transparent"}));
				
				sIFR.replaceElement("h2.article-header",
									named({sFlashSrc: "/flash/sifr/FranklinGothicHeavyItalic.swf", sColor: "#FFFFFF", sWmode: "transparent"}));				
				
				sIFR.replaceElement("div#body-calendar h3 span",
									named({sFlashSrc: "/flash/sifr/FranklinGothicHeavy.swf", sColor: "#FFFFFF", sWmode: "transparent"}));
				
				sIFR.replaceElement("div#body-calendar caption span#caption-month", 
									named({sFlashSrc: "/flash/sifr/FranklinGothicHeavyItalic.swf", sColor: "#FFFFFF", sWmode: "transparent"}));
				
				sIFR.replaceElement("#tour-stage-nav-header strong", 
									named({sFlashSrc: "/flash/sifr/FranklinGothicHeavyItalic.swf", sColor: "#000", sWmode: "transparent"}));				
				
				sIFR.replaceElement("span#description", 
									named({sFlashSrc: "/flash/sifr/FranklinGothicItalic.swf", sColor: "#000", sWmode: "transparent"}));								
				
				sIFR.replaceElement("#tour-stage-nav-header span#description2", 
									named({sFlashSrc: "/flash/sifr/FranklinGothicItalic.swf", sColor: "#000", sWmode: "transparent"}));												
				
				sIFR.replaceElement("#h2-daily", 
									named({sFlashSrc: "/flash/sifr/FranklinGothicHeavyItalic.swf", sColor: "#000", sWmode: "transparent"}));																												
				
				sIFR.replaceElement("#tour-body h3.sifr", 
									named({sFlashSrc: "/flash/sifr/FranklinGothicHeavyItalic.swf", sColor: "#000", sWmode: "transparent"}));																
				
				sIFR.replaceElement("h4.infobox", 
									named({sFlashSrc: "/flash/sifr/FranklinGothicHeavyItalic.swf", sColor: "#000", sWmode: "transparent"}));																				
				
				sIFR.replaceElement("#middlecol #headline h3", 
									named({sFlashSrc: "/flash/sifr/FranklinGothicHeavyItalic.swf", sColor: "#FFFFFF", sWmode: "transparent"}));	
				sIFR.replaceElement("#middlecol #headline h5", 
									named({sFlashSrc: "/flash/sifr/FranklinGothicHeavyItalic.swf", sColor: "#CB0000", sWmode: "transparent"}));
									
				sIFR.replaceElement("#photooftheday h2", 
									named({sFlashSrc: "/flash/sifr/FranklinGothicHeavyItalic.swf", sColor: "#000", sWmode: "transparent"}));				
				sIFR.replaceElement("#latestnews h2", 
									named({sFlashSrc: "/flash/sifr/FranklinGothicHeavyItalic.swf", sColor: "#fff", sWmode: "transparent"}));																		
				
				sIFR.replaceElement("#registration-wrapper h2", 
									named({sFlashSrc: "/flash/sifr/FranklinGothicHeavyItalic.swf", sColor: "#FFFFFF", sWmode: "transparent"}));																								
				sIFR.replaceElement("#registration-wrapper h3", 
									named({sFlashSrc: "/flash/sifr/FranklinGothicHeavyItalic.swf", sColor: "#FFFFFF", sWmode: "transparent"}));																								

			}
		},
		
		formDHTML:function(){
			
			initButtonOvers();
			
			function initButtonOvers(){
			   var aButtons = document.getElementsByTagName("input");
			   var iLength = aButtons.length;
			   for (var i = 0; i < iLength; i++){
				   if (aButtons[i].type == 'image'){
					   aButtons[i].onmouseover = mouseOverFormImage;
					   aButtons[i].onmouseout = mouseOverFormImage;
				   }
			   }
			}
			
			function mouseOverFormImage(event){
			   var id = this.id;
			   id = id.replace(/-/g, '_');
				   if (!oButtonsOffset[id])
						   return false;
			   var offset = oButtonsOffset[id];
			   var evt = window.event?window.event:event;
			   var bOver = evt.type == 'mouseover';
			   var vOffset = bOver ? '-' + offset + 'px' : '0';
			   this.style.backgroundPosition = '0 ' + vOffset;
			}
			
		}
}

//Main Features DHTML class 
function MainFeatures(){
	
	return {
			
			init:function(){
				var ul = document.getElementById('main-subnav');
                                if (!ul)
                                        return;
				var oLI = ul.getElementsByTagName('li');
				iLength = oLI.length;
				
				for (var i = 0; i < iLength; i++){
					oLI[i].onmouseover = function(){
						page.mainFeatures.show(this);
					}
					oLI[i].onmouseout = function(){
						page.mainFeatures.hide(this);
					}
					//oLI[i].getElementsByTagName('div')[0].getElementsByTagName('a')[0].onmouseout = function(){
					//	page.mainFeatures.hide(this.parentNode);
					//}				
					//oLI[i].getElementsByTagName('div')[0].getElementsByTagName('a')[0].onclick = function(){
					//
					//}									
				}
			},
			
			show:function(oLI){
				var aLI = oLI.parentNode.getElementsByTagName('li');
				for(var i = 0; i < aLI.length; i++){
					page.mainFeatures.hide(aLI[i]);
				}
				//oLI.getElementsByTagName('span')[0].style.backgroundPosition = "0px -38px";
				var sGenreClass = oLI.className.replace(/^main\-subnav\s{1,}(\w*).*$/, "$1");
				var sStyleDescription =  'description ' + page.mainFeatures.getFeatureGenreStyle(sGenreClass) ;
				
				oLI.getElementsByTagName('a')[0].className = sStyleDescription;
				oLI.getElementsByTagName('span')[1].className = sStyleDescription;
				
				oLI.getElementsByTagName('span')[2].style.backgroundPosition = "0px -16px";
				oLI.getElementsByTagName('div')[1].style.display = "block";
			},
			
			hide:function(oLI){
				oLI.getElementsByTagName('a')[0].className = '';
				oLI.getElementsByTagName('span')[0].style.backgroundPosition = "0 0";
				oLI.getElementsByTagName('span')[1].className = 'description';
				oLI.getElementsByTagName('span')[2].style.backgroundPosition = "0 0";
				oLI.getElementsByTagName('div')[1].style.display = "none";
			},
			
			getFeatureGenreStyle:function(sGenreClass){
				var cssClassNameHash = {
					tour:	'sStyleSubNavTour',
					bulls_and_rodeo:	'sStyleSubNavBullsAndRodeo',
					field_sports:	'sStyleSubNavFieldSports',
					oln_series:	'sStyleSubNavOLNSeries',
					action_sports:	'sStyleSubNavActionSports'
				}
				
				if (cssClassNameHash[sGenreClass]){
					return cssClassNameHash[sGenreClass];
				}
			}
		
		}

	
}

//Programming Grid class - responsible for grid DHTML - instantiated by all appropriate pagechild objects
function ProgrammingGrid(){
    
   return {
        
            init:function(tableName){
                var table = document.getElementById(tableName);
                var links = table.getElementsByTagName('a');
                for (var i = 0; i < links.length; i++){
                    if(links[i].className == 'info'){
                        links[i].active = false;
                        links[i].onclick = page.grid.infoClickDelegate;
                        links[i].onmouseover = page.grid.infoOverDelegate;
                        links[i].onmouseout = page.grid.infoOverDelegate;
                    }
                }
            },
            
            infoOverDelegate:function(event){
                var evt = window.event ? window.event : event;
                var over = evt.type == 'mouseover';
                var row = this.parentNode.parentNode;
                var active = (this.active) ? true : over ;
                page.grid.infoDrawActive(this, active);
            },
            
            infoClickDelegate:function(){
                this.active = !this.active;
                page.grid.infoShowHide(this);
                page.grid.infoDrawActive(this, this.active);
                return false;
            },
            
            infoShowHide:function(_link){
                var divs = _link.parentNode.parentNode.getElementsByTagName('div');
                for (var i = 0; i < divs.length; i++){
                    if(divs[i].className == 'grid-item-description'){
                        divs[i].style.display = ((divs[i].style.display == 'none') || (divs[i].style.display == '')) ? 'block' : 'none' ;
                    }
                }
            },
            
            infoDrawActive:function(_link, active){
                var row = _link.parentNode.parentNode;
                var cells = row.getElementsByTagName('td');
                for (var i = 0; i < cells.length; i++){
                    cells[i].style.backgroundColor = active ? '#434242' : '#1C1C1C' ;
                }
            }
        
    }       

    
}