$(document).ready(function() {
	// Hide sub menus on load
	$('#nav ul').hide();
	
	// Handle clicks outside the menu
	$(document).click(function() {
	$('#nav li a').removeClass("selected");
	$('#nav ul:visible').slideUp();
	});
	
	$('#nav').click(function(event){event.stopPropagation()});
	$('#nav ul').click(function(event){event.stopPropagation()});

	// sub menu function
	$('#nav li a em').click(
	function() {
		
		// Highlight Active tab ONLY
		if ($(this).parent().next().is(':hidden')) {
		$('#nav li a').removeClass("selected");
		$(this).parent().addClass("selected");
		}

		// Hide Sub-menu if Parent menu is clicked and the sub menu is Visible
		if($(this).parent().next().is(':visible')) {
		$(this).parent().next().slideUp();
		return false;
		} else {

		// Continue...
		if( ($(this).parent().next().is('ul')) && ($(this).parent().next().is(':visible')) ) {
		return false;
		}

		if( ($(this).parent().next().is('ul')) && (!$(this).parent().next().is(':visible')) ) {
		$('#nav ul:visible').slideUp();
		$(this).parent().next().slideDown();
		return false;
		}
		
		}

	});
	
	$('.header-login').click(
	function() {
		if($('#login-form').css("display")=="none"){
			$('#login-form').fadeIn(function(){$('#navbar_username').focus()})}
		else{
			$('#login-form').fadeOut(function(){$('.side-header').css("display","block")})
			}
		return false
		});
/*
	$('#windowOpen').bind(
		'click',
		function() {
			if($('#window').css('display') == 'none') {
				$(this).TransferTo(
					{
						to:'window',
						className:'transferer2', 
						duration: 400,
						complete: function()
						{
							$('#window').show();
						}
					}
				);
			}
			this.blur();
			return false;
		}
	);
	$('#windowClose').bind(
		'click',
		function()
		{
			$('#window').TransferTo(
				{
					to:'windowOpen',
					className:'transferer2', 
					duration: 400
				}
			).hide();
		}
	);
	$('#windowMin').bind(
		'click',
		function()
		{
			$('#windowContent').SlideToggleUp(300);
			$('#windowBottom, #windowBottomContent').animate({height: 10}, 300);
			$('#window').animate({height:40},300).get(0).isMinimized = true;
			$(this).hide();
			$('#windowResize').hide();
			$('#windowMax').show();
		}
	);
	$('#windowMax').bind(
		'click',
		function()
		{
			var windowSize = $.iUtil.getSize(document.getElementById('windowContent'));
			$('#windowContent').SlideToggleUp(300);
			$('#windowBottom, #windowBottomContent').animate({height: windowSize.hb + 13}, 300);
			$('#window').animate({height:windowSize.hb+43}, 300).get(0).isMinimized = false;
			$(this).hide();
			$('#windowMin, #windowResize').show();
		}
	);
	$('#window').Resizable(
		{
			minWidth: 200,
			minHeight: 60,
			maxWidth: 700,
			maxHeight: 400,
			dragHandle: '#windowTop',
			handlers: {
				se: '#windowResize'
			},
			onResize : function(size, position) {
				$('#windowBottom, #windowBottomContent').css('height', size.height-33 + 'px');
				var windowContentEl = $('#windowContent').css('width', size.width - 25 + 'px');
				if (!document.getElementById('window').isMinimized) {
					windowContentEl.css('height', size.height - 48 + 'px');
				}
			}
		}
	);
	*/
});




