var LightBoxMessage = {};
$(document).ready(function(){
	LightBoxMessage = new (function(){
		$("a#rememberMeMessage").bind("click", rememberMeMessage_onClick);
		
		if ($("div.benefitsofregistration")) {
				$("div.benefitsofregistration p").show();
		}
		$("a#benefitsofregistration").bind("click", benefitsofregistration_onClick);
	})
	
	function rememberMeMessage_onClick(){
		showMessageInLightbox("LB_MESSAGE_REMEMBER_ME_EXPLAINED");
		return false;
	}
	
	function benefitsofregistration_onClick(){
		showMessageInLightbox("LB_MESSAGE_BENEFITS_OF_REGISTRATION");
		return false;	
	}
	
	function showMessageInLightbox(message){
		LightBox.setHTML(LightBox.loadingHTML);
		LightBox.showOverlay();
		LightBox.setOverlayTooltip("To close the message box click on the 'Close X' link") 
	    LightBox.showLightBox();		
	    var data ="";
	    data +="&message="+message;
		var ajax = $.ajax({
			url: "https://" + window.location.host + "/webapp/wcs/stores/servlet/SimpleAjaxMessage",
			dataType: "json",
			type: "get",
			data: data,
			success: showMessageLightBox,
			error: showRequestError
		});
	}
	
	function showMessageLightBox(json) {
		LightBox.hideLightBox();
		LightBox.setHTML(json.html);
		
		var dialogue = $("#lightBox")[0];

			$(dialogue).addClass("lightBoxLoginMessage");


		LightBox.showLightBox();
		LightBoxLoginMessage.init();
	}
	
	
	
	function showRequestError(XMLHttpRequest, textStatus, errorThrown) {
	    	
    	var html = '';
    	html += '<div id="lightBoxError">';
    	html +=		'<div class="heading"><h2>An error occured</h2><a href="#" class="closeLightBox">Close</a></div>'
    	html +=		'<div class="details">';
    	html +=			'<p>Request: '+XMLHttpRequest+'</p>';
    	html +=			'<p>Status: '+textStatus+'</p>';
    	html +=			'<p>Code: '+XMLHttpRequest.status+'</p>';
    	html +=			'<p>Error: '+errorThrown+'</p>';
    	html +=		'</div>';
    	html += '</div>';
    	LightBox.hideLightBox();
    	LightBox.setHTML(html);
    	LightBox.showLightBox();
    }
});
var LightBoxLoginMessage = new (function() {
	this.init = init;
	function init() {
		$("#lightBoxLogin .closeLightBox").bind("click", closeLightBox_onClick);
	}
	
	function closeLightBox_onClick() {
		var dialogue = $("#lightBox")[0];
		$(dialogue).removeClass("lightBoxLoginMessage");
		return false;
	}
	

});