//////FRIEND BLOCK START////////////
function previousfriends() {
	friendIndex--;
	for(var i=friendIndex, j=0;j<totalFriendDiv;i++, j++) {
    document.getElementById(friend_img_id+j).src = friend_path_list[i];
    document.getElementById("greenpost"+j).src = "/images/green_post.jpg";
    document.getElementById("friend_home"+j).src = "/images/green_wmail.jpg";
    document.getElementById(friend_name_id+j).innerHTML="<html><head></head><body>"+shink(friend_name_list[i])+"</body></html>";
    document.getElementById(friend_wmail+j).href = "/personal_member/index/" + friend_name_list[i];
    document.getElementById(friend_msg+j).href = "javascript:sendMessage('" + friend_name_list[i] + "');";
    if(friend_status_list[i] == "0")
      document.getElementById(friend_status_id+j).src = "/images/red_man.gif";
    else
      document.getElementById(friend_status_id+j).src = "/images/green_man.jpg";
  }
  if(friendIndex <= 0)
    document.getElementById(friendleft).style.display = "none";
	document.getElementById(friendright).style.display = "inline";
}

function nextfriends() {
	friendIndex++;
  for(var i=friendIndex, j=0;j<totalFriendDiv;i++,j++) {
    document.getElementById(friend_img_id+j).src = friend_path_list[i];
    document.getElementById("greenpost"+j).src = "/images/green_post.jpg";
    document.getElementById("friend_home"+j).src = "/images/green_wmail.jpg";
    document.getElementById(friend_wmail+j).href = "/personal_member/index/" + friend_name_list[i];
    document.getElementById(friend_msg+j).href = "javascript:sendMessage('" + friend_name_list[i] + "');";
    document.getElementById(friend_name_id+j).innerHTML="<html><head></head><body>"+shink(friend_name_list[i])+"</body></html>";
    if(friend_status_list[i] == "0")
      document.getElementById(friend_status_id+j).src = "/images/red_man.gif";
    else
      document.getElementById(friend_status_id+j).src = "/images/green_man.jpg";
  }
	if(friendIndex+totalFriendDiv == friend_name_list.length)
    document.getElementById(friendright).style.display = "none";
	document.getElementById(friendleft).style.display = "inline";
}

function loadfriends() {
	if(friend_id_list.length <= totalFriendDiv) {
		document.getElementById(friendleft).style.display = "none";
		document.getElementById(friendright).style.display = "none";
	}
	for(var i=friend_id_list.length;i<totalFriendDiv;i++) {
    if(document.getElementById(friend_div_id+i) != null)
        document.getElementById(friend_div_id+i).style.display = "none";
	}
  if(friend_path_list.length==1){
    document.getElementById('friend_img_id_1').style.display = "none";
    document.getElementById('friend_name_id_1').style.display = "none";
    document.getElementById('friend_status_id_1').style.display = "none";
    document.getElementById('friend_wmail1').style.display = "none";
    document.getElementById('friend_msg1').style.display = "none";
	}
	if(friendIndex == 0) {
		document.getElementById(friendleft).style.display = "none";
	}
	for(var i=0;i<friend_id_list.length;i++) {
		if(document.getElementById(friend_img_id+i) != null) {
			document.getElementById(friend_img_id+i).src = friend_path_list[i];
			document.getElementById("greenpost"+i).src = "/images/green_post.jpg";
			document.getElementById("friend_home"+i).src = "/images/green_wmail.jpg";
			document.getElementById(friend_wmail+i).href = "/personal_member/index/" + friend_name_list[i];
      document.getElementById(friend_msg+i).href = "javascript:sendMessage('" + friend_name_list[i] + "');";
			document.getElementById(friend_name_id+i).innerHTML="<html><head></head><body>"+shink(friend_name_list[i])+"</body></html>";
      if(friend_status_list[i] == "1")
        document.getElementById(friend_status_id+i).src = "/images/green_man.jpg";
      else
        document.getElementById(friend_status_id+i).src = "/images/red_man.gif";
		}else {
			break;
		}
	}
}

//////FRIEND BLOCK END////////////

///////member photos/////////////

function previousphoto() {
	photoindex--;
	for(var i=photoindex, j=0;j<totalPhotoDiv;i++, j++) {
    document.getElementById(photo_img_id+j).src = photo_path_list[i];
   document.getElementById(photo_name_id+j).innerHTML="<html><head></head><body>"+photo_name_list[i]+"</body></html>";
	}
	if(photoindex <= 0)
		document.getElementById(photoleft).style.display = "none";
	document.getElementById(photoright).style.display = "inline";
}

function nextphoto() {
	photoindex++;
  for(var i=photoindex, j=0;j<totalPhotoDiv;i++,j++) {
		document.getElementById(photo_img_id+j).src = photo_path_list[i];
		document.getElementById(photo_name_id+j).innerHTML="<html><head></head><body>"+photo_name_list[i]+"</body></html>";
	}
	if(photoindex+totalPhotoDiv == photo_name_list.length)
		document.getElementById(photoright).style.display = "none";
	document.getElementById(photoleft).style.display = "inline";
}

function loadphotos() {
	if(photo_id_list.length <= totalPhotoDiv) {
		document.getElementById(photoleft).style.display = "none";
		document.getElementById(photoright).style.display = "none";
	}
	for(var i=photo_id_list.length;i<totalPhotoDiv;i++) {
    if(document.getElementById(photo_div_id+i) != null)
      document.getElementById(photo_div_id+i).style.display = "none";
	}
	if(photoindex == 0) {
		document.getElementById(photoleft).style.display = "none";
	}
	for(var i=0;i<photo_id_list.length;i++) {
		if(document.getElementById(photo_img_id+i) != null) {
			document.getElementById(photo_img_id+i).src = photo_path_list[i];
			document.getElementById(photo_name_id+i).innerHTML="<html><head></head><body>"+photo_name_list[i]+"</body></html>";
		}else {
			break;
		}
	}
}

function previousvideo() {
	videoindex--;
	for(var i=videoindex, j=0;j<totalVideoDiv;i++, j++) {
    document.getElementById(source_img_id+j).src = sourceFrom(video_url[i]);
    document.getElementById(video_img_id+j).src = video_path_list[i];
	  document.getElementById(video_name_id+j).innerHTML="<html><head></head><body>"+video_name_list[i]+"</body></html>";
	}
	if(videoindex <= 0)
		document.getElementById(videoleft).style.display = "none";
	document.getElementById(videoright).style.display = "inline";
}

function nextvideo() {
	videoindex++;
  for(var i=videoindex, j=0;j<totalVideoDiv;i++,j++) {
		document.getElementById(source_img_id+j).src = sourceFrom(video_url[i]);
		document.getElementById(video_img_id+j).src = video_path_list[i];
		document.getElementById(video_name_id+j).innerHTML="<html><head></head><body>"+video_name_list[i]+"</body></html>";
	}
	if(videoindex+totalVideoDiv == video_name_list.length)
		document.getElementById(videoright).style.display = "none";
	document.getElementById(videoleft).style.display = "inline";
}

function loadvideos() {
	if(video_path_list.length <= totalVideoDiv) {
		document.getElementById(videoleft).style.display = "none";
		document.getElementById(videoright).style.display = "none";
	}
	for(var i=video_path_list.length;i<totalVideoDiv;i++) {
    if(document.getElementById(video_div_id+i) != null) {
      document.getElementById(video_div_id+i).style.display = "none";
      document.getElementById(source_img_id+i).style.display = "none";
    }
	}
  if(videoindex == 0) {
		document.getElementById(videoleft).style.display = "none";
	}
	for(var i=0;i<video_path_list.length;i++) {
		if(document.getElementById(video_img_id+i) != null) {		
 			document.getElementById(source_img_id+i).src = sourceFrom(video_url[i]);
			document.getElementById(video_img_id+i).src = video_path_list[i];
			document.getElementById(video_name_id+i).innerHTML="<html><head></head><body>"+video_name_list[i]+"</body></html>";
		}else {
			break;
		}
	}
}

function getImage(where) {
alert('DANI REVISA getImage en HOME.js');
  xmlHttp = GetXmlHttpObject();
  if (xmlHttp == null) {
    alert ("Browser does not support HTTP Request");
    return;
  } 

  var url;
  if(where == 0)
    url = "/dialogo/download_flickr_photo";
  else
    url = "/dialogo/download_youtube_video?page="+(video_path_list.length-1)/2;
  xmlHttp.onreadystatechange = stateChanged;
  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
 }

function GetXmlHttpObject() {
  var objXMLHttp = null;
  if (window.XMLHttpRequest) {
    objXMLHttp=new XMLHttpRequest();
  }else if (window.ActiveXObject) {
    objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  return objXMLHttp;
}

function stateChanged() {
  if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
    if(xmlHttp.responseText!='' && xmlHttp.responseText!="null") {
      var output = xmlHttp.responseText.split('^^');
      video_id_list[video_id_list.length] = ""+video_id_list.length;
      video_name_list[video_name_list.length] = shink(output[1]);
      video_path_list[video_path_list.length] = output[0];
    }
  } 
}
////// End AJAX 4 download photo from flickr site
function play_video(index) {
  if(index == current_id)
    window.open('/web_multimedia/youtube_video_play?url='+video_url[current_index],'Dialogo Social Network', 'width=440, height=365, resizable=no, scrollbars=no')
  else if(index == (current_id-2))
    window.open('/web_multimedia/youtube_video_play?url='+video_url[current_index-2],'Dialogo Social Network', 'width=440, height=365, resizable=no, scrollbars=no')
}
