(function($) {

  var cache = [];

  // Arguments are image paths relative to the current page.

  $.preLoadImages = function() {

    var args_len = arguments.length;

    for (var i = args_len; i--;) {

      var cacheImage = document.createElement('img');

      cacheImage.src = arguments[i];

      cache.push(cacheImage);

    }

  }

})(jQuery)


var mygallery;



function loadGallery()

{

	mygallery=new fadeSlideShow({

		wrapperid: "fadeshow1", //ID of blank DIV on page to house Slideshow

		dimensions: [640,385], //width/height of gallery in pixels. Should reflect dimensions of largest image

		imagearray: [

			["<object width=\"640\" height=\"385\"><param name=\"movie\" value=\"http://www.youtube.com/v/GrZFEJRwzAA?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/GrZFEJRwzAA?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"640\" height=\"385\"></embed></object>",2500]





		],

		displaymode: {type:'auto', pause:2500, cycles:1, wraparound:false},

		persist: false, //remember last viewed slide and recall within same session?

		fadeduration: 500, //transition duration (milliseconds)

		descreveal: "ondemand",

		togglerid: ""

	});





}



function closeGallery(){

	jQuery('#fadeshow1').html('');





	jQuery('#lightbox').animate({opacity:0},600);

	jQuery('#overlay').animate({opacity:0},1000, function() {

	

		jQuery('#overlay').hide();

		jQuery('#overlay').css({opacity:1});

		jQuery('#lightbox').hide();

		jQuery('#lightbox').css({opacity:1});

		jQuery('#outerImageContainer').css({width:0,height:0});

		jQuery('#imageDataContainer').hide();

		

	});









}



function loadLightbox(){

	var pageSize = getPageSize();

	jQuery('#overlay').css({height:pageSize.pageHeight+'px'});

	jQuery('#overlay').show();

	jQuery('#overlay').animate({opacity:.8},200);





	var pageScroll = getPageScroll();

	//var lightboxTop = pageScroll.y + (pageSize.winHeight / 15);

	var lightboxTop = pageScroll.y + (pageSize.winHeight - 350) / 2;



	jQuery('#lightbox').css({top:lightboxTop+'px'}).show();

	resizeImageContainer(640,385);





	setTimeout('loadGallery()',2000);

}



function resizeImageContainer(imgWidth,imgHeight) {

		// get current height and width

//		var cDims = {width:jQuery('#outerImageContainer').width(),height:jQuery('#outerImageContainer').height()};

		cDims = { width:100,height:100};



		// scalars based on change from old to new

		var xScale = ((imgWidth  + (10 * 2)) / cDims.width ) * 100;

		var yScale = ((imgHeight  + (10 * 2)) / cDims.height ) * 100;



		// calculate size difference between new and old image, and resize if necessary

		var wDiff = (cDims.width - 10 * 2) - imgWidth;

		var hDiff = (cDims.height - 10 * 2) - imgHeight;

		

		if(!( hDiff == 0)){

			if(!( wDiff == 0)){

				jQuery('#outerImageContainer').animate({height:yScale},600).animate({width:xScale},600, function (){

	jQuery('#imageDataContainer').css({'margin-top':'-38px'});

	jQuery('#imageDataContainer').show();



	jQuery('#imageDataContainer').animate({'margin-top':'0px'},600);

				

				

				});





			}

		}



//		if(!( hDiff == 0)){ new Effect.Scale('#outerImageContainer', yScale, {scaleX: false, duration: 600, queue: 'front'}); }

//		if(!( wDiff == 0)){ new Effect.Scale('#outerImageContainer', xScale, {scaleY: false, delay: this.resizeDuration, duration: 600}); }



		// if new and old image are same size and no scaling transition is necessary, 

		// do a quick pause to prevent image flicker.

		if((hDiff == 0) && (wDiff == 0)){

			if(navigator.appVersion.indexOf('MSIE')!=-1){ pause(250); } else { pause(100);} 

		}



//		$(this.getID('prevLinkImg')).setStyle({height:imgHeight+'px'});

//		$(this.getID('nextLinkImg')).setStyle({height:imgHeight+'px'});

		jQuery('#imageDataContainer').css({width:(imgWidth+(10 * 2))+'px'});



//		Lightbox.updateDetails();

	//	this.showImage();

}



function pause(numberMillis) {

		var now = new Date();

		var exitTime = now.getTime() + numberMillis;

		while(true){

			now = new Date();

			if (now.getTime() > exitTime)

				return;

		}

}





function getPageScroll(){

		var x,y;

		if (self.pageYOffset) {

			x = self.pageXOffset;

			y = self.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 getPageSize (){

		var scrollX,scrollY,windowX,windowY,pageX,pageY;

		if (window.innerHeight && window.scrollMaxY) {	

			scrollX = document.body.scrollWidth;

			scrollY = window.innerHeight + window.scrollMaxY;

		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac

			scrollX = document.body.scrollWidth;

			scrollY = document.body.scrollHeight;

		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari

			scrollX = document.body.offsetWidth;

			scrollY = document.body.offsetHeight;

		}

		

		if (self.innerHeight) {	// all except Explorer

			windowX = self.innerWidth;

			windowY = self.innerHeight;

		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode

			windowX = document.documentElement.clientWidth;

			windowY = document.documentElement.clientHeight;

		} else if (document.body) { // other Explorers

			windowX = document.body.clientWidth;

			windowY = document.body.clientHeight;

		}	

		

		pageY = (scrollY < windowY) ? windowY : scrollY; // for small pages with total height less then height of the viewport

		pageX = (scrollX < windowX) ? windowX : scrollX; // for small pages with total width less then width of the viewport

	

		return {pageWidth:pageX,pageHeight:pageY,winWidth:windowX,winHeight:windowY};

	}




