/**
 * NikeBiz
 * Requires prototype library 1.6
 * 
 */


/** GLOBALS **/
var aTypeSizes = ['typeSmaller', 'typeNormal', 'typeLarger', 'typeLargest'];
var nCurrentSize = 1;


/**
 * adds classNames to form input fields to
 * achieve a more consistent style across
 * browsers
 */
function initFormFields() {
	$$('input[type="submit"]').each(function(el) {
		if (!el.hasClassName('inputSubmit')) {
			el.addClassName('inputSubmit');		
		}
		
		el.observe('mouseover', function(event) {
			Event.element(event).className = 'inputSubmitHover';
		});
		
		el.observe('mouseout', function(event) {
			Event.element(event).className = 'inputSubmit';
		});
	});
				
	$$('input[type="text"]').each(function(el) {
		if(!el.hasClassName('inputText')) {
			el.addClassName('inputText');		
		}
	});
	
	$$('input[type="password"]').each(function(el) {
		if(!el.hasClassName('inputText')) {
			el.addClassName('inputText');		
		}
	});
	
	$$('textarea').each(function(el) {
		if(!el.hasClassName('inputTextArea')) {
			el.addClassName('inputTextArea');
		}
	});
	
	/*$$('select').each(function(el) {
		if(!el.hasClassName('inputSelect')) {
			el.addClassName('inputSelect');
		}
	});*/			
}


function initSearch() {
	var form = $('searchForm');
	if (form) {
		var input = form['searchInput'];
					
		// $(input).value = "SEARCH NIKEBIZ.COM";
					
		// Event.observe(input, 'focus', searchFocus);
		// Event.observe(input, 'blur', searchUnFocus);
	
		Event.observe('searchBtn', 'mouseover', function(event) {
				Event.element(event).src = "http://nikebiz.com/images/btn_searchHover.gif";
			}
		);
		
		Event.observe('searchBtn', 'mouseout', function(event) {
				Event.element(event).src = "http://nikebiz.com/images/btn_search.gif";
			}
		);			
	}
		
}
			
function searchFocus() {
	var form = $('searchForm');
	var input = form['searchInput'];

	$(input).value = "";			
}
			
function searchUnFocus() {
	var form = $('searchForm');
	var input = form['searchInput'];
				
	var val = $F(input);
				
	if (val == "") {
		$(input).value = "SEARCH NIKEBIZ.COM";	
	}				
}

function setCookie(sName, sValue, oExpires, sPath, sDomain, bSecure) {
	var sCookie = sName + "=" + encodeURIComponent(sValue);
	
	if (oExpires) {
		SCookie += "; expires=" + oExpires.toGMTString();
	}
	
	if (sPath) {
		sCookie += "; path=" + sPath;
	}
	
	if (sDomain) {
		sCookie += "; domain= " + sDomain;
	}
	
	if (bSecure) {
		sCookie += "; secure";
	}
	
	document.cookie = sCookie;
}

function getCookie(sName) {
	var sRE = "(?:; )?" + sName + "=([^;]*);?";
	var oRE = new RegExp(sRE);
	
	if (oRE.test(document.cookie)) {
		return decodeURIComponent(RegExp["$1"]);
	} else {
		return null;
	}
}

function deleteCookie(sName, sPath, sDomain) {
	setCookie(sName, "", new Date(0), sPath, sDomain);
}

function increaseTextSize() {
	if (nCurrentSize != (aTypeSizes.length - 1)) {
		setActiveTextSize('mainColumn', aTypeSizes[++nCurrentSize]);
	}
}
			
function decreaseTextSize() {
	if (nCurrentSize != 0) {
		setActiveTextSize('mainColumn', aTypeSizes[--nCurrentSize]);
	}			
}

function setActiveTextSize(sId, sFontClass) {
	aTypeSizes.each(function(item){
		$(sId).removeClassName(item);
	});
	$(sId).addClassName = sFontClass;
	setCookie("ActiveFontSize", sFontClass);
}

function applyTextSize() {
	var sCurrentFontSize ='typeNormal';
	if (getCookie('ActiveFontSize')) {
    	sCurrentFontSize = getCookie('ActiveFontSize');
		var nIndex = aTypeSizes.indexOf(sCurrentFontSize);
		if (nIndex != -1) { 
			nCurrentSize = nIndex; 
			setActiveTextSize('mainColumn', sCurrentFontSize);
		}
	} else {
		setActiveTextSize('mainColumn', sCurrentFontSize);
		nCurrentSize = 1; // default text size
	}
}

function newWindow(sLink, scrollbars) {
	if (scrollbars === undefined) {
		scrollbars = false;
	}
	var nHeight = 900;
	if(window.screen) {
		nHeight = Math.floor(screen.availHeight);
		nHeight = Math.floor(.9 * nHeight);
	}

	var additionalOptions = (scrollbars) ? ',scrollbars=yes' : '';
	myWin = window.open(sLink, "taleo", 'width=720,height=' + nHeight + ',top=0,left=100,resizable=yes' + additionalOptions);
	myWin.focus();
}

function setHomeLinkAttr() {
	var e = $('nikeLogo');
	var a = e.childElements();
	a[0].setAttribute('title', 'Return to Nikebiz homepage');
}

Event.onReady( function() {
	initSearch();
	initFormFields();
	applyTextSize();
	setHomeLinkAttr();
});

