var smsHotSpotList = {}; /* sms hotspot object list */


$(document).ready(function(){
	initSMSHotspot();
});



function initSMSHotspot()
{
	getSMSHotspotData(true);
}


function getSMSHotspotData(run_update)
{
	var data = {
		op: "get_sms_hotspots"
	}
	
	var options = {
		type: "GET",
		data: data,
		url: "http://www.swingersparadise.se/services/json_get.php",
		dataType: "json",
		success: function (data){
			smsHotSpotList = data;
			
			if (run_update)
			{
				updateSMSHotspot($("ul.sms-hotspot li").eq(1), 0);
				setTimeout(function(){ getSMSHotspotData(false); }, 1000*90);
			}
			else setTimeout(function(){ getSMSHotspotData(false); }, 1000*90);
		},
		error: handleError
	}
	
	$.ajax(options); // make the ajax call
}


function updateSMSHotspot(jq, index, startIndex)
{
	if (!smsHotSpotList) return;
	
	if (typeof startIndex == "undefined") startIndex = index; /* save start index */
	
	var link = smsHotSpotList[index].username != "" ? "<a href='/visa-profil/"+smsHotSpotList[index].user_id+"/'>"+smsHotSpotList[index].username+"</a>" : "Anonym";
	
	jq.html(link + " säger: " + smsHotSpotList[index].msg + " <span>("+smsHotSpotList[index].datetime+")</span>"); /* set content */
	
	jq.animate({opacity:1}, 600, "easeInQuint", function(){
		setTimeout(function(){ jq.animate({opacity:0}, 600, "easeOutQuint", function(){
			if (index+1 < smsHotSpotList.length) index = index+1;
			else index = startIndex;
			
			setTimeout(function(){ updateSMSHotspot(jq, index, startIndex); }, 0); });
		}, 4000);
	});
}



function handleError(XMLHttpRequest, textStatus, errorThrown)
{
	alert('error status: ' + XMLHttpRequest.status + ', statusText: ' + XMLHttpRequest.statusText + ", textStatus: " + textStatus + ", errorThrown: " + errorThrown);
}