$(document).ready(function()
{
	Shadowbox.init();
	
	if ($('#login-header #username').val() == '') {
		$('#login-header #username').focus();
	} else {
		$('#login-header #password').focus();
	}
	
	$('span.required').hide();
	
	$('#login-form #header-login').click(function()
	{
		// validate and process form here  
		$('span.required').hide();
		
		if ($('#login-form #username').val() == '')
		{  
			$('span.username').show();  
			$('#login-form #username').focus();  
			return false;  
		}  

		if ($('#login-form #password').val() == '')
		{  
			$('span.password').show();  
			$('#login-form #password').focus();  
			return false;  
		}
	});	

	$('#submit-support').click(function()
	{  
		// validate and process form here  
		$('span.required').hide();

		if ($('input#subject').val() == '')
		{  
			$('span.subject').show();  
			$(this).focus();  
			return false;  
		}  

		if ($('select#sdk-version').val() == '')
		{  
			$('span.sdk-version').show();  
			$(this).focus();  
			return false;  
		}

		if ($('textarea#description').val() == '')
		{  
			$('span.description').show();  
			$(this).focus();  
			return false;  
		}
	});
	
	//	new way of logging in
	$('#login-link').click(function()
	{
		$('#login-form').animate(
		{
			top: 0,
			opacity: 1
		}, 500, function()
		{
			$(this).fadeIn();
			$('#login-form #username').focus();
		});
		
		$('#dev-center').animate(
		{
			top: '-61px',
			opacity: 0
		}, 500, function()
		{
			$(this).hide();
			$('#header').css({top: 0});
		});
		
		return false;
	});
	
	$('#close-login-form').click(function()
	{
		$('#login-form').animate(
		{
			top: '-34px',
			opacity: 0
		}, 500, function()
		{
			$(this).hide();
		});
		
		$('#dev-center').animate(
		{
			top: '-95px',
			opacity: 1
		}, 500, function()
		{
			$(this).fadeIn();
			$('#header').css({top: '34px'});
		});		
				
		return false;
	});
	
	$('#flash').hide().fadeIn('slow');
	
	setTimeout(function()
	{
  		$("#flash").fadeOut("slow", function()
		{
 			 $("#flash").remove();
      	});
	}, 5000);
	
	if ($('#datepicker').size()) {
	    $('#datepicker').datepick({dateFormat: 'MM d, yy'}); 
	}
	
	if ($('textarea.tinymce').size()) {
	    $('textarea.tinymce').tinymce(
    	{
    		// Location of TinyMCE script
    		script_url: '/js/tiny_mce/tiny_mce.js',
    		plugins : "safari,spellchecker,fullscreen",
    		// General options
    		theme: "advanced",		
    		theme_advanced_buttons1: "bold,italic,strikethrough,|,bullist,numlist,blockquote,|,justifyleft,justifycenter,justifyright,|,link,unlink,|spellchecker,|,fullscreen,code",
    		theme_advanced_buttons2: "formatselect,underline,justifyfull,forecolor,|,pastetext,pasteword,removeformat,|,media,charmap,|,outdent,indent,|,undo,redo,wp_help",
    		theme_advanced_buttons3: '',
    		theme_advanced_buttons4: '',

    		theme_advanced_toolbar_location:"top",
    		theme_advanced_toolbar_align:"left",
    		theme_advanced_statusbar_location:"bottom",
    		theme_advanced_resizing : true
    	});
    }
});
