ob = function(el){
	return document.getElementById(el); 
}
showIndGallery = function(){ 
        galleryShowInd = true; 
	buildGalleryTemplate();
        getGalleryParams(); 
	galleryParams.lang.onclick=function(){ switchLanguage(lang, imgs[currentNum]); }
	galleryParams.prevNav.onclick=function(){ if(currentNum > 0){ switchGalleryImg('prev'); } }
	galleryParams.allNav.onclick=function(){ showAllGallery();  }
	galleryParams.nextNav.onclick=function(){ if(currentNum < imgs.length){ switchGalleryImg('next'); } }
	switchGalleryImg(false, imgs, galleryParams);
}
switchLanguage = function(lang,img){
                var img = img; 
                galleryParams.editionB.obj.innerHTML = eval('galleryParams.editionB.label_'+lang);
                galleryParams.framedB.obj.innerHTML = eval('galleryParams.framedB.label_'+lang);
                galleryParams.matB.obj.innerHTML = eval('galleryParams.matB.label_'+lang);

                galleryParams.printB.obj.innerHTML = eval('galleryParams.printB.label_'+lang);
                galleryParams.description.innerHTML = eval('img.body_'+lang);    
		galleryParams.footerQuote.obj.innerHTML = eval('galleryParams.footerQuote.label_'+lang);
		galleryParams.footerCaption.obj.innerHTML = eval('galleryParams.footerCaption.label_'+lang);
		galleryParams.footerOr.obj.innerHTML = eval('galleryParams.footerOr.label_'+lang);
		
		/* Gallery Right Link */
		var thisImgNum = img.number; 
		if(typeof galleryRightLink == "undefined"){
                galleryRightLink = document.createElement('div'); 
                galleryRightLink.innerHTML = 'I want this photo &rsaquo;&rsaquo;';
                galleryRightLink.className = 'galleryRightInterestedLink';
//		alert(galleryParams.galleryRight.childNodes.length); 
                galleryParams.galleryRight.insertBefore(galleryRightLink, galleryParams.galleryRight.childNodes[3]); 
                }
                /*
                if(typeof galleryRightEmailtofriend == "undefined"){
                galleryRightEmailtofriend = document.createElement('div'); 
                galleryRightEmailtofriend.innerHTML = 'Email to a friend &rsaquo;&rsaquo;';
                galleryRightEmailtofriend.className = 'galleryRightInterestedLink';
                galleryParams.galleryRight.insertBefore(galleryRightEmailtofriend, galleryParams.galleryRight.childNodes[4]); 
                } 
                */
                
                galleryRightLink.onclick = function(){ location.href="/contact/images/"+thisImgNum; }
                
		if(lang == 'en'){
                   lang = 'fr';
                   var newLangLabel = 'Fran&#231;ais';
		}else{
                   var newLangLabel = 'English';
                   lang = 'en';
		} 
                galleryParams.lang.onclick=function(){ switchLanguage(lang,img); }
                galleryParams.lang.innerHTML = newLangLabel; 
	}

	switchGalleryImg = function(direction){
                if(!galleryShowInd){ showIndGallery(); } 
                galleryShowInd = true; 
              
		if(direction){
                    if(direction == 'next'){
                        ++currentNum; 
                    }else if(direction == 'prev'){
                        --currentNum;
                    } 
                } 
                
                if(currentNum <= 0){ currentNum = 0;     }
		if(currentNum >= (imgs.length - 1)){ currentNum = imgs.length - 1;  }	
		galleryParams.nextNav.className = (currentNum == (imgs.length - 1)) ? 'end' : ''; 
		galleryParams.prevNav.className = (currentNum <= 0) ? 'end' : ''; 
                galleryParams.galleryShowing.innerHTML = (parseInt(currentNum) + 1); 
		for(n = 0; n < imgs.length; n++){
			if(n == currentNum){
                        galleryParams.img.innerHTML = ''; 
                	galleryLeftImg = new Image();
			galleryLeftImg.src = "/images/gallery/large/"+imgs[n].number+".jpg"; 
			galleryLeftImg.id = 'galleryLeftImg'; 
                        galleryParams.title.innerHTML = imgs[n].title;
			galleryParams.number.innerHTML = imgs[n].number;
			galleryParams.size.innerHTML = imgs[n].size; 
			galleryParams.edition.innerHTML = imgs[n].edition;
			galleryParams.priceFrame.innerHTML = imgs[n].price_frame; 
			galleryParams.priceMat.innerHTML = imgs[n].price_mat; 
			galleryParams.pricePrint.innerHTML = imgs[n].price_print;
			switchLanguage(lang, imgs[n]); 
                        var thisImgNumber = imgs[n].number; 
		        galleryLeftImg.onload = function(){ 
                        galleryParams.img.style.height = this.height +'px'; 
                        galleryParams.img.style.width = this.width+'px'; 
                        galleryParams.img.appendChild(galleryLeftImg);  
                } 
			}
		}
	}
buildGalleryTemplate = function(){


        galleryContent.innerHTML = '<table cellpadding="0" cellspacing="0"><tr valign="top"><td id="galleryLeft"><div id="galleryIndNav"><span id="prevNav" >&lsaquo;&lsaquo;prev</span> | <span id="allNav">All</span> | <span id="nextNav">next&rsaquo;&rsaquo;</span>&nbsp;<span id="galleryShowingNav">Showing <span id="galleryShowing">'+currentNum+'</span> of '+imgs.length+'</span></div><div id="galleryLeftWrapper" style=" margin: auto; "></div><div id="galleryIndFooter"> <span id="footerCaption"> </span> - <a href="mailto:info@nature-n-focus.com">info@nature-n-focus.com</a> <span id="footerOr"></span> 506-532-2121 <br><a href="http://www.nature-n-focus.com"><b>www.nature-n-focus.com</b></a> &quot;<b id="footerQuote"></b>&quot;</div> <div id="galleryBottomClear">&nbsp;</div></td><td id="galleryRight"><span id="galleryIndTitle"></span><span id="lang">Fran&#231;ais</span><div id="galleryIndSpecs"><div id="specParams"><b id="photoB" class="galleryParam">Photo#</b> <span id="galleryIndNumber" class="galleryParamValue"></span><br><b id="sizeB" class="galleryParam">Size</b> <span class="galleryParamValue" id="galleryIndSize"></span><br><b id="editionB" class="galleryParam">Edition</b> <span class="galleryParamValue" id="galleryIndEdition"></span><div style="clear: both; ">&nbsp;</div></div><div id="galleryIndPricing"><b id="framedB" class="galleryParamP">Framed</b><span id="galleryIndPriceFrame" class="galleryParamValue"></span><b id="matB" class="galleryParamP">Mat</b><span id="galleryIndPriceMat" class="galleryParamValue"></span><b id="printB" class="galleryParamP">Print</b><span id="galleryIndPricePrint" class="galleryParamValue"></span><div style="clear: both; height: 0; ">&nbsp;</div></div></div><div id="galleryIndDescription_wrapper"> <span id="galleryIndDescription"></span><div style="text-align: center; "><br></div> </div><img src="/images/smpl.jpg" id="smpl" alt="Shooting Memories, Preserving Life"></td></tr></table>';   
	galleryContent.innerHTML += '';
}
showAllGallery = function(){
	galleryShowInd = false;         
	galleryContent.innerHTML = '';
	for(n = 0; n < imgs.length; n++){ 
		var d = document.createElement('div');
		var d1 = document.createElement('div');
		var d2 = document.createElement('div');
		var d3 = document.createElement('div');
                var caption = document.createElement('div'); 
		d.className = 'galleryBlockWrapper';
		d1.className = 'galleryThumbWrapper';
		d2.className = 'galleryThumb';
		d3.className = 'galleryThumbInside';
		dImg = new Image(100,100);
		dImg.src = '/images/gallery/thumbs/'+imgs[n].number+'.jpg';
		dImg.id = 'thumb'+n;
		dImg.className = 'thumbImg';
		d3.appendChild(dImg);
		d2.appendChild(d3);
		d1.appendChild(d2);
		d.appendChild(d1);
                caption.className = 'galleryThumbCaption';
                caption.innerHTML = imgs[n].title;
                caption.innerHTML += (imgs[n].type == 'new') ? '<div class="new">Just Added!</div>' : '';
 
                d.appendChild(caption);  
		galleryContent.appendChild(d);
	}
	galleryContent.innerHTML += '<div id="galleryBottomClear">&nbsp;</div>';
	var thumbImgs = document.getElementsByTagName('img');
	var imgNum = 0;
	for(n = 0; n < thumbImgs.length; n++){ if(thumbImgs[n].className == 'thumbImg'){  thumbImgs[n].onclick=function(){ currentNum = this.id.substr(5); showIndGallery(); } }}
}
getGalleryParams = function(){
      galleryParams = {
		'img' : ob('galleryLeftWrapper'), 
		'galleryRight' : ob('galleryRight'),
		'title':  ob('galleryIndTitle'),
		'number': ob('galleryIndNumber'),
		'size' : ob('galleryIndSize'),
		'edition': ob('galleryIndEdition'),
		'priceFrame' : ob('galleryIndPriceFrame'),
		'priceMat' :  ob('galleryIndPriceMat'),
		'pricePrint': ob('galleryIndPricePrint'),
		'description' :  ob('galleryIndDescription'),
		'prevNav' : ob('prevNav'),
		'nextNav' : ob('nextNav'),
                'allNav' : ob('allNav'),
		'lang' : ob('lang'),
		'photoB' : ob('photoB'),
		'editionB' : { 'obj' : ob('editionB'), 'label_en' : 'Edition', 'label_fr' : '&#201;dition total'}, 
		'framedB' : { 'obj' : ob('framedB'), 'label_en' : 'Framed', 'label_fr' : 'Encadrer'},
                'matB' : { 'obj' : ob('matB'), 'label_en' : 'Mat', 'label_fr' : 'Passe Partout'},
                'printB' : { 'obj' : ob('printB'), 'label_en' : 'Print', 'label_fr' : '&#201;preuve'},
		'footerQuote' :   {  'obj' : ob('footerQuote'), 'label_en':'Shooting Memories..Preserving Life','label_fr':'&#201;clairer les Souvenirs...Pr&#233;server la Vie'},
		'footerCaption':  {  'obj' : ob('footerCaption'), 'label_en' : 'Other sizes are available on Archival Paper or Canvas.   Contact Bob Belliveau-Ferrin Lemieux.', 'label_fr' : 'D&#8217;autres dimensions sont disponibles, sur papier archives ou sur toile.  Pour tout renseignement s&#8217;adresser &#224; Bob Belliveau-Ferrin Lemieux'},
		'footerOr':   { 'obj' : ob('footerOr'), 'label_en' : 'or', 'label_fr' : 'ou'},
                'galleryShowing' : ob('galleryShowing') 

	};
}


