		/*class QuoteCycler:
		// starts when instantiated
		// cycles qoutes.
		// dependencies: 
		// - jquery.min
		// - latestMsgs.json - sample content:

{ "list":
  [{"name": "1Erik","group":"superduper", "text":"hejhej", "time":"alldeles nyss"},
  {"name": "2Erik","group":"superduper", "text":"hejhej", "time":"alldeles nyss"},
  {"name": "3Erik","group":"superduper", "text":"hejhej", "time":"alldeles nyss"},
  {"name": "4Erik","group":"superduper", "text":"hejhej", "time":"alldeles nyss"}]
}
		*/
		
		//class definition
		function QuoteCycler(_filename, _hideShowId) {
	        var filename = _filename;
	        var hideShowId = _hideShowId;
			var msgs = new Array();
       		var msgIndex = 0;
       		var isPaused = false;
           	fetchData();
           	
           	
	        function showNextMsgInIndex(repeat) {
           		
	        	if (isPaused) return;
	           	$("#"+hideShowId).fadeTo('medium', 0, function() {
	            	

	           		//fetch content
	        		q = msgs[msgIndex];
		        	msgIndex --;
		        	
		        	//insert new content
	            	for (param in q) {
	        			$("#quote_"+param).html(q[param]);
	        		}   
	            	
	            	//make smiley jump
	            	$("#live-qoute-smiley").css("padding-top", Math.random()*10+"px");
	            	$("#live-qoute-smiley").css("margin-left", Math.random()*5+"px");	            	
	
	            	$("#"+hideShowId).fadeTo('medium', 1, function(){
	                		
	        			 var timerCallback = function() {
		        			 	if (repeat) getNextMsg();
	        				 };
	        			 t = setTimeout(timerCallback, Math.random()*10000+500);
//	        			 t = setTimeout(timerCallback, Math.random()*200);
	        		});
	        	});
	        }
	        
	        function getNextMsg() {
	            if (msgIndex>0 && msgs.length>0) {
					showNextMsgInIndex(true);
	          	} else if (msgIndex ==0) {
	          		//show last message at the same time
	           		showNextMsgInIndex(false);
	               	//fetch new data
	               	fetchData();
		        }
	        }
	        function fetchData () {
	               	$.getJSON(filename, function(data) {
		               	if (data!=null) {
		               		msgs = data.list;
		               		msgIndex = msgs.length;
		               		getNextMsg();
	               	 	}
					});
	        }
	        this.pause = function () {
	        	isPaused = true;
	        };
	        this.restart = function() {
	        	isPaused = false;
	        	showNextMsgInIndex(true);
	        };
		}
		
		//start cycle
		var quoteCycler = new QuoteCycler("/weblogic/latestMsgs.json", "live-quote");
		//qouteCycler.pause();
		//qouteCycler.restart();
		
		