// JavaScript Document

var xmlHttp;

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function load_avatars(str,limitstart)
{
	var base_url = document.getElementById('base_url').value;
	
	document.getElementById('signup_avatar').innerHTML='<div style="clear:both; padding-top:150px; height:180px;" align="center"><img src="'+base_url+'/images/loading.gif"></div>';
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url= base_url+"/ajaxfunctions.php";
	url=url+"?page=load_avatars&limitstart="+limitstart;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("signup_avatar").innerHTML=xmlHttp.responseText;
	} 
}

function load_favourites(str,limitstart)
{
	var base_url = document.getElementById('base_url').value;
	
	document.getElementById('user_fav').innerHTML='<div style="clear:both; padding-top:100px; height:100px;" align="center"><img src="'+base_url+'/images/loading.gif"></div>';
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url= base_url+"/ajaxfunctions.php";
	url=url+"?page=load_favourites&limitstart="+limitstart+"&str="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged1;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged1() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("user_fav").innerHTML=xmlHttp.responseText;
		
		$(document).ready(function() {
		
			//Select all anchor tag with rel set to tooltip
			$('a[rel=tooltip]').mouseover(function(e) {
				
				//Grab the title attribute's value and assign it to a variable
				var tip = $(this).attr('title');	
				
				//Remove the title attribute's to avoid the native tooltip from the browser
				$(this).attr('title','');
				
				//Append the tooltip template and its value
				$(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');		
						
				//Show the tooltip with faceIn effect
				$('#tooltip').fadeIn('500');
				$('#tooltip').fadeTo('10',0.9);
				
			}).mousemove(function(e) {
			
				//Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
				$('#tooltip').css('top', e.pageY + 10 );
				$('#tooltip').css('left', e.pageX + 20 );
				
			}).mouseout(function() {
			
				//Put back the title attribute's value
				$(this).attr('title',$('.tipBody').html());
			
				//Remove the appended tooltip template
				$(this).children('div#tooltip').remove();
				
			});
		
		});
	} 
}
