$(document).ready(function()
{
	$('a.showcase').click(function()
	{
		var the_href = this.href.replace(new RegExp("watch\\?v=", "i"), 'v/')+'&autoplay=1';
		$.fancybox({
			'padding':0,
			'autoScale':false,
			'transitionIn':'none',
			'transitionOut':'none',
			'title':'',
			'width':640,
			'height':390,
			'href':the_href,
			'type':'swf',
			'swf':{'allowfullscreen':'true','wmode':'transparent'}
		});
		return false;
	});

/*
	$('a.showcase').fancybox({
		'padding'				: 0,
		'autoScale'			: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'width'					: '960px',
		'height'				: '600px',
		'swf'						: {
			'wmode':'transparent',
			//'flashvars':'videoPath=/showcase/movie.f4v&posterPath=/showcase/com/poster/myPosterFrame.jpg&skinPath=/showcase/com/skin/skin.swf'
		}
	});
*/

	$('a.login').click(function()
	{
		$('#box-signup').hide();
		$('#box-login').show();
		$('#box-login .validation-failed').removeClass('validation-failed');
		var t = $('#login').outerHeight();
		var l = ($('#login').position().left + $('#login').outerWidth()) - ($('#box-login').outerWidth() - 8);
		$('#box-login').css({'top':t+'px','left':l+'px'});
		$(window).scrollTop(0);
		return false;
	});

	$('a.signup').click(function()
	{
		if (pageTracker != undefined)
			pageTracker._trackPageview($(this).attr('href'));

		$('#overlay').show();
		$('#box-login').hide();
		$('#box-signup').show();
		$('#box-signup .validation-failed').removeClass('validation-failed');
		$('#box-signup').center();
		return false;
	});


	$(window).resize(function()
	{
		if ($('#wrapper').height() < $(window).height()){var h = Math.round(($(window).height() + 241) - ($('#footer').position().top + $('#footer').outerHeight()));$('#content').css({'min-height':h});}

		if ($('#box-login').is(':visible'))
		{
			var t = $('#login').outerHeight();
			var l = ($('#login').position().left + $('#login').outerWidth()) - ($('#box-login').outerWidth() - 8);
			$('#box-login').css({'top':t+'px','left':l+'px'});
		}
		if ($('#box-signup').is(':visible'))
		{
			$('#box-signup').center();
		}
	});

	if ($('#wrapper').height() < $(window).height()){var h = Math.round(($(window).height() + 241) - ($('#footer').position().top + $('#footer').outerHeight()));$('#content').css({'min-height':h});}
	$(document).click(function(e){if (!$(e.target).hasClass('box') && !$(e.target).parents().hasClass('box')){$('.box').hide();$('#overlay').hide();}});
	$('#nav a').live('mousedown',function(){$(this).css('margin-top', '1px');});
	$('#nav a').live('mouseup',function(){$(this).css('margin-top', '0px');});
	$('.help-box').click(function(){window.location = '/help';return false;});
	$('.twitter-box').click(function(){window.open('http://twitter.com/SimpleCMS');return false;});
	$('form').each(function(){$(this).validate();});
	$('input').live('keypress',function(e){if (e.keyCode == '13')$(this).parent().parent().parent().parent().submit();});
	$('.form-submit').live('click',function(){$form = $(this).parent().parent().parent();if ($form){if (!$form.valid())return false;$form.submit();}});
	$('.tweet-input a').click(function(){window.open('http://twitter.com/home?status=@SimpleCMS '+encodeURIComponent($('#frm_tweet').val()));});
	$('.new-window').live('click',function(){return !window.open($(this).attr('href'));});
	$('#testimonials div').hide();$('#testimonials div.'+$('#testimonials').attr('class')).show();
});

jQuery.fn.center = function()
{
	this.css('position','fixed');
	this.css('z-index','2000');
	this.css('top', ($(window).height() - this.height()) / 2 + 'px');
	this.css('left', ($(window).width() - this.width()) / 2 + 'px');
	return this;
}

