function getWallpapers(category) {
	
	var handleSuccess = function(o){
		if(o.responseText !== undefined){
			var wallpaper = get_item('wallpaperTable');
			wallpaper.innerHTML = o.responseText;
			initImageProcess();
			checkselectedWallpaper();
		}
	}

	var handleFailure = function(o){
		if(o.responseText !== undefined){
			/*
			div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
			div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
			div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";
			*/
		}
	}

var sUrl = app_web_root + "wallpapers/" + category;
 
	var callback =
		{
		  success:handleSuccess,
		  failure:handleFailure,
		  argument: { foo:"foo", bar:"bar" }
		};
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);

}

var last_click = '0';

function getClickTime() {
	var d = new Date();
	var t = d.getTime();

	if(last_click == '0') {
		last_click = t;
		return 0;
	}
	else {
		var result = parseInt(t) - parseInt(last_click);
		last_click = t;
		return result;
	}
}

var last_id = 999;
//manage selected wallpaper///
function getCatWallpaper(id) {
	
	if(last_id == 999 || last_id != id || (getClickTime() > 3000) ) {
		last_id = id;
		
		var i=1;
		while(get_item('wall' + i) ) {
			var walltab = get_item('wall' + i);
			walltab.className = 'tab';
			i++;
		}
		var catItem = get_item('wall' + id);	

		catItem.className = 'selectedTab';
		if(id == 7) {
			start_session = 'yes';
			uploadWallpaper();
		}
		else {
			start_session = 'no';
			getWallpapers(id);
		}
	}
}


function selectWallpaper(id) {
	var selWallVal = get_item('selectedWallpaper');
	
	if(selWallVal.value == id) {
		selWallVal.value = "";
	}
	else {
		if(selWallVal.value) {
		if(imgWall = get_item('wallimg' + selWallVal.value)) {
		imgWall.className = 'defaultWall';
			}
		}	
		selWallVal.value = id;
	}

	var imgWall1 = get_item('wallimg' + id);

	if(imgWall1.className == 'selectedWall') {
		imgWall1.className = 'defaultWall';
	}
	else {
		imgWall1.className = 'selectedWall';
	}
}

function checkselectedWallpaper() {
	var selWallVal = get_item('selectedWallpaper');
	
	if(selWallVal.value) {
		if(checkWall = get_item('wallimg' + selWallVal.value) ) {
			checkWall.className = 'selectedWall';
		}
	}
}

function uploadWallpaper() {
	//showUpload();

	var handleSuccess = function(o){
		if(o.responseText !== undefined){
			var wallpaper = get_item('wallpaperTable');
			wallpaper.innerHTML = o.responseText;
			initImageProcess();
			checkSessionWallpaper();
			checkselectedWallpaper();
		}
	}

	var handleFailure = function(o){
		if(o.responseText !== undefined){
		}
	}

	var sUrl = app_web_root + "wallpapers/upload";
	var callback =
		{
		  success:handleSuccess,
		  failure:handleFailure,
		  argument: { foo:"foo", bar:"bar" }
		};
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
}


function checkSessionWallpaper() {
	if(florin == 'wallpaper') {

	var handleSuccess = function(o){
		if(o.responseText !== undefined){
			if( get_item('own_images') ) {
				var own_img = get_item('own_images');
				if(o.responseText.length > 50) {
					own_img.innerHTML =  o.responseText;
					get_item('wall_upload_description').style.display = 'none';
					selectWallpaper(999);
				}
				checkselectedWallpaper();	
			}
		}
	}

	var handleFailure = function(o){
		if(o.responseText !== undefined){
		}
	}

	if(img_itm = get_item('wallimg999') ) {
		var aux = img_itm.src;
		aux = aux.substr(-36);
		if(aux[0] == '/') {
			aux = aux.substr(1);
		}
	}

	if(aux) {
		var sUrl = app_web_root + "wallpapers/ownfile/" + aux;
	}
	else {
		var sUrl = app_web_root + "wallpapers/ownfile/";
	}
	
	var callback =
		{
		  success:handleSuccess,
		  failure:handleFailure,
		  argument: { foo:"foo", bar:"bar" }
		};

	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);

		if(start_session == 'yes') {
			setTimeout("checkSessionWallpaper();", 5000);
		}
	}
}


////////////////loading opacity/////////////////
function initImageProcess() {
	var wids_div = get_item('widsss');
	wids_content = wids_div.innerHTML;
	wids = wids_content.split('_');

	for(p = 0; p < wids.length; p++) {
		initImage(wids[p]);
	}
}

function initImage(id) {

  imageId = id;
  imageId = 'wallcont'+imageId;
  imageId = imageId.replace('\n', '');

  image = get_item(imageId);

	if(image) {	
  setOpacity(image, 0);
  image.style.visibility = 'visible';
  fadeIn(imageId,0);
	}
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;

  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";

  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;

  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;

  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }
  }
}