var messageOffset, peekValue, messageHeight, theClickerPosition;


jQuery(document).ready(function() {
	
		// Message bar slider
		// Slightly expand and hide the bar
		var messageOffset = $('#messageSlider').css('right');
		var peekValue = parseFloat(messageOffset, 10) + 5 + 'px';
		var messageHeight = $('#messageSlider').height();
		var theClickerPosition = messageHeight/2;
		
		$('#messageClicker').css({ height : messageHeight}).find('span').css({ marginTop : theClickerPosition});
		$('#messageSlider').fadeIn();
		
		function peek() {
			$('#messageSlider').animate({ right : peekValue}, {queue : false});
		}
		function aboo() {
			$('#messageSlider').animate({ right : messageOffset}, {queue : false});
		}
		// bind the peek-aboo functions
		$('#messageClicker').bind({
			mouseenter : function() {peek();},
			mouseleave : function() {aboo();}
		});
		// Click togggle to show/hide the bar. Rebinds the peek-aboo functions on close
		$('#messageClicker').click(function(){
			// unbind the peekaboo effect
			$('#messageClicker').unbind('mouseleave').unbind('mouseenter').removeClass('closed');
			// Animate the menu to fly out
			$('#messageSlider').animate({ right : 0});
			// rebind the mouseleave function, to collapse the menu on mouse out		
			$('#messageSlider').bind({
				mouseleave : function() {
					aboo();
					// Rebind the peekaboo effect once the menu has collapsed
					$('#messageClicker').addClass('closed').bind({
						mouseenter : function() {peek();},
						mouseleave : function() {aboo();}
					});				
				}
			})		
		},
			function() {
			$('#messageSlider').animate({ right : messageOffset}, function() {
				$('#messageClicker')
				.bind('mouseenter', function(){peek();})
				.bind('mouseleave', function(){aboo();});
			});
		});
	

//Message bar slider
//Slightly expand and hide the bar
messageOffset = $('#messageSlider').css('right');
peekValue = parseFloat(messageOffset, 10) + 5 + 'px';
messageHeight = $('#messageSlider').height();
theClickerPosition = messageHeight/2;
$('#messageClicker').css({ height : messageHeight}).find('span').css({ marginTop : theClickerPosition});
$('#messageSlider').fadeIn();

//bind the peek-aboo functions
$('#messageClicker').bind({
	mouseenter : function() {peek();},
	mouseleave : function() {aboo();}
});
//Click togggle to show/hide the bar. Rebinds the peek-aboo functions on close
$('#messageClicker').click(showLMB, hideLMB);


		
});

function peek() {
	//alert(peekValue);
	$('#messageSlider').animate({ right : peekValue}, {queue : false});
}
function aboo() {
	//alert(messageOffset);
	$('#messageSlider').animate({ right : messageOffset}, {queue : false});
}
function showLMB(){
	// unbind the peekaboo effect
	$('#messageClicker').unbind('mouseleave').unbind('mouseenter').removeClass('closed');
	// Animate the menu to fly out
	$('#messageSlider').animate({ right : 0});
	// rebind the mouseleave function, to collapse the menu on mouse out		
	$('#messageSlider').bind({
		mouseleave : function() {
			aboo();
			// Rebind the peekaboo effect once the menu has collapsed
			$('#messageClicker').addClass('closed').bind({
				mouseenter : function() {peek();},
				mouseleave : function() {aboo();}
			});				
		}
	})		
}

function hideLMB() {
	if (typeof messageOffset == 'undefined') {
		messageOffset = '-320px';
	}
	
	jQuery('#messageClicker').addClass('closed');
	
	$('#messageSlider').animate({ right : messageOffset}, function() {
		$('#messageClicker')
		.bind('mouseenter', function(){peek();})
		.bind('mouseleave', function(){aboo();});
	});
}


