﻿// set up arrays to hold photo details; use 4 parallel arrays
countLength = 0; // will hold the total number of photos to be loaded
globalCount=0; // will hold the number of photos loaded so far

//These array's will be responsible for holding the Photo details.
var photoid = new Array();
var phototitleid = new Array();
var photoserverid = new Array();
var photosecret = new Array();

/*
*Summary:  function to obtain details of photos from flickr, which has to be abtained later
*Return: Will COntinue listening Flickr response to Print Photo image response.
*Author: Soham Dave
*/
function sendData()
{
    var request = createRequest(); // from xhr.js
    var url = "flickrproxy.php?method=flickr.people.getPublicPhotos&api_key=9a62e6b68d280b7893d35e93f35fed6e&parametertype=user_id&parametervalue=44127485@N06";			   
    request.open("GET", url, true);
    request.onreadystatechange = function() {getData(request)};	
    request.send(null);   	
}
/*
*Summary: function to retrieve data sent from flickr and build JavaScript arrays holding that data after doing so,
*Return: Will Print the Photo Data received 
*Author: Soham Dave
*/
function getData(xhr) 
{
   // pick up the correct XMLHttpRequest object, and check its state
  if ((xhr.readyState == 4) &&( xhr.status == 200))
  { 
    var xmlobject = xhr.responseXML;
    var photos =  xmlobject.getElementsByTagName("photo");
    countLength = photos.length;
	document.getElementById("flickr_photos").innerHTML="";
    for (var i = 0; i < photos.length; i++) 
	{
		//Use the DOM Model to fetch the details necessary for photo printing.
    	photoid[i] = photos[i].getAttribute("id");
    	phototitleid[i] = photos[i].getAttribute("title");
    	photoserverid[i] = photos[i].getAttribute("server");
    	photosecret[i] = photos[i].getAttribute("secret");
		tempStr="http://farm3.static.flickr.com/";		
		document.getElementById("flickr_photos").innerHTML=	document.getElementById("flickr_photos").innerHTML + " <a href=\""+ tempStr + photoserverid[i] + "\/" + photoid[i]+ "_" + photosecret[i] + ".jpg\"  title=\"  " + phototitleid[i]+ " \" rel=\"lightbox[roadtrip]\"> <img src=\" "+ tempStr + photoserverid[i] + "\/" + photoid[i]+ "_" + photosecret[i] + ".jpg\"  alt=\"  " + phototitleid[i]+ " \" style=\"width:215px;height:250px;\" /></a>";
   }  
   //Put the photo image on HTML Pages
    document.getElementById("flickr_photos").innerHTML = document.getElementById("flickr_photos").innerHTML + "<br /><br /><a href=\"#\" onclick=\"HideSection('flickr_photos','flickr_photos');\">Hide Photos</a><p class=\"more\"><a href=\"#container\" title=\"Back to Top\"> Back to Top >>>>></a></p>";
  }   
  
}
