function toggleLarge(set_thumb_per_page,set_gallery_per_page) {

	if (document.getElementById('gallery-large')) {
	
		Effect.Appear('gallery-large',{ duration: 0.0 });
		Effect.Fade('gallery-small',{ duration: 0.0 });
	
	}
	
	if (document.getElementById('image-large')) {
	
		Effect.Appear('image-large',{ duration: 0.0 });
		Effect.Fade('image-small',{ duration: 0.0 });
	
	}
	
}

function toggleSmall(set_thumb_per_page,set_gallery_per_page) {

	if (document.getElementById('gallery-large')) {
	
		Effect.Appear('gallery-small',{ duration: 0.0 });
		Effect.Fade('gallery-large',{ duration: 0.0 });
	
	}
	
	if (document.getElementById('image-large')) {
	
		Effect.Appear('image-small',{ duration: 0.0 });
		Effect.Fade('image-large',{ duration: 0.0 });
	
	}

}

/*
*
*	Function to update the preferences cookie
*
*	cookieKey		= integer:	value of item in the prefs to change
*	cookieValue 	= string:	value of the item to be changed
*	cookieDefault 	= string:	defualt cookie data if preferences don't exist yet
*
*/
function updateCookie (cookieKey,cookieValue,cookieDefault) {
	
	cookieKey = parseInt(cookieKey);
	
	var pixariaCookie = readCookie('psg_prefs');
	
	if (!pixariaCookie) {
		
		createCookie('psg_prefs',cookieDefault,360);
		
		var pixariaCookie = cookieDefault;

	}
	
	var cookieElements = pixariaCookie.split("|");
	
	var cookieVersion		= cookieElements[0];
	var imagesPerPage		= cookieElements[1];
	var galleriesPerPage	= cookieElements[2];
	var viewThumbView		= cookieElements[3];
	
	if (cookieKey == 1) {
		cookieData = '1|' + cookieValue + '|' + galleriesPerPage + '|' + viewThumbView;
	}
	
	if (cookieKey == 2) {
		cookieData = '1|' + imagesPerPage + '|' + cookieValue + '|' + viewThumbView;
	}
	
	if (cookieKey == 3) {
		cookieData = '1|' + imagesPerPage + '|' + galleriesPerPage + '|' + cookieValue;
	}
	
	createCookie('psg_prefs',cookieData,360)
	
}

/*
*
*	Function to create a cookie
*
*/
function createCookie(name,value,days) {

	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";

}

/*
*
*	Function to read data from a cookie
*
*/
function readCookie(name) {

	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;

}

/*
*
*	Function to erase a cookie
*
*/
function eraseCookie(name) {

	createCookie(name,"",-1);
	
}

/*
*	This function opens a popup window to view an image preview
*/
function imagePreviewWindow(strFile,nWidth,nHeight) {
	
	width 	= parseInt (nWidth) - 2;
	height 	= parseInt (nHeight) - 2;
	
	window.open(strFile, "Image","toolbar=no,location=no,directories=no,menubar=no,status=yes,scrollbars=no,resizable=no,width=" + width + ",height=" + height);

}


/*
*
*
*
*/
function confirmSubmit(theCommand)
{
    var msg=theCommand;
    return confirm(msg);
}

    


/*
*
*
*
*/
function openPop(strFile,nWidth,nHeight,bStatus,bscroll,btoolbar,blocation,bresize,bdirectories,bmenubar) {

window.open(strFile, "help","toolbar=" + btoolbar + ",location=" + blocation + ",directories=" + bdirectories + ",menubar=" + bmenubar + ",status=" + bStatus + ",scrollbars=" + bscroll +",resizable=" + bresize + ",width=" + nWidth + ",height=" + nHeight);
}



/*
*
*
*
*/
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}



/*
*
*
*
*/
var DHTML = (document.getElementById || document.all || document.layers);

function getObj(name)
{
  if (document.getElementById)
  {
        this.obj = document.getElementById(name);
        this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
        this.obj = document.all[name];
        this.style = document.all[name].style;
  }
  else if (document.layers)
  {
        this.obj = document.layers[name];
        this.style = document.layers[name];
  }
}



/*
*	Selects all thumbnail checkboxes with name formElement
*/
function selectAllImages(formElement)   { setAllSelect(true,formElement); }


/*
*	Deselects all thumbnail checkboxes with name formElement
*/
function deselectAllImages(formElement) { setAllSelect(false,formElement); }


/*
*	Toggles selection state (boolean) for all checkboxes formElement
*/
function setAllSelect(state,formElement) {
	
	var formName	= getThumbnailFormId();
	var elFrm		= document.getElementById(formName);
	
	for (var i = 0; i < elFrm.elements.length; i++) {
		var ourEl = elFrm.elements[i];
		if (ourEl.type == "checkbox")
			if (ourEl.name.indexOf(formElement) != -1)
				ourEl.checked = state;
		}
		
}



/*
*	Returns array of all checkboxes with the name photoid[]
*/
function getSelectedImages() {
	
	var formName	= getThumbnailFormId();
	var elFrm		= document.getElementById(formName);
	var strParams	= "";	
	
	//If selected, add image Id to the list
	for (var i = 0; i < elFrm.elements.length; i++) {
		var ourEl = elFrm.elements[i];
		if (ourEl.type == "checkbox")
			if (ourEl.checked && (ourEl.name.indexOf("photoid[]") != -1))				 
				strParams = strParams + ourEl.value + ",";					
	}
	//Remove Last delimiter.
	strParams = strParams.substr(0,strParams.length-1);	
	return strParams;
	
}

/*
*	Submits the thumbnail grid add to lightbox form
*/
function addSelectionToLightbox () {

	var formName	= getThumbnailFormId();
	var elFrm		= document.getElementById(formName);
	elFrm.submit();
	
}

/*
*	Submits the thumbnail grid remove from lightbox form
*/
function removeSelectionFromLightbox () {

	var formName	= getThumbnailFormId();
	var elFrm		= document.getElementById(formName);
	elFrm.submit();
	
}

/*
*	Returns the id of the thumbnail form being viewed
*/
function getThumbnailFormId() {
	
	var thumbsFormSmall = new getObj('image-small');
	var thumbsFormLarge = new getObj('image-large');
	
	if (thumbsFormSmall.style.display == 'none') {
		return 'thumb_grid_large';
	} else {
		return 'thumb_grid_small';
	}
	
}

/*
*
*
*
*/
function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function



/*
*
*
*
*/
function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function



/*
*
*
*
*/
function changeCSS(theClass,element,value) {
//documentation for this script at http://www.shawnolson.net/a/503/
 var cssRules;
 if (document.all) {
  cssRules = 'rules';
 }
 else if (document.getElementById) {
  cssRules = 'cssRules';
 }
 for (var S = 0; S < document.styleSheets.length; S++){
  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	document.styleSheets[S][cssRules][R].style[element] = value;
   }
  }
 }	
}


/*
*
*
*
*/
Event.observe(window,'load',function(){ changeCSS('.thumbnail','background','#FFF'); },false);


/*
 * Fabtabulous! Simple tabs using Prototype
 * http://tetlaw.id.au/view/blog/fabtabulous-simple-tabs-using-prototype/
 * Andrew Tetlaw
 * version 1.1 2006-05-06
 * http://creativecommons.org/licenses/by-sa/2.5/
 */
var Fabtabs = Class.create();

Fabtabs.prototype = {
	initialize : function(element) {
		this.element = $(element);
		var options = Object.extend({}, arguments[1] || {});
		this.menu = $A(this.element.getElementsByTagName('a'));
		var loader = document.getElementById('loader');
		loader.style.display = 'none';
		this.show(this.getInitialTab());
		this.menu.each(this.setupTab.bind(this));
	},
	setupTab : function(elm) {
		Event.observe(elm,'click',this.activate.bindAsEventListener(this),false)
	},
	activate :  function(ev) {
		var elm = Event.findElement(ev, "a");
		Event.stop(ev);
		this.show(elm);
		this.menu.without(elm).each(this.hide.bind(this));
	},
	hide : function(elm) {
		$(elm).removeClassName('active-tab');
		$(this.tabID(elm)).removeClassName('active-tab-body');
	},
	show : function(elm) {
		$(elm).addClassName('active-tab');
		$(this.tabID(elm)).addClassName('active-tab-body');

	},
	tabID : function(elm) {
		return elm.href.match(/#(\w.+)/)[1];
	},
	getInitialTab : function() {
		if(document.location.href.match(/#(\w.+)/)) {
			var loc = RegExp.$1;
			var elm = this.menu.find(function(value) { return value.href.match(/#(\w.+)/)[1] == loc; });
			return elm || this.menu.first();
		} else {
			return this.menu.first();
		}
	}
}

Event.observe(window,'load',function(){ if (document.getElementById('tab-container')) { new Fabtabs('tabs'); } },false);
