/*********************************************************************************************************/
var autoRefreshTimeOutValue;
var jsClockTimeOutValue;
var minutes=60000;
var loopDuration = minutes*1;
var countClock=60;
var timeoutVal="";
var msgCounter=0;
var totalMsgCount=15;
var customCounter=totalMsgCount;
var shuandaMessengerTimeout;
var ShuandaMessengercookieName='read_messages';
var jsAjaxTimeOutError='HATA... Lutfen Tekrar deneyin';

var menuArray=new Array(6);
menuArray[0]='messages';
menuArray[1]='most_followings';
menuArray[2]='new_members';
menuArray[3]='most_messaging';
menuArray[4]='most_friends';
menuArray[5]='most_directs';


function changeVision(mode) {
	/*for(var i=0; i<6; i++) {
		if(menuArray[i] == mode) {
			dgid(menuArray[i]).className='menu_selected';
		}
		else
			dgid(menuArray[i]).className='menu_normal';
	}*/
	clearTimeout(timeoutVal);
	msgCounter=0;
	timeoutVal=checkNewMessagesVision("NewMessages",mode);
}

function travel(mode) {
	msgCounter++;
	if(msgCounter <totalMsgCount) {
		timeoutVal=setTimeout("travel(\'"+mode+"\')",5000);
		//document.getElementById("msgcount").innerHTML=tab_index;
		$("#gmaps_container").get(0).gmap.jq_maps.goTo($("#gmaps_container").get(0), msgCounter-1);
	}
	else {
		 changeVision(mode);
		//window.location.reload();
	}
}


function checkNewMessagesVision(targetDiv,mode) {
	//document.getElementById("waitLog").style.display="block";
	//document.getElementById("waitLog2").style.display="block";
	jQuery.ajax({
		url: '/dummy_tunnel.php',
		type: 'POST',
		data: 'mode='+mode,
		dataType:'xml',
		timeout: 950000,
		error: function(){
			clearTimeout(timeoutVal);
			timeoutVal=checkNewMessagesVision("NewMessages");
		},
		success: function(response){
			var simpleContent = "";
			var username = "";
			var maximizedContent = "";
			var latitude = "";
			var longitude = "";
			var zoom = "";
			var icon = "";
			var time = "";
			var source="";
			var user_image = "";
			var user_message = "";
			var arrayIndex=0;
			jQuery("/shuandavision/messages/message", response).each(function(){
				simpleContent = jQuery("simpleContent", this).text();
				username = jQuery("username", this).text();
				maximizedContent = jQuery("maximizedContent", this).text();
				latitude = jQuery("latitude", this).text();
				longitude = jQuery("longitude", this).text();
				zoom = jQuery("zoom", this).text();
				source = jQuery("source", this).text();
				icon = jQuery("icon", this).text();
				time= jQuery("time", this).text();
				user_image = jQuery("user_image", this).text();
				user_message= jQuery("user_message", this).text();
				locations_data.locations[arrayIndex].simpleContent=simpleContent;
				locations_data.locations[arrayIndex].username=username;
				locations_data.locations[arrayIndex].source=source;
				locations_data.locations[arrayIndex].maximizedContent=maximizedContent;
				locations_data.locations[arrayIndex].latitude=latitude;
				locations_data.locations[arrayIndex].longitude=longitude;
				locations_data.locations[arrayIndex].zoom=zoom;
				locations_data.locations[arrayIndex].icon=icon;
				locations_data.locations[arrayIndex].time=time;
				locations_data.locations[arrayIndex].user_image=user_image;
				locations_data.locations[arrayIndex].user_message=user_message;
				arrayIndex++;
			});
		//	document.getElementById("waitLog").style.display="none";
		//	document.getElementById("waitLog2").style.display="none";
		$("#gmaps_container").gmaps({
			data: locations_data,
			infopanel: $("#gmaps_info").get(0),
			relativepath: "http://www.shuanda.net/"
		});
			travel(mode);
			return;
		}
	});
}


function closeMe(obj) {
	document.getElementById(obj).style.display='none';
//	document.getElementById("dummy").style.display='none';
	//document.getElementById("Disabler").style.display='none';
}


function dgByName(x) {
	return document.getElementsByName(x);
}


if(document.getElementById) {
var getRefById = function(id) {
return document.getElementById(id);
};
} else if(document.all) {
var getRefById = function(id) {
return document.all[id];
};
} else {
var getRefById = function() {
return null;
};
}


function dgid(val) {
	return document.getElementById(val);
}