var E2GalleryPro={version:"1.3"};
var openclose=true;
var slidesHidden = false;
var imagecontainer = $('images');
var busy = false;
var previousid = "0";
var currentthumbpos = 0;
var showInfoType="show";
var movedamount=0;
var imagenumber=Number(1);
var thumbnailNumberPos;
var thumbSizing;
var totalthumbsvisible=0;

var currentThumbSpot =1;
var thumbWidth=setThumbWidth;
var largeHtmlIsCreated;
var galleryHeight;
var showThumbs = "hide";
var fsisopen = "closed";
var animatingPop = false;
var moving=false;
var timer;
var playing=false;
var prevHidden = false;
var nextHidden = false;
var totalNumImages;
var totalNumQuicktime;
var totalNumMedia;
var closinggalleries=false;
var currentGallery = maingalleries[0]["gallerynum"];
var currentimage = 0;
var lastimage = maingalleries[0]["end"];
var startImage=maingalleries[0]["start"];
var largeIsOpen = false;
function openforsale(){
	if(fsisopen=="open"){
		//$('testmessage').set('text',"For Sale Button is: "+fsisopen);
		fsisopen = "closed";
		var showForSaleForm = new Fx.Morph('fsbox',{duration:transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
		showForSaleForm.start({'bottom':-277});
		var showclosebtn = new Fx.Morph('fsclose',{duration:transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
		showclosebtn.start({'opacity':0});
	}else{
		
		fsisopen = "open";							
		var showForSaleForm = new Fx.Morph('fsbox',{duration:transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
		showForSaleForm.start({'bottom':-100});
		var showclosebtn = new Fx.Morph('fsclose',{duration:transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
		showclosebtn.start({'opacity':1});		
	}
}
function addImage(idnum) {
		currentimage = galleryimages[idnum]['imgid'];
		filetype = galleryimages[idnum]['filetype'];
		$('imgloader').empty();
		$('infoloader').empty();
		var newInfo = '';
		if(galleryimages[idnum]['title']){
			//alert(galleryimages[idnum]['title'])
			newInfo += '<h2>'+galleryimages[idnum]['title']+'</h2>';
			if(galleryimages[idnum]['forsale']==true){
				newInfo+='<div id="purchasebtn">'+purchaseprinttxt+'</div>';
			}
		}
		if(galleryimages[idnum]['description']){
			newInfo += '<span class="description">'+galleryimages[idnum]['description']+'</span>';
			if(galleryimages[idnum]['forsale']==true){
				newInfo+='<div id="purchasebtn">'+purchaseprinttxt+'</div>';
			}
		}
		if(galleryimages[idnum]['copyright']){
			newInfo += '<div class="copyright"><strong>Copyright:</strong> '+galleryimages[idnum]['copyright']+'</div>';
			if(galleryimages[idnum]['forsale']==true){
				newInfo+='<div id="purchasebtn">'+purchaseprinttxt+'</div>';
			}
		}
		if(galleryimages[idnum]['author']){
			newInfo += '<div class="author"><strong>Author:</strong> '+galleryimages[idnum]['author']+'</div>';
			if(galleryimages[idnum]['forsale']==true){
				newInfo+='<div id="purchasebtn">'+purchaseprinttxt+'</div>';
			}
		}
		if(newInfo==''){
			newInfo+='<h2>No Image Information Available</h2>';
			if(galleryimages[idnum]['forsale']==true){
				newInfo+='<div id="purchasebtn">'+purchaseprinttxt+'</div>';
			}
		}
		$('infoloader').set('html',newInfo);

		var fadenewinfo = new Fx.Morph('infoloader', {duration:transitionspeed });		
		
		var fadenewimg = new Fx.Morph('imgloader', {duration:transitionspeed, onComplete: function(){busy=false;} });
		
		var fadeimg = new Fx.Morph('imgloader', {duration:transitionspeed, onComplete:function(){
			if(filetype =='image'){
				var newHTML = "<img src='"+galleryimages[idnum]['path']+galleryimages[idnum]['src']+"' id='imgsrc' title='"+galleryimages[idnum]['title']+"' />";
				$('imgloader').set('html',newHTML);
				fadenewimg.start({'opacity':1});
			}
			// FLV, MP4
			if (filetype =='flv' ||filetype =='mp4') {
				
				fileWidth = galleryimages[idnum]['width']   || flashdefaultWidth;
				fileHeight = galleryimages[idnum]['height'] || flashdefaultHeight;
				media = new Swiff(''+NBpath+'?videoURL='+galleryimages[idnum]['mediaURL']+'&allowSmoothing=true&autoPlay='+autoplay+'&buffer=6&showTimecode='+showTimecode+'&loop=true&controlColour='+controllerColor+'&scaleIfFullScreen=true&showScalingButton=false', {
					id: 'MediaboxSWF',
					width: mediaWidth,
					height: mediaHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
				});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// .MOV
			} else if (filetype =='mov') {
				
				var mediaHTML = '<object width="'+galleryimages[idnum]['width']+'" height="'+galleryimages[idnum]['height']+'" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab"> <param name="src" value="'+galleryimages[idnum]['mediaURL']+'"><param name="autoplay" value="'+autoplay+'"><param name="controller" value="true"><embed src="'+galleryimages[idnum]['mediaURL']+'" width="'+galleryimages[idnum]['width']+'" height="'+galleryimages[idnum]['height']+'" autoplay="'+autoplay+'" controller="true" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>';
				$('imgloader').set('html',mediaHTML);
				
				fadenewimg.start({'opacity':1});
			// SWF
			} else if (filetype =='swf') {
				
				fileWidth = galleryimages[idnum]['width']   || flashdefaultWidth;
				fileHeight = galleryimages[idnum]['height'] || flashdefaultHeight;
				media = new Swiff(galleryimages[idnum]['mediaURL'], {
					id: 'e2gallerySWF',
					width: fileWidth,
					height: fileHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// Blip.tv
			} else if (filetype =='blip.tv') {
				
				fileWidth = galleryimages[idnum]['width']   || "640px";
				fileHeight = galleryimages[idnum]['height'] || "390px";
				media = new Swiff(galleryimages[idnum]['mediaURL'], {
					src: galleryimages[idnum]['mediaURL'],
					width: fileWidth,
					height: fileHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// DailyMotion
			} else if (filetype =='dailymotion') {
				
				fileWidth = galleryimages[idnum]['width']   || "480px";
				fileHeight = galleryimages[idnum]['height'] || "381px";
				media = new Swiff(galleryimages[idnum]['mediaURL'], {
					id: mediaId,
					width: fileWidth,
					height: fileHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// Flickr
			} else if (filetype =='flickr') {
				
				fileWidth = galleryimages[idnum]['width']   || "500px";
				fileHeight = galleryimages[idnum]['height'] || "375px";
				mediaSplit = galleryimages[idnum]['mediaURL'].split('/');
				mediaId = mediaSplit[5];
				media = new Swiff('http://www.flickr.com/apps/video/stewart.swf', {
					id: mediaId,
					classid: 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
					width: fileWidth,
					height: fileHeight,
					params: {flashvars: 'photo_id='+mediaId+'&amp;show_info_box='+flInfo, wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// Google Video
			} else if (filetype =='google') {
				
				fileWidth = galleryimages[idnum]['width']   || "400px";
				fileHeight = galleryimages[idnum]['height'] || "326px";
				mediaSplit = galleryimages[idnum]['mediaURL'].split('=');
				mediaId = mediaSplit[1];
				media = new Swiff('http://video.google.com/googleplayer.swf?docId='+mediaId+'&autoplay='+autoplayNum, {
					id: mediaId,
					width: fileWidth,
					height: fileHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// Metacafe
			} else if (filetype =='metacafe') {
				
				fileWidth = galleryimages[idnum]['width']   || "400px";
				fileHeight = galleryimages[idnum]['height'] || "345px";
				mediaSplit = galleryimages[idnum]['mediaURL'].split('/');
				mediaId = mediaSplit[4];
				media = new Swiff('http://www.metacafe.com/fplayer/'+mediaId+'/.swf', {
					id: mediaId,
					width: fileWidth,
					height: fileHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// MyspaceTV
			} else if (filetype =='myspace') {
				
				fileWidth = galleryimages[idnum]['width']   || "425px";
				fileHeight = galleryimages[idnum]['height'] || "360px";
				mediaSplit = galleryimages[idnum]['mediaURL'].split('=');
				mediaId = mediaSplit[2];
				media = new Swiff('http://lads.myspace.com/videos/vplayer.swf?m='+mediaId+'&v=2&type=video', {
					id: mediaId,
					width: fileWidth,
					height: fileHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// Revver
			} else if (filetype =='revver') {
				
				fileWidth = galleryimages[idnum]['width']   
				fileHeight = galleryimages[idnum]['height'] 
				mediaSplit = galleryimages[idnum]['mediaURL'].split('/');
				mediaId = mediaSplit[4];
				media = new Swiff('http://flash.revver.com/player/1.0/player.swf?mediaId='+mediaId+'&affiliateId='+revverID+'&allowFullScreen='+revverFullscreen+'&backColor=#'+revverBack+'&frontColor=#'+revverFront+'&gradColor=#'+revverGrad+'&shareUrl=revver', {
					id: mediaId,
					width: fileWidth,
					height: fileHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// Rutube
			} else if (filetype =='rutube') {
				
				fileWidth = galleryimages[idnum]['width']   || "470px";
				fileHeight = galleryimages[idnum]['height'] || "353px";
				mediaSplit = galleryimages[idnum]['mediaURL'].split('=');
				mediaId = mediaSplit[1];
				media = new Swiff('http://video.rutube.ru/'+mediaId, {
					movie: 'http://video.rutube.ru/'+mediaId,
					width: fileWidth,
					height: fileHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// Seesmic
			} else if (filetype =='seesmicm') {
				
				fileWidth = galleryimages[idnum]['width']   || "435px";
				fileHeight = galleryimages[idnum]['height'] || "355px";
				mediaSplit = galleryimages[idnum]['mediaURL'].split('/');
				mediaId = mediaSplit[5];
				media = new Swiff('http://seesmic.com/Standalone.swf?video='+mediaId, {
					id: mediaId,
					width: fileWidth,
					height: fileHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// Tudou
			} else if (filetype =='tudou') {
				
				fileWidth = galleryimages[idnum]['width']   || "400px";
				fileHeight = galleryimages[idnum]['height'] || "340px";
				mediaSplit = galleryimages[idnum]['mediaURL'].split('/');
				mediaId = mediaSplit[5];
				media = new Swiff('http://www.tudou.com/v/'+mediaId, {
					width: fileWidth,
					height: fileHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// YouKu
			} else if (filetype =='youku') {
				
				fileWidth = galleryimages[idnum]['width']   || "480px";
				fileHeight = galleryimages[idnum]['height'] || "400px";
				mediaSplit = galleryimages[idnum]['mediaURL'].split('id_');
				mediaId = mediaSplit[1];
				media = new Swiff('http://player.youku.com/player.php/sid/'+mediaId+'=/v.swf', {
					width: fileWidth,
					height: fileHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// YouTube
			} else 	if (filetype =='youtube') {
				
				mediaSplit = galleryimages[idnum]['mediaURL'].split('v=');
				mediaId = mediaSplit[1];
				if (mediaId.match(/fmt=18/i)) {
					mediaFmt = '&ap=%2526fmt%3D18';
					mediaWidth = galleryimages[idnum]['width'] || "560px";
					mediaHeight = galleryimages[idnum]['height'] || "345px";
				} else if (mediaId.match(/fmt=22/i)) {
					mediaFmt = '&ap=%2526fmt%3D22';
					mediaWidth = galleryimages[idnum]['width'] || "640px";
					mediaHeight = galleryimages[idnum]['height'] || "385px";
				} else {
					mediaFmt = ytQuality;
					mediaWidth = galleryimages[idnum]['width'] || "480px";
					mediaHeight = galleryimages[idnum]['height'] || "295px";
				}
				media = new Swiff('http://www.youtube.com/v/'+mediaId+'&autoplay='+autoplayNum+'&fs='+fullscreenNum+mediaFmt+'&color1=0x'+ytColor1+'&color2=0x'+ytColor2, {
					id: mediaId,
					width: mediaWidth,
					height: mediaHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// Veoh
			}
			else if (filetype =='veoh') {
				
				fileWidth = galleryimages[idnum]['width']   || "410px";
				fileHeight = galleryimages[idnum]['height'] || "341px";
				mediaSplit = galleryimages[idnum]['mediaURL'].split('videos/');
				mediaId = mediaSplit[1];
				media = new Swiff('http://www.veoh.com/videodetails2.swf?permalinkId='+mediaId+'&player=videodetailsembedded&videoAutoPlay='+AutoplayNum, {
					id: mediaId,
					width: fileWidth,
					height: fileHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// Viddler
			} else if (filetype =='viddler') {
				
				fileWidth = galleryimages[idnum]['width']   || "437px";
				fileHeight = galleryimages[idnum]['height'] || "370px";
				mediaSplit = galleryimages[idnum]['mediaURL'].split('/');
				mediaId = mediaSplit[4];
				media = new Swiff(galleryimages[idnum]['mediaURL'], {
					id: 'viddler_'+mediaId,
					movie: galleryimages[idnum]['mediaURL'],
					classid: 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
					width: fileWidth,
					height: fileHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen, id: 'viddler_'+mediaId, movie: galleryimages[idnum]['mediaURL']}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// Vimeo
			} else if (filetype =='vimeo') {
				
				fileWidth = galleryimages[idnum]['width']   || "400px";
				fileHeight = galleryimages[idnum]['height'] || "225px";
				mediaSplit = galleryimages[idnum]['mediaURL'].split('/');
				mediaId = mediaSplit[3];
				media = new Swiff('http://www.vimeo.com/moogaloop.swf?clip_id='+mediaId+'&amp;server=www.vimeo.com&amp;fullscreen='+fullscreenNum+'&amp;show_title='+vmTitle+'&amp;show_byline='+vmByline+'&amp;show_portrait='+vmPortrait+'&amp;color='+vmColor, {
					id: mediaId,
					width: fileWidth,
					height: fileHeight,
					params: {wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			// 12seconds
			} else if (filetype =='12seconds') {
				
				fileWidth = galleryimages[idnum]['width']   || "430px";
				fileHeight = galleryimages[idnum]['height'] || "360px";
				mediaSplit = galleryimages[idnum]['mediaURL'].split('/');
				mediaId = mediaSplit[5];
				media = new Swiff('http://embed.12seconds.tv/players/remotePlayer.swf', {
					id: mediaId,
					width: fileWidth,
					height: fileHeight,
					params: {flashvars: 'vid='+mediaId+'', wmode: 'opaque', bgcolor: bgcolor, allowscriptaccess: scriptaccess, allowfullscreen: fullscreen}
					});
				media.inject('imgloader');
				fadenewimg.start({'opacity':1});
			}
			//begin for sale if
			if(galleryimages[idnum]['forsale']==true){
				$('fsbox').empty();
				var fsbtn     = new Element('div', {'id':"fsbutton"}).inject($('fsbox'), 'top');
				var fstop     = new Element('div', {'id':"fstop"}).inject($('fsbox'));
				var fscontent = new Element('div', {'id':"forsale"}).inject($('fsbox'));
					$('fsbutton').set('html',orderText+"<div id='fsclose'></div>");
				if(galleryimages[idnum]['title']==""||galleryimages[idnum]['title']==null){
					placeTitle = galleryimages[idnum]['src'];
				}else{
					placeTitle = galleryimages[idnum]['title'];
				}
					var showForSale = new Fx.Morph('fsbox', {duration:transitionspeed, transition: Fx.Transitions.Expo.easeInOut, onComplete: function(){
					var paymenttype = galleryimages[idnum]['paytype'];
					if(paymenttype=='paypal'){
						numOfPrices = galleryimages[idnum]['numOfPrices'];
						
						/*paypalform+='<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">';
						paypalform+='<input type="hidden" name="cmd" value="_s-xclick">';
						paypalform+='<input type="hidden" name="hosted_button_id" value="'+paypalButtonId+'">';
						paypalform+= '<img src="'+thumbPath+galleryimages[idnum]['src']+'" border="0"  class="forsalethumb" align="left" />';
						paypalform+= '<strong>Buy: '+placeTitle+'</strong><br />';
						paypalform+= purchaseOf+placeTitle+shipinginfoshort+'<br />';
						paypalform+='<input type="hidden" name="on0" value="Photo Sizes">'+selectSizes+": ";
						paypalform+='<select name="os0">';
						for (i=1;i<=numOfPrices;i++){
							if(galleryimages[idnum]['pricecurrency'+i+'']=="&euro;"){
								pricingFormat = +''+galleryimages[idnum]['price'+i+'']+''+galleryimages[idnum]['pricecurrencysymbol'+i+''];
							}else{
								pricingFormat = galleryimages[idnum]['pricecurrencysymbol'+i+'']+''+galleryimages[idnum]['price'+i+''];
							}
							paypalform+= '<option value="'+galleryimages[idnum]['price'+i+'']+'">'+galleryimages[idnum]['pricesize'+i+'']+' - '+pricingFormat+'</option>';
						}
						paypalform+='</select>';
						paypalform+='<input type="hidden" name="currency_code" value="'+galleryimages[idnum]['pricecurrency'+i+'']+'">';
						paypalform+='<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">';
						paypalform+='<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">';
						paypalform+= '<hr /><br />';
						paypalform+='</form>';*/
						
						paypalform='';
						paypalform+='<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">';
						paypalform+='	<input type="hidden" name="cmd" value="_s-xclick">';
						paypalform+='	<input type="hidden" name="hosted_button_id" value="'+paypalButtonId+'">';
						paypalform+= '	<img src="'+thumbPath+galleryimages[idnum]['src']+'" border="0"  class="forsalethumb" align="left" />';
						paypalform+= '	<strong>Buy: '+placeTitle+'</strong><br />';
						paypalform+= '	'+purchaseOf+placeTitle+shipinginfoshort+'<br />';
						paypalform+='	<table>';
						paypalform+='	<tr><td><input type="hidden" name="on0" value="'+galleryimages[idnum]['src']+' - '+paypalSelectText+'">'+galleryimages[idnum]['src']+' -'+paypalSelectText+'</td></tr><tr><td><select name="os0">';
									for (i=1;i<=numOfPrices;i++){
										if(galleryimages[idnum]['pricecurrency'+i+'']=="&euro;"){
											pricingFormat = +''+galleryimages[idnum]['price'+i+'']+''+galleryimages[idnum]['pricecurrencysymbol'+i+''];
										}else{
											pricingFormat = galleryimages[idnum]['pricecurrencysymbol'+i+'']+''+galleryimages[idnum]['price'+i+''];
										}
										paypalform+= '<option value="'+galleryimages[idnum]['pricesize'+i+'']+'">'+galleryimages[idnum]['pricesize'+i+'']+' '+pricingFormat+'';
										
									}
						paypalform+='	</select> </td></tr>';
						paypalform+='	</table>';
						paypalform+='	<input type="hidden" name="currency_code" value="'+galleryimages[idnum]['pricecurrency'+i+'']+'">';
						paypalform+='	<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">';
						paypalform+='	<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">';
						paypalform+='</form>';

						
						$('forsale').set('html',paypalform);	
					}
					if(paymenttype=="google"){
						numOfPrices = galleryimages[idnum]['numOfPrices'];
						googleform='';
							googleform+='<form action="https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/'+merchantId+'" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm">';
								googleform+='<img src="'+thumbPath+galleryimages[idnum]['src']+'" border="0"  class="forsalethumb" align="left" />';
								googleform+='<strong>Buy: '+placeTitle+'</strong>';
								googleform+='<br />';
								googleform+=purchaseOf+placeTitle+shipinginfoshort+'<br />';
								googleform+=selectSizes+': ';
								googleform+='<select name="item_selection_1">';
								for (i=1;i<=numOfPrices;i++){
									if(galleryimages[idnum]['pricecurrency'+i+'']=="&euro;"){
										pricingFormat = galleryimages[idnum]['price'+i+'']+' '+galleryimages[idnum]['pricecurrencysymbol'+i+''];
									}else{
										pricingFormat = galleryimages[idnum]['pricecurrencysymbol'+i+'']+''+galleryimages[idnum]['price'+i+''];
									}
									googleform+= ' 	<option value="'+i+'">'+galleryimages[idnum]['pricesize'+i+'']+' - '+pricingFormat+'</option>';
								}
								googleform+='</select><br />';
								for (i=1;i<=numOfPrices;i++){
									googleform+='<input name="item_option_name_'+i+'" type="hidden" value="'+galleryimages[idnum]['pricesize'+i+'']+' Print"/>';
									googleform+='<input name="item_option_price_'+i+'" type="hidden" value="'+galleryimages[idnum]['price'+i+'']+'"/>';
									googleform+='<input name="item_option_description_'+i+'" type="hidden" value="'+galleryimages[idnum]['pricesize'+i+'']+' '+placeTitle+'"/>';
									googleform+='<input name="item_option_quantity_'+i+'" type="hidden" value="1"/>';
									googleform+='<input name="item_option_currency_'+i+'" type="hidden" value="'+galleryimages[idnum]['pricecurrency'+i+'']+'"/>';
								}
								
								googleform+='<input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id='+merchantId+'&amp;w=121&amp;h=44&amp;style=trans&amp;variant=text&amp;loc=en_US" type="image"/>';
							googleform+='</form><hr /><br />';

						$('forsale').set('html',googleform);
					}
					$('fsbutton').addEvent('click', function(){
						openforsale();
						var hideThumbPop = new Fx.Morph('thumbnailPopUp', {duration: 50, transition: Fx.Transitions.Expo.easeInOut});
						hideThumbPop.start({
							'opacity':0
						});
					});
									
				} });
				//fsisopen = false;
				showForSale.start({	'opacity':1,'bottom':-277});
				var showclosebtn = new Fx.Morph('fsclose',{duration:transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
				showclosebtn.start({'opacity':0});
			}
			//end for sale if
			//$('testmessage').set('text',"For Sale Button is: "+fsisopen);			
		} });
	var highlight = new Fx.Morph(""+idnum+"" , {duration: 100, transition: Fx.Transitions.linear});
	highlight.start({
		'border-color': '#FFF',
		'background-color': '#FFF',
		'opacity':1
	});
	fadenewinfo.start({'opacity':1});
	fadeimg.start({'opacity':0});
	var unloadloading = new Fx.Morph('loading',{duration: 200, onComplete:function(){}});
	unloadloading.start({'opacity':0});
	
}

function setThumbClick(gallery){
	thumbPath= maingalleries[gallery]["thumbpath"];
	imagenumber = Number(1);
	$$('.thumbnail').addEvent('click', function(e){
		if(playing==true){ slideshow();}
		if(!busy){
			if(filetype != 'image'){$('imgloader').empty();}
			busy=true;
			var id = this.id;
			imagenumber = this.get('rel');	
			imagenumber = Number(imagenumber);
			$('numOf').set('text', imagenumber+' of ').inject('photoNum', 'top');
			//alert(imagenumber);
			var currentimage=Number(galleryimages[id]['imgid']);
			loadimage(Number(id), Number(imagenumber));
			var unhighlight = new Fx.Morph(""+previousid+"", {duration: 500, transition: Fx.Transitions.Expo.easeInOut });
			unhighlight.start({
				'border-color': '#FFF',
				'background-color': '#FFF',
				'opacity':.5
			});
			var highlight = new Fx.Morph(id , {duration: 500, transition: Fx.Transitions.linear});
			highlight.start({
				'border-color': '#FFF',
				'background-color': '#FFF',
				'opacity':1
			});
			previousid = currentimage;
		}
	});
	$('next').addEvent('click', function(e){
		if(playing==true){ slideshow();}
		if(!busy){
			busy=true;
			nextnum=Number(currentimage+1);
			imagenumber=Number(imagenumber+1); 
			realNum = $(''+nextnum+'').get('rel');
			$('numOf').set('text', realNum+' of ').inject('photoNum', 'top');
			loadimage(nextnum, imagenumber);
			var unhighlight = new Fx.Morph(""+currentimage+"", {duration: 500, transition: Fx.Transitions.Expo.easeInOut});
			unhighlight.start({
				'border-color': '#FFF',
				'background-color': '#FFF',
				'opacity':.5
			});
			thumbinview = $('thumbnails').getCoordinates().width;
			maxThumbsVisible = Math.floor(thumbinview/setThumbWidth);
			thumbsMod = imagenumber%maxThumbsVisible;
			if(imagenumber>=maxThumbsVisible && thumbsMod==1 || maxThumbsVisible==1){
				movethumbs("more");
			}
			//$('testmessage').set('text',thumbsMod);
			
			currentimage=Number(galleryimages[nextnum]['imgid']);
			previousid = currentimage;
		}
	});
	$('previous').addEvent('click', function(e){
		if(playing==true){ slideshow();}
		if(!busy){
			thumbinview = $('thumbnails').getCoordinates().width;
			maxThumbsVisible = Math.floor(thumbinview/setThumbWidth);
			thumbsMod = (imagenumber)%maxThumbsVisible;
			if(imagenumber>=maxThumbsVisible && thumbsMod==1 || maxThumbsVisible==1){
				movethumbs("back");
			}
			previousnum=Number(currentimage-1);
			busy=true;
			imagenumber=Number(imagenumber-1); 
			realNum = $(''+previousnum+'').get('rel');
			$('numOf').set('text', realNum+' of ').inject('photoNum', 'top');
			loadimage(""+previousnum+"", imagenumber);
			var unhighlight = new Fx.Morph(""+currentimage+"", {duration: 500, transition: Fx.Transitions.Expo.easeInOut});
			unhighlight.start({
				'border-color': '#FFF',
				'background-color': '#FFF',
				'opacity':.5
			});
			
			//$('testmessage').set('text',"imgnumthumbpos= "+imgnumthumbpos+", thumbinview = "+thumbinview+", thumbWidth="+thumbWidth);
			currentimage=Number(galleryimages[previousnum]['imgid']);
			previousid = currentimage;
		}
	});
	$(window.document).addEvent('keydown',function(e){
		 if(e.key == 'right' && currentimage!=lastimage){ 
		 	if(playing==true){ slideshow();}
			if(!busy){
				busy=true;
				nextnum=Number(currentimage+1);
				imagenumber=Number(imagenumber+1); 
				realNum = $(''+nextnum+'').get('rel');
				$('numOf').set('text', realNum+' of ').inject('photoNum', 'top');
				loadimage(nextnum, imagenumber);
				var unhighlight = new Fx.Morph(""+currentimage+"", {duration: 500, transition: Fx.Transitions.Expo.easeInOut});
				unhighlight.start({
					'border-color': '#FFF',
					'background-color': '#FFF',
					'opacity':.5
				});
				thumbinview = $('thumbnails').getCoordinates().width;
				maxThumbsVisible = Math.floor(thumbinview/setThumbWidth);
				thumbsMod = imagenumber%maxThumbsVisible;
				if(imagenumber>=maxThumbsVisible && thumbsMod==1 || maxThumbsVisible==1){
					movethumbs("more");
				}
				//$('testmessage').set('text',thumbsMod);
				
				currentimage=Number(galleryimages[nextnum]['imgid']);
				previousid = currentimage;
			}
		 }
		 if(e.key == 'left' && currentimage!=0){
			if(playing==true){ slideshow();}
			if(!busy){
				thumbinview = $('thumbnails').getCoordinates().width;
				maxThumbsVisible = Math.floor(thumbinview/setThumbWidth);
				thumbsMod = (imagenumber)%maxThumbsVisible;
				if(imagenumber>=maxThumbsVisible && thumbsMod==1 || maxThumbsVisible==1){
					movethumbs("back");
				}
				previousnum=Number(currentimage-1);
				busy=true;
				imagenumber=Number(imagenumber-1); 
				realNum = $(''+previousnum+'').get('rel');
				$('numOf').set('text', realNum+' of ').inject('photoNum', 'top');
				loadimage(""+previousnum+"", imagenumber);
				var unhighlight = new Fx.Morph(""+currentimage+"", {duration: 500, transition: Fx.Transitions.Expo.easeInOut});
				unhighlight.start({
					'border-color': '#FFF',
					'background-color': '#FFF',
					'opacity':.5
				});
				
				//$('testmessage').set('text',"imgnumthumbpos= "+imgnumthumbpos+", thumbinview = "+thumbinview+", thumbWidth="+thumbWidth);
				currentimage=Number(galleryimages[previousnum]['imgid']);
				previousid = currentimage;
			}	 
		 }
	});
	$$('.thumbnail').addEvent('mouseenter', function(){
		
		myid = this.id
		var filetype = galleryimages[myid]['filetype'];
		var showThumbPop = new Fx.Morph('thumbnailPopUp', {duration: 25, transition: Fx.Transitions.Expo.easeInOut, onComplete:function(){
			$('thumbnailPopUp').empty();
				if(filetype =='image'){
					var setThumbImagePop = new Element('img', {'src':thumbPath+galleryimages[myid]['src'],'id':'thumbPop'}).inject($('thumbnailPopUp'));
				}else{
					var setThumbImagePop = new Element('img', {'src':galleryimages[myid]['src'],'id':'thumbPop'}).inject($('thumbnailPopUp'));
				}
				myX = $('gallery').getCoordinates().width;
				myY = $('images').getCoordinates().height;
				myImgWidth=$('thumbPop').getCoordinates().width;
				myImgHeight=$('thumbPop').getCoordinates().height;
				myNewX = ((myX/2)-(myImgWidth/2))
				myNewY = (myY-(myImgHeight/2))-(($('thumbnailPopUp').getCoordinates().height/2)+6);
				//$('testmessage').set('text',myNewX);
				if(animatingPop!=true){
					animatingPop=true;
					var myFunction = function(){
					$('thumbnailPopUp').setStyles({position: 'absolute', 'top': (myNewY), 'left': myNewX,'visibility': 'hidden' });
						var showThumbPop = new Fx.Morph('thumbnailPopUp', {duration: 200, transition: Fx.Transitions.Expo.easeOut, onComplete:function(){animatingPop=false;}});
						showThumbPop.start({
							'top': myNewY,
							'left': myNewX,
							'opacity':1
						})
					};
					myFunction.delay(250);
				}
		
		}});
		showThumbPop.start({
			'opacity':0
		});
		if(myid!=currentimage){
			var highlight = new Fx.Morph(myid, {duration: 100, transition: Fx.Transitions.Expo.easeInOut});
			highlight.start({
				'border-color': '#FFF',
				'background-color': '#FFF',
				'opacity':1
			});
		}
	});
	$$('.thumbnail').addEvent('mouseleave', function(){
		myid = this.id
		var hideThumbPop = new Fx.Morph('thumbnailPopUp', {duration: 50, transition: Fx.Transitions.Expo.easeInOut});
		hideThumbPop.start({
			'opacity':0
		});
		if(myid!=currentimage){
			var highlight = new Fx.Morph(myid, {duration: 50, transition: Fx.Transitions.Expo.easeInOut});
			highlight.start({
				'border-color': '#FFF',
				'background-color': '#FFF',
				'opacity':.5
			});
			
			//$('testmessage').set('text',myid);
		}
	});
}
function loadThumbs(gallery,loadgal){
	var thumbWrap = $('thumbnailwrap');
	thumbnailNumberPos=1;
	totalNumImages=0;
	totalNumMedia=0;
	totalNumQuicktime=0;
	$('thumbnailwrap').empty();
	startImage = maingalleries[gallery]["start"];
	endImage = maingalleries[gallery]["end"];
	thumbPath= maingalleries[gallery]["thumbpath"];
	lastimage = maingalleries[gallery]["end"];
	currentGallery = maingalleries[gallery]["gallerynum"];
	currentimage=Number(galleryimages[startImage]['imgid']);
	
	previousid = Number(startImage);
	
	busy = false;
	for (i=startImage;i<=endImage;i++){
		filetype = galleryimages[i]['filetype'];
		filetitle = galleryimages[i]['title'];
		if(totalthumbsvisible<$('thumbnails').getCoordinates().width-setThumbWidth){
			totalthumbsvisible+=setThumbWidth;
		}
		
		thumbWidth+=setThumbWidth;
		thumbWrap.setStyles({'width':thumbWidth});
		var currentImgId = i;
		
			
		if(filetype =='image'){	
			if(filetitle == ""){
				var el     = new Element('div', {'class': 'thumbnail','id':galleryimages[i]['imgid'], 'rel':thumbnailNumberPos});
				var img    = new Element('img', {'src':thumbPath+galleryimages[i]['src'], 'rel': " "}).injectInside(el);
				
			}else{
				var el     = new Element('div', {'class': 'thumbnail','id':galleryimages[i]['imgid'], 'rel':thumbnailNumberPos});
				var img    = new Element('img', {'src':thumbPath+galleryimages[i]['src'], 'rel': " ", 'class':' controls', 'title':galleryimages[i]['title']}).injectInside(el);
				
			}totalNumImages++;
		}
		if(filetype == 'flv ' || filetype =='mov' || filetype =='mp4' || filetype =='mp3 ' || filetype =='aac' || filetype =='swf' || filetype =='blip' || filetype =='dailymotion' || filetype =='flickr' || filetype =='googlevideo' || filetype =='metacafe' || filetype =='myspacetv' || filetype =='revver' || filetype =='rutube' || filetype =='seesmic' || filetype =='tudou' || filetype =='youku' || filetype =='youtube' || filetype =='Veoh' || filetype =='viddler' || filetype =='vimeo' || filetype =='12seconds'){	
			var el     = new Element('div', {'class': 'thumbnail','id':galleryimages[i]['imgid'], 'rel':thumbnailNumberPos});
			var img    = new Element('img', {'src':galleryimages[i]['src'], 'class':' controls', 'title':galleryimages[i]['title']}).injectInside(el);
			totalNumMedia++;
		}
		
		if(totalNumMedia>1){
			flashCount = totalNumMedia+" Media Files | ";
		}else if(totalNumMedia==1){
			flashCount = totalNumMedia+" Media File | ";
		}else{
			flashCount = "";
		}
		$('flashNum').set('html',flashCount);
				
		if(totalNumImages>1){
			imagecountHTML = totalNumImages+" Photos | ";
		}else if(totalNumImages==1){
			imagecountHTML = totalNumImages+" Photo | ";
		}else{
			imagecountHTML = "";
		}
		
		$('photoNum').set('html','<span id="numOf">1 of </span>'+imagecountHTML);
		el.injectInside($('thumbnailwrap'));
		thumbnailNumberPos++;
		$(""+i+"").setStyles({'opacity':0});
		var fadeInThumb =  new Fx.Morph(""+i+"", {duration: 100, transition: Fx.Transitions.Expo.easeInOut,wait:true});
		if(i==0){
			fadeInThumb.start({'opacity':1});
		}else{
			fadeInThumb.start({'opacity':.5});
		}
		if(i == endImage){
			thumbnailsviewable = Math.floor($('thumbnails').getCoordinates().width);
			
			if(thumbWidth>thumbnailsviewable){
				var setthumbleft = new Fx.Morph('thumbleft',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
				setthumbleft.start({
					'opacity':0 ,
					'left':-40
				});
				var setthumbright = new Fx.Morph('thumbright',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
				setthumbright.start({
					'opacity':.75 ,
					'right': 0
				});
				//$('testmessage').set('text',thumbWidth+ "is greater than "+thumbnailsviewable);
			}else{
				var setthumbleft = new Fx.Morph('thumbleft',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
				setthumbleft.start({
					'opacity':0 ,
					'left':-40
				});
				var setthumbright = new Fx.Morph('thumbright',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
				setthumbright.start({
					'opacity':0 ,
					'right': -40
				});
				//$('testmessage').set('text',thumbWidth+ "is less than "+thumbnailsviewable);
			}
			if(loadgal=="loadNew"){
				thumbWrap.setStyles({'left':0});
				currentthumbpos = 0;
				loadimage(Number(startImage));
			}
			setThumbClick(gallery);
		}
		var tipName = $$('.controls');
		var toolTips = new Tips(tipName, {
		
			showDelay: 100,    
			hideDelay: 100,   
			offsets: {
				'x': 8,      
				'y': 8    
			},
			title:'title',
			text: null,
			className:'minitooltips',
			fixed: false,
			onShow: function(toolTipElement){
				toolTipElement.fade(1);
			},
			onHide: function(toolTipElement){
				toolTipElement.fade(0);
			}
		});
	}
}
function galleries(){
	var hideThumbPop = new Fx.Morph('thumbnailPopUp', {duration: 50, transition: Fx.Transitions.Expo.easeInOut});
		hideThumbPop.start({
			'opacity':0
		});
	if(playing==true){ slideshow();}
	var opengallerymenu = new Fx.Morph('galleries', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
	var hidefsbox = new Fx.Morph('fsbox', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
	filetype = galleryimages[currentimage]['filetype'];
	galleryheight = $('gallery').getCoordinates().height;
	hiddenGalpas = (galleryheight - $('controls').getCoordinates().height);
	controlHeight = $('controls').getCoordinates().height;
	if(openclose == true){
		if(filetype!="image"){$('imgloader').setStyle('visibility', 'hidden');}
		opengallerymenu.start({
			'bottom': [-galleryheight, controlHeight]
		});
		if(slidesHidden==true){
			showthumbbox();
		}
		openclose = false;
		hidefsbox.start({'opacity':0});
	}else{
		closinggalleries=true;
		opengallerymenu.start({
			'bottom': -(hiddenGalpas-1)
		}).addEvent('onComplete', function(){
			if(closinggalleries==true){
				if(filetype!="image"){
					$('imgloader').setStyle('visibility', 'visible');closinggalleries=false;
				}
			}
		});
		hidefsbox.start({'opacity':1});
		
		openclose = true;
	}
}
function loadimage(e,imgnum){
	
	fsisopen = "closed";
	var showForSale = new Fx.Morph('fsbox', {duration:transitionspeed, transition: Fx.Transitions.Expo.easeInOut });
	showForSale.start({'opacity':0,'bottom':-305});
	//alert(lastimage);
	if(e == startImage){
		$('previous').setStyles({'visibility': 'hidden'});
		prevHidden = true;
	}else{
		$('previous').setStyles({'visibility': 'visible'});
		prevHidden = false;
	}
	if(e == lastimage){
		$('next').setStyles({'visibility': 'hidden'});
		nextHidden = true;
		
	}else{
		$('next').setStyles({'visibility': 'visible'});
		nextHidden = false;
	}
	var gallerypos = $('images');
	var loadingpos = $('loading');
	var overallgalpos = $('gallery');
	$('loading').setStyles({
		'position': 'absolute',
		'opacity': 0,
		'left': (overallgalpos.getCoordinates().width / 2) - (loadingpos.getCoordinates().width / 2),
		'top': (gallerypos.getCoordinates().height / 2) - (loadingpos.getCoordinates().height / 2)
	});
	if(imagesloaded[e] != e){
		imagesloaded[e] = e;
		var fadeoldinfo = new Fx.Morph('infoloader', {duration: transitionspeed,transition: Fx.Transitions.Expo.easeInOut});
		var fadeoldimage = new Fx.Morph('imgloader', {duration: transitionspeed,transition: Fx.Transitions.Expo.easeInOut, onComplete:function(){
			$('imgloader').empty();
			filetype = galleryimages[e]['filetype'];
			if(filetype=='image'){
				new Asset.image(galleryimages[e]['path']+galleryimages[e]['src'],{ onload: function(){
					var resizewrap = new Fx.Morph('imagewrap', {duration: 500, transition: Fx.Transitions.Expo.easeInOut, onComplete: function(){addImage(e);}});
					resizewrap.start({
						'height':galleryimages[e]['height'],
						'width':galleryimages[e]['width'],
						'opacity':1,
						'top':(((gallerypos.getCoordinates().height / 2) - (galleryimages[e]['height'] / 2))),
						'left':(((gallerypos.getCoordinates().width / 2) - (galleryimages[e]['width'] / 2)))
					});
					}
				});
			  }
			  if(filetype == 'flv ' || filetype =='mov' || filetype =='mp4' || filetype =='mp3 ' || filetype =='aac' || filetype =='swf' || filetype =='blip' || filetype =='dailymotion' || filetype =='flickr' || filetype =='googlevideo' || filetype =='metacafe' || filetype =='myspacetv' || filetype =='revver' || filetype =='rutube' || filetype =='seesmic' || filetype =='tudou' || filetype =='youku' || filetype =='youtube' || filetype =='Veoh' || filetype =='viddler' || filetype =='vimeo' || filetype =='12seconds'){
			  	if(playing==true){ slideshow();}
				var resizewrap = new Fx.Morph('imagewrap', {duration: 500, transition: Fx.Transitions.Expo.easeInOut, onComplete: function(){addImage(e);}});
					resizewrap.start({
						'height':galleryimages[e]['height'],
						'width':galleryimages[e]['width'],
						'opacity':1,
						'top':(((gallerypos.getCoordinates().height / 2) - (galleryimages[e]['height'] / 2))),
						'left':(((gallerypos.getCoordinates().width / 2) - (galleryimages[e]['width'] / 2)))
					});
			  }
			}
		});
		var loadingimage = new Fx.Morph('loading',{duration: 200,transition: Fx.Transitions.Expo.easeInOut });
		fadeoldinfo.start({'opacity':0});
		fadeoldimage.start({'opacity':0});
		loadingimage.start({'opacity':1});
	}else{
		var fadeoldimage = new Fx.Morph('imgloader',{duration: transitionspeed,transition: Fx.Transitions.Expo.easeInOut, onComplete:function(){
			$('imgloader').empty();
			filetype = galleryimages[e]['filetype'];
			if(filetype=='image'){
				var resizewrap = new Fx.Morph('imagewrap', {duration: 300, transition: Fx.Transitions.Expo.easeInOut, onComplete: function(){addImage(e);}});
					resizewrap.start({
						'height':galleryimages[e]['height'],
						'width':galleryimages[e]['width'],
						'opacity':1,
						'top':(((gallerypos.getCoordinates().height / 2) - (galleryimages[e]['height'] / 2))),
						'left':(((gallerypos.getCoordinates().width / 2) - (galleryimages[e]['width'] / 2)))
				});
			  }
			  if(filetype == 'flv ' || filetype =='mov' || filetype =='mp4' || filetype =='mp3 ' || filetype =='aac' || filetype =='swf' || filetype =='blip' || filetype =='dailymotion' || filetype =='flickr' || filetype =='googlevideo' || filetype =='metacafe' || filetype =='myspacetv' || filetype =='revver' || filetype =='rutube' || filetype =='seesmic' || filetype =='tudou' || filetype =='youku' || filetype =='youtube' || filetype =='Veoh' || filetype =='viddler' || filetype =='vimeo' || filetype =='12seconds'){
			  	if(playing==true){ slideshow();}
				var resizewrap = new Fx.Morph('imagewrap', {duration: 300, transition: Fx.Transitions.Expo.easeInOut, onComplete: function(){addImage(e);}});
					resizewrap.start({
						'height':galleryimages[e]['height'],
						'width':galleryimages[e]['width'],
						'opacity':1,
						'top':(((gallerypos.getCoordinates().height / 2) - (galleryimages[e]['height'] / 2))),
						'left':(((gallerypos.getCoordinates().width / 2) - (galleryimages[e]['width'] / 2)))
				});
			 }
		   }
		});
				
		fadeoldimage.start({'opacity':0});
		
	}
}
function nextprev(type, theevent){
	if(type == 'previous'){
		var fadeprevious = new Fx.Morph('previous', {duration: 200, transition: Fx.Transitions.Expo.easeInOut});
		if(currentimage != startImage){
			if(theevent=='enter'){
				fadeprevious.start({
					'opacity': 1
				});
			}
		}
		if(theevent=='exit' && currentimage!=startImage){
			fadeprevious.start({
				'opacity': .5
			});		
		}
	}	
	if(type == 'next'){
		var fadenext = new Fx.Morph('next', {duration: 200, transition: Fx.Transitions.Expo.easeInOut});
		if(currentimage != lastimage){
			if(theevent=='enter'){
				fadenext.start({
					'opacity': 1
				});
			}
		}
		if(theevent=='exit' && currentimage!=lastimage){
			fadenext.start({
				'opacity': .5
			});		
		}
	}
}
function creategalleries(){
	var categorylength = maingalleries.length-1;
	//alert(categorylength);
	var createGallery = function(maingalleries, index) {
		var el     		= new Element('div', {'class': 'gallery','id':"gallery"+maingalleries.gallerynum});
		var name   		= new Element('h3').set('html',maingalleries.name).injectInside(el);
		var img    		= new Element('img', {'src':maingalleries.mainthumb+maingalleries.src , 'class': 'galleryimg','title':maingalleries.name , 'rel': maingalleries.description}).injectAfter(name);
		
		el.injectInside($('galleryset'));
		
		if(categorylength == index){
			var customTips = $$('.galleryimg');
 
			var toolTips = new Tips(customTips, {
			
				showDelay: 100,    
				hideDelay: 100,   
				offsets: {
					'x': 0,      
					'y': 125    
				},
				className:'tooltips',
				fixed: true,
				onShow: function(toolTipElement){
					toolTipElement.fade(1);
				},
				onHide: function(toolTipElement){
					toolTipElement.fade(0);
				}
			});
			
			$$('.gallery').addEvent('click', function(e){
				if(playing==true){ slideshow();}
				var id = this.id;
				galleryID = ""+id+"";
				galleries();
				galleryNum = Number(galleryID.slice(7));
				loadThumbs(galleryNum,"loadNew");
				//alert(galleryNum[0]);
				movedamount=0;
			});
		}
	}	
	maingalleries.each(function(maingalleries, index) { createGallery(maingalleries, index); })
	
	var divclear   	= new Element('div', {'class':"clear"});
	divclear.inject($('galleryset'), 'bottom');
		
	/*var gallerSetHeight = $('galleryset').getCoordinates().height;
	var galleryView = $('gallery').getCoordinates().height;
	
	if(gallerSetHeight > galleryView){
		var el = new Element('div', {'id': 'movegalleryset'});
		el.inject($('galleries'), 'bottom');
		
		$('movegalleryset').setStyles({
			'height':10,
			'width':'100%',
			'opacity':1,
			'top':($('galleries').getCoordinates().height)-10,
			'background-color': '#000000'
		});
	}*/
		
}
function movethumbs(direction){
	var thumbnailMargin = $('thumbnailwrap').getFirst().getStyle('margin-left').toInt();
	var moveamount=$('thumbnails').getCoordinates().width;
	var thumbBoxWidth = setThumbWidth*(totalNumImages);
	var movethumbbox = new Fx.Morph('thumbnailwrap', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
	thisminusthat =	thumbBoxWidth-moveamount
	//$('testmessage').set('text',"moveamount="+moveamount+", total number of thumbs="+thumbnailNumberPos);
	if(direction=="back"){
		if(!moving){
			moving=true;
			if(currentthumbpos!=0){
				move=(currentthumbpos+moveamount);
				movethumbbox.start({ left: [currentthumbpos, move]}).addEvent('onComplete',function(){ moving=false; } );
				currentthumbpos+=moveamount;
				movedamount-=moveamount;
			}
		}
	}
	if(direction=="more"){
		if(!moving){
			moving=true;
			move=(currentthumbpos-moveamount);
			var movethumbs = new Fx.Morph('thumbgall', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
			movethumbbox.start({ left: [currentthumbpos, move]}).addEvent('onComplete',function(){ moving=false; } );
			currentthumbpos-=moveamount;
			movedamount+=moveamount;
		}
	}
	thumbnailsviewable = $('thumbnails').getCoordinates().width;
	//alert(movedamount)
	if(currentthumbpos==0){
			var setthumbleft = new Fx.Morph('thumbleft',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
			setthumbleft.start({
				'opacity':0 ,
				'left':-40
			});
			var setthumbright = new Fx.Morph('thumbright',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
			setthumbright.start({
				'opacity':.75,
				'right': 0 
			});
	}else if(movedamount<thumbBoxWidth-moveamount){
			var setthumbleft = new Fx.Morph('thumbleft',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
			setthumbleft.start({
				'opacity':.75,
				'left': 0 
			});
			var setthumbright = new Fx.Morph('thumbright',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
			setthumbright.start({
				'opacity':.75,
				'right': 0 
			});
	}else{
			var setthumbleft = new Fx.Morph('thumbleft',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
			setthumbleft.start({
				'opacity':.75 ,
				'left':0
			});
			var setthumbright = new Fx.Morph('thumbright',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
			setthumbright.start({
				'opacity':0 ,
				'right':-40
			});
	}
}
function smallMessage(type, message,height){
	var showMessage = new Fx.Morph('smallmessage', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
	if(type=="show"){
		$('smallmessage').setStyles({
			'opacity':0,
			'bottom': -80,
			'left':(($('images').getCoordinates().width / 2) - (($('smallmessage').getCoordinates().width / 2)))
		});
		$('smallmessage').set('text',message);
		showMessage.start({
			'bottom': (-80)+height,
			'opacity': 1
		});
	}
	if(type=="hide"){
		showMessage.start({
			'bottom': -80,
			'opacity': 0
		});
	}
}
function showInfo(height){
	var showInfoBar = new Fx.Morph('imageinfo', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
	if(showInfoType=="show"){
		
		showInfoType="hide";
		$('imageinfo').setStyles({
			'background-color':'#000',
			'bottom':-300,
			'width': '100%',
			'opacity':0
		});
		showInfoBar.start({
			'bottom': (-300)+height,
			'opacity': .9
		});
		
	}
	else if(showInfoType=="hide"){
	
		showInfoType="show";
		showInfoBar.start({
			'bottom': -300,
			'opacity': 0
		});
		
	}
}
function loadLarge(){
	largeId = galleryimages[currentimage]['imgid'];
	var fadenewlrgimg = new Fx.Morph('lrgloader', {duration:transitionspeed});
	var newHTML = "<img src='"+galleryimages[largeId]['lrgpath']+galleryimages[largeId]['src']+"' id='imgsrc' title='"+galleryimages[largeId]['title']+"' />";
	$('lrgloader').set('html',newHTML);
	fadenewlrgimg.start({'opacity':.99999});	
	var fadeclosebtn = new Fx.Morph('closebtn', {duration: 500, transition: Fx.Transitions.Expo.easeInOut});
	fadeclosebtn.start({'opacity':1});
}
function slideshow(){
	if(playing==false){
		$('slideshow').set('html','<img src="'+designPath+'pause.png" alt="'+pauseText+'" title="'+pauseText+'" class="controls" border="0" align="absmiddle" />');
		playing=true;
		pp="play"
		var tipName = $$('.controls');
		var toolTips = new Tips(tipName, {
		
			showDelay: 100,    
			hideDelay: 100,   
			offsets: {
				'x': 8,      
				'y': 8    
			},
			title:'title',
			text: null,
			className:'minitooltips',
			fixed: false,
			onShow: function(toolTipElement){
				toolTipElement.fade(1);
			},
			onHide: function(toolTipElement){
				toolTipElement.fade(0);
			}
		});
		var unhighlight = new Fx.Morph(""+currentimage+"", {duration: 500, transition: Fx.Transitions.Expo.easeInOut});
		unhighlight.start({
			'border-color': '#FFF',
			'background-color': '#FFF',
				'opacity':.5
		});
		if(currentimage!=lastimage){
			nextImage = currentimage+1;
			thumbinview = $('thumbnails').getCoordinates().width;
			maxThumbsVisible = Math.floor(thumbinview/setThumbWidth);
			thumbsMod = (nextImage+1)%maxThumbsVisible;
			//$('testmessage').set('text',thumbsMod);
			if((nextImage+1)>=maxThumbsVisible && thumbsMod==1 || maxThumbsVisible==1){
				movethumbs("more");
			}
		}else{
			var movethumbbox = new Fx.Morph('thumbnailwrap', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
			movethumbbox.start({ left: [currentthumbpos, 0]}).addEvent('onComplete',function(){ moving=false; } );
			currentthumbpos=0;
			nextImage = startImage;
			if(currentthumbpos==0){
					var setthumbleft = new Fx.Morph('thumbleft',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
					setthumbleft.start({
						'opacity':0 ,
						'left':-40
					});
					var setthumbright = new Fx.Morph('thumbright',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
					setthumbright.start({
						'opacity':.75,
						'right': 0 
					});
			}else if(movedamount<thumbBoxWidth-moveamount){
					var setthumbleft = new Fx.Morph('thumbleft',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
					setthumbleft.start({
						'opacity':.75,
						'left': 0 
					});
					var setthumbright = new Fx.Morph('thumbright',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
					setthumbright.start({
						'opacity':.75,
						'right': 0 
					});
			}else{
					var setthumbleft = new Fx.Morph('thumbleft',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
					setthumbleft.start({
						'opacity':.75 ,
						'left':0
					});
					var setthumbright = new Fx.Morph('thumbright',{duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
					setthumbright.start({
						'opacity':0 ,
						'right':-40
					});
			}
		}
			imagenumber = $(""+nextImage+"").get('rel');	
			$('numOf').set('text', imagenumber+' of ').inject('photoNum', 'top');
			loadimage(nextImage);
			
	}else{
		slideShow = $clear(timer);
		$('slideshow').set('html','<img src="'+designPath+'play.png" alt="'+playText+'" title="'+playText+'" class="controls" border="0" align="absmiddle" />');
		playing=false;
		pp="pause"
		var tipName = $$('.controls');
		var toolTips = new Tips(tipName, {
		
			showDelay: 100,    
			hideDelay: 100,   
			offsets: {
				'x': 8,      
				'y': 8    
			},
			title:'title',
			text: null,
			className:'minitooltips',
			fixed: false,
			onShow: function(toolTipElement){
				toolTipElement.fade(1);
			},
			onHide: function(toolTipElement){
				toolTipElement.fade(0);
			}
		});
	}
	var slideShow = function() { 
		if(currentimage!=lastimage){
			nextImage = currentimage+1;
			thumbinview = $('thumbnails').getCoordinates().width;
			maxThumbsVisible = Math.floor(thumbinview/setThumbWidth);
			thumbsMod = (nextImage+1)%maxThumbsVisible;
			//$('testmessage').set('text',thumbsMod);
			if((nextImage+1)>=maxThumbsVisible && thumbsMod==1 || maxThumbsVisible==1){
				movethumbs("more");
			}
		}
		if(currentimage != lastimage&&pp=="play"){
			//slideShow = $clear(timer);
			var unhighlight = new Fx.Morph(""+currentimage+"", {duration: 500, transition: Fx.Transitions.Expo.easeInOut});
			unhighlight.start({
				'border-color': '#FFF',
				'background-color': '#FFF',
				'opacity':.5
			});
			imagenumber = $(""+nextImage+"").get('rel');	
			$('numOf').set('text', imagenumber+' of ').inject('photoNum', 'top');
			loadimage(nextImage);
			//timer = slideShow.periodical(6000);
		}
		else{
			slideShow = $clear(timer);
			$('slideshow').set('html','<img src="'+designPath+'play.png" alt="'+playText+'" title="'+playText+'" class="controls" border="0" align="absmiddle" />');
			playing=false;
			pp="pause"
			var tipName = $$('.controls');
			var toolTips = new Tips(tipName, {
			
				showDelay: 100,    
				hideDelay: 100,   
				offsets: {
					'x': 8,      
					'y': 8    
				},
				title:'title',
				text: null,
				className:'minitooltips',
				fixed: false,
				onShow: function(toolTipElement){
					toolTipElement.fade(1);
				},
				onHide: function(toolTipElement){
					toolTipElement.fade(0);
				}
			});
		}
	}
	timer = slideShow.periodical(slideshowtime);
}
function showthumbbox(){
	if(openclose!=false){
		minusThumb = $('thumbbox').getCoordinates().height;
		minusControls = $('controls').getCoordinates().height;
		var galleryShrink = new Fx.Morph('gallery', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
		var thumbnailHide = new Fx.Morph('thumbbox', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
		if(showThumbs=="show"){
			showThumbs="hide";
			thumbnailHide.start({
				'opacity': 1
			});
			galleryShrink.start({
				'height': galleryHeight
			});
			
			slidesHidden = false;
		}
		else if(showThumbs=="hide"){
			showThumbs="show";
			thumbnailHide.start({
				'opacity': 0
			});
			galleryShrink.start({
				'height': (galleryHeight)-(minusThumb)
			});
			
			slidesHidden = true;
			
		}
	}
}
var resizeTimeout;
prepareResize = function(){ 
	$clear(resizeTimeout); 
	resizeTimeout = realResize.delay(300);
} 
function createBackDrop(){
	if(largeHtmlIsCreated==null||largeHtmlIsCreated==""){
			var largeimageHTML     	= new Element('div', {'id':"largeimage"}).injectInside(document.body);
			var lrgwrapHTML     	= new Element('div', {'id':"lrgwrap",'class':"close"}).injectInside('largeimage');
			var closeBtnHTML     	= new Element('div', {'id':"closebtn",'class':"close"}).injectInside('largeimage');
			var lrgloaderHTML     	= new Element('div', {'id':"lrgloader"}).injectInside('lrgwrap');
			var largeimageHTML     	= new Element('div', {'id':"backdrop",'class':"close"}).injectInside(document.body);
			$('largeimage').set('opacity',0);
			$('closebtn').set('opacity',0);
			$('largeimage').setStyles({
				'height':0,
				'width':0,
				'opacity':0,
				'top':($('gallery').getCoordinates().height )-50,
				'left': (window.getWidth() / 2)
			});
			$('backdrop').set('opacity',0);
			$('backdrop').setStyles({
				'height':0,
				'width':0,
				'opacity':0,
				'top':($('gallery').getCoordinates().height / 2)-50,
				'left': (window.getWidth() / 2)
			});
			$$('.close').addEvent('click', 
				function(){
					largeIsOpen = false;
					$clear(resizeTimeout);
					var fadeclosebtn = new Fx.Morph('closebtn', {duration: 500, transition: Fx.Transitions.Expo.easeInOut,onComplete:function(){
							$('lrgloader').empty();
							var resizelrgWrap = new Fx.Morph('lrgwrap', {duration: 500, transition: Fx.Transitions.Expo.easeInOut});
							var resizelarge = new Fx.Morph('largeimage', {duration: 500, transition: Fx.Transitions.Expo.easeInOut});
							var resizebackdrop = new Fx.Morph('backdrop', {duration: 1000, transition: Fx.Transitions.Expo.easeInOut,onComplete:function(){
								$('backdrop').setStyles({'height':0,
									'width':0,
									'opacity':0,
									'top':($('imagewrap').getCoordinates().height / 2)+50,
									'left': (window.getWidth() / 2)
								});
								
							}});
							resizelrgWrap.start({
								'height':0,
								'width':0,
								'opacity':0
							});
							resizelarge.start({
								'height':0,
								'width':0,
								'opacity':0,
								'top':($('imagewrap').getCoordinates().height / 2)+50,
								'left': (window.getWidth() / 2) 
							});
							resizebackdrop.start({
								'opacity':0
								
							});	
						}
					});
					fadeclosebtn.start({
						'opacity':0
					});
				}
			);
			largeHtmlIsCreated = true;
		}
		if(galleryimages[currentimage]['lrgheight']&&galleryimages[currentimage]['lrgwidth']){
				var loadingimage = new Fx.Morph('loading',{duration: 200,transition: Fx.Transitions.Expo.easeInOut });
				loadingimage.start({'opacity':1});
				$('backdrop').setStyles(
					{
						'opacity':0,
						'height':window.getScrollHeight(),
						'width':'100%',
						'top':0,
						'left':0 
					}
				);
				
				var resizebackdrop = new Fx.Morph('backdrop', {duration: 500, transition: Fx.Transitions.Expo.easeInOut,onComplete:function(){
					largeIsOpen = true;
					new Asset.image(galleryimages[currentimage]['lrgpath']+galleryimages[currentimage]['src'],{ onload: function(){
						var loadingimage = new Fx.Morph('loading',{duration: 200,transition: Fx.Transitions.Expo.easeInOut });
						var resizelrgWrap = new Fx.Morph('lrgwrap', {duration: 500, transition: Fx.Transitions.Expo.easeInOut});
						var resizelarge = new Fx.Morph('largeimage', {duration: 500, transition: Fx.Transitions.Expo.easeInOut});
						loadingimage.start({'opacity':0});
						resizelrgWrap.start({
							'width':galleryimages[currentimage]['lrgwidth'],
							'height':galleryimages[currentimage]['lrgheight'],
							'opacity':1
						});
						resizelarge.start({
							'width':galleryimages[currentimage]['lrgwidth'],
							'height':galleryimages[currentimage]['lrgheight'],
							'opacity':1,
							'top':window.getScroll().y+20,
							'left': ((window.getWidth() / 2) - (galleryimages[currentimage]['lrgwidth'] / 2))
						}).addEvent('onComplete',function(){
							$('lrgloader').empty();
							var setLrgwrapper = new Fx.Morph('lrgloader', {duration: 500, transition: Fx.Transitions.Expo.easeInOut});
							setLrgwrapper.start({
								'opacity':0,
								'width':galleryimages[currentimage]['lrgwidth'],
								'height':galleryimages[currentimage]['lrgheight'],
								'top':((($('largeimage').getCoordinates().height / 2) - (galleryimages[currentimage]['lrgheight'] / 2))),
								'left':((($('largeimage').getCoordinates().width / 2) - (galleryimages[currentimage]['lrgwidth'] / 2)))
							}).addEvent('onComplete',function(){loadLarge();});
							
						});
					}
				});
				
				
					}
				});
				resizebackdrop.start({'opacity':.5});
				
				window.addEvent('resize',prepareResize); 
				 
				realResize = function(){ 
				   
				   var resizebackdrop = new Fx.Morph('backdrop', {duration: 100, transition: Fx.Transitions.Expo.easeInOut,onComplete:function(){}});
				   var resizelarge = new Fx.Morph('largeimage', {duration: 100, transition: Fx.Transitions.Expo.easeInOut});
				   resizebackdrop.start({
						'opacity':.5,
						'height':window.getScrollHeight()
					});
					resizelarge.start({
						'top':window.getScroll().y+20,
						'left': ((window.getWidth() / 2) - (galleryimages[currentimage]['lrgwidth'] / 2))
					})
				} 
				$(window.document).addEvent('keydown',function(e){
					 if(e.key == 'esc'&& largeIsOpen==true ){ 
					 	largeIsOpen = false;
					 	$clear(resizeTimeout);
						var fadeclosebtn = new Fx.Morph('closebtn', {duration: 500, transition: Fx.Transitions.Expo.easeInOut,onComplete:function(){
								$('lrgloader').empty();
								var resizelrgWrap = new Fx.Morph('lrgwrap', {duration: 500, transition: Fx.Transitions.Expo.easeInOut});
								var resizelarge = new Fx.Morph('largeimage', {duration: 500, transition: Fx.Transitions.Expo.easeInOut});
								var resizebackdrop = new Fx.Morph('backdrop', {duration: 1000, transition: Fx.Transitions.Expo.easeInOut,onComplete:function(){
									$('backdrop').setStyles({'height':0,
										'width':0,
										'opacity':0,
										'top':($('imagewrap').getCoordinates().height / 2)+50,
										'left': (window.getWidth() / 2)
									});
								}});
								resizelrgWrap.start({
									'height':0,
									'width':0,
									'opacity':0
								});
								resizelarge.start({
									'height':0,
									'width':0,
									'opacity':0,
									'top':($('imagewrap').getCoordinates().height / 2)+50,
									'left': (window.getWidth() / 2) 
								});
								resizebackdrop.start({
									'opacity':0
									
								});	
							}
						});
						fadeclosebtn.start({
							'opacity':0
						});
					 }
				});
			}
}

window.addEvent('domready', function() {
	$('slideshow').addEvent('click', function(){slideshow();});
	$('showthumbbox').addEvent('click', function(){showthumbbox();});
	$('showinfo').addEvent('click', function(){showInfo(135);});
	$('opengallery').addEvent('click', function(){galleries()});
	$('previous').addEvent('mouseenter', function(){nextprev('previous', 'enter')
		var hideThumbPop = new Fx.Morph('thumbnailPopUp', {duration: 50, transition: Fx.Transitions.Expo.easeInOut});
		hideThumbPop.start({
			'opacity':0
		});
	});
	$('images').addEvent('mouseenter', function(){nextprev('previous', 'exit');nextprev('next', 'exit');
		var hideThumbPop = new Fx.Morph('thumbnailPopUp', {duration: 50, transition: Fx.Transitions.Expo.easeInOut});
		hideThumbPop.start({
			'opacity':0
		});
		var fadeThumbLeft = new Fx.Morph('thumbleft', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
		fadeThumbLeft.start({
			'opacity': .75
		});
		var fadeThumbRight = new Fx.Morph('thumbright', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
		fadeThumbRight.start({
			'opacity': .75
		});
	});
	$('controls').addEvent('mouseenter', function(){nextprev('previous', 'exit');nextprev('next', 'exit');
		var hideThumbPop = new Fx.Morph('thumbnailPopUp', {duration: 50, transition: Fx.Transitions.Expo.easeInOut});
		hideThumbPop.start({
			'opacity':0
		});
	});
	$('previous').addEvent('mouseleave', function(){nextprev('previous', 'exit');nextprev('next', 'exit');});
	
	$('next').addEvent('mouseenter', function(){nextprev('next', 'enter');nextprev('previous', 'exit');
		var hideThumbPop = new Fx.Morph('thumbnailPopUp', {duration: 50, transition: Fx.Transitions.Expo.easeInOut});
		hideThumbPop.start({
			'opacity':0
		});
	});
	$('next').addEvent('mouseleave', function(){nextprev('next', 'exit');nextprev('previous', 'exit');});
	$('thumbleft').addEvent('mouseleave', function(){ 
		var fadeThumbLeft = new Fx.Morph('thumbleft', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
		fadeThumbLeft.start({
			'opacity': .75
		});
		var fadeThumbRight = new Fx.Morph('thumbright', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
		fadeThumbRight.start({
			'opacity': .75
		});
	});
	$('thumbleft').addEvent('mouseenter', function(){ 
		var fadeThumbLeft = new Fx.Morph('thumbleft', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
		fadeThumbLeft.start({
			'opacity': 1
		});
		var hideThumbPop = new Fx.Morph('thumbnailPopUp', {duration: 50, transition: Fx.Transitions.Expo.easeInOut});
		hideThumbPop.start({
			'opacity':0
		});
		var fadeThumbRight = new Fx.Morph('thumbright', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
		fadeThumbRight.start({
			'opacity': .75
		});
	});
	$('thumbright').addEvent('mouseleave', function(){  
		var fadeThumbRight = new Fx.Morph('thumbright', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
		fadeThumbRight.start({
			'opacity': .75
		});
	});
	$('thumbright').addEvent('mouseenter', function(){  
		var fadeThumbRight = new Fx.Morph('thumbright', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
		fadeThumbRight.start({
			'opacity': 1
		});
		var hideThumbPop = new Fx.Morph('thumbnailPopUp', {duration: 50, transition: Fx.Transitions.Expo.easeInOut});
		hideThumbPop.start({
			'opacity':0
		});
		var fadeThumbLeft = new Fx.Morph('thumbleft', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
		fadeThumbLeft.start({
			'opacity': .75
		});
		
	});
	$('thumbleft').addEvent('click', function(){ movethumbs("back") });
	$('thumbright').addEvent('click', function(){  movethumbs("more")  });
	$('thumbnailwrap').addEvent('mouseleave', function(){
		var hideThumbPop = new Fx.Morph('thumbnailPopUp', {duration: 50, transition: Fx.Transitions.Expo.easeInOut});
		hideThumbPop.start({
			'opacity':0
		});
	});
	var loadpause = new Asset.image(designPath+'pause.png');
	galleryHeight = $('gallery').getCoordinates().height;
	$('imgloader').addEvent('click', function(){ createBackDrop(); });
	$('imgloader').addEvent('mouseenter', 
		function(){
			if(galleryimages[currentimage]['lrgheight']&&galleryimages[currentimage]['lrgwidth']){
				smallMessage("show","Click Image to Enlarge", 25);
			}
		}
	);
	$('imgloader').addEvent('mouseleave', 
		function(){
			if(galleryimages[currentimage]['lrgheight']&&galleryimages[currentimage]['lrgwidth']){
				smallMessage("hide");
			}
			if(currentimage!=0){
				var fadeThumbRight = new Fx.Morph('thumbright', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
				fadeThumbRight.start({
					'opacity': .75
				});
				var hideThumbPop = new Fx.Morph('thumbnailPopUp', {duration: 50, transition: Fx.Transitions.Expo.easeInOut});
				hideThumbPop.start({
					'opacity':0
				});
				var fadeThumbLeft = new Fx.Morph('thumbleft', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
				fadeThumbLeft.start({
					'opacity': .75
				});
			}
			if(currentimage!=lastimage){
				var fadeThumbLeft = new Fx.Morph('thumbleft', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
				fadeThumbLeft.start({
					'opacity': .75
				});
				var hideThumbPop = new Fx.Morph('thumbnailPopUp', {duration: 50, transition: Fx.Transitions.Expo.easeInOut});
				hideThumbPop.start({
					'opacity':0
				});
				var fadeThumbRight = new Fx.Morph('thumbright', {duration: transitionspeed, transition: Fx.Transitions.Expo.easeInOut});
				fadeThumbRight.start({
					'opacity': .75
				});
			}
		}
	);
	
	$('fsbox').setStyles({'left':($('gallery').getCoordinates().width / 2)-($('fsbox').getCoordinates().width / 2)});
	$('previous').set('opacity',.5);
	$('next').set('opacity',.5);
	creategalleries();
	loadThumbs(0,'loadNew');
	$('imagewrap').set('opacity',0);
	thumbSizing = $('1').getCoordinates().width	
	thumbRightMargin = $('1').getStyle('margin-right').toInt()	
	thumbLeftMargin = $('1').getStyle('margin-left').toInt()	
	//$('testmessage').set('text',thumbSizing+thumbRightMargin+thumbLeftMargin);	
	setThumbWidth = Number(thumbSizing+thumbRightMargin+thumbLeftMargin);
	thumbWidth = Number(setThumbWidth);
	var tipName = $$('.controls');
 
	var toolTips = new Tips(tipName, {
	
		showDelay: 100,    
		hideDelay: 100,   
		offsets: {
			'x': 8,      
			'y': 8    
		},
		title:'title',
		text: null,
		className:'minitooltips',
		fixed: false,
		onShow: function(toolTipElement){
			toolTipElement.fade(1);
		},
		onHide: function(toolTipElement){
			toolTipElement.fade(0);
		}
	});
	$(window.document).addEvent('keydown',function(e){
		 if(e.key == 'space' && playing==true){ slideshow();}
		 if(e.key == 'esc' && playing==true){ slideshow();}
		 if(e.key == 'esc' && openclose==false){ galleries();}
	});
});