function reloadImages()
{

var Ajax = new Object();

var Page = new Object();

Page.width;
Page.height;
Page.top;

Page.loadOut = function ()
{
	document.getElementById('loading').innerHTML ='';	
}

Page.getPageCenterX = function ()
{
	var fWidth;
	var fHeight;		
	//For old IE browsers 
	if(document.all) 
	{ 
		fWidth 	= document.body.clientWidth; 
		fHeight = document.body.clientHeight; 
	} 
	//For DOM1 browsers 
	else if(document.getElementById &&!document.all)
	{ 
		fWidth 	= innerWidth; 
		fHeight = innerHeight; 
	} 
	else if(document.getElementById) 
	{ 
		fWidth 	= innerWidth; 
		fHeight = innerHeight; 		
	} 
	//For Opera 
	else if (is.op) 
	{ 
		fWidth 	= innerWidth; 
		fHeight = innerHeight; 		
	} 
	//For old Netscape 
	else if (document.layers) 
	{ 
		fWidth 	= window.innerWidth; 
		fHeight = window.innerHeight; 		
	}

	Page.width 	= fWidth;
	Page.height = fHeight;
	Page.top 	= window.document.body.scrollTop;
}

Ajax.RequestSongId = function(feedurl, callbackMethod)
{
	Page.getPageCenterX();
	
	url = feedurl;
	
	Ajax.RequestSongId = Ajax.createRequestObject();
	Ajax.RequestSongId.onreadystatechange = callbackMethod;
	Ajax.RequestSongId.open("POST", url, true);
	Ajax.RequestSongId.send(url);
}

Ajax.ResponseSongId = function ()
{
	if(Ajax.CheckReadyState(Ajax.RequestSongId))
	{	
		var	response = Ajax.RequestSongId.responseXML.documentElement;
		var _data 	 = response.getElementsByTagName('song');
		var song_id  = response.getElementsByTagName('id')[0].firstChild.data;
		
		Ajax.RequestImage('content_ajax.php?method=getImageXML&param=', song_id, Ajax.ResponseImage);
		Ajax.RequestContent('content_ajax.php?method=getContentXML&param=', song_id, Ajax.ResponseContent);
	}
}

Ajax.RequestImage = function(feedurl, song_id, callbackMethod)
{
	Page.getPageCenterX();
	
	url = feedurl+song_id;
	
	Ajax.RequestImage = Ajax.createRequestObject();
	Ajax.RequestImage.onreadystatechange = callbackMethod;
	Ajax.RequestImage.open("POST", url, true);
	Ajax.RequestImage.send(url);
}

Ajax.ResponseImage = function ()
{
	if(Ajax.CheckReadyState(Ajax.RequestImage))
	{	
		document.getElementById("flash-player").innerHTML = Ajax.RequestImage.responseText;
	}
}

Ajax.RequestContent = function(feedurl, song_id, callbackMethod)
{
	Page.getPageCenterX();
	
	url = feedurl+song_id;
	
	Ajax.RequestContent = Ajax.createRequestObject();
	Ajax.RequestContent.onreadystatechange = callbackMethod;
	Ajax.RequestContent.open("POST", url, true);
	Ajax.RequestContent.send(url);
}

Ajax.ResponseContent = function ()
{
	if(Ajax.CheckReadyState(Ajax.RequestContent))
	{	
		document.getElementById("songinfo-header").innerHTML = Ajax.RequestContent.responseText;
	}
}

Ajax.createRequestObject = function()
{
	var obj;
	if(window.XMLHttpRequest)
	{
		obj = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		obj = new ActiveXObject("MSXML2.XMLHTTP");
	}
	return obj;
}

Ajax.CheckReadyState = function(obj)
{
	if(obj.readyState < 4) {		
		
		document.getElementById('loading').style.top = (Page.top + Page.height/2)+150;
		document.getElementById('loading').style.left = Page.width/2-675;
		document.getElementById('loading').style.position = "absolute";
		
		document.getElementById('loading').innerHTML = "<table align='center'><td class='columnHeader'>&nbsp;</td></table>";  
	}
	if(obj.readyState == 1) { document.getElementById('loading').innerHTML = " "; }
	if(obj.readyState == 2) { document.getElementById('loading').innerHTML = " "; }
	if(obj.readyState == 3) { document.getElementById('loading').innerHTML = " "; }	
	if(obj.readyState == 4)
	{
		if(obj.status == 200)
		{
			document.getElementById('loading').innerHTML = "<div class='floaterText'> </div>";
			//setTimeout('Page.loadOut()',2000);
			return true;
		}
		else
		{
			document.getElementById('loading').innerHTML = "HTTP " + obj.status;
		}
	}
}

	Ajax.RequestSongId('content_ajax.php?method=getSongXML', Ajax.ResponseSongId);
	
}

function startUpload(){
  var file = document.getElementById('uploadify').value;
  if(file == "" || file == undefined) {
    return false;
  } else {
    document.getElementById('f1_upload_process').style.visibility = 'visible';
    return true;
  }
}

function stopUpload(success, user_id){
  if(success == 2){
     alert("No file uploaded");
  }
  else if(success == 3){
     alert("File upload failed");
  }
  else if(success == 4){
     alert("Data copy failure");
  }

  document.getElementById('f1_upload_process').style.visibility = 'hidden';
  refreshImageForm(user_id);
  return true;   
}

function refreshImageForm(user_id){
  $.ajax({
		type: "GET",
		url: "update_profile.php",
		data: "type=showimage&user_id="+user_id,
		cache: false,
		async: false,
		success: function(result) {
			// apply star rating to element
			$("#show_image").html(result);
		},
		error: function(result) {
			alert("some error occured, please try again later");
		}
	});
}
