/*
Declare global variables.
*/
var map;
var request;
var response;
var execute_function;
var master_photo_data = new Array();
var master_photo_data_current_index = 0;
/*
Function: 			buildImageURL
Author:				Chris Tibbitts
Revised On:			9/11/2007
Purpose:  			Constructs the url to an image on flickr.
Parameters:	
	farm_id: 		Obtained from the flickr XML; this represents the id of the server farm at Flickr.
	server_id:		Obtained from the flickr XML; this represents the id of the server at Flickr.
	image_id:		Obtained from the flickr XML; this represents the id of the image at Flickr.
	secret:			Obtained from the flickr XML; this represents the shared secret of the image at Flickr.
	size:			This represents the maximum size of the image at Flickr. See predefined values below.
						[s] small square 75x75. 
						[t] thumbnail, 100 on longest side. 
						[m] small, 240 on longest side.
						[-] medium, 500 on longest side. 
						[b] large, 1024 on longest side (only exists for very large original images). 
						[o] original image, either a jpg, gif or png, depending on source format. 		
	ext:			This is the file format extension of the image file.
Return Value: 		A string containing the complete URL of the given image.
*/
function buildImageURL(farm_id, server_id, image_id, secret, size, ext){
 	var url = "http://farm"+farm_id+".static.flickr.com/"+server_id+"/"+image_id+"_"+secret+"_"+size+"."+ext;
	return url;
}

/*
Function: 			requestFlickrRESTData
Author:				Chris Tibbitts
Revised On:			9/11/2007
Purpose:  			Requests via AJAX an XML data set from Flickr in REST format.
Parameters:	
	request_URL: 	The Flickr URL that will provide the desired data.
	callback:		The function to execute when the request is complete.
Return Value: 		None.
*/
function requestFlickrRESTData(request_URL, f){
	var url = request_URL;
	execute_function = f;
	// Mozilla and Safari
    if (window.XMLHttpRequest) {
        request = new XMLHttpRequest();
        request.onreadystatechange = receiveFlickrRESTData;
        request.open("GET", url, true);
        request.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        request = new ActiveXObject("Microsoft.XMLHTTP");
        if (request) {
            request.onreadystatechange = receiveFlickrRESTData;
            request.open("GET", url, true);
            request.send();
        }
    }
}

/*
Function: 			receiveFlickrRESTData
Author:				Chris Tibbitts
Revised On:			9/11/2007
Purpose:  			Receives REST data set from Flickr in standard XML format. Assigns this data to global variable "response".
Parameters:			None.
Return Value: 		None.
*/
function receiveFlickrRESTData(){
	 // only if request shows "complete"
    if (request.readyState == 4) {
        // only if "OK"
        if (request.status == 200) {
			//alert(request.responseXML.xml); //View XML in IE
			//alert(new XMLSerializer().serializeToString(request.responseXML)); //View XML in Mozilla
			response = request.responseXML.documentElement;
			dispatcher(execute_function);
			//alert(response);
        } else {
            alert("There was a problem retrieving the XML data from Flickr:\n" + request.statusText);
        }
    }
}

