/**  Site: launches scripts for the site. **/
	var Site = {
		start: function(){
			//preloadNavigationItems();
			//preloadMemberImages();
			Switcher.start();
			Slider.start();
			
//			flashPlayer.pp('welcome');
		}
	};

	/**  Switcher: Changes switcher background automatically, on a timer. 
	*   If a switch gets mouse focus, it becomes the switcher background. Also, a mootools tooltip is displayed.
	*   When a switch loses focus, the automatic rotation continues, from that selected switch.
	*   HREFs in links should be set to "#", for mootools tooltips. **/
	var Switcher = {
		timerOn: true, 
		timerRunning: null,

		items: null,
		imageSrc: null,

		current: null,

		/* Times 8 seconds before running function to automatically rotate.
		   Will only start a new timer if the previous one has finished. */
		timerStart: function(){
		    if(Switcher.timerRunning == null){ Switcher.timerRunning = setTimeout("Switcher.rotateSwitch()",8000);  }
		},

		/* Needs to be run when a timer completes. 
		   Resets timerRunning to its default state. */
		clearTimer: function(){
		    clearTimeout(Switcher.timerRunning);
		    Switcher.timerRunning = null;
		},

		/* If the timer is set to on, rotates switcher background, and kicks timer off again. 
		   If timer is off, halts rotation. */
		rotateSwitch: function(el){
			result = Switcher.imageSrc.indexOf(Switcher.current); //Searches to see if there is an image currently being displayed. Returns the number of the image.

			if(result == -1){ Switcher.setSwitch(Switcher.items[0]); Switcher.current = Switcher.imageSrc[0]; }
			else if(Switcher.imageSrc[result + 1] == undefined) { Switcher.setSwitch(Switcher.items[0]); Switcher.current = Switcher.imageSrc[0]; }
			else { Switcher.setSwitch(Switcher.items[result + 1]); Switcher.current = Switcher.imageSrc[result + 1]; }

		    if(Switcher.timerOn){
				Switcher.clearTimer();
				Switcher.timerStart();
		    }

			else { Switcher.timerStart(); }
 		},
		
		setSwitch: function(el){	
			if(el = el.getParent('li')){ 
				Switcher.hideAll();
				el.fade('in');
			}
 		},
		
		getSwitches: function(){
			switcherItem = $$('li.switcherItem img');
			return switcherItem; 
		},
 		
		getSrc: function(switcherImage){
			imageSrc = [];
			switcherImage.each(function(img){
				imageSrc.push(img.get('src'));
			});
			
			return imageSrc;
		},
	
 		hideAll: function(){
 			var items = $$('.switcherItem');
 			items.each(function(item){
				item.fade('out');
 			});
 		},
		
		/* Sets up mouseenter and mouseleave behaviour on switches, as well as mootools tooltips. 
		   Also starts initial timer. Executed on 'domready'. */
		start: function(){ 
			Switcher.items = Switcher.getSwitches();
			Switcher.imageSrc = Switcher.getSrc(Switcher.items);
			Switcher.current = $$('li.switcherActive img')[0].get('src');

 			var items = $$('.switcherItem');
 			items.each(function(item){
				if(!item.hasClass('switcherActive')){ item.setStyle('opacity', '0'); }
 			});
			
 
			Switcher.timerStart();
		}

	};	
	
	
	// ---------- SLIDER ---------- //

	var Slider = {
		e: null,
		v: null,
		
		hideVideo: function(){
			videoViewer = $$('.videoViewer');
			videoViewer.each(function(v) {
				if(v.hasClass('show')) { v.removeClass('show'); }
				if(!v.hasClass('hide')){ v.addClass('hide'); }
			});
		},

		showVideo: function(id){
			v = $$('#' + id + ' embed.videoViewer');
			
			if(v.hasClass('hide')){ v.removeClass('hide'); }
			if(v.hasClass('show')){ v.addClass('show'); }		
		},
			
		scrollTo: function(el){
				//Grabs and resets any active links
				active = $$('.sliActiveLink');
				active.each(function(e){
					e.removeClass('sliActiveLink');
				});
				
				Slider.hideVideo();	 
				if(Slider.e){ Slider.e.cancel(); }
				
				id = 'sli' + el.get('id').substr(3);
				el.addClass('sliActiveLink'); //Sets activated link as active.
				Slider.e = new Fx.Scroll('sliderWindow', { duration: 1000, wait: false });
				
				Slider.e.toElement(id);
				Slider.v = Slider.showVideo.delay(1000,'',id);
		},	
	
		start: function(){
			selectors = $$('#sliderShortcuts li');
			items = $$('div.sliderItem');

			selectors.each(function(el){
				el = el.getChildren('a')[0];
				el.addEvent('click', function(e){
					new Event(e).stop();
					Slider.scrollTo(el);
					//Floater.moveFloat(el);
				});
			});
		}
	};
	
	var Floater = {
		moveFloat: function(el){
			var fl = $('floaterFloat');
			var pos = (el.getParent().getPosition());
			
			fx = new Fx.Morph(fl, { transition: Fx.Transitions.Elastic.easeOut, duration: 1500 });
			fx.start({ 'top': ( pos['y'] - 238 ) });	
		}
	};

	var flashPlayer = { 
		sendEvent: function(swf,typ,prm) { 
  			flashPlayer.thisMovie(swf).sendEvent(typ,prm); 
		},

//		getUpdate(typ,pr1,pr2,swf){},
		
		thisMovie: function(swf) {
  			if(navigator.appName.indexOf("Microsoft") != -1) {
   			 return window[swf];
  			} else {
    		 return document[swf];
  			}
		},
		
		pp: function(id){
			flashPlayer.sendEvent(id,'playpause');
		}
	};


	window.addEvent('domready', Site.start);

