// JS for MacTV Site

$(document).ready(function() {

	var def = $('.showreel_text').html();

	$('.details').hide();
	
	//$('.showreel_item').each( function() {
	//	$(this).SlideInLeft(2000);
	//});

	$('div.showreel_item').hover(function() {
		var pr_id = $(this).attr('id');
		$(this).children('img').css('opacity', '1.0');
		$(this).siblings().children('img').css('opacity', '0.3');
		$(this).children('.details').css('bottom', '-4px');
		$(this).children('.details').show();
		$(this).siblings().children('.details').hide();
		
		// append a random number to each URL to stop IE caching the ajax requests
		// and fcuking up the multilingualness of it all
		$('.showreel_text').load('/episodes/display/' + pr_id + '#' + Math.floor(Math.random()*1000));
	}, function() {
		$('.showreel_text').html(def);
		$(this).children('.details').hide();
		$(this).children('img').css('opacity', '1.0');
		$(this).siblings().children('img').css('opacity', '1.0');
	});
	
	$('div.year ul').hide();
	
	$('div.year h2').click(function() {
		$(this).siblings('ul').slideToggle('slow');
	});
	
	$('div.mugshot').children('h2').hide();
	$('div.mugshot').children('p').hide();
	
	$('div.mugshot').css({cursor: "pointer", clear: "none", position: "relative", float: "left"});
	$('div.mugshot h2').css({padding: "20px 0 0 0", color: "#000", background: "#D2E1F9", position: "absolute", top: "0", opacity: "0.7", left: "0", width: "140px", height: "110px"});
	
	$('div.mugshot').hover(function() {
		$(this).children('h2').show();
	}, function () {
		$(this).children('h2').hide();
	});
	
	$('div.mugshot').click(function() {
		var position = $(this).position();
		var left = position.left - 30;
		var top = position.top - 40;
		var head = $(this).children('h2').text();
		var content = $(this).children('p').text();
		
		$('div#mugpop').empty();
		$('div#mugpop').css({border: "1px solid #000", position: 'absolute',top: top,  left: left, opacity: "0.97", width: "200px", height: "240px"});
		
		$('div#mugpop').append('<h3>' + head + '</h3>');
		$('div#mugpop').append('<p>' + content + '</p>');
		
		$('div#mugpop').append('<p class="close"><a href="#">X Close</a></p>');
		
		$('div#mugpop').show();
		
		$('div#mugpop').click(function() {
			$(this).hide();
		});
	});
	
	$('div.year').hide();
	$('div.first').show();
	
	$('div#productions h2').click(function() {
		var current_header = $(this).html();
		$('div.year').hide();
		$(this).next().toggle();
	});
	
	$('p.prod_title').hide();
	
	$('div.prod a').hover(function() {
		$(this).children('p.prod_title').css({cursor: "pointer", border: "1px solid #000", opacity: "0.6", padding: "20px 0 0 0", background: "#D2E1F9", color: "#000", width: '202px', height: '117px', top: '0', left: '0'});
		$(this).children('p.prod_title').show();
	}, function () {
		$(this).children('p.prod_title').hide();
	});

	$('ul.more').hide();
	
	$('a.more').click(function() {
		$(this).parent().next('.more').slideToggle('fast');
	});
	
	
});