/*

	Fudge vs. Prototype & Scriptaculous

	written by Phil (phil at fudgestudios.com) and Mike "1312" (mike at fudgestudios.com)

	for Area 17 (www.area17.com)
	

	This javascript is the main javascript for the sites actions.
	
*/

// --------------------------------------------------------------------------------------------------------------
// set up variables

var isSafari = false;
var isSafari3 = false;
var isIE = false;
var isIE7 = false;	

// --------------------------------------------------------------------------------------------------------------
// what to do on DOM ready
document.observe("dom:loaded", runOnDOMready);
// Event.observe(window, 'load', function() { runOnLoaded(); });



function runOnDOMready() {	
	var moving = false;	
		if($('move-left')) {	
			// find out how many content-containers we've got
			var pages = $$('.content-container').length - 1;
			var currentPage = 0;

			$('move-left').observe('click', function(event) {
				if(moving==false) {	
					moving = true;
					new Effect.MoveBy('float-container-inner', 0, 468, {duration: .75,  transition: Effect.Transitions.sinoidal, afterFinish:function() {
						moving = false;
					}});
					currentPage--;
					if(currentPage == 0) {
						Element.hide('move-left');
					}
					Element.show('move-right');	
				}		
			});
			$('move-right').observe('click', function(event) {
				if(moving==false) {	
					if(currentPage < pages) {
						moving = true;					
						new Effect.MoveBy('float-container-inner', 0, -468, {duration: .75,  transition: Effect.Transitions.sinoidal, afterFinish:function() {
							moving=false;
						}});
						currentPage++;
						if(currentPage == pages) {
							Element.hide('move-right');
						}
						Element.show('move-left');
					}
				}
			});		
		
			// hide the left one on load
			Element.hide('move-left');
		}
		
		if($('project-selector')) {
						
			$('current-sector').update(sectors[0]);
			$('current-sector').observe('click', function(event) {
				Element.toggle('project-selector');
				//alert("!");
				Element.toggle('project-list');
			})

			// create the list
			sectors.each(function(s, index) {
				newEl = "<li id=\""+sectors[index].toLowerCase().gsub(" ","")+"\"><a href=\"#\">"+sectors[index]+"</a></li>";
				newListItem = $('project-selector').insert(newEl, {position: "bottom"});			
			})
			
			// hide by default
			Element.hide('project-selector');
			
			// create the list items
			$$('ul#project-selector li').each(function(s, index) {
				$(s).observe('click', function(event) {	
					Element.hide('project-selector');
					$('current-sector').update(sectors[index]);	
					
					outputProjectList(this.id);					
					Element.toggle('project-list');
					
					// activate the first project
					firstItem = $$('#project-list li')[0];
					var so = new SWFObject("/swf/projects/"+firstItem.id, "projectmovie", "522", "477", "8", "#fff");
					so.addParam("wmode", "transparent");			
					so.write("column-right");
										
					$$('#project-list li').each(function(s, index) {
						s.removeClassName('active');
					})
					firstItem.addClassName('active');					
				});
			})						
		}
		outputProjectList('distribution');
		$$('#project-list li')[0].addClassName('active');
}

function outputProjectList(which) {
	$('project-list').update('');
	eval(which).each(function(s, index) {
		newEl = "<li id=\""+s[1]+"\"><a href=\"#\">"+s[0]+"</a></li>";
		newListItem = $('project-list').insert(newEl, {position: "bottom"});
	})
	$$('#project-list li').each(function(s, index) {
		s.observe('click', function(event) {
			var so = new SWFObject("/swf/projects/"+s.id, "projectmovie", "522", "477", "8", "#fff");
			so.addParam("wmode", "transparent");			
			so.write("column-right");

			$$('#project-list li').each(function(s, index) {
				s.removeClassName('active');
			})
			this.addClassName('active');
		})
	})
	// $$('#project-list li')[0].addClassName('active');	
}