/*----------------------------------*/
/*GENERAL SETTINGS & ANIMATION-----*/
/*--------------------------------*/

JAME.Components.TreeMenu.prototype.initPageLoadBreadCrumb = function() {
			return false;
}

JAME.Components.TreeMenu.prototype.handleMainMenuClickEvent = function() {

		var self = this;

		this.mainMenu.onclick  = function(e) {

			//normalize the event
			e = JAME.Events.Normalize(e);
			e.preventDefault();
			e.stopPropagation();

			var target = e.target;
			//check what triggered the event and get the li tag
			if(target.tagName.toLowerCase()==='a') target=target.parentNode;
			if(target.tagName.toLowerCase()!=='li') return;

			if(self.closingTimer) clearTimeout(self.closingTimer);

			self.dispatch('onClick',target);

			if(self.expandedLI) {
				var hostname   = window.location.protocol+'//'+window.location.hostname+'/';

				var clickedURL = JAME.DOM.firstNode(target).href;
				if(clickedURL.indexOf(hostname)==-1)
					clickedURL=hostname+clickedURL;

				var seenURL = hostname+window.location.hash.replace('#/','');
				if(self.expandedLI===target && self.mainMenu.isOpened) {
					self.expandedLI=undefined;
					return self.closeMainMenu();
				}

				if(seenURL==clickedURL && self.expandedLI===target && self.mainMenu.isOpened){
					 return self.closeMainMenu();
				}
			}

			if(target.parentNode===self.root && target.getElementsByTagName('ol')[0]){
				 self.openMainMenu();
			}

			if(self.expandedLI && self.expandedLI.parentNode!==self.root) {

				var ancestors = self.getAncestorTree(self.expandedLI);
				var link=JAME.DOM.firstNode(ancestors[ancestors.length-2].parentNode).href;

				if(link && JAME.DOM.firstNode(target).href===link) {
					return;
				}
			}

			self.hideExpandedTree(target);

			self.expandedLI=target;

			JAME.CSS.setStyles(JAME.DOM.firstNode(target),{color:this.onColor});

			//try to get the target submenu
			var submenu = target.getElementsByTagName('ol')[0];

			self.onClick(target,submenu);
			//if  we have a submenu
			if(submenu) {
				self.moveDot(getElementTop(self.expandedLI),getElementLeft(self.expandedLI));
				var OLLiChildren = self.hideLiElements(submenu);
				//display the submenu
				self.displayOLElement(submenu);
				self.showLiElements(OLLiChildren);
				return;
			}
			//close the menu again in 3.5s
			self.closingTimer = setTimeout(function() {
				self.closeMainMenu();
			},1000);
			//set the url address in the bar
			SWFAddress.setValue(window.Value(e.target.href)[1]);
		}
}



//this event fires just before we make the ajax call
//here you can modify the current displayed content
//like fade out elements,move them,etc.

JAME.ASYNC.Events.addListener('onPreLoadHTML',function() {

	//show loader

	if(JAME.$('loader-container')) {

		var img = parse('#loader-container img');
		img.src='/snowboard/local/img/ajax-loader.gif';
		JAME.CSS.setStyles(JAME.$('loader-container'),{width:'0px',backgroundImage:'none',backgroundColor:'transparent'});
		JAME.$('loader-container').style.display='block';
		JAME.CSS.setStyles(JAME.$('loader-container'),{
			left:'118px',
			top:'26px',
			width:'12px',
			height:'12px'
		});
	}

});

function setAddressFromFlash(url){
	displayProductFromOverview(url);
}


JAME.ASYNC.Events.addListener('onFullLoad',function() {

	var string=location.href;
	if(string.match(/\/snowboard\/(#)?$/)){
		new JAME.Ajax({
			url:'/snowboard/?ajax=true&output=raw',
			onSuccess:function(resp){
				JAME.$('website').innerHTML=resp;
				createTopFeatureAnimations();
			}
		});
	}

});
var createTopFeatureAnimations = function() {

	if(!window.topFeatures){
		window.topFeatures = new JAME.Components.Panels({
			container:JAME.$('top-features-area'),
			panels   :parse('#features li'),
			navigationOff:false,
			customId:'feature-panels',
			padding:20,
			to:'top'
		});
	}

	window.topFeatures.startSlideShow(6000);

	window.crossFader = null;
	window.crossFader = new JAME.Components.CrossFader({imgs:parse('#pic img')});
}

JAME.ASYNC.Events.addListener('onFullLoad',function() {

	if(!JAME.$('top-news')) {

		if(window.crossFader){
			window.crossFader.stop();
			window.crossFader = null;
		}
		if(window.topFeatures) {
			window.topFeatures.stopSlideShow();
			window.topFeatures = null;
		}
	}
});














//EVENTS ARE WRITTEN IN DISPATCHING ORDER

//onload fading and menu settings

window.getDepth = function(elm,root) {
		var	depth=0;
		do {
			if(elm===root) return depth;
			elm=elm.parentNode;
			depth++;
		}while(elm);
}

window.getPosition = function(elm,root) {

		var elms = root.getElementsByTagName('li');
		var ln   = elms.length;

		if(JAME.DOM.lastNode(root)  === elm) return ln;
		if(JAME.DOM.firstNode(root) === elm) return 1;
		for(var i=1;i<ln-1;i++)
			if(elms[i]===elm) return i+1;

			
}

	function jparent(elm) {
		return (elm) ? elm.parentNode : elm ;
	}

	function jcheckParent(target,origin) {
		do {
			if(target===origin) return true;
			target = jparent(target); 
		} while(target);
		return false;
	}


var loaderBar=function(){
	if(JAME.ASYNC._gnlCounter && JAME.ASYNC._gnlCounter>0){

		if(JAME.$('loader-container')) new JAME.FX({duration:10}).Tween(JAME.$('progressBar'),{width:[12]});
	}

}

JAME.ASYNC.Events.addListener('onLoadProgress',loaderBar);
JAME.ASYNC.Events.addListener('onFullLoad',function() {JAME.ASYNC._gnlCounter++;});

JAME.ASYNC.Events.addListener('onFullLoad',function() {

	document.body.style.marginTop='0px';
	var menu = JAME.$('globalmenu');
	var uri = SWFAddress.getValue();

	/*==MENU LOGIC==*/

	window.TreeMenu = new JAME.Components.TreeMenu({
		startingDepth: 2,
	    mainMenu     : JAME.$('globalmenu'),
	    breadCrumb	 : JAME.$('breadCrumb'),
	    root		 : parse('#globalmenu ol.tree'),
		offColor	 : '#333',
		isDot	     : false,
		closedHeight : 53,
		openedHeight : 160

	});
	TreeMenu.closeMainMenu();

	var heads = parse('#globalmenu li.depth3');

	heads.each(function(elm,i) {
		elm.onmouseover=function(e) {
			e = JAME.Events.Normalize(e);
			if(elm.overed) return;
			var a = elm.getElementsByTagName('a')[0];
			new JAME.FX().Tween(a,{opacity:[1]});
			elm.overed=true;
		}
		elm.onmouseout=function(e) {
			e = JAME.Events.Normalize(e);
			if(jcheckParent(e.relatedTarget,elm)) return;
			if(!elm.overed) return;
			var a = elm.getElementsByTagName('a')[0];
			new JAME.FX().Tween(a,{opacity:[0]});
			elm.overed=false;
		}
	});

	/*==FIRST TIME FADE IN==*/

	var caller = arguments.callee;//save the function stack trace
	new JAME.FX({duration:40}).Tween(JAME.$('header-area'),{opacity:[.9,1]}).queue(
	function() { this.Tween(parse('#footer-area'),{opacity:[.9,1]}) },
	function() {
		//want to fire the fading just once so need to delete this event at the end
		JAME.ASYNC.Events.removeListener('onFullLoad',caller);
	});

	var searchli = JAME.$('searchproduct').cloneNode(true);
	JAME.$('searchproduct').parentNode.removeChild(JAME.$('searchproduct'));
	JAME.CSS.setStyles(searchli,{
		display:'block',
		opacity:1,
		position:'absolute',
		top:3,
		right:10
	});
	JAME.$('container').appendChild(searchli);

	searchli.onsubmit = function(e) {

		e  = JAME.Events.Normalize(e);
		e.preventDefault();

		var form        = e.target;
		var queryString = JAME.Form.serialize(form);
		var url         = form.action+'?'+queryString;
		var URLElements = Value(url);
		SWFAddress.setValue(URLElements[1]);

		queryString = null;
		form        = null;
		queryString = null;
		URLElements = null;
	}

});


JAME.ASYNC.Events.addListener('onFullLoad',function() {

	var ad=SWFAddress.getValue();
	if(! /\/products\/Overview/.test(ad) ) return;
		if(!JAME.$('MooFlow')) return;
		var products=parse('#MooFlow img');
		products=products && products.constructor===Array ? products : products ? [products]:[];

		document.body.style.height='100%';

		var mf = new MooFlow($('MooFlow'), {
			startIndex: Math.floor(products.length/2),
			useSlider: true,
			useAutoPlay:false,
			useCaption: true,
			useResize: false,
			useMouseWheel: true,
			useKeyInput: true,
			factor: ( /snowboard-/.test(ad) ) ? 40 : 110,
			onClickMain: function(mixedObject){
				if(JAME.$('loader-container')) JAME.$('loader-container').style.display='block';
				var url = mixedObject.href;
				new JAME.Ajax({
					url:url+'?output=raw',
					onSuccess:function(resp) {

						var div = JAME.DOM.createNode('div');
						div.innerHTML=resp;
						JAME.CSS.setStyles(div,{
							position:'absolute',
							top:600,
							left:0,
							opacity:0,
							width:892,
							zIndex:1
						});
						var close = JAME.DOM.createNode('div');
						close.innerHTML='CLOSE';
						JAME.CSS.setStyles(close,{
							position:'absolute',
							top:25,
							right:30,
							fontSize:13,
							opacity:0,
							cursor:'pointer',
							color:'#aa0000',
							zIndex:1
						});
						close.onclick = function() {
							new JAME.FX({duration:600}).Tween(div,{left:[0,-600]}).queue(
							function() {
									div.parentNode.removeChild(div);
								new JAME.FX({duration:600}).Tween(close,{opacity:[0],top:[0]}).queue(
								function() {
									close.parentNode.removeChild(close);
								})
							});
						}
						JAME.$('website').appendChild(div);
						JAME.$('website').appendChild(close);
						if(JAME.$('loader-container')) JAME.$('loader-container').style.display='none';
						new JAME.FX({duration:800,easing:JAME.FX.Transition.Back.Out}).Tween(div,{top:[0],height:[0,890],opacity:[1]}).queue(
							function() {
								new JAME.FX({duration:800,easing:JAME.FX.Transition.Back.Out}).Tween(close,{opacity:[1],top:[0,25]});
							}
						);
						abortJAMELoading(1);
						SWFAddress.setValue(Value(url)[1]);
						setTimeout(function() {
							abortJAMELoading(undefined);
						},300)
						JAME.ASYNC.Events.dispatch('onFullLoad');
					},
					timeout:8000
				});
			}
		});
	
});


var displayProductFromOverview=function(url){

	if(JAME.$('loader-container')) JAME.$('loader-container').style.display='block';

	new JAME.Ajax({
		url:url+'?output=raw',
		onSuccess:function(resp) {

			var div = JAME.DOM.createNode('div');
			div.innerHTML=resp;
			JAME.CSS.setStyles(div,{
				position:'absolute',
				top:600,
				left:0,
				opacity:0,
				width:892,
				zIndex:1
			});
			var close = JAME.DOM.createNode('div');
			close.innerHTML='CLOSE';
			JAME.CSS.setStyles(close,{
				position:'absolute',
				top:25,
				right:30,
				fontSize:13,
				opacity:0,
				cursor:'pointer',
				color:'#aa0000',
				zIndex:1
			});
			close.onclick = function() {
				new JAME.FX({duration:600}).Tween(div,{left:[0,-600]}).queue(
				function() {
					div.parentNode.removeChild(div);
					new JAME.FX({duration:600}).Tween(close,{opacity:[0],top:[0]}).queue(
					function() {
						close.parentNode.removeChild(close);
					})
				});
			}
			JAME.$('website').appendChild(div);
			JAME.$('website').appendChild(close);
			if(JAME.$('loader-container')) JAME.$('loader-container').style.display='none';
			new JAME.FX({duration:800,easing:JAME.FX.Transition.Back.Out}).Tween(div,{top:[0],height:[0,890],opacity:[1]}).queue(
				function() {
					new JAME.FX({duration:800,easing:JAME.FX.Transition.Back.Out}).Tween(close,{opacity:[1],top:[0,25]});
				}
			);
			abortJAMELoading(1);
			SWFAddress.setValue(Value(url)[1]);
			setTimeout(function() {
				abortJAMELoading(undefined);
			},300)
			JAME.ASYNC.Events.dispatch('onFullLoad');
		},
		timeout:8000
	});
}


JAME.ASYNC.Events.addListener('onFullLoad',function() {

	if(! /\/products\/Overview/.test(SWFAddress.getValue()) ) return;


	JAME.$('products').onclick=function(e) {

		e = JAME.Events.Normalize(e);
		if(JAME.$('jcontainer')) {
			JAME.$('jparent').parentNode.removeChild(JAME.$('jparent'))
		}
		if(e.target.nodeName.toLowerCase()==='img') {

			var clone  = JAME.$('products').cloneNode(true);
			clone.id='test';


			var html ='<div id="jcontainer">'+
							'<h3 id="productLinks">PRODUCTS WITHIN THIS CATEGORY</h3>'+
							'<div id="test">'+clone.innerHTML+
							'<br /><div style="clear:both"></div>'+	
							'</div></div>';

			var div = JAME.DOM.createNode('div');
			div.id='jparent';
			div.innerHTML=html;
			var imgs =JAME.$('products').getElementsByTagName('img');
			var imgs2=div.getElementsByTagName('img');
			for(i=0;i<imgs.length;i++) {
				var height = imgs[i].height;
				var width  = imgs[i].width;
				var ratio = (height/width>1.5) ? [3,2]:[2.5,2.5];

				imgs2[i].style.height=(height/ratio[0])+'px';
				imgs2[i].style.width=(width/ratio[1])+'px';
				JAME.CSS.setStyles(imgs2[i],{opacity:1,display:'block'});
			}
			window.ProductsListUp=div;
			window.ProductsListUpSet=false;
			JAME.CSS.setStyles(div,{
				width:300,
				top:55,
				right:2,
				position:'absolute'
			});

		}
	}

});

JAME.ASYNC.Events.addListener('onFullLoad',function() {

	if(!JAME.$('breadCrumb')) return;

	JAME.$('breadCrumb').onclick=function(e) {
		e = JAME.Events.Normalize(e);
		var target = e.target;

		if(target.nodeName.toLowerCase()!=='a') return;
		var pos = getPosition(target.parentNode,JAME.$('breadCrumb'));

		//atomic and ski doesn't interact with the menu
		if(pos<=2) return;

		e.preventDefault();
		e.stopPropagation();
		window.TreeMenu.openMainMenu();
	}
			JAME.CSS.setStyles(JAME.$('website'),{height: 'auto'});
});


/*-------------------*/
/*=PAGES EFFECT-----*/
/*-----------------*/

/*-------------------*/
/*GOODIES & VIDEO---*/
/*-----------------*/

JAME.ASYNC.Events.addListener('onFullLoad',function() {
	if(! /(?:goodies)\/(?:Video|FreeskiTV)/.test(SWFAddress.getValue()) ) return;

	var links = parse("#html_container a.lightwindow");

	links = links && links.constructor === Array?links : links ? [links]:[];
	links.each(function(elm) {
			if(!elm) return;
			elm.onclick=function(e) {
				e = JAME.Events.Normalize(e);
				var elm = e.target;
				e.preventDefault();
				var myURI = elm.href;
				if(!myURI || elm.nodeName.toLowerCase()=='img') {
					myURI = elm.parentNode.href;
					elm.title = elm.alt;
				}
				open_lightwindow(myURI,elm.title);
			}
	});
	JAME.ASYNC.stack.push(links);
});

function open_lightwindow(myURI,myTitle) {

	var effect  = JAME.$('html_contents2').state ? {}:{position:['relative','relative'],left:[0,450],width:[880,400]};
	var divs  = parse('.vgitem_left');
	divs = divs && divs.constructor===Array ? divs : divs ? [divs] :[];
	var divs2 = parse('.vgitem_right');
	divs2 = divs2 && divs2.constructor===Array ? divs2 : divs2 ? [divs2] :[];
	if(!JAME.$('html_contents2').state){
	new JAME.FX({duration:10}).Tween(divs,{width:[430,160],overflow:['visible','hidden']});
	new JAME.FX({duration:10}).Tween(divs2,{width:[430,160],overflow:['visible','hidden']});

	divs.each(function(elm,i) {
			elm.onmouseover=function() {
				JAME.$('displayBox').innerHTML=elm.innerHTML;
				JAME.$('displayBox').getElementsByTagName('div')[0].style.display='none';
				JAME.$('displayBox').getElementsByTagName('a')[0].parentNode.style.display='none';
				new JAME.FX().Tween(JAME.$('displayBox'),{display:['block'],opacity:[1],left:[getElementLeft(elm)-100],top:[600]})
			}
	})
	divs2.each(function(elm,i) {
			elm.onmouseover=function() {
				JAME.$('displayBox').innerHTML=elm.innerHTML;
				JAME.$('displayBox').getElementsByTagName('div')[0].style.display='none';
				JAME.$('displayBox').getElementsByTagName('a')[0].parentNode.style.display='none';
				new JAME.FX().Tween(JAME.$('displayBox'),{display:['block'],opacity:[1],left:[getElementLeft(elm)-100],top:[600]})
			}
	})
	}
	new JAME.FX({duration:200}).Tween(JAME.$('html_contents2'),effect).queue(function() {
		var me = this;
		JAME.$('html_contents2').state=true;
		myURI= myURI.replace('.xhtml','.flv');
		myURI= myURI.replace('/snowboard/goodies/Video/','/images/video/movies/');

		if(!JAME.$('flash-container')) {
			var div = JAME.DOM.createNode('div');
			div.id="flash-container";
			JAME.$('website').appendChild(div);
			JAME.CSS.setStyles(div,{
				position:'absolute',
				top:80,
				left:40,
				height:348,
				width:360,
				backgroundColor:'black',
				color:'white',
				border:'3px solid white'
			});
			var close     = JAME.DOM.createNode('div');
			close.innerHTML = "CLOSE";
			JAME.CSS.setStyles(close,{cursor:'pointer'});
			close.onclick = function(e) {
				JAME.$('html_contents2').state=false;
				JAME.CSS.setStyles(div,{display:'none'});
				new JAME.FX({duration:10}).Tween(divs,{width:[160,400],overflow:['visible','hidden']});
				new JAME.FX({duration:10}).Tween(divs2,{width:[160,400],overflow:['visible','hidden']});
				divs.each(function(elm,i) {
						elm.onmouseover=null;
				})
				divs2.each(function(elm,i) {
					elm.onmouseover=null;
				})
				new JAME.FX().Tween(JAME.$('displayBox'),{display:['none'],opacity:[0]})
				me.reverse();
			}
			JAME.CSS.setStyles(close,{float:'right',marginRight:3});
			div.appendChild(close);
			var title   = JAME.DOM.createNode('h2');
			    title.id= "tv-title";
			JAME.CSS.setStyles(title,{float:'left',color:'white',padding:'5px',fontSize:14});
			div.appendChild(title);
		}
		else {
			swfobject.removeSWF("flash");
		}
	 	JAME.CSS.setStyles(JAME.$('flash-container'),{display:'block'});

		JAME.$('tv-title').innerHTML=myTitle;

		var flash=JAME.DOM.createNode('div');
		flash.id="flash";
		JAME.$('flash-container').appendChild(flash);

		var swf='/snowboard/local/swf/flv_player.swf?vid=';
		swf+=myURI;
		var flashvars = {'vid':myURI};
		var params = {};
		var attributes = {};
		swfobject.embedSWF(swf, "flash", "360", "320", "9.0.0","expressInstall.swf", flashvars, params, attributes);

	});
}


/*---------------------*/
/*=TEAM VIEW-----------*/
/*-------------------*/

JAME.ASYNC.Events.addListener('onFullLoad',function() {

	if(! /(?:athletes\/Riders-)/.test(SWFAddress.getValue()) ) return;

	var riders = parse('.riders');

	riders.each(function(elm,i) {

		elm.top  = getElementTop(elm)-135;
		elm.left = getElementLeft(elm);
		JAME.CSS.setStyles(elm,{
			left:0,
			top:250
		});
		setTimeout(function() {
			new JAME.FX({duration:250}).Tween(elm,{ 
				position:['relative','absolute'],
				opacity:[0,1]
			})
		},250*i);
	});

	setTimeout(function() {
	riders.reverse().each(function(elm,i) {
		setTimeout(function() {
			new JAME.FX({duration:450}).Tween(elm,{ 
				position:['absolute','static'],
				top:[0,elm.top],
				left:[0,elm.left],
				opacity:[0,.9]
			}).queue(function() {

				elm.style.top='0px';
				elm.style.left='0px';
				elm.style.position='relative';

			});
		},450*i);
	});
	},260*riders.length);
});



/*---------------------*/
/*=TEAM BLOGS VIEW----*/
/*-------------------*/

JAME.ASYNC.Events.addListener('onFullLoad',function() {

	if(! /(?:athletes\/RidersBlog)/.test(SWFAddress.getValue()) ) return;

	var riders = parse('#html_contents div.riders');

	riders.each(function(rider,i) {
		new JAME.FX({duration:450}).Tween(rider,{
				opacity:[0,.9]
		})
		if(!rider.id) return;

		var div       = JAME.DOM.createNode('span');	
		div.innerHTML = 'loading...';
		div.className = 'riderRSSFeed';
		rider.appendChild(div);

	
		setTimeout(function() {

		new JAME.Ajax({
			url:'/cgi-bin/atomic/snowboard/index.cgi?view=athletes.GetRiderRSS&output=raw&pk='+rider.id,
			onSuccess: function(resp) {
				div.innerHTML = '<h2>LATEST ENTRIES</h2>'+resp;
				var toggle    = div.getElementsByTagName('span')[0];
				var feed      = div.getElementsByTagName('ul')[0];
				var height    = JAME.CSS.getStyle(feed,'height');


			},
			onError:function() {
				div.innerHTML='';
			},
			timeout:20000,
			retryLimit:1
		});
		},300*i);
		    
	});


});


JAME.Components.Scroller = function(options) {

		this.container           = options.container;
		this.contained           = options.contained;
		this.maxHeight           = options.maxHeight;
		this.maxWidth            = options.maxWidth;
		this.speed				 = options.speed || 1;
		this.scrollY             = (options.scrollY!==undefined) ?options.scrollY:  true;
		this.scrollX             = (options.scrollX!==undefined) ?options.scrollX:  true;
		this.interval            = undefined;
		this.container.maxHeight = parseInt(this.maxHeight) || parseInt(JAME.CSS.getStyle(this.container,'height'));
		this.container.maxWidth  = parseInt(this.maxWidth)  || parseInt(JAME.CSS.getStyle(this.container,'width'));
		this.contained.maxHeight = parseInt(JAME.CSS.getStyle(this.contained,'height'))+10;

		if(JAME.CSS.getStyle(JAME.DOM.firstNode(this.contained),'float')=='left'){
			var tagName=JAME.DOM.firstNode(this.contained).tagName.toLowerCase();
			var tags = this.contained.getElementsByTagName(tagName);
			this.contained.maxWidth  =tags[0].offsetWidth*tags.length;
		}
		else {
			this.contained.maxWidth  = parseInt(JAME.CSS.getStyle(this.contained,'width'));
		}
		if(this.contained.maxWidth!=0 && this.contained.tagName.toLowerCase()!='img') this.contained.style.width  = this.contained.maxWidth+'px';





		this.downContainer  = options.downContainer || undefined;
		this.upContainer  = options.upContainer || undefined;
		JAME.CSS.setStyles(this.container,{
			overflow       :'hidden',	
			cursor         :'pointer',
			position       :'relative',
			height         : this.container.maxHeight,
			width          : this.container.maxWidth
		});
		JAME.CSS.setStyles(this.contained,{
			position       :'relative',	
			top            : 0,
			left 		   : 0
		});
		this._setCenter();
		this._setDiffXY();
		this._setCurrentXY(this._getCenter('X',0),0);
		if(this.isActive()) 
			this.downContainer ? this._handleMouseDown() : this._handleMouseMove();

		JAME.extend(this,new JAME.Events.EventDispatcher());

};

JAME.Components.Scroller.prototype = {

	isActive : function() {
		return (this.diffX>=0 && this.diffY>=0) ? false : true;
	},
	//clear interval and put image the contents centered
	_resetState : function() {
		if(this.interval) clearInterval(this.interval);
		this._setCurrentXY(this._getCenter('X',0),this._getCenter('Y',0));
	},
	//calculate the diff between the container width/height and the contained width/height
	_setDiffXY  : function() {
		this.diffX  = this.container['maxWidth']  - this.contained['maxWidth'];
		this.diffY  = this.container['maxHeight'] - this.contained['maxHeight'];
	},
	//set the actual position of the contained
	_setCurrentXY : function(X,Y) {
		if(this.scrollY) JAME.CSS.setStyle(this.contained,'top',Y);
		if(this.scrollX) JAME.CSS.setStyle(this.contained,'left',X);	
	},

	//adjust contained position according to mouse position
	_calculateContainedPosition : function(axe,mousePosition,containedPosition) {

		var XorY = axe ==='Y' ? 'Height' : 'Width';
		var newPosition = 0;

		//how far the mouse is from the center point (300,-300)
		var ratio   = this['center'+axe] - mousePosition;
		//a proportional expression of the distance from the center point (1.15,-1.15)
		    ratio   = this.contained['max'+XorY]*(ratio/this.container['max'+XorY])/100;
		//add the ratio to the contained actual position: 420+1.15

		newPosition     = containedPosition + ratio*this.speed;

		//below logic is:
		//ex : container height : 450
		//containee height : 1820
		// diff (boundary) = 450 -1820 = -1370
		// new position = -1550
        //if we go that far (because we don't have any boundary value to check against)
		// the element won't be visible anymore
		// so reset to the above diff -1370 
		// basically the element can't go up to a point where it is not visible
		//if(axe==='Y') JAME.$('searchstring').value = parseInt(newPosition)+':'+this['diff'+axe];
		if(newPosition <= this['diff'+axe]) newPosition = this['diff'+axe];
		// the same thing but the other way round
		if(newPosition>=0) newPosition=0;
		//else new position between the boundaries
		return newPosition;

	},
	getElementTop:function(obj,parent){
    var topValue= 0;
    while(obj && obj!==parent){
	topValue+= obj.offsetTop;
	obj= obj.offsetParent;
    }
    return topValue;
	},
	getElementLeft:function(obj,parent){
    var leftValue= 0;
    while(obj && obj!==parent){
	leftValue+= obj.offsetLeft;
	obj= obj.offsetParent;
    }
    return leftValue;
	},
	_setCenter : function() {
		this.centerX  = parseInt(parseInt(this.container.maxWidth)/2);
		this.centerY  = parseInt(parseInt(this.container.maxHeight)/2);
	},

	_getCenter : function(axe,current) {

		var XorY = axe ==='Y' ? 'Height' : 'Width';

		if(current==0 && this.container['max'+XorY]-this.contained['max'+XorY]>0) {
			var mid = parseInt(this.contained['max'+XorY])/2;
			return this['center'+axe]-mid;
		}
		return current;

	},

	_setActiveScrolling : function(X,Y) {

		this.scrollingTop    = (Y==0)                  ? false : true;
		this.scrollingBottom = (Y <= this['diffY'])    ? false : true;
		this.scrollingLeft   = (X==0)                  ? false : true;
		this.scrollingRight  = (X <= this['diffX'])    ? false : true;
	},

	scrollTop : function() {
		if(this.interval) clearInterval(this.interval);
		new JAME.FX({duration:800}).Tween(this.contained,{top:[0]});
		this._setActiveScrolling(parseFloat(JAME.CSS.getStyle(this.contained,'left')),0);
		this.dispatch('onScroll',parseFloat(JAME.CSS.getStyle(this.contained,'left')),0);
	},
	scrollBottom : function() {
		if(this.interval) clearInterval(this.interval);
		new JAME.FX({duration:800}).Tween(this.contained,{top:[this.diffY]});
		this._setActiveScrolling(parseFloat(JAME.CSS.getStyle(this.contained,'left')),this.diffY);
		this.dispatch('onScroll',parseFloat(JAME.CSS.getStyle(this.contained,'left')),this.diffY);
	},

	_handleMouseDown : function() {

		var me = this;

		this.downContainer.handler=-1;
		this.upContainer.handler =1;
		this.upContainer.onmousedown = this.downContainer.onmousedown=function(e){

			var e = JAME.Events.Normalize(e);
			
			if(me.interval) clearInterval(me.interval);
			if(me.contained.__ON) return;
			var self = this;

			me.interval = setInterval(function() {
				var currentX = parseInt(me.contained.style.left);
				var currentY = parseInt(me.contained.style.top);
				currentX += (self.handler==-1) ? -10 : 10;
				currentY += (self.handler==-1) ? -10 : 10;
				//calculate Y
				if(me.scrollY) {
					if(currentY <= me['diffY']) currentY = me['diffY'];
					if(currentY>=0) currentY=0;
					
					currentY = me._getCenter('Y',currentY);
				}

				//calculate X
				if(me.scrollX) {
					if(currentX <= me['diffX']) currentX = me['diffX'];
					if(currentX>=0) currentX=0;
				    currentX = me._getCenter('X',currentX);
				}
				if((currentX==me['diffX'] || currentX==0) && (currentY==me['diffY'] || currentY==0) )
					clearInterval(me.interval);
				me._setActiveScrolling(currentX,currentY);
				me.dispatch('onScroll',currentX,currentY);

				me._setCurrentXY(currentX,currentY);

			},20);
		}
		this.container.onmouseout= this.upContainer.onmouseup=this.downContainer.onmouseup=function(e){
			if(me.interval) clearInterval(me.interval);
		}

	},


	_handleMouseMove : function() {

		var me = this;

		this.container.onmousemove=function(e){

			var e = JAME.Events.Normalize(e);
			
			if(me.interval) clearInterval(me.interval);
			if(me.contained.__ON) return;
			//get the actual position of the target
			var currentX = parseInt(me.contained.style.left);
			var currentY = parseInt(me.contained.style.top);

			//layerX/Y gives us the relative position of the target
			//even if we're listing to container, the bubble can send us the containee positions
			//we want to get the mouse position relative to the container
			//if the mouse is on the containee, we need to substract its position to get the position
			//relative to the container
			var position = JAME.CSS.getStyle(e.target,'position');
			var mouseX = e.layerX+( ((e.target!==me.container && position=='static') || (e.target===me.contained)) ? currentX : 0);
			var mouseY = e.layerY+( ((e.target!==me.container && position=='static')|| (e.target===me.contained)) ? currentY  : 0);


			//if the target has a relative position 
			//we need to add to the mouse position the element actual offset
			//relative to the main containee
			//IE sends the coordinate relative to the target, 
			//even if the target is not positioned relatively
			//so we should always add the offset 

			if( (window.attachEvent && e.target.nodeName.toLowerCase()==='img')
				|| (e.target!==me.container && e.target!==me.contained && position && position!='static') )
			{
				mouseY+= me.getElementTop(e.target,me.contained);
				mouseX+= me.getElementLeft(e.target,me.contained);
			}

			me.dispatch('onMouseMove',e,mouseX,mouseY,currentX,currentY,position);
			me.interval = setInterval(function() {

				//calculate Y
				if(me.scrollY) {
					currentY = me._calculateContainedPosition('Y',mouseY,currentY);
					currentY = me._getCenter('Y',currentY);
				}

				//calculate X
				if(me.scrollX) {
				   currentX = me._calculateContainedPosition('X',mouseX,currentX);
				   currentX =me._getCenter('X',currentX);
				}

				me._setActiveScrolling(currentX,currentY);
				me.dispatch('onScroll',currentX,currentY);

				me._setCurrentXY(currentX,currentY);

			},10);
		}
		this.container.onmouseout=function(e){
			var e = JAME.Events.Normalize(e);
			var to = e.relatedTarget || document;
			do {
				if(to===me.container) return;
				to = to.parentNode
			} while(to);
			if(me.interval) clearInterval(me.interval);
		}
	}
};


//onload fading and menu settings

JAME.ASYNC.Events.addListener('onFullLoad',function() {
	if(! /info\/News\/[0-9]+\.html|faq\/Show\/[0-9]+\.html/.test(SWFAddress.getValue())) return;



	var imgList = JAME.$('website').getElementsByTagName('img');
	var imgs=[];
	for(var i=0;i<imgList.length;i++) imgs.push(imgList[i]);

	var loader = new JAME.Preloader(imgs);

	var top = JAME.DOM.createNode('div');
	JAME.CSS.setStyles(top,{
		position:'absolute',
		fontSize:1,	
		bottom:360,	
		right:10,
		visibility:'hidden',
		height:12,
		width:12,
		backgroundImage:'url(/ski/local/img/arrow-bw-up.gif)'
	});
	JAME.$('newscontents-wrapper').appendChild(top);

	var bottom = JAME.DOM.createNode('div');
	JAME.CSS.setStyles(bottom,{
		position:'absolute',
		bottom:340,	
		right:10,
		visibility:'hidden',
		height:12,
		width:12,
		fontSize:1,	
		backgroundImage:'url(/ski/local/img/arrow-bw-down.gif)'
	});
	JAME.$('newscontents-wrapper').appendChild(bottom);

	loader.addListener('onLoadComplete',function() {


		var scroller = new JAME.Components.Scroller({
			container : JAME.$('newscontents-wrapper'),
			contained : JAME.$('newscontents'),
			maxHeight : 591,
			speed :.5,
			scrollX:false,
			downContainer:bottom,
			upContainer:top
		});

		scroller.addListener('onScroll',function(eventName,X,Y) {
			
			if(scroller.scrollingTop && scroller.scrollingBottom) {
				top.style.visibility='visible';
				bottom.style.visibility='visible';
			}
			else if(scroller.scrollingTop) {
				top.style.visibility='visible';
				bottom.style.visibility='hidden';
			}
			else {
				top.style.visibility='hidden';
				bottom.style.visibility='visible';
			}
		});

		if(scroller.isActive()) {
			JAME.CSS.setStyles(bottom,{visibility:'visible'});
		}

	});
});



//onload fading and menu settings
JAME.ASYNC.Events.addListener('onFullLoad',function() {
	//if(! /info\/(News|Events)[a-zA-Z]+\.html/.test(SWFAddress.getValue()) ) return;
	if( !/info\/NewsTop.html/.test(SWFAddress.getValue())) return;


	var years = parse("div#years a");

	var list = parse('#news_list ol');
	var current=0;
	var maxHeight = 0;

	if(list.constructor == Array) {
		JAME.CSS.setStyles(JAME.$('news_list'),{display:'block',visibility:'hidden'});
		list.each(function(elm,i) {
   	     if(i==0) return;
			var height = parseInt(JAME.CSS.getStyle(elm,'height'));
     	   JAME.CSS.setStyles(elm,{opacity:0});
		    if (height > maxHeight) { maxHeight = height; }
		});
		years.each(function(elm,i) {
  			elm.onclick = function(e) {
     			e = JAME.Events.Normalize(e);
     			e.stopPropagation();
     			e.preventDefault();

				new JAME.FX({duration:100}).Tween(e.target,{backgroundColor:['#000000','#CC0000']});
				new JAME.FX({duration:100}).Tween(years[current],{backgroundColor:['#CC0000','#000000']});
     			var id = e.target.innerHTML;
	
     			var t  = current;
     			new JAME.FX({duration:200}).Tween(list[t],{opacity:[0]}).queue(function() {
        			JAME.CSS.setStyles(list[t],{display:'none'});
        			JAME.CSS.setStyles(JAME.$(id),{top: 0, display:'block'});
       				new JAME.FX().Tween(JAME.$(id),{opacity:[1]});
     			});
      			current=i;
  			}
		})
	}


	JAME.CSS.setStyles(JAME.$('news_list'),{height: maxHeight,display:'block',visibility:'visible'});
	JAME.CSS.setStyles(JAME.$('website'),{height: maxHeight+150});

});

/*=HOME CONTENTS */

JAME.ASYNC.Events.addListener('onFullLoad',function() {
	if(! /(?:home)/.test(SWFAddress.getValue()) ) return;
	if (window.TreeMenu) {
		window.TreeMenu.closeMainMenu();
	}

});

JAME.ASYNC.Events.addListener('onFullLoad',function() {

	if(JAME.$('technologies-details')) {
		JAME.CSS.setStyles(JAME.$('jpanels-container-overflow'),{
			position:'absolute',
			left:190,
			marginLeft:0
		})
	}
});