
var srvrParams = new Object();
var isFB = false;

previewClick = function(n){
	window.location = "/message/#?hop="+n;
}

templateClick = function(n){
	window.location = "/message/#?template="+n;
}




/* https://github.com/kilhage/jquery-class */


var mhopHtml = $.Class({

	init: function( ) {
		this.mode = 'reader';
		if(this.getParam('template')){
			this.isTemplate = true;
			this.loadHop(this.getParam('template'));
			return;
		}
		if(this.getParam('hop')){
			this.loadHop(this.getParam('hop'));
			return;
		}
		this.mode = 'editor';
		this.createDefEditMode();
    },

	loadHop: function(id) {
		var p = this;
		$.ajax({
		  url: '/get/html/',
		  data: {hop:id},
		  success: function(e){ p.getDataSuccess(e, p)},
		  dataType: 'html'
		});
	},
	
	
	getDataSuccess: function(data, prnt){
		if(data){
			$('#messageHopStage').append(data);
			
			var bgclr = $('#header').attr('bg');
			var stageHeight = parseFloat($('#header').attr('stageheight'));
			
			if(bgclr){
				if(isFB){
					$('#mhpCnvs').css('background-color', '#'+bgclr);
				} else {
					$('body').css('background-color', '#'+bgclr);
				}
			}
			if(!stageHeight){
				stageHeight = 200;
			}
			$('#messageHopStage').css('height', (stageHeight+50)+'px');
			
			if(this.isTemplate){
				$.modal("<div><div><b>Welcome to messagehop.</b><br>Currently to create a message on messagehop, Flash 10 is required. Although flash is not required to read messages. We are planning an html version soon, stay tuned.</div><div style=\"margin-top:15px;\"><span class=\"closeBtn\">Close</span></div></div>", {minHeight: 150, close: false, closeClass:'closeBtn', autoResize:true});
			}
			
		}
	},
	
	createDefEditMode : function( ) {
		$('#messageHopStage').css('height', 300+'px');
		var elm = $('<div></div>').addClass('glblBox');
		$(elm).html('\
			<table cellpadding="5px">\
				<tbody><tr>\
					<td>\
						<img src="http://www.messagehop.com/img/htmlogoNoFlsh.png">\
					</td>\
				</tr>\
				<tr>\
					<td>\
						<b>Welcome to messagehop.</b> Currently to create a message on messagehop, Flash 10 is required. Although flash is not required to read messages. We are planning an html version soon, stay tuned.</td>\
				</tr>\
				<tr>\
					<td>\
						<a href="http://get.adobe.com/flashplayer/" id="noFlash" target="_blank">Download Flash</a>\
					</td>\
				</tr>\
			</tbody></table>');
			$('#messageHopStage').append(elm);
		$(elm).css('top', 50+'px');
		$(elm).css('position', 'absolute');

	},
	
	getParam:  function(n) {
		if(srvrParams[n]){
			return srvrParams[n];
		}
		return SWFAddress.getParameter(n);
	}
	

		
});

