google.load("jquery", "1.3.2");
google.load("jqueryui", "1.7.2");

if (typeof(Whomix) == "undefined") {
	Whomix = {};
	Whomix.Defaults = {};
	Whomix.Defaults.baseDomain = "http://whomix.windbubbles.net/";
	Whomix.Defaults.baseAssetUrl = "http://whomix.windbubbles.net/";
  Whomix.Defaults.baseApiUrl = "http://whomix.windbubbles.net/api/";
}

Whomix.sortRemixesByDate = function(remixA, remixB, isDesc)
{
	try {
		var adate = remixA.id(); //remixA.date().getTime();
		var bdate = remixB.id(); //remixB.date().getTime();
		return (adate - bdate) * (isDesc ? -1 : 1);
	}
	catch(e) {
		this.write_err("Exception thrown during sort: " + e.message);
	}
}
Whomix.Remix = function(init_hash)
{

  this.classId = function()
	{
		return "Whomix.Remix";
	}

	this.yyyymmddToDate = function(theDate)
	{
		try {
			var tmp = theDate.split('.');
			return new Date(tmp[0], tmp[1], tmp[2]);
		}
		catch(e) {
			this.write_err("Exception thrown during sort: " + e.message);
		}
	}
	this.setAttrAtKey = function(key, val)
	{
		if (key == 'date') {
		  val = new Date(val);
		}
		else if (key == 'comments' || key == 'downloads')
		{
			val = parseInt(val);
		}
		this._attr[key] = val;
	}
	this.attr = function(arg1, arg2)
	{
		if (typeof(arg1) == 'object') {
			update_hash = arg1;
			for (k in update_hash) {
				this.setAttrAtKey(k, update_hash[k]);
			}
		}
		else if (typeof(arg1) == 'string') {
			if (typeof(arg2) == 'undefined') {
				return this._attr[arg1];
			} else {
				this.setAttrAtKey(arg1, arg2);
			}
		}
	}
	this.id = function()
	{
		return this.attr('id');
	}
	this.date = function()
	{
		return this.attr('date');
	}
	this.formattedDate = function()
	{
		var date = this.date();
		return date.getFullYear() + "." + this.padDigit(String(date.getMonth()),2,"0") + "." + this.padDigit(String(date.getDate()),2,"0");
	}
	this.padDigit = function(str, wantLength,padchar)
	{
		while (str.length < wantLength) {
			str = padchar + str;
		}
		return str;
	}
	this.formattedLength = function()
	{
		var lenS = parseFloat(this.attr('length'));
		var minutes = Math.floor(lenS/60.0);
		return String(minutes) + ":" + this.padDigit(String(Math.floor(lenS - (minutes*60))), 2, "0");
	}
	this.isFullyPopulated = function()
	{
		try {
			if (this.date() && this.attr('blurb') && this.attr('length')) {
				return true;
			}
		}
		catch(e)
		{
		}
		return false;
	}
	
	this._attr = {};

	var k;
	for (k in init_hash) {
		this.setAttrAtKey(k, init_hash[k]);
	}
}

Whomix.Gadget = 
{
	classId: function() { return "Whomix.Gadget"; },
  baseDomain: Whomix.Defaults.baseDomain,
  baseAssetUrl: Whomix.Defaults.baseAssetUrl,
  baseApiUrl: Whomix.Defaults.baseApiUrl,
	setEnvironment: function(map)
	{
		if (!this._env) {
			this._env = {};
		}
		for (var k in map) {
		  this._env[k] = map[k];
		}
	},
	env: function(k) {
		return this._env[k];
	},
	contentDiv: function()
	{
		return $("#"+this._env['contentDiv']);
	},
	isGadgetsEnabled: function() {
		if (this._testedGadgets) {
			return this._isGadgetsEnabled;
		}
		this._isGadgetsEnabled = false;
		try {
			gadgets.util.escapeString("test");
			this._isGadgetsEnabled = true;
		}
		catch(e)
		{
		}
		this._testedGadgets = true;
	},
	trackView: function(viewPath)
	{
		if (!this.isGadgetsEnabled()) {
			return;
		}
		try {
			var strPath = "/view" + viewPath;
			if (!this._analytics) {
				this._analytics = new _IG_GA("UA-11062339-2");
			}
			this._analytics.reportPageview(strPath);
		}
		catch(e)
		{
		}
	},
	localize: function(msgStr)
	{
	  if (!this.isGadgetsEnabled()) {
			return msgStr;
		}
		try {
	  	if (!this._googlePrefs) {
				this._googlePrefs =  new gadgets.Prefs();
			}
			return this._googlePrefs.getMsg(msgStr);
		}
		catch(e)
		{
		}
		return msgStr;
	},
	write_err: function(errString)
	{
		this.contentDiv().append("<span class=\"wmgdt_error\">" + errString + "</span>");
	},
	registerCustomJqueryPlugins: function()
	{
/* Copyright (c) 2009 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
  * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
	* Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
	* Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
	*
	* Version: 3.0.2
	* 
	* Requires: 1.2.2+
*/
(function(c){var a=["DOMMouseScroll","mousewheel"];c.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var d=a.length;d;){this.addEventListener(a[--d],b,false)}}else{this.onmousewheel=b}},teardown:function(){if(this.removeEventListener){for(var d=a.length;d;){this.removeEventListener(a[--d],b,false)}}else{this.onmousewheel=null}}};c.fn.extend({mousewheel:function(d){return d?this.bind("mousewheel",d):this.trigger("mousewheel")},unmousewheel:function(d){return this.unbind("mousewheel",d)}});function b(f){var d=[].slice.call(arguments,1),g=0,e=true;f=c.event.fix(f||window.event);f.type="mousewheel";if(f.wheelDelta){g=f.wheelDelta/120}if(f.detail){g=-f.detail/3}d.unshift(f,g);return c.event.handle.apply(this,d)}})(jQuery);
		$.fn.disableTextSelect = function() {
			try {
				return this.each(function(){
					if($.browser.mozilla){//Firefox
						$(this).css('MozUserSelect','none');
					}else if($.browser.msie){//IE
						$(this).bind('selectstart',function(){return false;});
					}else{//Opera, etc.
						$(this).mousedown(function(){return false;});
					}
				});
			}
			catch(e) {
			
			}
		};
	},
	jsonRequest: function(url, handler)
	{
	  if (this.isGadgetsEnabled())
		{
		  var params = {},
					self =this;

			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
			params[gadgets.io.RequestParameters.REFRESH_INTERVAL] = 10;
			gadgets.io.makeRequest(url, function(jsonObj) {
					if(!jsonObj.data) {
					  jsonObj.data = eval("(" + jsonObj.text + ")");
					}
					var passarg = arguments;
					passarg[0] = jsonObj;
					handler.apply(self, passarg);
				}, params
			);
		}
		else {
			var self = this;
			$.get(url, function(response) {
			  var jsonObj = { text: response,
											  data: eval("(" + response + ")") };
				var passarg = arguments;
				passarg[0] = jsonObj;
				handler.apply(self, passarg);
			});
		}
	},
	wrapLink: function(url, innerText, options)
	{
	  var attr = [];
		if (options) {
			if (options.cssClass) {
				attr.push("class=\"", options.cssClass, "\" ");
			}
			if (options.id) {
				attr.push("id=\"", options.id, "\" ");
			}
			if (options.target) {
				attr.push("target=\"", options.target, "\" ");
			}
		}
	  return "<a " + attr.join('') + "href=\"" + url + "\">" + innerText + "</a>";
	},
	urlFor: function(selector)
	{
	  if (selector == "base") {
			return this.baseDomain;
		}
		else if (selector == "asset")
		{
			return this.baseAssetUrl + arguments[1].urlparam;
		}
		else if (selector == "no_api") {
			return this.baseDomain + "/" + arguments[1].urlparam;
		}
		else if (selector == "remixes") {
		  return this.baseApiUrl + "remixes";
		}
		else if (selector == "reviews") {
			return this.baseApiUrl + "reviews";
		}
		else if (selector == "remix") {
		  var hashObj = arguments[1];
			var remixId = hashObj.id;
			if (hashObj.no_api == true){
				return this.baseDomain + "/remix/" + remixId;
			}
			if (hashObj.action == "download") {
				return this.baseApiUrl + "remix/download/" + remixId + "." + hashObj.format;
			}
			else {
				return this.baseApiUrl + "remix/" + remixId;
			}
		}
	},
	onTabClicked: function(clickedId)
	{
		var $tab = $("#"+clickedId);
		if (!$tab.hasClass("activeTab")) {
			// no clicking on other tabs until remixes loaded
			if (clickedId != this.env("remixesTab") && !this._remixList) {
				return false;
			}
			$(".activeTab").removeClass("activeTab");
			$tab.addClass("activeTab");
			this.removeVerticalSlider();
			this.contentDiv().empty();
			this.contentDiv().scrollTop(0);
			if (clickedId == this.env("remixesTab") ) {
				(this._remixList == undefined) ? this.requestRemixesList() : this.remixesListReceivedJson();
			}
			else if (clickedId == this.env("latestFeedbackTab") ) {
				var $rc = $("#recentcomments").clone();
				var $ft = $('<div>').attr('id', 'feedbackTable');
				$ft.html($("ul", $rc).html())
				$ft.append($("</a>").attr('href', 'http://disqus.com/').text('Powered by Disqus'));
				this.contentDiv().empty();
				this.contentDiv().append($ft);
				this.bindMouseWheelWithElement("#feedbackTable");
				this.trackView('/gadget/reviews/latest');
				
//				this.requestLatestFeedback();
			}
			else if (clickedId == this.env("twitterTab") ) {
				this.requestLatestTwitter();
			}
		}
		return false;
	},
	start: function()
	{
		//this.requestRemixesList();
	  var self = this;
		var clickFn = function() {
			self.onTabClicked.apply(self, [$(this).attr('id')]);
			return false;
		}
		$("#" + this.env("remixesTab")).bind("click", clickFn);
		$("#" + this.env("latestFeedbackTab")).bind("click", clickFn);
		$("#" + this.env("twitterTab")).bind("click", clickFn);
		$("#" + this.env("remixesTab")).trigger("click");
		this.contentDiv().bind("CONTENT_WANTS_SCROLL", function(e, data) {
			self.contentDiv().stop();
			self.contentDiv().animate({"scrollTop": data.scrollTop}, data.duration);
		});
	},
	requestLatestFeedback: function()
	{
		try {
			this.contentDiv().html("<span class=\"loadingmsg\">"+this.localize("LoadingFeedback")+"</span>");
			this.jsonRequest(this.urlFor("reviews"), this.latestFeedbackReceivedJson);
		}
		catch(e) {
			this.write_err("requestLatestFeedback failed: " + e.message);
		}
	},
	requestRemixesList: function() 
	{
		try {    
			this.contentDiv().html("<span class=\"loadingmsg\">"+this.localize("Loading")+"</span>");
			var theUrl = this.urlFor("remixes");
			if (this._hasRequestedRemixes) {
			  theUrl += "?"+String(new Date().getTime());
			}
			this._hasRequestedRemixes = true;
			this.jsonRequest(theUrl, this.remixesListReceivedJson);
		} 
		catch(e) { 
			this.write_err("requestRemixesList failed: " + e.message); 
		}
	},
	registerPulling: function()
	{
		var self=this;
		var mouseDragTopOffsetKey = "mouseDragStartOffsetY";
  	//$(".mouseTrackable").disableTextSelect();
  
		$(".mouseTrackable").click(function() {
	 	 	self.contentDiv().stop(true);
			var elementOffset = $(this).offset().top;
			var contentOffset = self.contentDiv().offset().top; 
			var targetOffset = elementOffset - contentOffset;
			var newScroll = targetOffset + self.contentDiv().scrollTop() - self.contentDiv().height()/3;
			self.contentDiv().animate({"scrollTop": newScroll}, 200);
			return false;
		});
	},
	displayRemixDetails: function(theRemix)
	{
		this.trackView('/gadget/remixDetails/' + theRemix.id());
		var download = this.wrapLink(this.urlFor("remix",{action: "download",
																													id: theRemix.id(),
																											format: "mp3"}), "[↓ mp3]");
		var theHtml = "";
		theHtml += "<div>"+ this.localize("DetailsFeedback") + 
							this.wrapLink(this.urlFor("remix", {no_api: true, id: theRemix.id()}), this.urlFor("base"), {target: "new"+theRemix.id()}) + "</div>";
		theHtml += "<div>" + this.localize("Download") + download + "</div>";
		$("#explodedRemixDetails").html(theHtml);
  	theHtml = "";
		theHtml += theRemix.formattedDate() + "  [" + theRemix.formattedLength()  + "]";
		$("#explodedRemixDetailsHeader").html(theHtml);
	},
	remixDetailsReceivedJson: function(response)
	{
		theRemixData = response.data['entry'];
		theRemix = this.remixById(theRemixData.id);
		theRemix.attr(theRemixData); //update with more detailed info
		this.displayRemixDetails(theRemix);
	},
	embedFlashPlayer: function(targetContainer, remixId)
	{
		var flashvar_str = "playlist="+remixId+"&volume=0.5&autostart=true";

		if (!this.isGadgetsEnabled())
		{
		var wmp_url = this.urlFor("asset", {urlparam: "js/WhomixPlayer.swf?"+flashvar_str});
			$("#"+targetContainer).media( {
			src: wmp_url, 
			width: 300, 
			height: 168,
			params: {flashvars: flashvar_str, AllowsScriptAccess: "always", SWLiveConnect: true, quality: "high"}, 
			attrs: {id: "WhomixVideo"} });
		}
		else
		{
		var wmp_url = this.urlFor("asset", {urlparam: "js/WhomixPlayer.swf"});
			gadgets.flash.embedFlash(wmp_url, "explodedRemixVideo", 9, {
						swf_version: 9,
						id: "WhomixVideo",
						wmode: "window",
						width: "300",
						height: "168",
						bgcolor: "#000000",
						quality: "high",
						play: true,
						swliveconnect: true,
						allowscriptaccess: "always",
						flashvars: flashvar_str
					})
		}
	},
	processClickOnRemixList: function(clickedEl)
	{
		var self = this;
		try {
			$("tr.wm_expanded").remove();
    	$trParent = $(clickedEl).parent("tr");
				remixId = $trParent.attr('id').split('_')[1];
				$expTd = $(".exploding", $trParent);
				if ($expTd.attr('_wmexploded') == "true") {
					$expTd.html("+");
					$expTd.attr('_wmexploded', "");
				}
				else {
				 	$expTd.html("-");
				 	$expTd.attr('_wmexploded', "true");
				 	var parTr = $trParent;
				 	parTr.after("<tr class=\"wm_expanded\"><td colspan=\"5\"><div id=\"explodedRemixDiv\"><div id=\"explodedRemixDetailsHeader\"></div><div id=\"explodedRemixVideo\"></div><div id=\"explodedRemixDetails\"></div></div></td></tr>");
					self.embedFlashPlayer("explodedRemixVideo", remixId);
					var theRemix = self.remixById(remixId);
					if (theRemix.isFullyPopulated()) {
						self.displayRemixDetails(theRemix);
					} else {
						self.jsonRequest(self.urlFor("remix",{id: remixId}), self.remixDetailsReceivedJson);
					}
				}
				return false;
			}
			catch(e) {
				self.write_err("exception: " + e.message);
			}
	},
	remixById: function(id) {
 		var k;
		var searchId = parseInt(id);
		for (k=0; k < this._remixList.length; ++k)
		{
		  if (searchId == parseInt(this._remixList[k].id()))
			{
				return this._remixList[k];
			}
		}
		return null;
	},
	removeVerticalSlider: function()
	{
	  $("#content_outerdiv").unbind("mousemove");	
		$("#verticalSlider").remove();
	},
	attachVerticalSlider: function()
	{
		var self = this;
		try {
			var selVerticalSlider = "#verticalSlider";

			$("#content_outerdiv").bind("mousemove", function(e) {
				var xoff = e.pageX - $("#content_outerdiv").offset().left;
				var $theSliderDiv = $(selVerticalSlider);
				
				if (! $theSliderDiv[0]  && xoff < 7)
				{
					$(this).append('<div id="' + selVerticalSlider.substr(1) + '" style="position:absolute;height:350px;width:10px;top:0px;left:5px;"></div>');
					$(selVerticalSlider).css("top", self.contentDiv().offset().top + 10);
					$(selVerticalSlider).css("left", self.contentDiv().offset().left);
					$(selVerticalSlider).height(self.contentDiv().height()-20);
					$(selVerticalSlider).slider({
							orientation: "vertical",
							range: "min",
							min: 0,
							max: $("#remixList").height(),
							value: $("#remixList").height() - self.contentDiv().scrollTop(),
							start: function(event, ui) {
								self.isSliding = true;
							},
							stop: function(event, ui) {
								self.isSliding = false;
								self.contentDiv().parent().trigger("mousemove",event);
							},
							slide: function(event, ui) {
								self.contentDiv().stop();
		  					self.contentDiv().animate({"scrollTop": $("#remixList").height() - ui.value}, 200);
							
							//$("#amount").val(ui.value);
							}
					});
					$(selVerticalSlider).css({"opacity": 0});
					$(selVerticalSlider).animate({"opacity": 1}, 200);
					$theSliderDiv = $(selVerticalSlider);
				}
				else if (xoff > 20 && $theSliderDiv[0] && !self.isSliding) {
					$(selVerticalSlider).animate({"opacity": 0}, 200, "linear",function() {
						$theSliderDiv.remove()
						});
				}
			});
			this.bindMouseWheelWithElement("#remixList", function(eventData) {
			  var $slider = $(selVerticalSlider);
				if ($slider[0]) {
					$slider.slider('value', $("#remixList").height() - eventData.scrollTop);
				}
			});
		}
		catch(e) {
			this.write_err("Exception thrown " + e.message);
		}
	},
	createRemixListTable: function()
	{
		this.trackView('/gadget/remixList');
		var self = this;
		try {
			var html = [];
			var entryCount = this._remixList.length;
			html.push('<table id="remixList" class=""><thead><tr>', 
							'<th id="header_date">-</th>',
							'<th id="header_name">',  this.localize('Track'), '</th>', 
							'<th id="header_remixer">', this.localize('Remixer'), '</th>',
							'<th id="header_comments">✍</th>',
							'<th id="header_downloads">#</th>', 
							'</tr></thead><tbody>');
			
			for (k =0; k < entryCount; ++k) {
				var entry = this._remixList[k];
				var remixId = entry.id();
				var tdExplode = "<span class=\"exploding\" id=\"rowxplode_" + remixId + "\">+</a>"
				
				html.push("<tr id=\"rowId_",  remixId, "\">",
										"<td class=\"tdCenter activatesSlider\">", tdExplode,
										"</td><td>", entry.attr('name'),
										"</td><td>", entry.attr('remixer'),  
										"</td><td class='tdRight'>", entry.attr('comments'),
										"</td><td class='tdRight'>",  entry.attr('downloads'), 
										"</td></tr>" );
			}
			html.push("</tbody></table>");
			self.contentDiv().html(html.join(''));
			$("#remixList tr:odd").addClass("oddLine");
 	   	$("#remixList td").addClass("mouseTrackable");
					
			$("#remixList td").click( function() {
				self.processClickOnRemixList(this);
			});

			$("#remixList th").click( function() {
				var $this = $(this);
				var isDesc = $this.hasClass('orderDesc');
				var theId = $this.attr('id');
				var theKey = theId.split('_')[1];
				self.sortRemixTableBy(theKey, isDesc);
				if (!isDesc) {
					$("#"+theId).addClass('orderDesc');
				}
			});
			$("#remixList th").each(function() {
				var theId = $(this).attr('id');
				var theKey = theId.split('_')[1];
				$(this).css("cursor","hand");
			});
		}
		catch(e) {
			this.write_err("Exception thrown " + e.message);
		}
	},
	sortRemixTableBy: function(sortKey, isDesc)
	{
		var backupList = [],
				k,
				self = this;
		
		/*
		for (k = 0; k < this._remixList.length; ++k)
		{
			backupList[k] = this._remixList[k];
		}
		*/

		if ('date' == sortKey) {
			this._remixList.sort(function(a,b) {
				return Whomix.sortRemixesByDate(a,b,isDesc);
			});
		}
		else {
			this._remixList.sort( function(a,b) {
				return ((a.attr(sortKey) < b.attr(sortKey)) ? 1 : -1) * (isDesc ? 1 : -1);
			});
		}
		$("#remixList").remove();
		this.createRemixListTable();
	},
  // this code basically taken as-is from drunkenfist.com.
  // maybe customize later, maybe not
  twitterResponseCallback: function(obj)
	{
  	var user, bgcolor, tweet, postedAt, icon, userURL;

		var $twitDiv = $('<div id="innerTwit" style="text-align:center;width:350px;"></div>');
		var $twitList = $('<ul id="twitterList"></ul>');
  	for (var i = 0; i < obj.results.length; ++i)
  	{
    	var subo = obj.results[i];
    	icon = subo.profile_image_url;
    	user = subo.from_user;
    	userURL = "http://twitter.com/" + user;
    	tweet = subo.text;
    	postedAt = subo.created_at;
    	formattedText = [];
			formattedText.push("<strong><a href='", 
													userURL, 
													"'>", 
													user, 
													"</a></strong>: ", 
													tweet, 
													" <span class='time' style='font-size:80%;'>(", 
													postedAt, 
													" GMT)</span>");
    	var $twitLine = $("<li></li>");
			$twitLine.append(formattedText.join(''));
 	 		$twitLine.css({"background-image": "url("+icon+")"});
			$twitList.append($twitLine);
		}
		$("li:odd").addClass("oddLine");
		$twitDiv.append($twitList).append('<p>'+this.localize("ContactWhomixOnTwitter")+' <a href="http://twitter.com/home?status=@whomix">@whomix</a></p>').append('<p><img src="http://search.twitter.com/images/powered-by-twitter-sig.gif" style="text-align:center;opacity:0.2;margin-top:50px;"></p>');
		this.contentDiv().append($twitDiv);
		$("#innerTwit").css({"margin-left": (this.contentDiv().width()-360)/2 + "px"});
		this.bindMouseWheelWithElement("#innerTwit");
	},
	requestLatestTwitter: function()
	{
		var hashname = "whomix";
  	//function doTwitterSearch(hashname) {
  	var respJson = document.createElement("script");
  	respJson.type = "text/javascript";
  	respJson.src = "http://search.twitter.com/search.json?callback=Whomix.Gadget.twitterResponseCallback&q=" + hashname + "+-pub&since_id=1330676281"; //%23
  	document.getElementsByTagName("head")[0].appendChild(respJson);
	},
	bindMouseWheelWithElement: function(inElement, callback)
	{
		var self = this;
		var scrollSpeed = 0;
		var rep = null;
		this.contentDiv().unbind("mousewheel");
		
		var $inElement = $(inElement);
		this.contentDiv().bind("mousewheel", function(e,delta) {
			scrollSpeed -= 10.0*delta;
				if (!rep) {
					rep = setInterval(function() {
						scrollSpeed = 0.8*scrollSpeed;
						if (Math.abs(scrollSpeed) < 0.1) {
						  clearInterval(rep);
							rep = null;
						}
						var scrollPos = self.contentDiv().scrollTop() + scrollSpeed;
						if (scrollPos < 0 || scrollPos > $inElement.height()) {
							scrollSpeed = 0;
						}
						var newScroll = Math.max(0, Math.min($inElement.height(), scrollPos));
						var eventData = {scrollTop: newScroll, animate: true, duration: 50};
						if (callback) {
							callback(eventData);
						}
						self.contentDiv().trigger("CONTENT_WANTS_SCROLL", [eventData]);
					}, 50);
				}
				return false;
			});
	},
	latestFeedbackReceivedJson: function(response)
	{
		try {
			var jsondata = response.data;
			var reviews = jsondata['reviews'];
			var k;
			var html = [];
			html.push('<table id="feedbackTable">');
			for (k=0; k < reviews.length; ++k)
			{
			  var theRemix = this.remixById(reviews[k].remix.id);
				html.push('<tr><td>');
				//html.push(this.wrapLink(this.urlFor("remix",{id: theRemix.attr('id')}), theRemix.attr('name')));
				html.push(this.wrapLink(this.urlFor(remix, {no_api:true, id: theRemix.id()}), theRemix.attr('name'), {target: "new"+theRemix.id()}));
				html.push('</td><td><div style="background-color:#181818;margin:5px;">');
				html.push(reviews[k].review.text);
				html.push('</div>');
				html.push('<div style="width:100%;text-align:right;">', reviews[k].review.date, " by ", reviews[k].review.reviewer, '</div>');
				html.push('</td></tr>');
			}
			html.push('</table>');
			this.contentDiv().html(html.join(''));
			
			this.bindMouseWheelWithElement("#feedbackTable");
			this.trackView('/gadget/reviews/latest');
		}
		catch(e) {
			this.write_err("Exception thrown " + e.message);
		}
	},
	remixesListReceivedJson: function(response) 
	{ 
		var self = this;
		if (response == undefined && this._remixList)
		{
		}
		else{
			try {
				var jsondata = response.data;
				var entries = jsondata['entries'];
				var k;
				var remixList = [];
				for (k=0; k < entries.length; ++k)
				{
					remixList[k] = new Whomix.Remix(entries[k]);
				}
				this._remixList = remixList.sort(function(a,b) {
					return Whomix.sortRemixesByDate(a,b,true);
				});
			}
			catch(e) {
				this.write_err("Exception thrown " + e.message + " in remixesListReceivedJson.");
				setTimeout( function() {
					self.requestRemixesList();
				}, 2000);
			}
		}
		this.createRemixListTable();
		this.attachVerticalSlider();
		this.registerPulling();
	}
};


if (Whomix.Gadget.isGadgetsEnabled()) {
		gadgets.util.registerOnLoadHandler( function() {
		  Whomix.Gadget.registerCustomJqueryPlugins();
			Whomix.Gadget.start();
	});
}
else {
	google.setOnLoadCallback( function() {
		Whomix.Gadget.registerCustomJqueryPlugins();
		Whomix.Gadget.start();
	});
}

