// JavaScript Document
var RandomImage = new function() {
	var image_directory = 'production-company/images';
	
	var images = {
		'feature_lt.jpg': ['Hotbed Runs with LT', 'http://www.hotbed.com/production-company/documentaries/LT.html'],
		
		'otter.jpg': ['Hotbed Goes Animal', 'http://www.hotbed.com/production-company/commercials/arizona_zoo_otter-1.html'],
		
		'homepage_cc_banner.jpg': ['Groovy On Rails','http://www.hotbed.com/production-company/commercials/cc.html'],
		
		'homepage_vos_banner.jpg': ['Hotbed Feature Film','http://www.valleyofthesunthemovie.com'],
		'feature_newport.jpg': ['Valley of the Sun Plays Newport Beach', 'http://newportbeach.slated.com/2011/films/valleyofthesun_stokesmcintyre_newportbeach2011'],
		'feature_newport.jpg': ['Valley of the Sun Plays Newport Beach', 'http://newportbeach.slated.com/2011/films/valleyofthesun_stokesmcintyre_newportbeach2011'],
		'feature_newport.jpg': ['Valley of the Sun Plays Newport Beach', 'http://newportbeach.slated.com/2011/films/valleyofthesun_stokesmcintyre_newportbeach2011']
	};
	
	return {
		pickImage: function() {
			var images_with_index = RandomImage.convertToIndexArray(images);
			var index = RandomImage.getRandom(images_with_index.length - 1);
			var file_name = images_with_index[index];
			var title = images[file_name][0];
			var play_link = images[file_name][1];
			
			$('#random_image').css('background-image', 'url(' + image_directory + '/' + file_name + ')').hide().fadeIn(1000);
			$('#random_image_text').text(title);
			$('#random_image_link').attr('href', play_link);

		},
		convertToIndexArray: function(images) {
			var images_with_index = [];
			$.each(images, function(file_name) {
				images_with_index.push(file_name);
			});
			return images_with_index;
			// ['homepage.jpg', 'homepage_tortoise.jpg', 'homepage_jamie_1.jpg', 'homepage_jamie.jpg', 'homepage_banner.jpg', 'homepage_aldo.jpg']
		},
		getRandom: function(max_value) {
			return Math.floor(Math.random() * (max_value + 1));
		}
	};
};

jQuery(document).ready(function() {
	RandomImage.pickImage();
});

