﻿var secs;
var timerID = null;
var timerRunning = false;
var delay = 100;
var x=0;
var y=0;
var id;
var image_index=1;

function init()
{
	setCookie("dis","none");
}

function showhide(a,b)
{
	var thedis=getCookie("dis");
	if(a==0)
	{ 
		document.getElementById("main").style.display="none";
		document.getElementById("bg").style.display="none";
		setCookie("dis","none");
	}
	else
	{			
			document.getElementById("main").style.display="block";
			document.getElementById("bgimg").src="graphics/gallery/popup/1.jpg";
			document.getElementById("bg").style.display="block";
			
			
			x=0;
			y=0;
			secs = 10;
			id=a;
			StartTheTimer();
			setCookie("dis",a);
			
			
	}
}



 function getCookie(name) {
	var cname = name + "=";
	var dc = document.cookie;
	
	if (dc.length > 0) {
		begin = dc.indexOf(cname);
		if (begin != -1) {
			begin += cname.length;
			end = dc.indexOf(";", begin);
			if (end == -1) end = dc.length;
				return unescape(dc.substring(begin, end));
		}
	}
	return null;
	
 } // end function


 function setCookie(name, value, expires, path, domain, secure) {

	document.cookie = name + "=" + escape(value) + 
	((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
	((path == null) ? "" : "; path=" + path) +
	((domain == null) ? "" : "; domain=" + domain) +
	((secure == null) ? "" : "; secure");

 } // end function
 
 


function StartTheTimer()
{

    if (secs==0)
    {
        StopTheClock()
    }
    else
    {
    	document.getElementById("main").style.opacity=x;
    	document.getElementById("main").style.filter="alpha(opacity="+y+")";
		x+=0.1;
		y+=10;
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}

function StopTheClock()
{
    if(timerRunning)
    clearTimeout(timerID)
    timerRunning = false
}



function ImageFlip(image_array)
{
 	var len = image_array.length;
 	var rand=Math.floor(Math.random()*len) ;
 	
 	document.getElementById("gallery_thumb").src="graphics/gallery/thumb/" + image_array[rand] + ".jpg";
 	document.getElementById("image_link").href="javascript:showhide('gallery'," + image_array[rand] + ")";
}

function rotate(dir)
{

	var next_index=image_index+1;
	var prev_index=image_index-1;
	if(next_index > 25)
	{
		next_index=1;
	}
	if(prev_index < 1)
	{
		prev_index=25
	}
	if(dir=="next")
	{
		document.getElementById("bgimg").src="graphics/gallery/popup/" + next_index + ".jpg";
		image_index=next_index;
	}
	else if(dir=="back")
	{
		document.getElementById("bgimg").src="graphics/gallery/popup/" + prev_index + ".jpg";
		image_index=prev_index;
	}

}







