// global namespace 
var VV= {};

VV.headerMenu= function(){
	return {
		show: function (e, menuID, buttonID, eventNS){
			$('#'+menuID).show();
			$('#'+buttonID).addClass('showing');
			$(document).bind('click.'+eventNS, function (e){ VV.headerMenu.hide(e, menuID, buttonID, eventNS) });
			$('#'+menuID).bind('click.'+eventNS, function (e){
				e.stopPropagation();
			});
		},
		
		hide: function (e, menuID, buttonID, eventNS){
			$('#'+menuID).hide();
			$('#'+buttonID).removeClass('showing');
			$(document).unbind('click.'+eventNS);
		},
		
		toggle: function (e, menuID, buttonID, eventNS){
			if ($.browser.msie && $.browser.version < 7) return true;
	
			// create jquery event object from browser event
			var e = new jQuery.Event(e);
			e.preventDefault();
			e.stopPropagation();
	
			if ($('#'+menuID).css('display') == 'none'){
				VV.headerMenu.show(e, menuID, buttonID, eventNS);
			} else {
				VV.headerMenu.hide(e, menuID, buttonID, eventNS);
			}
	
			return false;
		}
	}
}();

VV.loggedMenu = function () {
	var menuID = 'menu';
	var buttonID = 'toggleMenu';
	var eventNS = 'VV_'+menuID;

	return {
		show: function (e){
			VV.headerMenu.show(e, menuID, buttonID, eventNS);
		},
		hide: function (e){
			VV.headerMenu.hide(e, menuID, buttonID, eventNS);
		},
		toggle: function (e){
			VV.headerMenu.toggle(e, menuID, buttonID, eventNS);
		}
	}
}();

/* warning */
VV.warning= function(){
	return {
		show: function(e, boxID, tipID, eventNS){
			console.log(tipID);
			var clone= tipID.clone();
			$("#cart-form").append( clone );
			
			clone.css({ top: ( boxID.position().top - ( clone.height() ) ) +  "px", left: ( boxID.position().left + ( boxID.width() / 2 ) - ( clone.width() / 2 ) ) + "px" });
			clone.fadeTo('fast', 1);
			
			boxID.bind('blur.'+eventNS, function(e){
				VV.warning.hide(e, boxID, clone, eventNS);
			});
			
			e.stopPropagation();
		},
		
		hide: function(e, boxID, tipID, eventNS){
			tipID.fadeOut('fast', function(){ tipID.remove(); });
			boxID.unbind('blur.'+eventNS);
		},
		
		toggle: function(e, boxID, tipID, eventNS){
			if ($.browser.msie && $.browser.version < 7) return true;
			
			tipID= $("#"+tipID);
			
			// create jquery event object from browser event
			var e = new jQuery.Event(e);
			e.preventDefault();
			e.stopPropagation();
			
			VV.warning.show(e, boxID, tipID, eventNS);
			
			return true;
		}
	}
}();

VV.toggleWarning= function(){
	var eventNS = 'VV_warning';
	var tipID= 'warning';
	
	return {
		show: function (e, boxID){
			boxID= $(boxID);
			VV.warning.show(e, boxID, tipID, eventNS);
		},
		hide: function (e, boxID){
			boxID= $(boxID);
			VV.warning.hide(e, boxID, tipID, eventNS);
		},
		toggle: function (e, boxID){
			boxID= $(boxID);
			VV.warning.toggle(e, boxID, tipID, eventNS);
		}
	}
}();
