/**
 * @author Ejnar
 */

/*The Following is a setCookie function to put on one of the other pages that can link to this page and start the gallery with a specific picture
		 *It consists of 4 special functions: setGalleryCookie (which is placed on the page where the original link is. It is then called with the desired  
		 *gallery image as an argument and sets it as a cookie named gallerystartImg which can be retrieved when the produkt page is loaded.
		 *getGalleryCookie is on the product page and gets the cookie with the galleryStartImg and checkGallery function then runs the showGallery with that as argument.
		 *deleteGalleryCookie erases the cookie so it wont launch the gallery next time you visit the page.*/

function setGalleryCookie (startImgNr,galleryPage)
		{
			var pageRequested="produkter/ceropegia/index_products.html";
			switch (galleryPage) 
			{
				case 1:
				pageRequested="produkter/ceropegia/index_products.html";
				break;
				case 2:
				pageRequested="produkter/senecio/index_products2.html";
				break;
				case 3:
				pageRequested="produkter/parthenocissu/index_products3.html";
				break;
				case 4:
				pageRequested="gartneri/omos/index_greenhouse2.html";
				break;
				case 5:
				pageRequested="heste/hestene/index_horse.html";
				break;
				case 6:
				pageRequested="heste/arrangementer/index_Arrangements.html";
				break;			
			};
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+1);
			document.cookie="galleryStartImg="+startImgNr+";expiredays="+exdate.toUTCString();
			location.href=pageRequested;
		};
		
		
		function getGalleryCookie (c_name)
		{
			if (document.cookie.length>0) 
			{
				c_start=document.cookie.indexOf(c_name+"=");
				if (c_start!=-1)
				 {
				 	c_start=c_start+c_name.length+1;
					c_end=document.cookie.indexOf(";",c_start);
					if (c_end==-1) c_end=document.cookie.length;
					return document.cookie.substring(c_start,c_end);
				 };
			};
			return "";
		};
		
		function checkCookie()
		{
			galleryStart=getGalleryCookie ("galleryStartImg");
			if (galleryStart!=null && galleryStart!="")
			{
				showGallery(galleryStart);
				deleteGalleryCookie ()
			};
		};

		function deleteGalleryCookie ()
		{
			var exdate=new Date();
			exdate.setDate(exdate.getDate()-2);
			document.cookie="galleryStartImg=;expiredays="+exdate.toUTCString();
		};
