/**
 * Luma JS library
 * 
 * @author	Devin Smith <devins@luma-pictures.com>
 * @date	2009.09.18
 *
 * This library was written exclusively for luma-pictures.com
 *
 */

var luma = {
	transitions: {
		shotFade: {duration: 500, transition: Fx.Transitions.Sine.easeOut},
		moveShotOut: {duration: 150, transition: Fx.Transitions.Quart.easeOut},
		moveShotIn: {duration: 300, transition: Fx.Transitions.Quart.easeIn},
		newsFade:  {duration: 1000, transition: Fx.Transitions.Sine.easeOut}
	},
	cookie: {
		set: function(name,value) {
			var exdate = new Date();
			exdate.setDate(exdate.getDate() + 180);
			document.cookie = name + '=' + escape(value) + ';path=/;expires=' + exdate.toGMTString();
		},
		get: function(name) {
			if (document.cookie.length > 0) {
				c_start=document.cookie.indexOf(name + '=');
				if (c_start!=-1) {
					c_start=c_start + name.length + 1;
					c_end=document.cookie.indexOf(';',c_start);
					if (c_end==-1)  {
						c_end=document.cookie.length;
					}
	    			return unescape(document.cookie.substring(c_start,c_end));
				}
			}
			return '';
		}
	},
	swapCss: {
		current: 'white',
		swap: function() {
			if (luma.swapCss.current == 'black') {
				luma.swapCss.current = 'white';
			} else {
				luma.swapCss.current = 'black';
			}
			$('loadCss').innerHTML = '<link rel=\'stylesheet\' type=\'text/css\' href=\'/assets/css/color_' + luma.swapCss.current + '.css\'>';


			luma.cookie.set('css_color',luma.swapCss.current);
			if (location.href) {
				location.href = location.href;
			}
		}
	},
	init: function() {
		if (browser.name != 'MSIE') {
			$('sungrad').style.display = '';
		}

		
		luma.resizeFooter();
		luma.resizeFooter();

		window.onresize = function(e) {
			luma.resizeFooter();
		}
		
		window.onscroll = function(e) {
			luma.resizeFooter();
		}

		luma.navigation.init('.submenu');
				
		if (browser.name != 'MSIE') {
			$$('.buttonLink img, .subtool img, .article img, .projectImg').each(function(el, i){
				el.addEvent('mouseover', function() {
					el.set('tween', {duration: 200, transition: Fx.Transitions.Sine.easeOut});
					el.tween('opacity', .7);
				});	
				el.addEvent('mouseout', function() {
					el.set('tween', {duration: 350, transition: Fx.Transitions.Sine.easeOut});
					el.tween('opacity', 1);	
				});
			});
		}
		
		//luma.attachScrollbar($('content_jobs'), $('scrollbar1'), $('handle1') );
		
		//its the buzz page
		if ($('content_buzz')) {
			luma.buzz.init();
		}
		
		//its the projects page
		if ($('content_projects')) {
			luma.projects.init();
		}
		
		//has news feed 
		if ($('newsFeed')) {
			luma.feed.init('', $('newsFeed'));
		}
		
		//its the about page
		if ($('aboutPics')) {
			luma.about.init();
		}
			
		//its the people page
		if ($('content_people')) {
			luma.people.init();
		}
		
		// its the jobs page
		if ($('content_jobs')) {
			luma.jobs.init();            
		}
		
		// its the project page
		if ($('projectSlides')) {
			luma.project.init();
		}
		
		// its the homepage
		if ($('mainContentVid') && luma.qtcheck()) {

			luma.reel.init();
			
		} else if ($('mainContent')) {
			$('mainContent').style.display = '';
			$('mainContentVid').style.display = 'none';	
			$('mainContentThumbs').style.display = 'none';
			
			new Request.JSON({url: baseUrl + 'ajax/slideshowImages', onSuccess: function(response){
				luma.reelImages = response;
				luma.preloadCycle(luma.reelImages);
				luma.cycleImages('mainContent',luma.reelImages,luma.cycleOffset);
				luma.cycleTimer = (function(){ luma.cycleImages('mainContent',luma.reelImages,luma.cycleOffset)}).periodical(8000, luma);
				
			}}).get();	
		
		}
		
		
		if ($('projectSlidesContent')) {
			$$('.reelImg').each(function(el, i) {
				if (el.getElement('img')) {
					el.getElement('img').set('tween', {duration: 350, transition: Fx.Transitions.Sine.easeOut});
				
					el.addEvent('mouseover', function() {
						el.getElement('img').tween('opacity', 1);	
					});
					el.addEvent('mouseout', function() {
						el.getElement('img').tween('opacity', 0);	
					});
				}
			});
			
			$$('.reelLink').each(function(el, i) {
				el.getElement('.download img').set('tween', {duration: 350, transition: Fx.Transitions.Sine.easeOut});
			
				el.addEvent('mouseover', function() {
					el.getElement('.download img').tween('opacity', 1);	
				});
				el.addEvent('mouseout', function() {
					el.getElement('.download img').tween('opacity', 0);	
				});
			});
		}


		// need to find out if we have a hash var and expand to it here
		//luma.history.timer = (function(){ luma.history.check()}).periodical(10, luma);
		
		if ($('content') && browser.name != 'MSIE') {
			$('content').set('tween', {duration: 250, transition: Fx.Transitions.Sine.easeOut});
			$('content').tween('opacity', [0,1]);	
		}
		
		luma.easteregg.init();
		
		// attach project feeds
		$$('.projectFeed').each(function(el) {
			//el
		});

	},
	
	easteregg: {
		init: function() {
			luma.keybindings.bindings = {};
			if ($('content_people')) {
				luma.keybindings.bindings.people = {
					event: luma.easteregg.people,
					modifier: 'alt',
					key: 'D'
				}
			}

			if ($('mainContentVid')) {
				luma.keybindings.bindings.yaris = {
					event: luma.easteregg.yaris,
					modifier: 'alt',
					key: 'Y'
				}
			}
			
			if (luma.reel.movie) {
				luma.keybindings.bindings.movie = {
					event: luma.easteregg.playMovie,
					modifier: '',
					key: ' '
				}
			}
			
			luma.keybindings.bindings.swapcss = {
				event: luma.easteregg.swapCss,
				modifier: 'alt',
				key: 'C'
			}
			luma.keybindings.bindings.pink = {
				event: luma.easteregg.pink,
				modifier: 'alt',
				key: 'P'
			}
				
			luma.keybindings.init();
		},

		yaris: function() {
			luma.reel.play('7');
		},
		playMovie: function() {
			luma.movie.play();
		},
		swapCss: function() {
			luma.swapCss.swap();
		},
		pink: function() {
			document.body.setStyle('background-color','#ff27a6');
		},
		people: function() {		
			$$('.hidden_person').each(function(el) {
				el.setStyle('display', '');
			});
		}
	},	
	
	keybindings: {
		bindings: {},
		init: function() {
			var element = document;
			if (element.addEventListener) {
				//element.addEventListener("keydown", luma.keybindings.listener, false);
				element.addEventListener("keyup", luma.keybindings.listener, false);
				element.addEventListener("keypress", luma.keybindings.listener, false);
			} else if (element.attachEvent) {
				element.attachEvent("onkeydown", luma.keybindings.listener);
				element.attachEvent("onkeyup", luma.keybindings.listener);
				element.attachEvent("onkeypress", luma.keybindings.listener);
            }
        },
        
		listener: function(e) {
			e = e || window.event;
			// get keycode
			var code;
			var ret;
			if (e.keyCode) {
				code = e.keyCode;
			} else if (e.which) {
				code = e.which;
			}
			// translate to character (no special key translation yet)
			var ch = String.fromCharCode(code);

			for (x in luma.keybindings.bindings) {
				if (
					(
						(luma.keybindings.bindings[x].modifier == 'alt' && e.altKey)
						|| (luma.keybindings.bindings[x].modifier == 'ctrl' && e.ctrlKey)
						|| luma.keybindings.bindings[x].modifier == ''
					)
					&& ch == luma.keybindings.bindings[x].key) {
					luma.keybindings.bindings[x].event();
					ret =  luma.keybindings.cancelEvent(e);
				} else {
					ret =  true;
				}
			}
			return ret;
        },
        
		cancelEvent: function(e) {
			// try to prevent sideeffects (browser defults)
			e = e || window.event;
			e.cancelBubble = true;
			e.returnValue = false;
			if (e.stopPropagation) e.stopPropagation();
			if (e.preventDefault) e.preventDefault();	
			return false;
        }
	
	},
	
	staticHeight: 0,
	resizeFooter: function() {

		if ($(document.body).getHeight()-155 > $('wrapper').getHeight()) {
			$('wrapperMatcher').setStyle('height',$(document.body).getHeight()-155-1);
		} else {
			$('wrapperMatcher').setStyle('height',$('wrapper').getHeight()-155-1);
		}
	},
	
	jobs: {
		accordion: [],
		init: function () {
			$$('.accordion').each(function(el) {
				el = $(el);
				var accordion = new Accordion(el, (el.hasClass('one') ? '.one' : '.two') + ' div.jobTitle h1', (el.hasClass('one') ? '.one' : '.two') + ' div.job', {
					opacity: true,
					alwaysHide: true,
					display: -1,
					duration: 350,
					transition: Fx.Transitions.Sine.easeOut
				});
			});
	
		},
		populateEmail: function(jobId) {
			// traverse the dom and populate an email link, then launch it
			
			new Request.JSON({
				url: baseUrl + 'jobs/email?id=' + jobId,
				onSuccess: function(response){
					location.href = response.content;
				}
			}).get();
			
		}
	},
	
	navigation: {
		uninits: [],
		init: function(classname) {
			$$(classname).each(function(el) {
				el.addEvent('mouseover', function() {
					// weird hack to get opacity to work when the element is set to display non
					if (!luma.navigation.uninits[el.getElement('li.full').get('id')]) {
						el.getElement('li.full').style.display = '';
						el.getElement('li.full').setStyle('opacity',0);
						luma.navigation.uninits[el.getElement('li.full').get('id')] = true;
					} else {
						el.getElement('li.full').style.display = '';
					}

					el.getElement('li.full').set('morph', {duration: 300, transition: Fx.Transitions.Quart.easeOut});
					el.getElement('li.full').morph({
						'opacity': 1
					});


				});
				el.addEvent('mouseout', function() {
					el.getElement('li.full').set('morph', {duration: 300, transition: Fx.Transitions.Quart.easeOut});
					el.getElement('li.full').morph({
						'opacity': 0
					});
					
				});
			});		
		}
	},
	
	project : {
		slides: {},
		slideCollection: {},
		videos: {},
		currentVideo: null,
		current: 0,
		distance: 408,
		init: function() {
			luma.project.slides = new Fx.Scroll('projectSlides', {
				duration: 650,
				transition: Fx.Transitions.Quad.easeOut

			});
			/*
			for (x in luma.project.slideCollection) {
				luma.project.showImage( luma.project.slideCollection[x]);
				break;
			}
			*/
			eval(luma.project.initcmd);
			luma.project.slides.toTop();
		},
		
		scroll: function(direction) {

			var positionCurrent = $('projectSlides').getPosition($('projectSlidesContainer'));

			luma.project.slides.cancel();

			var items = $('projectSlidesContent').getElements('div');
			if (direction == 'back') {
				luma.project.current -= 4;
			} else {
				luma.project.current += 4;
			}
			if (luma.project.current <= 0) {
				luma.project.slides.toTop();
				luma.project.current = 0;
				if ($('slidesUp')) {
					$('slidesUp').style.display = 'none';
				}
				if ($('slidesDown')) {
					$('slidesDown').style.display = '';
				}
			} else if (items[luma.project.current]) {
				var pos = items[luma.project.current];
				luma.project.slides.toElement(pos);
				if (items[luma.project.current+4]) {
					if ($('slidesDown')) {
						$('slidesDown').style.display = '';
					}
				} else {
					if ($('slidesDown')) {
						$('slidesDown').style.display = 'none';
					}
				}
				if ($('slidesUp')) {
					$('slidesUp').style.display = '';
				}
			} else {
				luma.project.slides.toBottom();
				luma.project.current = items.length-4;
				if ($('slidesDown')) {
					$('slidesDown').style.display = 'none';
				}
				if ($('slidesUp')) {
					$('slidesUp').style.display = '';
				}
			}		

		},
		
		showVideo: function(movie) {
	
			if (luma.project.movie) {
				luma.project.movie.destruct();
			}
			$('projectImage').innerHTML = '';
			luma.project.movie = new QuickControl('/assets/reel/' + luma.project.videos[movie].video, {
				id: 'mainVid',
				width: 960,
				height: luma.project.videos[movie].height,
				style: 'mainContentVid',
				container: 'projectImage',
				attributes: {
					autoplay: 'true',
					enablejavascript: 'false'
				},
				onEnded: function() {
					this.playing = false;
					luma.project.nextVideo();
				}
			});
			luma.project.currentVideo = movie;
			$('projectImage').setStyle('height',(luma.project.videos[movie].height+20) + 'px');
		},
		
		nextVideo: function() {
			var previous = '';
			
			for (x in luma.project.videos) {
				if (previous == luma.project.currentVideo) {
					luma.project.showVideo(x);
					return;
				}
				previous = x;
			}
			
			for (x in luma.project.videos) {
				//luma.project.showVideo(x);	
				//return;
			}
		},
		
		showImage: function(img) {
			if (luma.project.movie) {
				$('projectImage').innerHTML ='';
				luma.project.movie.destruct();
				luma.project.movie = null;
			}
			
			if ($('project_new')) {
				$('project_new').set('id','project_old');
				$('project_old').setStyle('z-index','1');
			}
			
			var content = new Element('div', {
			    'id': 'project_new',
			    'class': 'rounded',
			    'styles': {
			    	'z-index': 2,
			        'opacity': 0,
					'position': 'absolute',
			        'background': 'url(' + img + '?height=399&width=960&crop=1&rounded=3) center center',
			        'height': '399px',
			        'width': '960px',
			        'float': 'left',
			        'clear': 'none'
			    }
			});			
	
			if ($('project_old')) {
				var myEffects = new Fx.Morph('project_old', luma.transitions.shotFade);	 
				myEffects.start({
				    'opacity': 0
				}).chain(function() {
					$('project_old').destroy();
				});
			}
			
			$('projectImage').grab(content,'top');
			$('projectImage').setStyle('height','399px');
	
			var myEffects = new Fx.Morph('project_new', luma.transitions.shotFade);		 
			myEffects.start({
			
			    'opacity': 1
			});
		}		
	},
	
	reel: {
		movie: null,
		current: 0,
		init: function(movie) {
		if (console) {
			console.log('asd');
		}
			$('mainContent').style.display = 'none';
			$('mainContentVid').style.display = '';	
			$('mainContentThumbs').style.display = '';
		
			new Request.JSON({url: baseUrl + 'ajax/homeReels', onSuccess: function(response){
				luma.reel.reels = response;
				var completed = false;
				for (x in luma.reel.reels) {
					if (luma.reel.reels[x].play == '1') {
						luma.reel.play(x);
					}
				}							
			}}).get();
			
			//$('reelDownload').set('href','/assets/reel/1080/' + luma.reel.reels[movie].file + '.mov');
					
		},
		create: function(movie) {
			luma.reel.movie = new QuickControl('/assets/reel/' + luma.reel.reels[movie].file, {
				id: 'mainVid',
				width: 1200,
				height: 473,
				style: 'mainContentVid',
				container: 'mainContentVid',
				attributes: {
					autoplay: 'true',
					enablejavascript: 'false'
				},
				onEnded: function() {
					this.playing = false;
					luma.reel.next();								
				}
			});
		},
		next: function() {
			var previous = '';
			var completed = '';
			
			for (x in luma.reel.reels) {
				if (previous == luma.reel.current) {
					if (!luma.reel.reels[x].active || luma.reel.reels[x].active == '0') {
						previous = x;
					} else {
						luma.reel.play(x);
						return;
					}	
				}
				previous = x;
			}

			// if we havent played anything yet play the first
			for (x in luma.reel.reels) {
				luma.reel.play(x);	
				return;
			}
			
		},
		play: function(movie) {
					
			if (luma.reel.current != movie || !luma.reel.movie) {

				if (luma.reel.current) {
					var reelIcon = $('reel_img_' + luma.reel.current);
					if (reelIcon) {
						reelIcon.setStyle('background',reelIcon.getStyle('background').replace(')', '?bw=1)'));
					}
				}
				
				luma.reel.current = movie;
				
				if (luma.reel.movie) {
					luma.reel.movie.destruct();
				}
				
				luma.reel.create(movie);
				
				var reelIcon = $('reel_img_' + movie);
				if (reelIcon) {
					reelIcon.setStyle('background',reelIcon.getStyle('background').replace('?bw=1', ''));
				}
			}
		},		
		launchQt: function(movie) {
			return false;
			movie = baseUrl + 'assets/reel/' + luma.reel.reels[movie].download;

			$('qtLauncher').innerHTML = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="1" width="1"><param name="src" value="' + movie + '"/><param name="controller" value="false" /><param name="target" value="QuickTimePlayer" /><param name="href" value="' + movie + '" /><param name="bgcolor" value="#FFFFFF" /><param name="wmode" value="transparent" /><param name="autohref" value="true" />'
				+ '<embed hidden id="reelDownload" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/" height="1" width="1" src="' + movie + '" controller="false" target="QuickTimePlayer" href="' + movie + '" autohref="true" /></object>';
				
			if (luma.reel.movie) {
				luma.reel.movie.clear();
				luma.reel.movie = null;
			}
		}
	},
	
	history: {
		timer: null,
		hash: '',
		getHash: function () {
			var hash = location.hash;
			var hashReplace = /#(.*)/;
			hash = hashReplace.exec(hash);
			if (hash) {
				hash = hash[1];
			}
			return hash;

		},
		check: function() {
			var hash = this.history.getHash();
    		if (hash && hash != luma.history.hash) {
        		luma.history.hash = hash;
        		luma.displayPage(hash);
    		} else {
	    		luma.history.hash = 'home';
	        	luma.displayPage(luma.history.hash);
	    	}
		}
	},

	preloadCycle: function(images) {
		var content = '';
		for (var x = 0; x < images.length; x++) {
			content += '<img src="/assets/images/thumb/' + images[x].image +'?rounded=3&width=1200&height=496&crop=1" style="float: left; height: 1px; width: 1px;">';
		}
		$('preloader').innerHTML = content;		
	},
	cycleTimer: {},
	cycleOffset: 0,
	cycleImages: function(destination,images,offset) {

		var otherId = (offset == 0) ? (images.length - 1) : (offset - 1);
		
		var content = new Element('div', {
		    'id': destination + '_' + offset,
		    'class': 'rounded',
		    'html': images[offset].content,
		    'styles': {
		    	'z-index': 2,
		        'opacity': 0,
				'position': 'absolute',
		        'background': 'url(/assets/images/thumb/' + images[offset].image +'?rounded=3&width=1200&height=496&crop=1) center center',
		        'height': '496px',
		        'width': '1200px',
		        'float': 'left',
		        'clear': 'none'
		    }
		});

		if ($(destination + '_' + otherId)) {
			var myEffects = new Fx.Morph(destination + '_' + otherId, luma.transitions.shotFade);	 
			myEffects.start({
			    'opacity': 0
			}).chain(function() {
				$(destination + '_' + otherId).destroy();
			});
		}

		$(destination).grab(content,'top');

		var myEffects = new Fx.Morph(destination + '_' + offset, luma.transitions.shotFade);		 
		myEffects.start({
		    'opacity': 1
		});
		
		offset++;

		if (offset > images.length-1) {
			offset = 0;
		}
		luma.cycleOffset = offset;		

	},
	people: {
		init: function() {
			$$('.staffHover').each(function(el, i) {
				if (el.getElement('.large')) {
				
					el.getElement('.large img').setStyle('height',el.getElement('.small img').getStyle('height').replace('px', '')*2);
					el.getElement('.large img').setStyle('width',el.getElement('.small img').getStyle('width').replace('px', '')*2);
					el.getElement('.large img').setStyle('margin-top',-el.getElement('.small').getStyle('height').replace('px', '')-1);
					el.getElement('.large img').setStyle('margin-left',-el.getElement('.large').getStyle('width').replace('px', '')/2);
					el.getElement('.large').set('tween', {duration: 350, transition: Fx.Transitions.Sine.easeOut});
				
					el.addEvent('mouseover', function() {
						el.getElement('.large').tween('opacity', 1);	
					});
					el.addEvent('mouseout', function() {
						el.getElement('.large').tween('opacity', 0);
					});	
				}				
			});
		}
	},
	feed: {
		items: [],
		current: 0,
		init: function(id_project, target) {

			new Request.JSON({url: baseUrl + (id_project ? ('ajax/projectFeed?id_project=' + id_project) : 'ajax/newsFeed'), onSuccess: function(response){
				luma.feed.items = response;
				luma.feed.cycle(target); 
				(function(){ luma.feed.cycle(target); }).periodical(10000,this);
			}}).get();	

		},
		cycle: function(destination) {

			var otherId = (luma.feed.current == 0) ? (luma.feed.items.length - 1) : (luma.feed.current - 1);
			
			if (luma.feed.items[luma.feed.current]) {
				var htmlContent = '<a href="' + luma.feed.items[luma.feed.current].url + '">';
				if (luma.feed.items[luma.feed.current].type) {
					htmlContent += '<b>' + luma.feed.items[luma.feed.current].type + ': </b>' + luma.feed.items[luma.feed.current].title;
				} else {
					htmlContent +=  luma.feed.items[luma.feed.current].title;
				}

				
				
				var content = new Element('div', {
				    'id': destination + '_' + luma.feed.current,
				    'class': 'rounded feedContainer',
				    'html': '<table cellpadding="0" cellspacing="0"><tr><td>' + htmlContent + '</td></tr></table>',
				    'styles': {
				    	'z-index': 2,
				        'opacity': 0,
						'position': 'absolute',
				        'float': 'left',
				        'clear': 'none',
				        'font-size': '12px'
				    }
				});
		
				if ($(destination + '_' + otherId)) {
					var myEffects = new Fx.Morph(destination + '_' + otherId, luma.transitions.shotFade);	 
					myEffects.start({
					    'opacity': 0
					}).chain(function() {
						$(destination + '_' + otherId).destroy();
					});
				}
		
				$(destination).grab(content,'top');
		
				var myEffects = new Fx.Morph(destination + '_' + luma.feed.current, luma.transitions.shotFade);		 
				myEffects.start({
				    'opacity': 1
				});
				
				luma.feed.current++;
		
				if (luma.feed.current > luma.feed.items.length-1) {
					luma.feed.current = 0;
				}
				luma.feed.current = luma.feed.current;
				
			} else {
				var htmlContent = '';
			}
		}
	},	
	
	about: {
		items: [],
		current: 1,
		init: function() {		
			new Request.JSON({url: baseUrl + 'ajax/aboutPics', onSuccess: function(response){
				luma.about.items = response;
				luma.about.cycle($('aboutPics')); 
				//(function(){ luma.about.cycle($('aboutPics')); }).periodical(5000,this);
			}}).get();
		},
		cycle: function(destination) {
			
			var otherId = (luma.about.current == 0) ? (luma.about.items.length - 1) : (luma.about.current - 1);

			var content = new Element('div', {
			    'id': destination + '_' + luma.about.current,
			    'class': 'rounded',
			    'html': '',
			    'styles': {
			    	'z-index': 2,
			        'opacity': 0,
					'position': 'absolute',
			        'height': '416px',
			        'width': '800px',
			        'float': 'right',
			        'background': 'url('+ luma.about.items[luma.about.current] + ')',
			        'clear': 'none'
			    }
			});
	
			if ($(destination + '_' + otherId)) {
				var myEffects = new Fx.Morph(destination + '_' + otherId, luma.transitions.shotFade);	 
				myEffects.start({
				    'opacity': 0
				}).chain(function() {
					$(destination + '_' + otherId).destroy();
				});
			}
	
			$(destination).grab(content,'top');
	
			var myEffects = new Fx.Morph(destination + '_' + luma.about.current, luma.transitions.shotFade);		 
			myEffects.start({
			    'opacity': 1
			});
			
			luma.about.current++;
	
			if (luma.about.current > luma.about.items.length-1) {
				luma.about.current = 0;
			}
			luma.about.current = luma.about.current;
		}

	},
	
	projects: {
		init: function() {
			$$('.tab.contents').each(function(el, i) {
				if (el.getStyle('display') != 'none') {
					$('tabsections').setStyle('height',el.getHeight() + 'px');
				}
			});
			var activeTab = luma.cookie.get('tab_project');
			if (activeTab) {
				luma.projects.swap(activeTab);
			}
			var hash = luma.history.getHash();
			if (hash == 'commercials') {
				luma.projects.swap('tab_commercials');
			}
		},
		swap: function(item) {
			luma.cookie.set('tab_project',item);
			var container = item + '_container';
			item = $(item);			
			

			if (item && $(container)) {
				var link = $(container).getElement('a');
			
				$$('.projects .tab').each(function(el, i) {
					if (el != item) {
						var myEffects = new Fx.Morph(el, luma.transitions.moveShotOut);	 
						myEffects.start({
						    'opacity': 0
						}).chain(function() {
							item.setStyle('display','');
							var myEffects = new Fx.Morph(item, luma.transitions.moveShotIn);		 
							myEffects.start({
							    'opacity': 1
							});	
							
							el.setStyle('display','none');
						});
					}
				});
				
				$$('.projects .tablinks .tabContainer').each(function(el, i) {
					var elLink = el.getElement('a');
					if (elLink != link) {
						var arrow = el.getElement('.tabarrow');
						arrow.setStyle('display','none');
						elLink.addClass('inactive');
					} else {
						var arrow = el.getElement('.tabarrow');
						arrow.setStyle('display','');

						arrow.setStyle('margin-left',((el.getWidth()/2)-15) + 'px');
						elLink.removeClass('inactive');
					}
				});
			}
		}
	},
	
	buzz: {
		init: function() {
			$$('.tab.contents').each(function(el, i) {
				if (el.getStyle('display') != 'none') {
					$('tabsections').setStyle('height',el.getHeight() + 'px');
				}
			});
			// this is a safari 4 hack to force it to redraw the images and margins
			// -devin 2010.01.19
			$('buzzArticleContents').innerHTML = $('buzzArticleContents').innerHTML + ' ';
			Mediabox.scanPage();
		},
		
		swapdates: function(item, link) {

			item = $(item);

			if (item) {					
			
				$$('.buzz .datetab').each(function(el, i) {
					if (el != item) {
						var myEffects = new Fx.Morph(el, luma.transitions.moveShotOut);	 
						myEffects.start({
						    'opacity': 0
						}).chain(function() {
							el.setStyle('display','none');
							item.setStyle('display','');
							var myEffects = new Fx.Morph(item, luma.transitions.moveShotIn);		 
							myEffects.start({
							    'opacity': 1
							});	
						});
					}
				});
				
				$$('.buzz .tablinks.dates a').each(function(el, i) {
					if (el != link) {
						el.addClass('inactive');
					} else {
						el.removeClass('inactive');
					}
				});
			}
		},
		swap: function(item, container) {
			item = $(item);
			var link = $(container).getElement('a');

			if (item) {
			
				$$('.buzz .tab').each(function(el, i) {
					if (el != item) {
						var myEffects = new Fx.Morph(el, luma.transitions.moveShotOut);	 
						myEffects.start({
						    'opacity': 0
						}).chain(function() {
							item.setStyle('display','');
							var myEffects = new Fx.Morph(item, luma.transitions.moveShotIn);		 
							myEffects.start({
							    'opacity': 1
							});	
							
							el.setStyle('display','none');
						});
					}
				});
				
				$$('.buzz .tablinks.sections .tabContainer').each(function(el, i) {
					var elLink = el.getElement('a');
					if (elLink != link) {
						var arrow = el.getElement('.tabarrow');
						arrow.setStyle('display','none');
						elLink.addClass('inactive');
					} else {
						var arrow = el.getElement('.tabarrow');
						arrow.setStyle('display','');

						arrow.setStyle('margin-left',((el.getWidth()/2)-15) + 'px');
						elLink.removeClass('inactive');
					}
				});
			}
		}
	},

	qtcheck: function() {
		//@todo: fix this function to check properly
		return true;
		if (navigator.plugins) {
			for (i=0; i < navigator.plugins.length; i++ ) {
				if (navigator.plugins[i].name.indexOf("QuickTime") >= 0) {
					return true;
				}
			}
		}
		
		if ((navigator.appVersion.indexOf("Mac") > 0) && (navigator.appName.substring(0,9) == "Microsoft") && (parseInt(navigator.appVersion) < 5) ) {
			return true;
		}
		
		return false;
	},
	reelImages: []
}

window.addEvent('domready', function() {
	luma.init();
	
});

function initScreen() {
	setTimeout('window.scrollTo(0,1);',100);
}
function updateOrientation() {
	initScreen();
} 