$(function() {
	
	// Defunktify on tab switch
	$('.idTabs li a').click(function()
	{
		$('.expand-all').html('expand all sections');
		$('.all-open').removeClass('all-open');
		$('.open').removeClass('open');
		$('.expand').html('expand');
	});
	
	// expand all 
	$('.expand-all').click(function()
	{
		if ($(this).hasClass('all-open'))
		{
			$('.expand-all').removeClass('all-open');
			$('.expand-content').removeClass('open');
			$('.expand-all').html('expand all sections');
			$('.expand').html('expand');
		}
		else
		{
			$('.expand-all').html('collapse all sections');
			$('.expand-all').addClass('all-open');
			$('.expand-content').addClass('open');
			$('.expand').html('collapse');	
		}
		return false;
	});
	
	// expand one
	$('.expand-top').click(function()
	{
		if ($(this).siblings('.expand-content').hasClass('open'))
		{
			$(this).siblings('.open').removeClass('open');
			$(this).children('.expand').html('expand');
		}
		else
		{
			$(this).siblings('.expand-content').addClass('open');
			$(this).children('.expand').html('collapse');
		}
		return false;
	});
	
	
	// Lightbox for images
	$('a[href$=".jpg"]').fancybox();
	// Lightbox for youtube videos
	$('a[href*="http://www.youtube.com/watch"]').click(function()
	{
		$.fancybox({
			'autoScale': true,
			'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type': 'swf',
			'swf': {'wmode': 'transparent', 'allowfullscreen': 'true'}
		});

		return false;
	});
	// Lightbox for youtube playlists
	$('a[href*="http://www.youtube.com/playlist"]').click(function()
	{
		$.fancybox({
			'autoScale': true,
			'href' : this.href.replace(new RegExp("playlist\\?list=PL", "i"), 'p/') + '&hd=1',
			'type': 'swf',
			'swf': {'wmode': 'transparent', 'allowfullscreen': 'true'}
		});
		return false;
	});
	
	//Post a comment
	$('.comment').hover(function()
	{
		txt = $(this).html();
		newTxt = $(this).attr('title');
		$(this).html(newTxt);
	}, function(){
		$(this).html(txt);
	});
	
	/*// Reset default values on forms
	$('textarea').focus(function()
	{ 
		if($(this).val() == $(this).attr('defaultValue'))
		{$(this).val('');}
	});
	
	$('textarea').blur(function()
	{
		if($(this).val() == '')
		{$(this).val($(this).attr('defaultValue'));} 
	});
	$('input[type=text]').focus(function()
	{ 
		if($(this).val() == $(this).attr('defaultValue'))
		{$(this).val('');}
	});
	
	$('input[type=text]').blur(function()
	{
		if($(this).val() == '')
		{$(this).val($(this).attr('defaultValue'));} 
	});
	
	$('input[type=password]').focus(function()
	{
		if($(this).val() == $(this).attr('defaultValue'))
		{$(this).val('');}
	});
	
	$('input[type=password]').blur(function()
	{
		if($(this).val() == '')
		{$(this).val($(this).attr('defaultValue'));} 
	});*/
	
});

function redirectTo(location)
{
	window.location = location;
}

function suggestAccountUrl()
{
	var accountUrlTextField = document.getElementById('account_url');
	accountUrlTextField.value = document.getElementById('account_name').value.replace(/ /g, '');
}
