// JavaScript Document
/** -----------------------------------------------
  Image Preloader - v.1.1
  (c) 2007 http://www.haan.net
  You may use this script but please leave the credits on top intact.
  Please inform us of any improvements made.
  When useful, we will add your credits.
------------------------------------------------ */
var imgLoaded = new Array();
function imgPreload(imgQueue) {
	//alert('imgPreload(); '+imgQueue.length);
 	for (i=0;i<imgQueue.length;i++) {
  		imgLoaded[i] = new Image();
  		imgLoaded[i].src = imgQueue[i]; // change file extension, if necessary.
 		// uncomment next line for testing; click OK to continue loop and cancel to break
		//imgLoaded[i].onload=function(){ alert('onload:'+imgLoaded[i].src);}
		//if(imgLoaded[i].complete) alert('load complete:'+imgLoaded[i].src);
 	}
}

/**
 get all of Tag A is attribut 'rel' start with 'lightbox' 
 and put into array for preload function
*/
var imgQueue = new Array();
function getImageQueue(){
	//alert('getImageQueue()');
	var tagA = document.getElementsByTagName('a');
		for(var i=0; i<tagA.length; i++){
			if(tagA[i].getAttribute('rel') != null && tagA[i].getAttribute('rel').match(/^lightbox/) )
				imgQueue.push(tagA[i].href);
		}//end for
//	alert('Image in queue:'+imgQueue.length);
}//end function

function disableRightClick(){
	document.body.oncontextmenu = function(){return false;};
}
/** 
 call the function with the list of images (unique part of names)
 Multiple onload function created by: Simon Willison
 http://simon.incutio.com/archive/2004/05/26/addLoadEvent
*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
addLoadEvent(function() {
	//alert('addLoadEvent');
	disableRightClick();
	getImageQueue(); // push image url to imgQueue, for preload function
	if(imgQueue.length > 0)	imgPreload(imgQueue);
});