$(document).ready(function() {
	
	// dynamic text
	function dynamicTextUrl(text, textFormat) {
		text = encodeURIComponent(text);
		text = text.replace('...','%2E%2E%2E') // hack
		return("/dynamic_text/"+textFormat+"/"+text+".png");
	}
	function dynamicTextReplace(elmnt, text, textFormat) {
		if(!elmnt.replacementImage) {
			elmnt.replacementImage = document.createElement("img");
			elmnt.innerHTML = "";
			elmnt.appendChild(elmnt.replacementImage);
		}
		elmnt.replacementImage.src = dynamicTextUrl(text, textFormat);
		elmnt.replacementImage.alt = text;
	}
	$('#navigation .nav li a').each(function(){ dynamicTextReplace(this, this.innerHTML, "nav"); });
	//$('#subnavigation .nav li a').each(function(){ dynamicTextReplace(this, this.innerHTML, "subnav"); });


	$('h1.link a, h1.header').each(function(){ 
		this.innerHTML = this.innerHTML.toUpperCase();
		dynamicTextReplace(this, this.innerHTML, "header"); 
	});
	$('#production h3, #productions h3').each(function(){ dynamicTextReplace(this, this.innerHTML, "signal"); });
	
	// zebra stripes
	$('table.schedule tr:odd').addClass('zebra');
	
	// vroom
	$("#header.default").click(function(){ document.location = "/" });
	
	// give me more give me less
	$("a.more").click(function(){
		$(this).fadeOut('fast');
		$('#more').fadeIn('fast');
	});
	$("a.less").click(function(){
		$('.more').fadeIn('fast');
		$('#more').fadeOut('fast');
	});
	
	$(".review").hide(function(){
		$(".review:first").fadeIn();	
	});
	
	$("#reviews-all").click(function(){
		$(this).fadeOut('fast');
		$('.review').fadeIn('fast');
		$('#reviews-one').fadeIn('fast');
	});
	$("#reviews-one").click(function(){
		$(this).fadeOut('fast');
		$('.review').fadeOut('fast');
		$(".review:first").fadeIn();	
		$('#reviews-all').fadeIn('fast');
	});
	
	// videos
	$('#videos a').click(function(){
		var id = $(this).attr('href'), width = 368, height = 280;
		// console.log("Video ID is: "+id);
		$('#mainImage').html('<object width="'+width+'" height="'+height+'"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id='+id+'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id='+id+'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always"  width="'+width+'" height="'+height+'"></embed></object>');
		return false;
	});

});
