function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//-------------------------------------------------------------------
// tbg.js - Thickbox Gallery 2
// Copyright (c) 2006-2009 Yuji Takenaka <webmaster@davilin.com>
// Licensed under the MIT:
// http://www.opensource.org/licenses/mit-license.php
//-------------------------------------------------------------------

var tbgReq = false;
var tbgPrev = "";
var tbgEdit = false;
var tbgKey = "";

//-------------------------------------------------------------------
// call XMLHttpRequest
//-------------------------------------------------------------------
if(window.XMLHttpRequest && !(window.ActiveXObject)){
	try{
		tbgReq = new XMLHttpRequest();
	}catch(e){
		tbgReq = false;
	}
}else if(window.ActiveXObject){
	try{
		tbgReq = new ActiveXObject("MXSML2.XMLHTTP");
	}catch(e){
		try {
			tbgReq = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			tbgReq = false;
		}
	}
}
//-------------------------------------------------------------------
// catch keydown event
//-------------------------------------------------------------------
document.onkeydown = function(e){
	if(document.all){
		tbgKey = event.keyCode;
	}else if(document.getElementById){
		tbgKey = (e.keyCode!=0) ? e.keyCode : e.charCode;
	}else if(document.layers){
		tbgKey = e.which;
	}
}
//-------------------------------------------------------------------
// focus when username field exists
//-------------------------------------------------------------------
window.onload = function(){
	if(document.getElementById("username")){
		document.getElementById("username").focus();
	}
}
//-------------------------------------------------------------------
// show/hide function icons
//-------------------------------------------------------------------
function display_functions(obj){
	var target = obj.nextSibling;
	var value = "none";
	var icon = obj.src;
	if(icon.indexOf("funcp")!=-1){
		value = "block";
	}
	target.style.top = obj.offsetTop + 9;
	target.style.left = obj.offsetLeft;
	target.style.display = value;
	if(value=="none"){
		icon = icon.replace(/funcm/, "funcp");
	}else{
		icon = icon.replace(/funcp/, "funcm");
	}
	obj.src = icon;
}
//-------------------------------------------------------------------
// save description
//-------------------------------------------------------------------
function saveComment(obj, id, target, album, filename, noajax, def){
	if(tbgKey==13){
		if(tbgReq){
			var value = obj.value;
			if(value!=def){
				var url = target + "?a=" + album;
				var query = "z=description&v=" + filename + "&v1=" + value;
				if(tbgReq.readyState!=0 && tbgReq.readyState!=4){
					tbgReq.abort();
				}
				tbgReq.open("POST", url, true);
				tbgReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				tbgReq.send(query);
				tbgReq.onreadystatechange = function(){
					if(tbgReq.readyState == 4){
						if(tbgReq.responseText==""){;
							tbgPrev = "";
							restoreComment(obj);
							var elem = document.getElementById("tbg-anchor" + id);
							if(elem){
								elem.setAttribute("title", value);
							}
							elem = document.getElementById("tbg-thumbnail" + id);
							if(elem){
								elem.setAttribute("alt", value);
								elem.setAttribute("title", value);
							}
							elem = document.getElementById("caption-for-anchor" + id);
							if(elem){
								elem.innerText = value;
							}
						}else if(tbgReq.responseText=="0"){
							tbgPrev = "";
							restoreComment(obj);
						}else{
							restoreComment(obj);
							window.alert(tbgReq.responseText);
						}
					}
				}
			}else{
				restoreComment(obj);
			}
		}else{
			window.alert(noajax);
		}
	}else if(tbgKey==27){
		restoreComment(obj);
	}
}
//-------------------------------------------------------------------
// restore description
//-------------------------------------------------------------------
function restoreComment(obj){
	if(tbgPrev!=""){
		obj.value = tbgPrev;
		tbgPrev = "";
	}
	obj.style.backgroundColor = "#FFFFD3";
	obj.style.fontStyle = "italic";
	tbgEdit = false;
	obj.blur();
}
//-------------------------------------------------------------------
// change font and background-color of obj
//-------------------------------------------------------------------
function activateInput(obj){
	if(!tbgEdit){
		obj.style.backgroundColor = "#FFFFFF";
		obj.style.fontStyle = "normal";
		tbgPrev = obj.value;
		tbgEdit = true;
		obj.select();
	}
}
//-------------------------------------------------------------------
// output confirm message
//-------------------------------------------------------------------
function confirming(message){
	if(window.confirm(message)){
		return true;
	}else{
		return false;
	}
}

