	
	
/*******************************************************/

$(document).ready(function () {
    $(".year-label").attr("innerHTML",getYear());
    preloadImage();
});

/*********************************************************/
	
	function preloadImage(){
	    var src= $("#photo").attr("src");
		//$("#photo").attr("src","");
		var img = new Image();
		$(img).load(function () {
				showDiv('#toolbar-container',500);
		})
		.attr('src', src);	
	}
	
	function showDiv(element,timeout) {
		if (timeout==null || timeout==0) {
			$(element).show();
		} else {
			setTimeout('jQuery("'+element+'").show("slow")',timeout);
		}
	}
	
	function getRequestParams() {
		var thisUrl = location.search;
		var collection = new Array();
		if (thisUrl.indexOf("=") > -1) {
			thisUrl = thisUrl.replace(/\?/g, "");
			if (thisUrl.indexOf("&") > -1) {
				kvArray = thisUrl.split("&");
				for (i = 0; i < kvArray.length; i++) {
					pairArray = kvArray[i].split("=")
					collection[pairArray[0]] = pairArray[1];
				}
			} else {
				pairArray = thisUrl.split("=");
				collection[pairArray[0]] = pairArray[1];
			}
		}
		return collection;
	}
	
	
	function getParameter(name) {
		var Request = getRequestParams();
		return Request[name];
	}

	function writeSectionIndex() {
		var section=getParameter("section");
		var count=getParameter("count");
		var code="<a href=\"preview.htm?section="+section+"&count="+count+"\">";
		document.write(code);
	}
	
	function test() {
	  alert("Testing");
	}

	
	function nextShot() {
		var section=getParameter("section");
		var count=parseInt(getParameter("count"));
		var index=parseInt(getParameter("index"));
		var code="";
		
		
		if (section ==null || count==null || index==null) {
		//	alert("missing params");
			return;
		}

		if (index < count) {
		
			 index++;
			 code="<a href=\"cornice.html?section="+section+"&count="+count+"&image="+section+"/"+section+index+".jpg&index="+index+"\">";
		
		} else {
			//code="<a href=\"cornice.html?section="+section+"&count="+count+"&image="+section+"/"+section+"1.jpg&index=1\">";
			code="";
		}

	   // alert(code);
		document.write(code);
	
	}

	function showAdditionalImages() { 
		var params = new Array();
		var name = "img";
		var index = 1;
		params = getRequestParams();

		while (params[name+index] != null && index<5) {
			document.write("<img id='photo-additional' src='additionalimages/"+params[name+index]+"' style='clear:both'/>");
			index++;
		}
	}
	function writeCells(base, count) {
	    //alert("Writing cells for "+base+" ("+count+")");
	    
	    var columns=4;
	    var cells=(count/columns+1)*columns;
	    var photo="";
	    var code="";
	    var row="";
	    var k=0;
	    
	    for (var i = 1; i <= cells; i++) { 
	      if (i>count) photo="&nbsp;";
	      
	      else photo="<a href=\"cornice.html?section="+base+"&image="+base+"/"+base+i+".jpg&count="+count+"&index="+i+"\"><img src=\""+base+"/thumbs/"+base+i+".jpg\" border=0></a>";
	      row+="  <td>"+photo+"</td>\n"; 
	      
	      if ((i)%columns==0) {
	        row="<tr>\n"+row+"</tr>";
	        code+=row+"\n";
	        row="";
	      }
    	    }
    	    document.write(code);
    	    
	}
	
	
	function getYear() {
		return  new Date().getFullYear();		
	}
	
	
	function printExifData() { 
		printValues('Camera type: ','<EXIF_CAMERA_MODEL>'); 
		printValues('Lens type: ','<EXIF_COMPAT_LENS>'); 	 
		printValues('Focal lenght: ','<EXIF_FOCAL_LENGTH> (<EXIF_EQUIV_FOCAL_LENGTH> equiv.)'); 
		printValues('Aperture: ','<EXIF_APERTURE>'); 
		printValues('Shutter speed: ','<EXIF_EXPOSURE_TIME>'); 
		printValues('Exposure bias: ','<EXIF_APERTURE_BIAS>'); 
		printValues('Program: ','<EXPOSURE_PROGRAM>'); 
		printValues('Metering: ','<EXIF_METERING_MODE>'); 
		printValues('ISO: ','<EXIF_ISO>');
		printValues('Flash: ','<EXIF_FLASH>'); 
		}

			
	function printValues(label, value) {
		value.replace(" ","");
		if ( value == null || value == "" || value.charAt(0)=='<' ) return;
		document.write( "<span class='exiflabel'>" + label +"</span><span class='exifvalue'>"+ value + "</span>" + '<br />');
	} 

	function printCategories(halo) {
		
		var category="<IMAGE_CATEGORY>";
		document.write('&#8226; '+category);
	}
		function clearBox(box) {
			 if(box.value==box.defaultValue) {
				 box.value = "";
			 }
		 }
