// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function getElementsByTagNames(list,obj) {
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++) {
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++) {
			resultArray.push(tags[j]);
		}
	}
	var testNode = resultArray[0];
	if (!testNode) return [];
	if (testNode.sourceIndex) {
		resultArray.sort(function (a,b) {
				return a.sourceIndex - b.sourceIndex;
		});
	}
	else if (testNode.compareDocumentPosition) {
		resultArray.sort(function (a,b) {
				return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
	return resultArray;
}
function fb(){
	var inputs = getElementsByTagNames('input,textarea');
	var v = new Array();
	for ( i = 0; i < inputs.length-1; i++ ){
		if ( inputs[i].getAttribute("placeholder") != null ){
			v[i] = inputs[i].getAttribute("placeholder");
			inputs[i].value = v[i];
			inputs[i].onfocus = function(){ this.value = ''; }
			inputs[i].onblur = function(){ this.value = this.getAttribute("placeholder"); }
		}
	}
}
function qb(c){
	$('qb-inner').innerHTML = '';
	new Ajax.Updater('qb-inner', '/qb/'+c, {asynchronous:true, evalScripts:true});
	$('qb-inner').className = c;
	$('qb').style.display = 'block';
}
function qbhide(){ $('qb').style.display = 'none'; }
function qbshow(){ $('qb').style.display = 'block'; }
function loading(d, txt, n){
	n = n == null ? '..' : n;
	$(d).innerHTML = '<center>' + txt + '<br /><img src="/images/loading.gif" style="border: 0; padding: 0;"></center>';
}
function swap(a, b){
	new Effect.PhaseIn(''+a+'', {duration: 0.5});
	new Effect.PhaseOut(''+b+'', {duration: 0.5});
	$(a+'link').className = 'selected';
	$(b+'link').className = null;
}
function addalbum(){ $('albumajax').style.display = $('albumajax').style.display == 'none' ? 'block' : 'none'; }
function toggleCommentForm(){ new Effect.Phase('pic-commentform', 'blind'); }
function openPic(p,w,h){
	h = h+180;
	window.open(+p+'?f=1','','scrollbars=yes,toolbar=no,status=no,resizable=yes,width='+w+',height='+h);
}
function showcomments(){ new Effect.PhaseOut($('pic-comments-loading')); new Effect.PhaseIn($('pic-comments-inner')); }
function adjust_popup(){
	var w, h, fixedW, fixedH, diffW, diffH;
    if (document.documentElement && document.body.clientHeight==0){     // Catches IE6 and FF in DOCMODE
    	fixedW = document.documentElement.clientWidth;
    	fixedH = document.documentElement.clientHeight;
    	window.resizeTo(fixedW, fixedH);
    	diffW = fixedW - document.documentElement.clientWidth;
    	diffH = fixedH - document.documentElement.clientHeight;
    	w = fixedW + diffW + 16; // Vert Scrollbar Always On in DOCMODE.
    	h = fixedH + diffH;
    	if (w >= screen.availWidth) h += 16;
   	} else if (document.all) {
	   	fixedW = document.body.clientWidth;
	   	fixedH = document.body.clientHeight;
	   	window.resizeTo(fixedW, fixedH);
	   	diffW = fixedW - document.body.clientWidth;
	   	diffH = fixedH - document.body.clientHeight;
	   	w = fixedW + diffW;
	   	h = fixedH + diffH;
	   	if (h >= screen.availHeight) w += 16;
	   	if (w >= screen.availWidth)  h += 16;
	} else {
		fixedW = window.innerWidth;
		fixedH = window.innerHeight;
		window.resizeTo(fixedW, fixedH);
		diffW = fixedW - window.innerWidth;
		diffH = fixedH - window.innerHeight;
		w = fixedW + diffW;
		h = fixedH + diffH;
		if (w >= screen.availWidth)  h += 16;
		if (h >= screen.availHeight) w += 16;
	}
    w = Math.min(w,screen.availWidth)+10;
    h = 120+Math.min(h,screen.availHeight)+130;
    window.resizeTo(w,h);
    window.moveTo((screen.availWidth-w)/2, (screen.availHeight-h)/2);
}
function help(id){
	new Ajax.Request('/help/'+id, {
		asynchronous:true, evalScripts:true,
		onComplete:function(request){
			helpComplete(request.responseText, 'help-'+id);
		}
	});
}
function helpComplete(t,d){
	$(d).innerHTML = t;
	if($(d).style.display == 'none'){
	  new Effect.Appear(d, {duration: 0.75});
	}else{
	  new Effect.Fade(d, {duration: 0.75});
	}
}
function p(o, i, v){
	var boxes = new Array;
	boxes[0] = 'tl';
	boxes[1] = 'bl';
	boxes[2] = 'tr';
	boxes[3] = 'br';
	for ( x=0; x<boxes.length; x++ ){ $(boxes[x]).className = 'o'; }
	$(i).value = v;
	$(o).className = 'o sel';
}
function c(o, i, v){
	var boxes = new Array;
	boxes[0] = 'b';
	boxes[1] = 'w';	
	for ( x=0; x<boxes.length; x++ ){ $(boxes[x]).className = 'o'; }
	$(i).value = v;
	$(o).className = 'o sel';
}
function gup(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
  	var regex = new RegExp(regexS);
  	var results = regex.exec(window.location.href);
  	if(results == null){
    	return "";
  	}else{
    	return results[1];
  	}
}