
	
	
function loadImage (imageId) {
	
	if(gallery[gallKey].images[imageId].height>maxImageHeight){
		height=maxImageHeight
		width=gallery[gallKey].images[imageId].width*(height/gallery[gallKey].images[imageId].height)
		}
	else{
		height=gallery[gallKey].images[imageId].height
		width=gallery[gallKey].images[imageId].width
	}
	
	$('title').innerHTML ="Photo Gallery - "+gallery[gallKey].gallName+" - "+gallery[gallKey].images[imageId].title+"";
	

	//$('big_picture').setStyle('background-image', 'url(\"'+gallery[gallKey].images[imageId].fullpath+'\")');
	
	
	$('big_picture').set('src', gallery[gallKey].images[imageId].fullpath);	
	$('big_picture').set('class', 'image_' + imageId);
	$('big_picture').setStyle('height',  height+'px');
	$('big_picture').setStyle('width',  width+'px');


	$('iptc_info').innerHTML = "Title :"+ gallery[gallKey].images[imageId].title+"<br/>Description :"+gallery[gallKey].images[imageId].caption+"<br/>Date Taken :"+ gallery[gallKey].images[imageId].dateTime+"<br/>Camera :"+gallery[gallKey].images[imageId].camera+"<br/>ISO :"+ gallery[gallKey].images[imageId].iso+"<br/>Shutter Speed :"+gallery[gallKey].images[imageId].shutterSpeed+"<br/>Apeture :"+gallery[gallKey].images[imageId].aperture;
	$('iptc_info').fade('hide');
	$('iptc_info').setStyle('width', width+'px');
	
		$('link_info').innerHTML = "Cut and paste the Link to share the Image : www.andymain.co.uk/index.php?pg=gall&permId="+gallery[gallKey].images[imageId].permId;
	$('link_info').fade('hide');
	$('link_info').setStyle('width', width+'px');
	
	$('cart').fade(.2);	

									
		
	
	$('display_picture_img').setStyle('margin-top',  -height/2+'px');
	$('display_picture_img').setStyle('margin-left',  -width/2+'px');
	$('display_picture_img').setStyle('height',  height+33+'px');
	$('display_picture_img').setStyle('width',  width+10+'px');
	
	$('big_picture').fade(.999999);
	$('display_picture_container').fade(1);	

var  number_of_pictures=gallery[gallKey].images.length-1;

					if(imageId==0) {
						$('prev').set('class', 'deactivated');	
						$('next').erase('class');	
					} else if(imageId==number_of_pictures) {
						$('prev').erase('class');	
						$('next').set('class', 'deactivated');	
					} else {
						$('prev').set('class', 'activated');	
						$('next').erase('class');
					}
					
					
				
					//if(Browser.Engine.trident4) { $('left').tween('margin-left', '251px'); } else { $('left').tween('margin-left', '502px');}		
}


function galleryIndex() {
	
	
	$('title').innerHTML ="Photo Gallery";
	$('inside').erase('style');
	$('inside').innerHTML = "";
		var no_of_gallerys = gallery.length;
		
		
for (i=0;i<no_of_gallerys;i++){
	
	
			var new_image_cont = new Element('div', {
			'id': 'image_cont' + i,
			'class':'image_cont'
			});
			new_image_cont.appendText(gallery[i].gallName);
			
						if(gallery[i].images[0].height>gallery[i].images[0].width){
		height=maxThumbHeight
		width=gallery[i].images[0].width*(height/gallery[i].images[0].height)
		}
			if(gallery[i].images[0].height<gallery[i].images[0].width){
		width=maxThumbWidth
		height=gallery[i].images[0].height*(width/gallery[i].images[0].width)
		}
			
		var new_image = new Element('img', {
			'src': ''+ gallery[i].images[0].fullpath,
			'id': '' + i,
			'height':''+height,
			'width':''+width,
				'events': {
									'domready': function(){if(!Browser.Engine.trident4 && !Browser.Engine.trident5) {$(this).fade('hide');}},
	'load': function(){if(!Browser.Engine.trident4 && !Browser.Engine.trident5) {$(this).fade(.999999);}},
			'click': function(){ 
								gallKey = this.id; 
								$('inside').innerHTML = "";
								show_pictures(gallKey);
								}
				}
										});
		
				
		
		new_image_cont.inject($('inside'));
		new_image.inject($('image_cont' + i));

	}
	
	$('up').set('class', 'deactivated');	
		$('down').set('class', 'deactivated');
	}
	
	
function show_pictures (gallKey) {
	  
	var  number_of_pictures=gallery[gallKey].images.length;
	for(pic=0;pic<number_of_pictures;pic++) {
		
		
		$('title').innerHTML ="Photo Gallery - "+gallery[gallKey].gallName;
		
			var new_image_cont = new Element('div', {
			'id': 'image_cont' + pic,
			'class':'image_cont'
			});
			
			
				if(gallery[gallKey].images[pic].height>gallery[gallKey].images[pic].width){
		height=maxThumbHeight
		width=gallery[gallKey].images[pic].width*(height/gallery[gallKey].images[pic].height)
		}
			if(gallery[gallKey].images[pic].height<gallery[gallKey].images[pic].width){
		width=maxThumbWidth
		height=gallery[gallKey].images[pic].height*(width/gallery[gallKey].images[pic].width)
		}
			
			
		var new_image = new Element('img', {
			'src': ''+ gallery[gallKey].images[pic].fullpath,
			'id': '' + pic,
			'height':''+height,
			'width':''+width,
			'events': {
				'domready': function(){if(!Browser.Engine.trident4 && !Browser.Engine.trident5) {$(this).fade('hide');}},
	'load': function(){if(!Browser.Engine.trident4 && !Browser.Engine.trident5) {$(this).fade(.999999);}},
			'click': function(){
			loadImage(this.id);
								}}
						});
		
		new_image_cont.inject($('inside'));
		new_image.inject($('image_cont' + pic));
	}
vert_controls(gallKey);
}



function vert_controls(gallKey){
	
	if(gallKey == "index"){
	number_of_pictures=gallery.length;
	}else{
	number_of_pictures=gallery[gallKey].images.length;
}
		window.vertical_moves = 0;
	var rows = Math.ceil(number_of_pictures/5); 
	
	//alert("gallkey "+gallKey+" number of pics "+number_of_pictures+" rows "+rows +" vertical moves "+vertical_moves );
	
	if(rows>5) {
		$('up').removeEvents('click');
	$('up').addEvent('click', function(event){
			if(!$('up').hasClass('deactivated')) {
				//alert("gallkey "+gallKey+" number of pics "+number_of_pictures+" rows "+rows +" vertical moves "+vertical_moves );
				vertical_moves--;
				$('down').erase('class');
				$('inside').tween('margin-top', '-'+ (138 * vertical_moves) +'px');
				if (vertical_moves==0) {
					$('up').set('class', 'deactivated');	
				}
			}
		});
		
		$('down').removeEvents('click');
		$('down').addEvent('click', function(event){
			if(!$('down').hasClass('deactivated')) {
				//alert("gallkey "+gallKey+" number of pics "+number_of_pictures+" rows "+rows +" vertical moves "+vertical_moves );
				vertical_moves++;
				$('up').erase('class');	
				$('inside').tween('margin-top', '-'+ (137 * vertical_moves) +'px');
				if(vertical_moves == (rows-5)) {
					$('down').set('class', 'deactivated');	
				}
			}
		});
		
		$('down').erase('class');
		
	} else {
		$('up').set('class', 'deactivated');	
		$('down').set('class', 'deactivated');	
	}
	}


window.addEvent('domready', function() {		
									 
$('display_picture_container').innerHTML ="<div id=\"display_picture\"></div><div id=\"display_picture_img\"><img id=\"big_picture\"/><div id=\"iptc_info\"></div><div id=\"link_info\"></div><div id=\"close\"><img src=\"./gallery/closelabel.gif\"/></div><div id=\"prev\"></div> <div id=\"pic_controls\"><div id=\"info\"></div><div id=\"cart\"></div><div id=\"link\"></div></div><div id=\"next\"></div></div>";
   
   if(typeof( window[ 'imageId' ] ) != "undefined" ){
	window.number_of_pictures=gallery[gallKey].images.length-1;
	show_pictures(gallKey);
	loadImage(imageId);
	}else if(typeof( window[ 'gallKey' ] ) == "undefined" || gallKey=="index" ){
	window.number_of_pictures=gallery.length-1;
	galleryIndex();
	$('display_picture_container').fade('hide');
	}else{			
	window.number_of_pictures=gallery[gallKey].images.length-1;
	show_pictures(gallKey);
	$('display_picture_container').fade('hide');
		}
		

	
	var current_id = 1;
	
	$('prev').addEvent('click', function(){
		if(!$('prev').hasClass('deactivated')) {
			current_id = $('big_picture').get('class').replace('image_', '');
			current_id--;
			
			loadImage (current_id);
						
			if(current_id==0) { $('prev').set('class', 'deactivated'); }
			if(current_id==(number_of_pictures-1)) { $('next').erase('class');  }
		} 
	});
	
	$('next').addEvent('click', function(){
		if(!$('next').hasClass('deactivated')) {
			
			current_id = $('big_picture').get('class').replace('image_', '');
			current_id++;
			
	loadImage (current_id);		
	
			if(current_id==1) { $('prev').erase('class'); }
			if(current_id==number_of_pictures) { $('next').set('class', 'deactivated'); }
		} 
	});
	
	$('close').addEvent('click', function(){
		
		$('big_picture').fade(0);
		$('display_picture_container').fade(0);
		
		$('title').innerHTML ="Photo Gallery - "+gallery[gallKey].gallName;
		
	//	if(Browser.Engine.trident4) { $('up').setStyle('margin-left', '251px'); } else { $('up').setStyle('margin-left', '502px'); }
		
		//$('left').tween('margin-left', '7px');
		//$('up').tween('margin-left', '7px');
	});
	
	$('title').addEvent('click', function(){
		galleryIndex();	
	$('display_picture_container').fade('hide');
	});
	
		$('info').addEvent('click', function(){
									 if(!$('iptc_info').hasClass('activated')) {
									 $('iptc_info').fade(.80);
									 $('iptc_info').set('class', 'activated'); 
									 
									 }else{
									 $('iptc_info').erase('class');
									 $('iptc_info').fade('hide');
									 }
									 });
		
			$('link').addEvent('click', function(){
									 if(!$('link_info').hasClass('activated')) {
									 $('link_info').fade(.80);
									 $('link_info').set('class', 'activated'); 
									 
									 }else{
									 $('link_info').erase('class');
									 $('link_info').fade('hide');
									 }
									 });
		 
});
