<!--
/*
TODO: 
classify my css to prevent external interference.
*/

function parseThumbs(str)
{
	//alert(str);
	var aThumbs = str.split("|");
	var el = gbid('thumbs');
	el.innerHTML = "";
	
	gbid('fb_dir_title').innerHTML = aThumbs[0];
	
	// Send to a table?  Else dump all the images in the div.
	if (fastbox_columns > 0)
	{	
        // Create <table> element and a <tbody> element
        var tbl     = document.createElement("table");
        var tblBody = document.createElement("tbody");
		var i_column = fastbox_columns;
		
        // Create table cells.
        for (var j = 1; j < aThumbs.length; j++) 
		{
			// Create a table row.
			if (i_column == fastbox_columns)
			{
				var row = document.createElement("tr");
				i_column = 1;
			} 
			else
			{
				i_column++;				
			}
                var cell = document.createElement("td");

				aPath = aThumbs[j].split("/");
				
				var img = document.createElement("img");
				img.src = "images/" + aPath[0] + "/" + aPath[1] + "/_thumbs/th_" + aPath[2];
				img.width = fastbox_thumbnail_width;
				img.height = fastbox_thumbnail_height;
				
				var a = document.createElement("a");
				a.href =  fastbox_root + "/images/" + aPath[0] + "/" + aPath[1] + "/" + aPath[2];
				a.rel = "lightbox[y]";
				a.title = "<a href='" + fastbox_root + "/images/" + aPath[0] + "/" + aPath[1] + "/" + aPath[2] + "'>" + aPath[2] + "</a>";
				
				a.appendChild(img);
							
                cell.appendChild(a);
                row.appendChild(cell);

            // Add the row to the end of the table body if we have the row filled.
			if (i_column == fastbox_columns)
			{
    	        tblBody.appendChild(row);
				row = null;
			}
        }
		
		// For a partial last row on exit...
		if (row){tblBody.appendChild(row);}
		
        // Put the <tbody> in the <table>.
        tbl.appendChild(tblBody);
        el.appendChild(tbl);
        tbl.setAttribute("border", "0");
	}  // Just send images to the div container.
	else 
	{
		for (var i = 1; i < aThumbs.length; i++)
		{	
			aPath = aThumbs[i].split("/");
			
			var img = document.createElement("img");
			img.src = "images/" + aPath[0] + "/" + aPath[1] + "/_thumbs/th_" + aPath[2];
			
			var a = document.createElement("a");
			a.href =  "/gallery/images/" + aPath[0] + "/" + aPath[1] + "/" + aPath[2];
			a.rel = "lightbox[y]";
			a.title = aPath[2];
			
			a.appendChild(img);
			el.appendChild(a);
		}
	}
	
	// Now reload the GrayBox Scripts.
	/*
	GB_SETS = {}
	decoGreyboxLinks();
	*/


	scroll(0,0);
	gbid('fb_thumbs').style.width = "525px";
}

/* quick getElement reference */
function gbid()
{
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++)
	{
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

///////////////////////////////////////////// AJAX STUFF /////////////////////////////////////////////////////

//TODO: Error handler.
//TODO: build in "Post" capabilities.

/*
METHODS OF XMLHTTP OBJECT:-----------------------------------------------------------
abort() 	Stops the current request
getAllResponseHeaders() 	                                    Returns complete set of headers (labels and values) as a string
getResponseHeader("headerLabel") 	                            Returns the string value of a single header label
open("method", "URL"[, asyncFlag[, "userName"[, "password"]]]) 	Assigns destination URL, method, and other optional attributes of a pending request
send(content) 	                                                Transmits the request, optionally with a POST string or DOM object data
setRequestHeader("label", "value") 	                            Assigns a label/value pair to the header to be sent with a request

PROPERTIES OF XMLHTTP OBJECT:--------------------------------------------------------
onreadystatechange 	    Event handler for an event that fires at every state change
readyState 	            Status: 0 = uninitialized 1 = loading 2 = loaded 3 = interactive 4 = complete
responseText 	        String version of data returned from server process
responseXML 	        DOM-compatible document object of data returned from server process
status 	                Numeric code returned by server, such as 404 for "Not Found" or 200 for "OK"
statusText 	            String message accompanying the status code
*/

// Usage example:  ajaxThis(URL, parseGetResponse, true, true);
 
//Use this function to do all your ajax related stuff.
function ajaxThis(url, callBackFunction, async, bPreventServerCaching)
{
    //prevent browser caching by sending always sending a unique url.
    if (bPreventServerCaching){url = url + "&NoCache=" + Math.floor(Math.random()*10000);}
    //alert(url);
    var req = newXMLHttpRequest();    // Obtain an XMLHttpRequest instance
    var handlerFunction = getReadyStateHandler(req, callBackFunction);    // Set the handler function to receive callback notifications from the request object
    req.onreadystatechange = handlerFunction;
    req.open('GET', url, async);  // Third parameter specifies request is asynchronous.
    req.send(null);
}
 
// Returns a new XMLHttpRequest object, or false if this browser doesn't support it
function newXMLHttpRequest() 
{
/*
    try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
   } catch (e) {
    alert("Permission UniversalBrowserRead denied.");
   }  
*/
    var xmlreq = false;
    if (window.XMLHttpRequest) 
	{
        // Create XMLHttpRequest object in non-Microsoft browsers
        xmlreq = new XMLHttpRequest();
    }
	else if (window.ActiveXObject) 
	{
        // Create XMLHttpRequest via MS ActiveX
        try 
		{
            // Try to create XMLHttpRequest in later versions
            // of Internet Explorer
            xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
        }
		catch (e1)
		{
            try 
			{
                // Try version supported by older versions
                // of Internet Explorer
                xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
            } 
			catch (e2) 
			{
                doError(e2);
			}
		}
  }
  return xmlreq;
}
 
/* Returns a function that waits for the specified XMLHttpRequest
 * to complete, then passes its XML response
 * to the given handler function.
 * req - The XMLHttpRequest whose state is changing
 * responseXmlHandler - Function to pass the XML response to */
 
function getReadyStateHandler(req, responseXmlHandler)
{
    // Return an anonymous function that listens to the 
    // XMLHttpRequest instance
    return function () 
	{
    // If the request's status is "complete"
        if (req.readyState == 4) 
		{
            // Check that a successful server response was received
            if (req.status == 200) 
			{
                // Pass the XML payload of the response  
                //  to the handler function
                responseXmlHandler(req);
            }
			else
			{
                // An HTTP problem has occurred
                alert("HTTP error: "+req.status);
            }
        }
    }
}     


function ajax_rpc(oResponse)
{
	if (oResponse)
	{
		try 
		{
			//alert(oResponse.responseText);
			eval(oResponse.responseText);			
		} 
		catch (err)
		{
			alert(err + "\r\n" + oResponse.responseText);
		}
	}
}
//-->