/////////////////////////////////////////////////////
// 		Author:     cristian.deschamps@rocler.com
// 		Updated:    25 Mars 2007
// 		
// 		Content:	Main Javascript for Born4Sport.
/////////////////////////////////////////////////////
 
// ------[ Master Onload for all page. ]------------------------------------------------- //	
window.CoastMountain = window.CoastMountain || {};

CoastMountain = {
	Init : function() {
		
		// Nothing to init
		}
	
};
YAHOO.util.Event.addListener(window, "load", CoastMountain.Init, CoastMountain, true);

// ------[ Spotlight Browser ]------------------------------------------------- //
CoastMountain.Footer = {
	ScrollTimer : null,
	ScrollAutoTimer : null,
	Width : 182,
	FooterContent : null,
	FooterItems : null,
	AutoScroll : false,
	AutoScrollSpeed : 8000,
	
	Init : function() {
		this.FooterContent = document.getElementById('footer-content');	
		if(this.FooterContent != null) {
			this.FooterItems = this.FooterContent.getElementsByTagName('dl');
			var posx = 0;

			for(x=0; x<this.FooterItems.length; x++) {
				this.FooterItems[x].className = "footer-browser";
				this.FooterItems[x].style.left = posx+"px";
				posx = posx+this.Width;
				}
			
			var a = document.getElementById('footer-nav');	
			if(a != null) {
				if(this.FooterItems.length > 4) {
					a.onclick = this.Next;
					a.style.display = "block";
				} else {
					a.style.display = "none";
					}
				}
				
			if((this.AutoScroll) && (this.FooterItems.length > 3)) {
				CoastMountain.Footer.ScrollAutoTimer = setInterval("CoastMountain.Footer.Next();", CoastMountain.Footer.AutoScrollSpeed);		
				var obj = document.getElementById('footer');	
				
				obj.onmouseover = function() {
					clearInterval(CoastMountain.Footer.ScrollAutoTimer);
					CoastMountain.Footer.ScrollAutoTimer = null;
					}
					
				obj.onmouseout = function() {
					CoastMountain.Footer.ScrollAutoTimer = setInterval("CoastMountain.Footer.Next();", CoastMountain.Footer.AutoScrollSpeed);	
					}	
					
				}
			}		
		},
		
	Next : function() {
		if(!CoastMountain.Footer.ScrollTimer) {
			for(x=0; x<CoastMountain.Footer.FooterItems.length; x++) {
				newPosition = parseInt(CoastMountain.Footer.FooterItems[x].style.left)-CoastMountain.Footer.Width;
				CoastMountain.Footer.FooterItems[x].newPosition = newPosition;
				}	
			CoastMountain.Footer.ScrollTimer = setInterval("CoastMountain.Footer.Scroll();", 5);
			}			
		},
		
	Scroll : function() {
		if(parseInt(this.FooterItems[0].style.left) > this.FooterItems[0].newPosition) {
			for(x=0; x<this.FooterItems.length; x++) {
				posx = Math.floor(parseInt(this.FooterItems[x].style.left)-((parseInt(this.FooterItems[x].style.left)-this.FooterItems[x].newPosition)/7));
				this.FooterItems[x].style.left = posx+"px";
				}	   
		} else {
			clearInterval(CoastMountain.Footer.ScrollTimer);
			CoastMountain.Footer.ScrollTimer = null;
			endPosition = (this.FooterItems.length*this.Width)-this.Width;
			for(x=0; x<this.FooterItems.length; x++) {
				if(this.FooterItems[x].newPosition < 0) this.FooterItems[x].style.left = endPosition+"px";
				else this.FooterItems[x].style.left = this.FooterItems[x].newPosition+"px";
				}			
			}
		
		}

};
YAHOO.util.Event.addListener(window, "load", CoastMountain.Footer.Init, CoastMountain.Footer, true);

	
// ------[ Popup Window ]------------------------------------------------- //
CoastMountain.PopWindow = function(url,w,h,scroll,tools,name,center) {
	var str = "height=" + h + ",innerHeight=" + h;
	str += ",width=" + w + ",innerWidth=" + w;
	if(!center) var center = false;
	if(!scroll) scroll = 0;
	if(!tools) tools = 0;
	if(!name) name = "pop";
	if((window.screen) && (center)) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - w) / 2;
		var yc = (ah - h) / 2;
		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
		}
	pop = window.open(url,name,'toolbar=' + tools + ',location=0,directories=0,status=0,menubar=0,scrollbars=' + scroll + ',resizable=1,' + str).focus();	
};

// Exemple of link with the PopWindow:
// <a href="/folder/myPage.html" onclick="CoastMountain.PopWindow(this.href,350,400,1,0,'myPopWindowName',1); return false;"></a>

// used to simulate the hover pseudo class behaviour due to IE6 only supporting hover on anchor elements
function buttonMouseOver(elementId){
	document.getElementById(elementId).style.color='white';
	document.getElementById(elementId).style.cursor='pointer';
}	
function buttonMouseOut(elementId){
	document.getElementById(elementId).style.color='#000000';
	document.getElementById(elementId).style.cursor='default';
}