var stockMsgHeightShrink = ($.browser.msie ? ($.browser.version == 6.0 ? '0px' :'9px') : '6px');

var messageAnimationFunctions = {
	msgPanelOptions : {
		height : 54,			//height to animate (in px)
		delay : 1500, 			//animation delay
		defaultFontColor : '#006600' //default font colour
	},
	// animate the return message
	bounceMessage : function(msg) {
		messageAnimationFunctions.slide({
			height: messageAnimationFunctions.msgPanelOptions.height + 'px',
			duration: messageAnimationFunctions.msgPanelOptions.delay,
			data: msg				
			});	
				
		return false;
	},
	// create a slide and bounce effect 
	slide : function (slideOptions) {
		/*
		{slideOptions as JSON}
			height					animate to height
			duration 				delay on animation
			data
		*/
		var $tmessage = $('#stockMsgPanel');
		
		$tmessage.animate({opacity:1}, 0, function () {
			
			var msgBox = $tmessage.find('.messages');
			$tmessage.animate({ height: stockMsgHeightShrink, 'fontSize': '0px'}, 500, function () {
				$('body').attr('style','');	
				msgBox.show();	
				msgBox.html(slideOptions.data);	
				msgBox.fadeTo(slideOptions.duration, 1);
				//changes the colour of the message box font to default
				msgBox.css({'color':messageAnimationFunctions.msgPanelOptions.defaultFontColor, 'fontSize':'12px'});
				
				messageAnimationFunctions.msgFadeOut(900);
				$(this).animate({ height: slideOptions.height}, slideOptions.duration,'easeOutBounce');
				
				if($.browser.msie == true && $.browser.version == 6.0) {
					msgBox.css('backgroundColor','#e6e4e4');
				}
			});																	
		});	
	},		
		
	msgText : function (text) {
		if (text){
			var fadeMsgBox = $('.fadeMsgBox .msg');
			var msgs = $('#stockMsgPanel');
			
			if(msgs.height() > 10) {			
				msgs.animate({ height: '10px'}, 500, function () {				
					$(this).find('.messages').html('');						
					if(fadeMsgBox.css('display') == 'block'){
						messageAnimationFunctions.msgFadeOut(700, function () {
								fadeMsgBox.html(text);
								messageAnimationFunctions.msgFadeIn(700);
						});						
					} else {
						fadeMsgBox.html(text);
						messageAnimationFunctions.msgFadeIn(700);						
					}
				});
			} else {
				if(fadeMsgBox.css('display') == 'block'){
					messageAnimationFunctions.msgFadeOut(700, function () {
							fadeMsgBox.html(text);
							messageAnimationFunctions.msgFadeIn(700);
					});						
				} else {
					fadeMsgBox.html(text);
					messageAnimationFunctions.msgFadeIn(700);						
				}				
			}
		}
	},
	
	msgFadeIn : function (speed) {
		
		var fadeMsgBox = $('.fadeMsgBox .msg');		
			fadeMsgBox.fadeIn(speed ? speed : 100);
			
	},
	
	msgFadeOut : function (speed, callback) {
		
		callback = (callback ? callback : function () { return true; });
		
		var fadeMsgBox = $('.fadeMsgBox .msg');
		
		if(fadeMsgBox.css('display') == 'block')
			fadeMsgBox.fadeOut(speed ? speed : 100, callback);
	}
};

	
