var browser = navigator.appName;
var IE = "Microsoft Internet Explorer";
var vendor = navigator.vendor;
var safari = "Apple Computer, Inc.";

/* Begin show/hide Flash navigation function */
function flashNavigation(state) {
	var fullFlashNav = $('flashNav');
	
	if (state == "visible"){
		fullFlashNav.style.height="400px";	
	}
	
	else {
		fullFlashNav.style.height="20px";
	}
}

function fromFlash(page) {
	window.location=page;
}

/* End show/hide Flash navigation function */

/* Begin preload images function */
var loadImg = new Array('balls_nfl_up_on.png','balls_nfl_down_on.png','balls_nfl_down_off.png','balls_gst_up_on.png','balls_gst_down_on.png','balls_gst_down_off.png','balls_trad_up_on.png','balls_trad_down_on.png','balls_trad_down_off.png','balls_composite_up_on.png','balls_composite_down_on.png','balls_composite_down_off.png');

function preloadImages() {
	for (i=0; i<loadImg.length; i++) {
		var images = new Array();
		images[i] = new Image;
		images[i].src = 'http://www.wilson.com/football/balltitles/' + loadImg[i];
	}
}
/* End preload images function */

/* Begin expandable table function */

function imageSwap(mouseevent,arrowstate,id) {
	if (mouseevent == 'over'){
		$(id+'_img').setAttribute('src','http://www.wilson.com/football/balltitles/'+ id +'_'+arrowstate+'_on.png');
	}
	
	else if (mouseevent == 'out') {
		$(id+'_img').setAttribute('src','http://www.wilson.com/football/balltitles/'+ id +'_'+arrowstate+'_off.png');
	}	
	else {
		return;
	}
}

 function expand(mousestate,headerID) {
	var h3Expand = $(headerID);
	var tblExpand = $(headerID+'_table');
	var c = classAttr();
	var imgObj = $(headerID + "_img");
	var alt = getImgAlt(imgObj);
	var height = getImgHeight(imgObj);
	var width = getImgWidth(imgObj);
	
	if (tblExpand.style.display == "block") {
		tblExpand.style.display = "none";
		h3Expand.setAttribute(c,'expandHeader');
		h3Expand.onmouseover = function(){imageSwap('over','up',headerID);};
		h3Expand.onmouseout = function(){imageSwap('out','up',headerID);};
		h3Expand.innerHTML = "<img src=\"http://www.wilson.com/football/balltitles/"+ headerID+"_up_"+mousestate+".png\" id=\""+headerID+"_img\" width=\""+width+"\" height=\""+height+"\" alt=\""+alt+"\" title=\""+alt+"\" />";
		
	}
	
	else {
		tblExpand.style.display = "block";
		h3Expand.setAttribute(c,'expandedHeader');
		h3Expand.onmouseover = function(){imageSwap('over','down',headerID);};
		h3Expand.onmouseout = function(){imageSwap('out','down',headerID);};
		h3Expand.innerHTML = "<img src=\"http://www.wilson.com/football/balltitles/"+ headerID+"_down_"+mousestate+".png\" id=\""+headerID+"_img\" width=\""+width+"\" height=\""+height+"\" alt=\""+alt+"\" title=\""+alt+"\" />";
		
	}
}

function expandOnload() {
	var params = getURLParameters('split');
	var openTbl = "balls_" + params;
	
	/*******************
	If there is no query string, no parameter value, or the wrong parameter name has been used, do nothing. - KM
	*******************/
	if ((params == null) || (params == '')) {
		;
	}
	
	else {
		expand('off',openTbl);
	}	
}
/* End expandable table function */

/* Begin pop up function */
function popWindow(href,title,parameters) {
 window.open(href,title,parameters);
}
/* End pop up function */

/* Begin Flash detection and loading */

/* End Flash detection and loading  */

/* Begin helper functions */
/* Extracted from Prototype JS Library, http://prototype.conio.net/
 Written by Sam Stephenson, http://conio.net/ */
function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string') element = (document.getElementById) ? document.getElementById(element) : eval("document.all."+element) ;
    if (arguments.length == 1) return element;
    elements.push(element);
  }
  return elements;
}

/* Function to return the class attribute. IE and all other standards compliant browsers have different names for the class attribute object. */
function classAttr(){
	if (browser == IE ){
		class_att = 'className';
	}
	else {
		class_att = 'class';
	}
	
	return class_att;
	
}

/* Begin function to get img extension */
function getImgExt(obj){
	var src = obj.getAttribute('src');
	var imgExtPosition = src.lastIndexOf('.') + 1;	//Get the extension. Add 1 to get only the extension, not .extension
	
	var extension;
	
	if(src.match('clearpixel.gif')){	//If IE and the image is a PNG, return 'png', because the PNG transparency function causes the img src to be clearpixel.gif.
		extension = 'png';
	}
	
	else {
		var extension = src.slice(imgExtPosition);
	}
	return extension;
}
/* End function to get img extension */

/* Begin function to get img alt text */
function getImgAlt(obj){
	var alt_text = obj.getAttribute('alt');	
	return alt_text;
}
/* End function to get img alt text */

/* Begin function to get img height text */
function getImgHeight(obj){
	var img_h = obj.getAttribute('height');	
	return img_h;
}
/* End function to get img alt text */

/* Begin function to get img width text */
function getImgWidth(obj){
	var img_w = obj.getAttribute('width');	
	return img_w;
}
/* End function to get img alt text */

/* Begin registration popup function */
function open_reg(url){
    screenwidth = window.screen.width;
    screenheight = window.screen.height;

    windowleft = (screenwidth - 630)/2;
    windowtop = (screenheight - 610)/2;

    contacts = window.open(url,'open_contacts','width=630,height=610,history=no,resizable=no,status=no,scrollbars=yes,menubar=no,top=' + windowtop + ',left=' + windowleft);
}
/* End registration popup function */

/* Begin international popup function */
function open_intl(url){
    screenwidth = window.screen.width;
    screenheight = window.screen.height;

    windowleft = (screenwidth - 600)/2;
    windowtop = (screenheight - 500)/2;

    contacts = window.open(url,'open_contacts','width=630,height=500,history=no,resizable=no,status=no,scrollbars=yes,menubar=no,top=' + windowtop + ',left=' + windowleft);
}
/* End international popup function */