/* Stream The World Player Launcher
 *
 */
var FLEX_player = new function() {
	this.player = "andostream";
	this.width = 600;
	this.height = 404;

	this.getURL = function() {
		switch(this.player) {
			case "andostream": return "/common/player/andostream.php"; break;
			default: return false; break;
		}
	}

	this.launch = function(obj) {
		// obj should be JSON obj
		if(obj != undefined) {
			if(obj.width != undefined) this.width = parseInt(obj.width);
			if(obj.height != undefined) this.height = parseInt(obj.height);
			if(obj.player != undefined) this.player = obj.player;
		}

		var url = this.getURL();
		if(url !== false && this.width > 0 && this.height > 0) {
			var player_win = window.open(url, 'player_win', 'width='+this.width+',height='+this.height+',menubar=no,resizable=no,scrollbars=no,toolbar=no');
			return false;
		}
	}
}



/* AJAX Handler
 *
 */
function Ajax() {
 this.req = null;
 this.url = null;
 this.method = 'GET';
 this.async = true;
 this.status = null;
 this.statusText = '';
 this.postData = null;
 this.readyState = null;
 this.responseText = null;
 this.responseXML = null;
 this.handleResp = null;
 this.responseFormat = 'text', // 'text', 'xml', or 'object'
 this.mimeType = null;

 this.init = function() {
  if (!this.req) {
   try {
     // Try to create object for Firefox, Safari, IE7, etc.
     this.req = new XMLHttpRequest();
   }
   catch (e) {
     try {
       // Try to create object for later versions of IE.
       this.req = new ActiveXObject('MSXML2.XMLHTTP');
     }
     catch (e) {
       try {
         // Try to create object for early versions of IE.
         this.req = new ActiveXObject('Microsoft.XMLHTTP');
       }
       catch (e) {
         // Could not create an XMLHttpRequest object.
         return false;
       }
     }
   }
 }
 return this.req;
 };

 this.doReq = function() {
	if (!this.init()) {
		alert('Could not create XMLHttpRequest object.');
		return;
	}
	this.req.open(this.method, this.url, this.async);
	var self = this; // Fix loss-of-scope in inner function
	if(this.method=="POST") {
		this.req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	}
	this.req.onreadystatechange = function() {
		if (self.req.readyState == 4) {
		    switch (self.responseFormat) {
				case 'text':
					resp = self.req.responseText;
					break;
				case 'xml':
					resp = self.req.responseXML;
					break;
				case 'object':
					resp = req;
					break;
			}
			if (self.req.status >= 200 && self.req.status <= 299) {
				self.handleResp(resp);
			} else {
				self.handleErr(resp);
			}
   		}
	};
	this.req.send(this.postData);
  };

  this.doGet = function(url, hand, format) {
	  	this.url = url;
		this.handleResp = hand;
		this.responseFormat = format || 'text';
		this.method="GET";
		this.doReq();
	  };

  this.doPost = function(url, hand, format) {
	  	this.url = url.substring(0,url.indexOf('?'));
		this.handleResp = hand;
		this.responseFormat = format || 'text';
		this.method="POST";
		this.postData=url.substring(url.indexOf('?')+1, url.length);
		this.doReq();
	  };

  this.abort = function() {
  	if (this.req) {
		this.req.onreadystatechange = function() { };
		this.req.abort();
		this.req = null;
	}
  };

  this.setHandlerBoth = function(funcRef) {
	this.handleResp = funcRef;
	this.handleErr = funcRef;
  };

  this.setHandlerErr = function(funcRef) {
  	this.handleErr = funcRef;
  }


	this.handleErr = function() {
		var errorWin;
	try {
		errorWin = window.open('', 'errorWin');
		errorWin.document.body.innerHTML = this.responseText;
	}
	catch (e) {
		alert('An error occurred, but the error message cannot be '
     + 'displayed. This is probably because of your browser\'s '
     + 'pop-up blocker.\n'
     + 'Please allow pop-ups from this web site if you want to '
     + 'see the full error messages.\n'
     + '\n'
     + 'Status Code: ' + this.req.status + '\n'
     + 'Status Description: ' + this.req.statusText);
	}
	};

	this.setMimeType = function(mimeType) {
	 this.mimeType = mimeType;
	};
}


var xhtmlTools = {
	make:function(tagname, attributes, children) {
		if(arguments.length == 2 &&
			 (attributes instanceof Array || typeof attributes == "string")) {
			children = attributes;
			attributes = null;
		}

		// Create the element
		var e = document.createElement(tagname);

		// Set attributes
		if(attributes) {
			for(var name in attributes) {
				switch(name) {
					case "class": e.className=attributes[name]; break;
					case "onclick":
						if(window.addEventListener){ // Mozilla, Netscape, Firefox
							e.addEventListener('click', attributes[name], false);
						} else { // IE
							e.attachEvent('onclick', attributes[name], false);
						}
						break;
					case "onchange":
						if(window.addEventListener){ // Mozilla, Netscape, Firefox
							e.addEventListener('change', attributes[name], false);
						} else { // IE
							e.attachEvent('onchange', attributes[name], false);
						}
						break;
					default: e.setAttribute(name, attributes[name]); break;
				}
			}
		}

		// Add children, if any where specified.
		if(children != null) {
			if(children instanceof Array) { // If it really is an array
				for(var i = 0; i < children.length; i++) {
					var child = children[i];
					if(typeof child == "string")
						child = document.createTextNode(child);
					e.appendChild(child);
				}
			} else if(typeof children == "string") { // Handle single text child
				e.appendChild(document.createTextNode(children));
			} else e.appendChild(children);			// Handle any other single child
		}

		// Finally, return the element;
		return e;
	},

	maker:function(tag) {
		return function(attrs, kids) {
			if(arguments.length == 1) return xhtmlTools.make(tag, attrs);
			else return xhtmlTools.make (tag, attrs, kids);
		}
	}
}


function insertAtCursor(myField, myValue) {
//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}

var html_tags = {"div":xhtmlTools.maker("div"),
				 "textarea":xhtmlTools.maker("textarea"),
				 "p":xhtmlTools.maker("p"),
				 "span":xhtmlTools.maker("span"),
				 "p":xhtmlTools.maker("p"),
				 "form":xhtmlTools.maker("form"),
				 "input":xhtmlTools.maker("input"),
				 "a":xhtmlTools.maker("a"),
				 "ul":xhtmlTools.maker("ul"),
				 "select":xhtmlTools.maker("select"),
				 "option":xhtmlTools.maker("option"),
				 "img":xhtmlTools.maker("img"),
				 "li":xhtmlTools.maker("li"),
				 "table":xhtmlTools.maker("table"),
				 "thead":xhtmlTools.maker("thead"),
				 "tbody":xhtmlTools.maker("tbody"),
				 "tr":xhtmlTools.maker("tr"),
				 "th":xhtmlTools.maker("th"),
				 "td":xhtmlTools.maker("td"),
				 "br":xhtmlTools.maker("br"),
				 "h1":xhtmlTools.maker("h1"),
				 "h2":xhtmlTools.maker("h2"),
				 "h3":xhtmlTools.maker("h3"),
				 "h4":xhtmlTools.maker("h4")
				};

/***
* util object
* @version 1.0 build 100
* @package util
* @copyright (C) 2006 by RDG - All rights reserved!
**/

var messagedisplayed=false;

var util={

	schemes: {
			"critical": {
				bgcolor:"#cc0000",
				fgcolor:"#FFF",
				icon:"/common/images/icons/48x48/plain/delete.gif"
			},
			"warning": {
				bgcolor:"#FFFF99",
				fgcolor:"#000",
				icon:"/common/images/icons/48x48/plain/biginfo.gif"
			},
			"success": {
				bgcolor:"#71ed6e",
				fgcolor:"#003300",
				icon:"/common/images/icons/48x48/plain/check.gif"
			},
			"fatal": {
				bgcolor:"#000",
				fgcolor:"#FFF",
				icon:"/common/images/icons/48x48/plain/craig.gif"
			},
			"funny": {
				bgcolor:"#98ccfc",
				fgcolor:"brown",
				icon:"/common/images/icons/48x48/plain/guy.gif"
			}
	}
	,

	convert_smart_quotes : function(s) {
	    s = s.replace( /\u2018/g, "'" );
	    s = s.replace( /\u2019/g, "'" );
	    s = s.replace( /\u201c/g, '"' );
	    s = s.replace( /\u201d/g, '"' );
	    s = s.replace( /\u2013/g, '-' );
	    s = s.replace( /\u2014/g, '--' );

	    return s;
	},


	getDomain:function() {
		var domain_info = document.location;
		domain_info = domain_info.toString();
		return domain_info.substr(0, domain_info.indexOf('/admin/'));
	},

	/**
	* @function:
	* scrollMessage()
	*
	* @description:
	* Scrolls error message header
	*
	* @returns:
	* Nothing
	**/

	getMousePosition:function(e) {
		var posx = 0;
		var posy = 0;
		if (!e) var e = window.event;
		if (e.pageX || e.pageY) 	{
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY) 	{
			posx = e.clientX + document.body.scrollLeft
				+ document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop
				+ document.documentElement.scrollTop;
		}

		return {"posx":posx, "posy":posy };
	},

	scrollMessage:function(){

		var msg=document.getElementById("messages");

		if(messagedisplayed==false){

			var sel=document.getElementsByTagName("select");

			for(i=0;i<sel.length;i++){

				if(util.findPosY(sel[i])<100){

					sel[i].style.visibility="hidden";

				}
			}


			messagedisplayed=true;

			var content=msg.innerHTML;

         if(this.scheme=="funny"){

            content="Something Funny Happened!<br />"+content;

         }

			msg.innerHTML="<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\" height=\"100\"><tr><td valign=\"middle\" style=\"width:60px\"><a href=\"javascript:util.hideMessage()\" title=\"Click to close\"><img src=\""+this.schemes[this.scheme].icon+"\" border=\"0\" alt=\"Click to Close\"/></a></td><td valign=\"middle\"><div onclick=\"util.hideMessage()\" title=\"Click to close\" style=\"margin-right:60px;text-align:center;\">"+content+"</div></td></tr></table>";

		}


		var pageOffset = util.get_pageOffset();
		if(msg.offsetTop < pageOffset['y']-10){

			msg.style.top=(msg.offsetTop + 10) +  "px";
			setTimeout("util.scrollMessage()",20);
			return;
		} else {
			window.onscroll = util.adjustMessage;
		}
	},

	/**
	* @function:
	* hideMessage()
	*
	* @description:
	* Hides error message
	*
	* @returns:
	* Nothing
	**/

	adjustMessage:function() {
		var pageOffset = util.get_pageOffset();
		var msg=document.getElementById("messages");
		msg.style.top = pageOffset['y'] +  "px";
		window.onscroll = util.adjustMessage;
	},

	hideMessage:function(){

		var msg=document.getElementById("messages");

		if(msg.offsetTop >= -1*(msg.offsetHeight)){

			msg.style.top=(msg.offsetTop - 10) +  "px";

			setTimeout("util.hideMessage()",20);

			return;

		}

		var sel=document.getElementsByTagName("select");

		for(i=0;i<sel.length;i++){

			if(util.findPosY(sel[i])<=105){

				sel[i].style.visibility="visible";

			}
		}


		window.onscroll = null;
		messagedisplayed=false;
	},

	/**
	* @function:
	* setMessage(String text)
	*
	* @description:
	* Sets message text for errors
	*
	* @returns:
	* Nothing
	**/

	setMessage:function(text){

			var scheme = util.setMessage.arguments[1];

			if(scheme=='' || scheme==undefined)scheme='warning';

			this.scheme=scheme;

			if(!document.getElementById("messages")){

				var el=document.createElement("div");
				el.id="messages";

				el.style.visibility="visible";
				el.style.top="-100px";
				el.style.left="0px";
				el.style.width=(document.all ? document.body.offsetWidth : document.documentElement.offsetWidth)+"px";
				el.style.MozOpacity=.95;

				el.style.filter="alpha(opacity=95);";
				el.style.opacity=.95;

				el.style.font="bold 15px 'Microsoft Sans Serif',Verdana,sans-serif";
				el.style.color=this.schemes[scheme].fgcolor;
				el.style.position="absolute";

				el.style.zIndex="5000000";
				el.style.textAlign="center";

				el.style.height="99px";
				el.style.backgroundColor=this.schemes[scheme].bgcolor;
				el.style.borderBottom="1px solid #C0C0C0";

				el.onclick=function(){util.hideMessage();}

				el.innerHTML=text;
				document.body.appendChild(el);


			}else{

				if(messagedisplayed==false){

					var msg=document.getElementById("messages");
					msg.innerHTML=text;

				}

			}



	},

	get_pageOffset:function() {
		var x,y;
		if (window.pageYOffset) // all except Explorer
		{
			x = window.pageXOffset;
			y = window.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop)
			// Explorer 6 Strict
		{
			x = document.documentElement.scrollLeft;
			y = document.documentElement.scrollTop;
		}
		else if (document.body) // all other Explorers
		{
			x = document.body.scrollLeft;
			y = document.body.scrollTop;
		}
		return {"x":x,"y":y};
	},


	/**
	* @function
	* disableElement(Array [element ID's])
	*
	* @description
	* Disables any web page element by use of floating DIV
	*
	* @returns:
	* Nothing
	**/

	disableElements:function(els){

		for(i=0;i<els.length;i++){

			var el=document.getElementById(els[i]);

			if(el){

				if(!document.getElementById("disabler"+i)){

					var newbox=document.createElement("div");
					newbox.id="disabler"+i;
					document.body.appendChild(newbox);

				}else{

					var newbox=document.getElementById("disabler"+i);

				}

				newbox.style.position="absolute";
				newbox.style.top=util.findPosY(el)+"px";
				newbox.style.left=util.findPosX(el)+"px";
				newbox.style.width=el.offsetWidth+"px";
				newbox.style.height=el.offsetHeight+"px";
				newbox.style.zIndex=2000000;
				newbox.style.overflow="hidden";
				newbox.style.MozOpacity=.75;
				newbox.title="This element is disabled";
				newbox.style.opacity=.75;
				newbox.style.filter="alpha(opacity=75)";
				newbox.style.backgroundColor="#FFF";

			}
		}

	},

	/**
	* @function
	* findPosX(Object HTMLElement)
	*
	* @description
	* Finds true X coordinate of an HTML element
	*
	* @returns:
	* Integer
	**/

	findPosX:function(obj)
	{
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	},

	/**
	* @function
	* findPosY(Object HTMLElement)
	*
	* @description
	* Finds true Y coordinate of an HTML element
	*
	* @returns:
	* Integer
	**/

	findPosY:function(obj)
	{
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	},

	popupWin:function(href,hgt,wid){

		var win_name=util.popupWin.arguments[3];

		var resize=util.popupWin.arguments[4];

		var can_resize="no";

		if(!resize){

			can_resize="no";

		}else{

			can_resize=resize;

		}

		if(win_name == null) win_name="cms_popup_win";

		var pwin=window.open(href,win_name,"modal=yes,width="+wid+",height="+(hgt)+",screenX="+(screen.width/2-wid/2)+",left="+(screen.width/2-wid/2)+",screenY="+(screen.height/2-(hgt/2+50))+",top="+(screen.height/2-(hgt/2+50))+",toolbar=no,status=yes,scrollbars=yes,resizable="+resize);

		//return false;

	},

	fixSelBoxes:function(){

		var s=document.getElementsByTagName("select");

		for(i=0;i<s.length;i++){

         s[i].style.width="auto";

		}
		for(i=0;i<s.length;i++){

			s[i].style.width=(s[i].parentNode.offsetWidth)+"px";

		}
	},
	trim:function(s){
		return s.replace(/^\s+|\s+$/,'');
	}


}

var RDGonloader = new function() {
	this.functions = new Array();

	this.add = function(func) {
		RDGonloader.functions.push(func);
	};

	this.init = function() {
		for(var i in RDGonloader.functions) {
			eval(RDGonloader.functions[i]);
		}
	};
}

media = {
	writeFlash:function(swfFile, w, h, bg) {
		document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\""+w+"\" height=\""+h+"\" id=\"mainMovie\" align=\"middle\"><param name=\"allowScriptAccess\" value=\"sameDomain\" /><param name=\"movie\" value=\""+swfFile+"\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\""+bg+"\" /><embed src=\""+swfFile+"\" quality=\"high\" bgcolor=\""+bg+"\" width=\""+w+"\" height=\""+h+"\" name=\"mainMovie\" swLiveConnect=\"true\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object>");
	}
};

var formsUser = new function() {
	this.forms = [];

	this.register = function(form_id) {
		this.forms[form_id] = new rdg_form;
		this.forms[form_id].form_id = form_id;
	};

	this.addField = function(form_id, field_id, field_type, field_reqd, field_label) {
		this.forms[form_id].addField(field_id, field_type, field_reqd, field_label);
	};

	this.submit = function(form_id) {
		this.forms[form_id].submitForm();
	};
};

function rdg_form() {
	this.ajax = new Ajax();
	this.fields = [];
	this.form_id = null;
	this.errs = [];
	this.submitted = false;

	this.addField = function(field_id, field_type, field_reqd, field_label) {
		this.fields.push({"id":field_id,"type":field_type,"reqd":field_reqd,"label":field_label});
	}

	this.submitForm = function() {
		if(!this.submitted) {
			this.submitted = true;
			var found_file = false;
			var f = document.getElementById("form_"+this.form_id);
			var form_id = this.form_id;
			var found_error = false;

			var requestVars = "&form_id="+this.form_id;

			requestVars += "&comments="+escape(f.elements['comments'].value);
			requestVars += "&email_address="+escape(f.elements['email_address'].value);
			requestVars += "&subject="+escape(f.elements['subject'].value);

			for(i=0; i<this.fields.length; i++) {
				switch(this.fields[i]['type']) {
					case "birthdate":
					case "date":
						if(this.fields[i]['reqd']>0 && (
							f.elements["fields["+this.fields[i]['id']+"][month]"].value == "" ||
							f.elements["fields["+this.fields[i]['id']+"][day]"].value == "" ||
							f.elements["fields["+this.fields[i]['id']+"][year]"].value == "")) {
							this.errs.push(this.fields[i]['label'] +" is a required field");
						}

						requestVars += "&fields["+this.fields[i]['id']+"][month]="+f.elements["fields["+this.fields[i]['id']+"][month]"].value;
						requestVars += "&fields["+this.fields[i]['id']+"][day]="+f.elements["fields["+this.fields[i]['id']+"][day]"].value;
						requestVars += "&fields["+this.fields[i]['id']+"][year]="+f.elements["fields["+this.fields[i]['id']+"][year]"].value;
						break;
					case "file":
						found_file = true;
						break;
					case "radio":
						var radio_value = false;
						for(var j = 0; j < f.elements["fields["+this.fields[i]['id']+"]"].length; j++) {
							if(f.elements["fields["+this.fields[i]['id']+"]"][j].checked) {
								radio_value = f.elements["fields["+this.fields[i]['id']+"]"][j].value;
							}
						}
						if(this.fields[i]['reqd']>0 &&
							!radio_value) {
							this.errs.push(this.fields[i]['label'] +" is a required field");
						}
						requestVars += "&fields["+this.fields[i]['id']+"]="+radio_value;
						break;
					case "checkbox":
						if(this.fields[i]['reqd']>0 &&
							!f.elements["fields["+this.fields[i]['id']+"]"].checked) {
							this.errs.push(this.fields[i]['label'] +" is a required field");
						}
						requestVars += "&fields["+this.fields[i]['id']+"]="+(f.elements["fields["+this.fields[i]['id']+"]"].checked?1:0);
						break;
					case "email":
					case "textbox":
					case "textarea":
					default:
						if(this.fields[i]['reqd']>0 &&
							f.elements["fields["+this.fields[i]['id']+"]"].value == "") {
							this.errs.push(this.fields[i]['label'] +" is a required field");
						}
						requestVars += "&fields["+this.fields[i]['id']+"]="+escape(f.elements["fields["+this.fields[i]['id']+"]"].value);
						break;
				}
			}

			if(this.errs.length > 0) {
				var error_html = "";
				for(var i=0; i < this.errs.length; i++) {
					error_html += "<p class=\"error\">"+this.errs[i]+"</p>";
				}
				var c = document.getElementById("form_"+this.form_id+"_errors");
				c.innerHTML = error_html;
				c.style.display="block";
				this.submitted = false;
				this.errs = [];
			} else if(found_file) {
			  // Submit via POST
				f.submit();
			} else {
			  // Submit via AJAX
				(function($) {
					$.post("/common/forms/ajax_handler.php", $("#form_"+form_id).serialize(), function(resp) { finishFormSubmit(resp); }, "xml");
				})(jQuery);
			}
		}
	};
};

function finishFormSubmit(ajax_xml) {
	var xmlDom=ajax_xml;
	var root=xmlDom.documentElement;
	var error_found = false;
	var form_id = root.getAttribute("form_id");

	for(var i = 0; i < root.childNodes.length; i++) {
		switch(root.childNodes[i].nodeName) {
			case "errors":
				var sorry_url = root.childNodes[i].getAttribute("url");
				if(root.childNodes[i].childNodes.length > 0) {
					error_found = true;
					var under_age = false;
					var error_html = "";
					for(var j = 0; j < root.childNodes[i].childNodes.length; j++) {
						if(root.childNodes[i].childNodes[j].nodeName == "error") {
							if(root.childNodes[i].childNodes[j].firstChild.nodeValue == "User is under age") {
								under_age = true;
							}
							error_html += "\n<p class=\"error\">"+root.childNodes[i].childNodes[j].firstChild.nodeValue+"</p>";
						}
					}

					if(under_age && sorry_url != "") {
						document.location.href=sorry_url;
					} else {
						var c = document.getElementById("form_"+form_id+"_errors");
						c.innerHTML = error_html;
						c.style.display="block";
					}
				}

				break;
			case "message":
				if(!error_found) {
					var c = document.getElementById("form_"+form_id+"_container");
					c.innerHTML = root.childNodes[i].firstChild.nodeValue;
				}
				break;
		}
	}
}

function scroller(id, mode, speed, items) {
	this.id = id;
	this.c = null;
	this.m = null;
	this.left = 0;
	this.width = 0;
	this.items = items;
	this.index = 0;
	this.speed = speed;
	this.tim = 20;
	this.px = 4;
	this.hspeeds = [[1,20],[1,16],[1,13],[2,20],[2,16],[2,13],[3,20],[3,16],[3,13],[4,20]];
	this.vspeeds = [[1,40],[1,34],[1,27],[2,40],[2,34],[2,27],[3,40],[3,34],[3,27],[4,40]];
	this.tmp_px = 0;
	this.mode = mode;

	this.move = function() {
		switch(this.mode) {
			case "horizontal":
				this.left-=this.px;
				if(this.left < 0-this.m.offsetWidth) {
					this.index = (this.index+1) % this.items.length;
					this.start();
					// advance to next one
				} else {
					this.m.style.left = this.left + "px";
					var self = this;
					setTimeout(function() { self.move();}, this.tim);
				}
				break;
			case "vertical":
				this.top -= this.px;

				if(this.top < 0-this.m.offsetHeight) {
					this.index = (this.index+1) % this.items.length;
					this.start();
					// advance to next one
				} else {
					this.m.style.top = this.top + "px";
					var self = this;
					setTimeout(function() { self.move();}, this.tim);
				}
				break;
		}
	};

	this.click = function() {
		document.location.href = this.items[this.index][1];
	};

	this.start = function() {
		var self = this;
		if(this.items[this.index][1] != '') {
			this.m.onclick = function() { self.click(); }
		} else {
			this.m.onclick = function() {}
		}

		switch(this.mode) {
			case "horizontal":
				this.m.style.left = this.c.offsetWidth + "px";
				this.left = this.c.offsetWidth;
				break;
			case "vertical":
				this.top = this.c.offsetHeight;
				this.m.style.top = this.top + "px";
				break;
		}

		this.m.innerHTML = this.items[this.index][0];
		this.m.style.display = "inline";
		this.move();
	};

	this.mouseover = function() {
		this.tmp_px = this.px;
		this.px = 0;
		if(this.items[this.index][1] != "") {
			this.m.className='over';
		}
	};

	this.mouseout = function() {
		this.px = this.tmp_px;
		this.m.className='default';
	};

	this.load = function(txt) {
		this.items.push(txt);
	}

	this.init = function() {
		if(this.items.length > 0) {
			var self = this;
			this.m = document.getElementById(this.id);
			this.c = document.getElementById(this.id).parentNode;
			this.speed--;

			switch(this.mode) {
				case "horizontal":
					this.px = this.hspeeds[this.speed][0];
					this.tim = this.hspeeds[this.speed][1]
					break;
				case "vertical":
					this.px = this.vspeeds[this.speed][0];
					this.tim = this.vspeeds[this.speed][1]
					break;
			}

			this.m.onmouseover = function() { self.mouseover(); }
			this.m.onmouseout = function() { self.mouseout(); }
			this.start();
		}
	};
}


var wm_polls = [];

function poll_slot(slot_id, page_id, poll_id) {
	this.ajax = new Ajax();
	this.slot_id = slot_id;
	this.page_id = page_id;
	this.poll_id = poll_id;
	this.questions = [];
	this.init();
}

poll_slot.prototype.init = function() {
	var self = this;

	(function($) {
		$.get("/common/ajax.php", {"t":"poll", "xaction":"poll", "slot_id" : self.slot_id, "page_id" : self.page_id, "poll_id" : self.poll_id}, self.getPoll, "xml");
	})(jQuery);
}

poll_slot.prototype.getPoll = function(ajax_xml) {
	var xmlDom=ajax_xml;
	var root=xmlDom.documentElement;

	var slot_id = root.getAttribute('slot_id');
	
	var slot_html = "";
	
	x = root.firstChild;
	while(x) {
		var q_id = x.getAttribute('q_id');
		var display_results = x.getAttribute('display_results');
		wm_polls[slot_id].questions[q_id] = new poll_question(slot_id, q_id, display_results);
	
		// Update HTML
		y = x.firstChild;
		while(y) {
			switch(y.nodeName) {
				case "html":
					slot_html = slot_html + y.firstChild.nodeValue;
					break;
				case "answer":
					wm_polls[slot_id].questions[q_id].AddAnswer(new poll_answer(y.getAttribute('id'), y.getAttribute('votes')));
					break;
			}
			y = y.nextSibling;
		}
		x = x.nextSibling;
	
	}
	
	document.getElementById('poll_' + slot_id + '_container').innerHTML = slot_html;

}

function poll_answer(a_id, votes) {
	this.a_id = a_id;
	this.votes = votes;
	this.pct = 5;
}

poll_answer.prototype.incrementPCT = function(total_votes) {
	if(total_votes > 0) {
		document.getElementById("answer_"+this.a_id+"_bar").style.width=this.pct+"%";
		this.pct += 5;
		if (this.pct < (this.votes/total_votes) * 70) {
			var self = this;
			setTimeout(function() { self.incrementPCT(total_votes);}, 100);
		} else {
			var pct_print = Math.floor((this.votes/total_votes)*1000)/10;
			document.getElementById("answer_"+this.a_id+"_pct").innerHTML = pct_print+"%";
		}
	}
}


function poll_question(slot_id, q_id, display_results) {
	this.ajax = new Ajax();
	this.slot_id = slot_id;
	this.q_id = q_id;
	this.display_results = display_results;
	this.answers = [];
}

poll_question.prototype.AddAnswer = function(answer) {
	this.answers.push(answer);
}

poll_question.prototype.CheckIn = function() {
	return 'q_id = ' + this.q_id;
}

poll_question.prototype.blowup = function(img, e) {
	var coords = util.getMousePosition(e);
	var c = document.getElementById("Poll_"+this.q_id+"_blowup");
	c.innerHTML = "<span><img src=\"/includes/poll/media/large."+img+"\" alt=\"large image\" /></span>";
	c.style.left = (coords["posx"]-20)+"px";
	c.style.top = (coords["posy"]-20)+"px";
	c.style.display="block";
}

poll_question.prototype.hide = function() {
	var c = document.getElementById("Poll_"+this.q_id+"_blowup");
	c.style.display="none";
}

poll_question.prototype.Vote = function(fe) {
	var a_id = 0;
	for (var i=0; i < fe.answer.length; i++) {
		if(fe.answer[i].checked) { a_id = fe.answer[i].value; }
	}

	if(a_id>0) {
		document.getElementById("poll_answers_"+this.q_id).style.display="none";
		document.getElementById("poll_results_"+this.q_id).style.display="";

		if(this.display_results) {
			var total_votes = 0;
			for(var i = 0; i < this.answers.length; i++) {
				if(this.answers[i].a_id == a_id) {
					this.answers[i].votes++;
				}
				total_votes += parseInt(this.answers[i].votes);
			}

			for(var i = 0; i < this.answers.length; i++) {
				this.answers[i].incrementPCT(total_votes);
			}
		}
		var self = this;
		this.ajax.setMimetype="text/html";
		this.ajax.responseFormat="text";
		this.ajax.doGet("/common/poll/index.php?xaction=vote"+
				"&slot_id="+this.slot_id+
				"&q_id="+this.q_id+
				"&a_id="+a_id,
			function() { self.FinishVote; }, "text");

	}
}

poll_question.prototype.FinishVote = function(ajax_html) {
	alert(ajax_html);
}

// FCKeditor Mailto function
function mt(name, domain, subject, body) {
  location.href = 'mailto:' + name + '@' + domain + '?subject=' + subject + '&body=' + body;
}

/* Registered Users Functions */
var regObj = new function() {
	this.ready = true;

	this.register = function(fe) {
		if(regObj.ready) {
			regObj.ready = false;

			(function($) {
				$.post("/common/ajax.php", $("#registered_users-register_form").serialize(), regObj.finishAction, "json");
			})(jQuery);
		}
	};

	this.getPage = function(page) {
		(function($) {
			$.post("/common/ajax.php",
				{
					"t" : "registered_users",
					"xaction" : "get page",
					"page" : page
				},
				regObj.finishPage);
		})(jQuery);
	};

	this.finishPage = function(ajax_html) {
		document.getElementById("registered_users_container").innerHTML = ajax_html;
	};

	this.finishAction = function(ajax_json) {
		if(ajax_json.status == "error") regObj.ready = true;
		document.getElementById("registered_users_container").innerHTML = ajax_json.message;
	};

	this.login = function() {
		(function($) {
			$.post("/common/ajax.php", $("#registered_users-login_form").serialize(), regObj.finishLogin, "json");
		})(jQuery);
	};

	this.logout = function() {
		(function($) {
			$.post("/common/ajax.php", {"t" : "registered_users", "xaction":"logout"}, regObj.finishLogin, "json");
		})(jQuery);
	}

	this.finishLogin = function(ajax_json) {
		switch(ajax_json['status']) {
			case "ok": location.reload(true); break;
			case "error":
				document.getElementById("registered_users_container").innerHTML = ajax_json['message'];
				break;
			default:
				alert('what happen');
				break;

		}
	};

	this.forgotPassword = function(email) {
		(function($) {
			$.post("/common/ajax.php", $("#registered_users-forgot_password").serialize(), regObj.finishAction, "json");
		})(jQuery);
	};
}

function fillAvatar() {
	regObj.ready = true;
}

function waitAvatar() {
	regObj.ready = false;

}

var ratings = new function() {
	this.ajax = new Ajax();
	this.picks = {};

	this.hov = function(tool, toolid, value) {
		for(var i = 1; i <= 5; i++) {
			if(i > value) {
				document.getElementById("ratings_"+tool+"_"+toolid+"_"+i).className = "ratings_normal";
			} else {
				document.getElementById("ratings_"+tool+"_"+toolid+"_"+i).className = "ratings_over";
			}
		}
	};

	this.start = function(tool, toolid) {
		document.getElementById("ratings_"+tool+"_"+toolid+"_default").style.display="none";
	};

	this.end = function(tool, toolid) {
		var val = typeof(this.picks[tool+"_"+toolid]) != "undefined" ? this.picks[tool+"_"+toolid] : 0;
		if(val == 0)
			document.getElementById("ratings_"+tool+"_"+toolid+"_default").style.display="block";


		for(var i = 1; i <= 5; i++) {
			if(i > val) {
				document.getElementById("ratings_"+tool+"_"+toolid+"_"+i).className="ratings_normal";
			} else {
				document.getElementById("ratings_"+tool+"_"+toolid+"_"+i).className="ratings_over";
			}
		}
	};

	this.record = function(tool, toolid, value) {
		this.picks[tool+"_"+toolid] = value;

		var _ajax = new Ajax();
		_ajax.setMimetype="text/html";
		_ajax.responseFormat="text";
		_ajax.doGet("/common/ajax.php?t=ratings"+
				"&xaction=record"+
				"&tool="+tool+
				"&toolid="+toolid+
				"&value="+value,
			ratings.finishRecord, "text");
	};

	this.finishRecord = function(ajax_html) {
		// alert(ajax_html);
	};
}


/* Comments */
var comObj = new function() {
	this.ajax = new Ajax();
	this.tool = false;
	this.toolid = false;
	this.cmore = false;

	this.showHide = function(tool, toolid, action) {
		if(action == "show") {
			var c = document.getElementById("comments_show_"+tool+"_"+toolid);
			c.style.display = "none";

			comObj.changePage(tool, toolid, 1);
		} else {
			var c = document.getElementById("comments_"+tool+"_"+toolid);
			c.style.display = "none";

			var c = document.getElementById("comments_show_"+tool+"_"+toolid);
			c.style.display = "block";
		}
		return false;
	};

	this.changePage = function(tool, toolid, page) {
		if(!comObj.tool && !comObj.toolid) {
			comObj.tool = tool;
			comObj.toolid = toolid;

			comObj.ajax.setMimetype="text/html";
			comObj.ajax.responseFormat="text";
			comObj.ajax.method="POST";
			comObj.ajax.url = "/common/comments/index.php";
			comObj.ajax.postData = "xaction=get+comments"+
					"&tool="+tool+
					"&toolid="+toolid+
					"&page="+page;
			comObj.ajax.handleResp = comObj.finishChange;
			comObj.ajax.responseFormat = "text";

			comObj.ajax.doReq();
		}
		return false;
	};

	this.finishChange = function(ajax_html) {
		if(comObj.tool && comObj.toolid) {
			var c = document.getElementById("comments_"+comObj.tool+"_"+comObj.toolid);
			c.innerHTML = ajax_html;
			c.style.display = "block";

			comObj.tool = false;
			comObj.toolid = false;
		}
	};

	this.submitComment = function(tool, toolid) {
		var c = document.getElementById("comments_"+tool+"_"+toolid+"_textarea");
		if(!comObj.tool && !comObj.toolid && c.value.length > 0) {
			comObj.tool = tool;
			comObj.toolid = toolid;

			comObj.ajax.setMimetype="text/html";
			comObj.ajax.responseFormat="text";
			comObj.ajax.method="POST";
			comObj.ajax.url = "/common/ajax.php";
			comObj.ajax.postData =
					"t=comments"+
					"&xaction=submit+comment"+
					"&tool="+tool+
					"&toolid="+toolid+
					"&c_text="+escape(util.convert_smart_quotes(c.value));
			comObj.ajax.handleResp = comObj.finishComment;
			comObj.ajax.responseFormat = "text";

			comObj.ajax.doReq();
		}
	};

	this.finishComment = function(ajax_text) {
		var c = document.getElementById("comments_"+comObj.tool+"_"+comObj.toolid+"_form");
		c.innerHTML = ajax_text;

		comObj.tool = null;
		comObj.toolid = null;
	};

	this.report = function(c_id) {
		document.getElementById("comment_"+c_id).style.display="none";

		comObj.ajax.setMimetype="text/html";
		comObj.ajax.responseFormat="text";
		comObj.ajax.doGet("/common/comments/index.php?xaction=report"+
				"&c_id="+c_id,
			comObj.finishAbuse, "text");
		return false;
	};

	this.finishAbuse = function(ajax_text) {

	};

	this.showMore = function(c_id) {
		if(!comObj.cmore) {
			comObj.cmore = c_id;
			comObj.ajax.setMimetype="text/html";
			comObj.ajax.responseFormat="text";
			comObj.ajax.doGet("/common/comments/index.php?xaction=show+more"+
					"&c_id="+c_id,
				comObj.finishShowMore, "text");
		}
		return false;
	};

	this.finishShowMore = function(ajax_text) {
		if(comObj.cmore > 0 ) {
			var c = document.getElementById("comment_"+comObj.cmore);
			c.innerHTML = ajax_text;

			var c = document.getElementById("comment_more_"+comObj.cmore);
			c.style.display = "none";
		}

		comObj.cmore = false;
	};
}


window.onload = RDGonloader.init;


/* Gallery */
var Gallery = new function() {
	this._gallery = null;
	this._album = null;
	this._photo = null;
	this._list = null;
	this._index = null;
	this._tim1 = null;
	this._tim2 = null;
	this._tim3 = null;
	this._img_chng_callback = null;
	this._list_index = 0;
	this._startpic = 0;
	this._set = 0;
	this._imgcache = [];
	this._num_per_page = 30;
	this._num_pages = 1;
	this._is_national = 0;

	this.getAlbum = function(album) {
		Gallery._album = album;

		var ajax = new Ajax();
		ajax.setMimetype="text/xml";
		ajax.responseFormat="xml";
		ajax.doGet("/common/ajax.php?t=gallery&xaction=get+album&gallery_id="+Gallery._gallery+"&album_id="+album+"&is_national="+Gallery._is_national,
				Gallery.finishAlbum, "xml");
	};

	this.get_ALP_Album = function(album) {
		Gallery._album = album;

		(function($) {
			$.get("/common/ajax.php", 
				{
					"t" : "gallery",
					"xaction" : "get album",
					"gallery_id" : Gallery._gallery,
					"album_id" : album,
					"is_national" : Gallery._is_national
				},
				Gallery.finishAlbum, 
				"xml"
			);
		})(jQuery);
	};

	this.finishAlbum = function(ajax_xml) {
		var root = Gallery._root = ajax_xml.documentElement;
		Gallery._list = root.getElementsByTagName("item");
		Gallery._index = 0;
		Gallery.initAlbum();
	};

	this.initAlbum = function() {
		// Update Picture
		if(Gallery._root.getElementsByTagName("name")[0].firstChild !== null)
			document.getElementById("gallery_name").innerHTML = Gallery._root.getElementsByTagName("name")[0].firstChild.nodeValue;

		// Update Name
		if(Gallery._root.getElementsByTagName("desc")[0].firstChild !== null)
			document.getElementById("gallery_desc").innerHTML = Gallery._root.getElementsByTagName("desc")[0].firstChild.nodeValue;

		// Update Desc
		if(Gallery._root.getElementsByTagName("item_count")[0].firstChild !== null)
			document.getElementById("gallery_count").innerHTML = Gallery._root.getElementsByTagName("item_count")[0].firstChild.nodeValue+ " photos";


		var c = document.getElementById("gallery_thumbs");
		var imgs = [];
		c.style.width = 86*Gallery._list.length+"px";
		var html = "";
		for(var i = 0; i < Gallery._list.length; i++) {

			var n = Gallery._list[i];
			var lg_src = n.getElementsByTagName("file")[0].firstChild.nodeValue;
			var sm_src = "";
			
			
			if (n.getElementsByTagName("file")[0].attributes.length > 0 && n.getElementsByTagName("file")[0].attributes.getNamedItem("mode").value == "url") {
				sm_src = n.getElementsByTagName("thumb")[0].firstChild.nodeValue;
			} else {
				sm_src = Gallery._img_path + Gallery._gallery+"/images/album_"+Gallery._album+"/sm." + lg_src;
				lg_src = Gallery._img_path + Gallery._gallery+"/images/album_"+Gallery._album+"/lg." + lg_src;
			}
			
			html += "<li><img width=\"78\" height=\"78\" id=\"photo_"+i+"\" src=\"" + sm_src + "\" title=\""+((n.getElementsByTagName("name")[0].firstChild===null)?'':n.getElementsByTagName("name")[0].firstChild.nodeValue)+"\" onclick=\"Gallery.display(event)\" /></li>";
			
			// cache
			var img = new Image();
			img.src = lg_src;
			imgs.push(img);
		}

		c.innerHTML = html;

		if(Gallery._startpic > 0) {
			var i = 0;
			var found = false;
			while(i < Gallery._list.length && !found) {
				if(Gallery._list[i].getAttribute("id") == Gallery._startpic)
					found = true;
				else i++;
			}
			if(found) Gallery._index=i;
		}
		Gallery.initPhoto();
	};

	this.display = function(e) {
		var targ;
		e = e ? e : window.event;
		if (e.target) targ = e.target;
		else if (e.srcElement) targ = e.srcElement;
		if (targ.nodeType == 3) // defeat Safari bug
			targ = targ.parentNode;

		Gallery._index = targ.id.replace("photo_", "");
		if(Gallery._index - 3 == Gallery._list_index && Gallery._index < Gallery._list.length) {
			Gallery._list_index++;
			Gallery.slideThumbs();
		} else if( Gallery._index == Gallery._list_index && Gallery._list_index > 0) {
			Gallery._list_index--;
			Gallery.slideThumbs();
		}

		Gallery.initPhoto();
	};

	this.initPhoto = function() {
		clearTimeout(Gallery._tim3);

		Gallery._photo = Gallery._list[Gallery._index];

		// Update Picture
		if (Gallery._photo.getElementsByTagName("file")[0].attributes.length > 0 && Gallery._photo.getElementsByTagName("file")[0].attributes.getNamedItem("mode").value == "url") {
			src = Gallery._photo.getElementsByTagName("file")[0].firstChild.nodeValue;
			height = 347;

		} else {
			src = Gallery._img_path + Gallery._gallery+"/images/album_"+Gallery._album+"/lg." + Gallery._photo.getElementsByTagName("file")[0].firstChild.nodeValue;
			width = 0;
			height = 0;
		}
			
		tracking_iframe = document.getElementById('gallery_tracking_iframe');
		tracking_iframe.src = '/common/statistics/gallery_tracking.php?image_url=' + src;

		document.getElementById("photo_image").src = src;
		
		if (height > 0) {
			document.getElementById("photo_image").height = height;
		}
			
		// Update Name
		name =  (Gallery._photo.getElementsByTagName("name")[0].firstChild === null) ? "" : Gallery._photo.getElementsByTagName("name")[0].firstChild.nodeValue;
		document.getElementById("photo_name").innerHTML = name

		// Update Desc
		desc = (Gallery._photo.getElementsByTagName("desc")[0].firstChild === null) ? "" : Gallery._photo.getElementsByTagName("desc")[0].firstChild.nodeValue;
		document.getElementById("photo_desc").innerHTML = desc;
                // Brad Broerman -- Leave Commented out. (This is after merge of TritonSocial Branch into Trunk, 09-08-2011
		// var sharelink = document.getElementById("sharelink");
		// sharelink.onmouseover = function() { return addthis_open(sharelink, '', 'http://tooltest.rdg.com/gallery/display.php?album_id='+Gallery._album+'&pic='+Gallery._photo.getAttribute("id"), Gallery._photo.getElementsByTagName("name")[0].firstChild.nodeValue); }
		// onmouseover="" onmouseout="addthis_close()" onclick="return addthis_sendto()"

		// Update Ratings & Comments Area
		if(Gallery._imgcache[Gallery._photo.getAttribute("id")] == undefined) {
			var ajax = new Ajax();
			ajax.setMimetype="text/xml";
			ajax.responseFormat="xml";
			ajax.doGet("/common/ajax.php?t=gallery&xaction=get+item+data&item_id="+Gallery._photo.getAttribute("id")+"&is_national="+Gallery._is_national,
					Gallery.finishItemData, "xml");
		} else {
			Gallery.finishItemData(Gallery._imgcache[Gallery._photo.getAttribute("id")]);
		}
		
		if( this._img_chng_callback ) {
			this._img_chng_callback( Gallery._photo.getAttribute("id") );
		}
		
	};

        // Brad Broerman -- Leave This In. (This is after merge of TritonSocial Branch into Trunk, 09-08-2011
	this.setImgChgCallback = function( callback ) {
		this._img_chng_callback = callback;
	}
	
	this.finishItemData = function(ajax_xml) {
		var root = ajax_xml.documentElement;

		if(root.getElementsByTagName("id")[0].firstChild.nodeValue == Gallery._photo.getAttribute("id")) { // Current
			document.getElementById("item_rating").innerHTML = root.getElementsByTagName("rating")[0].firstChild.nodeValue;
//			document.getElementById("item_comments").innerHTML = root.getElementsByTagName("comments")[0].firstChild.nodeValue;
		}

		Gallery._imgcache[root.getElementsByTagName("id")[0].firstChild.nodeValue] = ajax_xml;
	};

	this.scrollThumbs = function(dir, b) {

		document.body.focus();
		if(b) {
			switch(dir) {
				case "left": Gallery._list_index-=4; break;
				case "right": Gallery._list_index+=4; break;
			}

			Gallery._tim1 = setTimeout( function() { Gallery.scrollThumbs(dir, true); }, 350);

			Gallery._list_index = (Gallery._list_index + 4) > Gallery._list.length ? Gallery._list.length-4 : Gallery._list_index;
			Gallery._list_index = Gallery._list_index < 0 ? 0 : Gallery._list_index;
			Gallery.slideThumbs();
		} else {
			clearTimeout(Gallery._tim1);
		}
	}

	this.slideThumbs = function() {
		var c = document.getElementById("gallery_thumbs");
		if(!parseInt(c.style.left)) c.style.left = "0px";

		var current = parseInt(c.style.left);
		var dest = Gallery._list_index * -86;
		var diff = dest - current;
		var tomove = Math.ceil(diff/2);

		if(tomove != 0)  {
			c.style.left = (current + tomove) + "px";
			Gallery._tim2 = setTimeout(Gallery.slideThumbs, 100);
		}
	}

	this.init = function(gallery, album, pic, alp_artist, is_national) {
		
		Gallery._is_national = is_national;
		Gallery._img_path = is_national ? "/media/gallery/" : "/includes/gallery/";
		 
		
		if(gallery > 0) {
			Gallery._gallery = gallery;
		}

		if (album > 0) {
			Gallery._album = album;
		}
	
		if(pic > 0) {
			Gallery._startpic = pic;
		}

		if (album > 0 && gallery > 0) {
			Gallery.getAlbum(album);
		} else if (alp_artist != "" ) {
			Gallery._album = alp_artist;
			Gallery.get_ALP_Album(alp_artist);
		}

	};

	this.next = function() {
		Gallery._index++;
		Gallery._list_index = Gallery._index-1; // (Gallery._index + 3 > Gallery._list.length)?Gallery._list.length-3:Gallery._index;
		if(Gallery._index == Gallery._list.length) {
			Gallery._index = 0;
			Gallery._list_index = 0;
		}

		Gallery._list_index = (Gallery._index + 3 > Gallery._list.length)
			? Gallery._list.length - 3
			: Gallery._list_index;

		Gallery.slideThumbs();
		Gallery.initPhoto();
	};

	this.previous = function() {
		Gallery._index--;
		Gallery._list_index = Gallery._index-1; // (Gallery._index - 3 > Gallery._list.length)?Gallery._list.length-3:Gallery._index;
		if(Gallery._index < 0) {
			Gallery._index = Gallery._list.length-1;
		}

		Gallery._list_index = (Gallery._index == 0) // + 3 > Gallery._list.length
			? 0
			: Gallery._list_index;
		Gallery._list_index = (Gallery._index + 3 > Gallery._list.length)
			? Gallery._list.length - 3
			: Gallery._list_index;

		Gallery.slideThumbs();
		Gallery.initPhoto();
	};


	this.toggleSet = function(e) {
		var targ;
		e = e ? e : window.event;
		if (e.target) targ = e.target;
		else if (e.srcElement) targ = e.srcElement;
		if (targ.nodeType == 3) // defeat Safari bug
			targ = targ.parentNode;

		var clickSet = targ.parentNode.parentNode;
		var setList = clickSet.parentNode;

		node = setList.firstChild;

		while(node) {
			if(node.nodeType == 1) {
				node.getElementsByTagName("ul")[0].className = (node.id == clickSet.id)
					? "set_body_open"
					: "set_body_closed";

			}
			node = node.nextSibling;
		}
	};

	this.init_index = function(gallery_id, set_id) {
		Gallery._gallery = gallery_id;
		Gallery._set = set_id;
		if(set_id > 0) {
			var ajax = new Ajax();
			ajax.setMimetype="text/xml";
			ajax.responseFormat="xml";
			ajax.doGet("/common/ajax.php?t=gallery&xaction=get+set&gallery_id="+Gallery._gallery+"&set_id="+set_id+"&is_national="+Gallery._is_national,
					Gallery.finishIndex, "xml");
		} else {
			var ajax = new Ajax();
			ajax.setMimetype="text/xml";
			ajax.responseFormat="xml";
			ajax.doGet("/common/ajax.php?t=gallery&xaction=get+albums&gallery_id="+Gallery._gallery+"&is_national="+Gallery._is_national,
					Gallery.finishIndex, "xml");
		}
	};


	this.printClick = function() {
		var print_win = window.open("/common/gallery/print.php?g="+Gallery._gallery+"&a="+Gallery._album+"&p="+Gallery._list[Gallery._index].getElementsByTagName("file")[0].firstChild.nodeValue, "print_win", "");
		print_win.focus();
	};
}
