// JavaScript Document
var RandomImage = new function() {
	var image_directory = 'production-company/images';
	
	var images = {
		'homepage.jpg': ['Hotbed Goes Animal for the Phoenix Zoo', 'production-company/commercials/arizona_zoo_otter.html'],
		'homepage_tortoise.jpg': ['Hotbed Goes Animal for the Phoenix Zoo', 'production-company/commercials/arizona_zoo_tortoise.html'],
		'rodbanner.jpg': ['', 'production-company/entertainment/rodhunter007challenge.html'],
		'homepage_jamie.jpg': ['Hotbed Captures Kripke', 'production-company/documentaries/jamie.html'],
		'homepage_banner.jpg': ['Hotbed Tackles LT for Vizio', 'production-company/documentaries/LT.html'],
		'homepage_aldo.jpg': ['Hotbed Kicks Off Its Shoes For ALDO', 'production-company/commercials/aldo_shoes.html'],
		'homepage_citrix_xenapp.jpg': ['Hotbed Goes Wild for Citrix', 'production-company/brand-films/citrix-xenapp.html']
	};
	
	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();
});
