//////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(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(friend_img_id+j).src = friend_path_list[i];
    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";
	}	
	if(friend_id_list.length==0)
	{
    document.getElementById('nullfriend').style.display="block"
	}
	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(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>";
	}

//  AJAX IMPLEMENTATION
//	if((photoindex+totalPhotoDiv+bufferImage) == photo_name_list.length) {
//	   getImage();
//	}

	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";
	}
    if(photo_id_list.length==0)
	{
    	document.getElementById('nullphoto').style.display="block"
	}
	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;
		}
	}
}


///////member photos ends/////////////

///////member video start/////////////
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+bufferImage) == video_name_list.length) {
//        if(video_name_list.length%2 == 0)
//	       getImage(0);
//	    else
//	       getImage(1);
//	}

	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";
        }
	}
    if(videoindex == 0) {
		document.getElementById(videoleft).style.display = "none";
	}
	if(video_path_list.length==0)
        	{  
        	    document.getElementById('source_img_id_0').style.display = "none";
        	    document.getElementById('source_img_id_1').style.display = "none";
        	    document.getElementById('source_img_id_2').style.display = "none";
        	    document.getElementById('source_img_id_3').style.display = "none";        	            	            	    
            	document.getElementById('nullvideo').style.display="block"
        	}
	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;
		}
	}
}


///////member video ends/////////////

////// Start AJAX 4 download photo from flickr site

function getImage() {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert ("Browser does not support HTTP Request");
        return;
    } 

    var url = "/dialogo/download_flickr_photo";
    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

var bufferImage = 2;
var xmlHttp = null;
var totalFriendDiv    = 2;
var friendIndex       = 0;

var friendleft          = "friend_left";
var friendright         = "friend_right";
var friend_div_id       = "friend_div_id_"; 
var friend_img_id       = "friend_img_id_"; 
var friend_name_id      = "friend_name_id_";
var friend_status_id    = "friend_status_id_";
var friend_wmail        = "friend_wmail";
var friend_msg          = "friend_msg";
var photoleft           = "photo_left";
var photoright          = "photo_right";

var friend_id_list      = new Array();
var friend_name_list    = new Array();
var friend_path_list    = new Array();
var friend_status_list  = new Array();
/////////// END FRIEND PART VARIABLE DECLARATIONS

/////////// START PHOTO PART VARIABLE DECLARATIONS
var photoleft   = "photo_left";
var photoright  = "photo_right";
var source_img_id      = "source_img_id_"; 

var photoindex      = 0;
var totalPhotoDiv   = 4;

var photo_div_id    = "photo_div_id_";
var photo_img_id    = "photo_img_id_";
var photo_name_id   = "photo_name_id_";

var photo_id_list   = new Array();
var photo_name_list = new Array();
var photo_path_list = new Array();
/////////// END PHOTO PART VARIABLE DECLARATIONS

/////////// START VIDEO PART VARIABLE DECLARATIONS
var videoleft   = "video_left";
var videoright  = "video_right";

var videoindex      = 0;
var totalVideoDiv   = 4;

var video_div_id    = "video_div_id_";
var video_img_id    = "video_img_id_";
var video_name_id   = "video_name_id_";

var video_id_list   = new Array();
var video_name_list = new Array();
var video_path_list = new Array();
var video_url       = new Array();
