/* --------------------------------------------------------------------------------------------- *\
 
	SOPHIAKNOWS GALLERY OBJECT LIBRARY
	SKGALLERY()
	Created:  1998-11-12             
	Issued:   1998-11-12             
	Modified: 2007-07-15             
	A.R. Tony Pisarra,
	SophiaKnows   

 * --------------------------------------------------------------------------------------------- *	
 * --------------------------------------------------------------------------------------------- *	

	This software may reproduced in whole or in part without limitations. Provided, a copy of
	this notice must appear in any human readable source code along with the following
	disclaimer:

	This is free software. It is made available on an as-is basis. Its authors make
	NO WARRANTY as to its merchantability or fitness for any specific purpose.


	A.R. Tony Pisarra,
	SophiaKnows.com

 * --------------------------------------------------------------------------------------------- *			
 * --------------------------------------------------------------------------------------------- *					



\* --------------------------------------------------------------------------------------------- */

// SKGallery: (Begin All)
// SKGallery: Prototype: Object
function SKGallery(images) {
	var args=SKGallery.arguments;
	this.images=new Array();
	this.slides=new Array();
	this.selected=0;
	this.name=((args[1])?args[1]:'SLIDE');
	this.preload(images)
	}
SKGallery.prototype.preload = function (images) {
	for(var i=0;image=images[i];i++) {
		this.slides[i] = new Image();
		this.slides[i].src = image.src;
		this.slides[i].alt  = ((image['alt'])?image['alt']:"");
		this.slides[i].title = ((image['title'])?image['title']:"");
		this.images[i] = image.src;
		}
	}
// SKGallery: Methods: Next
SKGallery.prototype.next = function () {
	this.selected=((this.selected<(this.images.length-1))?(this.selected+1):0);
	this.show(this.selected);
	}
// SKGallery: Methods: Back
SKGallery.prototype.back = function () {
	this.selected=((this.selected>0)?(this.selected-1):(this.images.length-1));
	this.show(this.selected);
	}
// SKGallery: Methods: Show
SKGallery.prototype.show = function (i) {
	var xImage = new Image();
	    xImage.src = this.images[i];
	this.length=this.images.length;
	this.selected=i;
	document.images[this.name+"-IMAGE"].src=this.images[i];
	if(this['maxlength']) {
		var redims = this.getredims(this.slides[i],this['maxlength']);
		document.images[this.name+"-IMAGE"].width = redims['width'];
		document.images[this.name+"-IMAGE"].height = redims['height'];
		}
	if(document.getElementById) { 
		if(counter=document.getElementById(this.name+"-COUNTER")) { counter.innerHTML=(parseInt(this.selected)+1)+" of "+this.images.length;}
		if(title=document.getElementById(this.name+"-TITLE")) { title.innerHTML=((this.slides[i].title)?this.slides[i].title:"") }	
		if(alt=document.getElementById(this.name+"-ALT")) { alt.innerHTML=((this.slides[i].alt)?this.slides[i].alt:"") }			
		}
	if(document.getElementById) { document.getElementById(this.name+"-COUNTER").innerHTML=(parseInt(this.selected)+1)+" of "+this.images.length;}
	}

SKGallery.prototype.getredims = function(image,maxlength) {
	var	xImage = new Image();
	    xImage.src = image.src;
	var factor = maxlength/xImage.width;
		factor =((factor*xImage.height<maxlength)? factor : (maxlength/xImage.height));	
	var dims = new Object();

		dims['width'] = ((xImage.width)? xImage.width*factor : "");
		dims['height'] =((xImage.height)? xImage.height*factor : "");
	return dims;
	}

// SKGallery: Methods: Tag
SKGallery.prototype.tag = function (i) {
	var args=SKGallery.prototype.tag.arguments;
	var tag = "<img ";
	    tag += "src=\""+this.images[i]+"\"";
	    tag += (args[1])?" width=\""+args[1]+"\"" : ""; 
	    tag += (args[2])?" height=\""+args[2]+"\"" : ""; 
	    tag += (args[3])?" name=\""+args[3]+"_image\"" : ""; 
	    tag += " border=\"0\" />";
	return tag;
	}
// SKGallery: (End All)


/* --------------------------------------------------------------------------------------------- *\
 
	SOPHIAKNOWS XML/AJAX UTILITIES
	Created:  2005-11-12             
	Issued:   2005-11-12             
	Modified: 2007-07-15             
	A.R. Tony Pisarra,
	SophiaKnows   

 * --------------------------------------------------------------------------------------------- *	
 * --------------------------------------------------------------------------------------------- *	

	This software may reproduced in whole or in part without limitations. Provided, a copy of
	this notice must appear in any human readable source code along with the following
	disclaimer:

	This is free software. It is made available on an as-is basis. Its authors make
	NO WARRANTY as to its merchantability or fitness for any specific purpose.


	A.R. Tony Pisarra,
	SophiaKnows.com

 * --------------------------------------------------------------------------------------------- *			
 * --------------------------------------------------------------------------------------------- *					



\* --------------------------------------------------------------------------------------------- */


//	E. AJAX-XML

//	E.1 AJAX: SKXML
function SKXml(url) {
	var args = SKXml.arguments;
	var tag = ((args[1])?args[1]:"item");
	this[tag]=new Array();	
	var xhReq = new createXMLHttpRequest();
	xhReq.open("GET", url, false);
	xhReq.send(null);
	var xml = this.xml = xhReq.responseXML;
	var itemlist = xml.documentElement.getElementsByTagName(tag);
	for(i=0;i<itemlist.length;i++) {
		this[tag][i] = new Object();
		this[tag][i].nodeValue =((itemlist[i]['firstChild'] )?decode_htmlentities( itemlist[i].firstChild.nodeValue ) :"" );
		for(a=0;a<itemlist[i].attributes.length;a++) {
			this[tag][i][itemlist[i].attributes[a].name] = itemlist[i].getAttribute(itemlist[i].attributes[a].name);
			}
		}
	}


SKXml.prototype.getElements = function(tag) {
	var itemlist = this.xml.documentElement.getElementsByTagName(tag);
	var elements = new Object();
	elements[tag]=new Array();	
	for(i=0;i<itemlist.length;i++) {
		elements[tag][i] = new Object();
		elements[tag][i].nodeValue =((itemlist[i]['firstChild'] )?decode_htmlentities( itemlist[i].firstChild.nodeValue ) :"" );
		for(a=0;a<itemlist[i].attributes.length;a++) {
			elements[tag][i][itemlist[i].attributes[a].name] = itemlist[i].getAttribute(itemlist[i].attributes[a].name);
			}
		}
	return elements[tag];
	}


// E.2 CREATE XMLHTTP SOURCE

function createXMLHttpRequest() {
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   alert("XMLHttpRequest not supported");
   return null;
 }

// GLOBAL: DECODE HTML ENTITIES	
function decode_htmlentities(str) {
	str = str.replace(/&amp;/gi,"&");
	str = str.replace(/&lt;(.+?)&gt;/g,"<$1>");
	return str;
	}


