Event.observe(document, 'dom:loaded', function() {
	
	// Bail on IE 6
	if (Prototype.Browser.IE) {
      var m = navigator.appVersion.match(/^.*MSIE\s*(\d+).*$/);
      if (!m || parseInt(m[1], 10) < 7) {
          return;
      }
    }
	
	var movieGroups=$H({
		'debate' : [
			{'id':'UgHun7Bxr8w', 'weight':3, 'thumb':2, 'caption':'Mac vs. PC: Moving Day'},
			{'id':'tteuCwb491U', 'weight':3, 'thumb':2, 'caption':'Mac vs. PC: Dress Up'},
			{'id':'PT5_TbUeGRw', 'weight':3, 'thumb':2, 'caption':'Mac vs. PC: Vista'},
			{'id':'gQRe_l2kXoA', 'weight':3, 'thumb':1, 'caption':'Mac vs. PC: No Domino'}
		],
		
		'work' : [
			{'id':'Kk22hWdpW8Y', 'weight':2, 'thumb':1, 'caption':'Brian talks about Near Infinity employees enjoying their work and having a passion for technology.'},
			{'id':'ea-GP_7DZJE', 'weight':3, 'thumb':1, 'caption':'Caroline expresses her appreciation for working with seasoned developers.'},
			{'id':'HcsymZr1rBg', 'weight':2, 'thumb':1, 'caption':'Chris talks about Near Infinity’s reputation.'},
			{'id':'BpKlcY_jbPU', 'weight':2, 'thumb':1, 'caption':'Jay talks about working with intelligent people.'},
			{'id':'zpZXWupTZF4', 'weight':2, 'thumb':1, 'caption':'Jeff talks about celebrating what all Near Infinity employees have in common – a passion for technology.'},
			{'id':'6Pjtmkn-8yw', 'weight':3, 'thumb':3, 'caption':'Jeff talks about how the company has evolved over time.'},
			{'id':'QS0FVAgbgpc', 'weight':3, 'thumb':1, 'caption':'Working with geniuses! John talks about the mark of quality at Near Infinity.'},
			{'id':'P_39GURVRD8', 'weight':3, 'thumb':1, 'caption':'Matt talks about what makes Near Infinity unique – its people.'},
			{'id':'YJTqwQ5d02o', 'weight':3, 'thumb':2, 'caption':'Passion, excitement, and being on the bleeding edge of technology – Mike says it’s all there.'},
			{'id':'-vwUvpSNxmE', 'weight':2, 'thumb':1, 'caption':'Nancy talks about being able to choose your own career path at Near Infinity.'},
			{'id':'pk6NJQJmXto', 'weight':3, 'thumb':1, 'caption':'Paul describes the benefits of working for a small company like Near Infinity.'},
			{'id':'Bpz6pMurFk8', 'weight':1, 'thumb':1, 'caption':'Scott talks about the quality of the people at Near Infinity.'}
		],
		
		'play' : [
			{'id':'5JNhp1UG8cQ', 'weight':1, 'thumb':1, 'caption':'Al about Near Infinity: it’s like one big family.'},
//employee departed	{'id':'Lve6fJHccc0', 'weight':2, 'thumb':1, 'caption':'Ben discusses the cohesive relationship NIC employees share.'},
			{'id':'Rj5uT6cAb7g', 'weight':3, 'thumb':1, 'caption':'Employees talk about unparalleled camaraderie at Near Infinity.'},
			{'id':'ZZDRwBkzX28', 'weight':2, 'thumb':1, 'caption':'Chris discusses the importance of family at Near Infinity.'},
			{'id':'gHG4yPDjNlM', 'weight':3, 'thumb':1, 'caption':'Dave sheds some light on the atmosphere at NIC.'},
			{'id':'ljtRRiVHFco', 'weight':3, 'thumb':3, 'caption':'Jeff shares his thoughts about work, family, and fun at Near Infinity.'},
			{'id':'XaU9Gqz7Jhk', 'weight':3, 'thumb':1, 'caption':'Mac or PC?'},
			{'id':'tA8itLRpoVI', 'weight':3, 'thumb':1, 'caption':'We are as intense on the field as we are in the office!'}
		],
		
		'learn' : [
			{'id':'j0p74VmW0dk', 'weight':1, 'thumb':1, 'caption':'Andrew talks about expanding his horizons by learning Ruby and Java.'},
			{'id':'PnvlM8z2aEs', 'weight':2, 'thumb':1, 'caption':'Bob introduces Near Infinity’s exciting new NIC-U program.'},
			{'id':'GIwenpw4ovA', 'weight':3, 'thumb':1, 'caption':'Bryan discusses how NIC encourages employees to consistently expand their skills.'},
			{'id':'mYb9rA1cbb4', 'weight':2, 'thumb':1, 'caption':'Jason talks about learning the Agile methodology and Java and giving presentations at NIC.'},
			{'id':'tWbZGfA-HNA', 'weight':3, 'thumb':2, 'caption':'Removing the red tape: Karen talks about how accessible training is to NIC employees.'},
			{'id':'Yt95m2YQbGw', 'weight':3, 'thumb':3, 'caption':'Steve talks about the investment Near Infinity puts into their employees.'},
			{'id':'rY7x6oX8kCc', 'weight':3, 'thumb':1, 'caption':'Employees converse about the technologies they want to learn more about.'}
			//, {'id':'', 'weight':3, 'thumb':1, 'caption':'Employees share why they choose to join NIC.'}
		]
	});

	var moviePools = $H();

	movieGroups.each(function(movieGroup){
		var moviePool = [];
		movieGroup.value.each(function(movie){
			movie.weight.times(function(){ moviePool.push(movie); });
		});
		moviePools[movieGroup.key] = moviePool;
	});

	$$('.randommovie').each(function(el){
		var movieType = el.classNames().find(function(cls){return moviePools[cls];});	
		var moviePool = moviePools[movieType];
		var movie = moviePool[Math.floor(Math.random() * moviePool.length)];
		var thumbnail = el.down('img');
		var thumbnailSize = thumbnail.getDimensions();
		
		el.down('.caption').innerHTML = movie.caption;

		thumbnail.insert({after:'<img width="37" height="36" class="playbutton" src="images/play_button.png" />'});
		el.down('img.playbutton').absolutize().clonePosition(thumbnail, {setWidth: false, setHeight: false, offsetLeft:(thumbnailSize.width-42)/1 , offsetTop:(thumbnailSize.height-86)/2});
		
		thumbnail.src = 'http://img.youtube.com/vi/#{id}/#{thumb}.jpg'.interpolate(movie);
		el.select('a').each(function(a){
			a.href = 'http://www.youtube.com/v/#{id}'.interpolate(movie);
			a.addClassName('lightwindow');
			a.addClassName('page-options');
			a.setAttribute('params', 'lightwindow_width=425,lightwindow_height=340,lightwindow_loading_animation=false');
		});
		
		moviePools[movieType] = moviePool.without(movie);
	});
		
	// Clean up... we're done
	moviePools = null;
	movieGroups = null;
});
