var editorialOpen = false;
var copywritingOpen = false;
var filmandscriptingOpen = false;

$(function() {

	if (!($.browser.msie && $.browser.version < 7))
	{
		$('.editorial-sub').hide();
		$('.editorial').click(openEditorial);
		
		$('.copywriting-sub').hide();
		$('.copywriting').click(openCopywriting);
		
		$('.film-and-scripting-sub').hide();
		$('.film-and-scripting').click(openFilmAndScripting);
		
		//$('.openable_image').hide();
		//$('.more_content').hide();
		$('.opener').html('<img src="images/arrow_more.png" width="17" height="17" alt="Show more...">');
		//$('.opener').click(showMoreContent);
		
		if ($('#content_scroller').length==1)
		{
			//$('#content_scroller').css({'position':'absolute', 'height':$(window).height()-270, 'overflow':'auto'});
			$('#overlay').addClass('overlay');
			$('#content_scroller').css({'position':'absolute', 'height':410, 'overflow':'auto'});
			//var scrollerPos = $(document).width();
			//scrollerPos -= 890;//$('#siteholder').width();
			//scrollerPos /= 2;
			//scrollerPos += 297;
			//$('#content_scroller').css({'width':($(document).width()-scrollerPos)+'px', 'top':'0', 'left':scrollerPos+'px', 'paddingTop':'260px'});
			resize();
	
			$('h1').css({'zIndex':10, 'position':'absolute'});
			$('#navigation').css('paddingTop', '264px');
			
			$('.openable').each(function() { $(this).data('orgheight', $(this).height()); });
		}
		$(window).resize(resize);
	}
});



function openEditorial()
{
	$('.editorial-sub').slideToggle('slow'); 
	editorialOpen = !editorialOpen;
	if (editorialOpen)
		$('.editorial .opener').html('<img src="images/arrow_less.png" width="17" height="17" alt="Show less...">');
	else
		$('.editorial .opener').html('<img src="images/arrow_more.png" width="17" height="17" alt="Show more...">');
}
function openCopywriting()
{
	$('.copywriting-sub').slideToggle('slow'); 
	copywritingOpen = !copywritingOpen;
	if (copywritingOpen)
		$('.copywriting .opener').html('<img src="images/arrow_less.png" width="17" height="17" alt="Show less...">');
	else
		$('.copywriting .opener').html('<img src="images/arrow_more.png" width="17" height="17" alt="Show more...">');
}
function openFilmAndScripting()
{
	$('.film-and-scripting-sub').slideToggle('slow'); 
	filmandscriptingOpen = !filmandscriptingOpen;
	if (filmandscriptingOpen)
		$('.film-and-scripting .opener').html('<img src="images/arrow_less.png" width="17" height="17" alt="Show less...">');
	else
		$('.film-and-scripting .opener').html('<img src="images/arrow_more.png" width="17" height="17" alt="Show more...">');
}

function resize()
{
	var scrollerPos = $(window).width();
	scrollerPos -= 890;//$('#siteholder').width();
	scrollerPos /= 2;
	scrollerPos += 297;
	$('#content_scroller').css({'width':($(window).width()-scrollerPos)+'px', 'top':'0', 'left':scrollerPos+'px', 'paddingTop':'260px'});	
}

function showMoreContent()
{
	var newHeight = $(this).attr('rel');
	
	//alert($(this).find('img').attr('src'));
	
	if ($(this).parent().parent().css('height')==newHeight+'px')
	{
		//$(this).parent().parent().animate({'height':$(this).parent().find('img').height()+'px'});
		$(this).parent().parent().animate({'height':$(this).parent().parent().data('orgheight')+'px'});
		$(this).find('img').attr('src','images/arrow_more.png');
		$(this).parent().parent().find('.more_content').fadeOut();
		$(this).parent().parent().find('.openable_image').fadeOut();
	}
	else
	{
		$(this).parent().parent().animate({'height':newHeight+'px'});
		$(this).find('img').attr('src','images/arrow_less.png');
		$(this).parent().parent().find('.more_content').fadeIn();
		$(this).parent().parent().find('.openable_image').fadeIn();
	}
}
