function setCookie(c_name, value, exdays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	{
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name)
		{
			return unescape(y);
		}
	}
}

function smooth_hide(id)
{
	var o = document.getElementById(id);
	if (o.style.display != 'none')
	{
		var height = o.offsetHeight - 5;
		if (height <= 0)
			o.style.display = "none";
		else
		{
			o.style.overflow = "hidden";
			o.style.height = height+"px";
			window.setTimeout("smooth_hide(\""+id+"\")", 10);
		}
	}
}

function ValidateFields(form)
{
	for (var i=0; i < form.elements.length; i++)
	{
		var element = form.elements[i];
		if (element.name[0] == "*" && element.value == "")
		{
			alert("Please fill in all the items marked with an *");
			return false;
		}
	}	
	return true;
}

function EmbedFlashObject(movie, width, height)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'); 	document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="myMovieName" width="'+width+'" height="'+height+'">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<param name="movie" value="'+movie+'">');
	document.write('<param name="allowScriptAccess" value="always">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="bgcolor" value="#FFFFFF">');
	document.write('<embed src="'+movie+'" allowscriptaccess="always" quality="high" bgcolor="#FFFFFF" wmode="transparent" name="myMovieName" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="'+width+'" align="" height="'+height+'">');
	document.write('</object>');
}

function BrowserDetect()
{
	var ua = navigator.userAgent.toLowerCase(); 
	this.isGecko   = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
	this.isSafari  = (ua.indexOf('safari') != - 1);
	this.isOpera   = (ua.indexOf('opera') != -1); 
	this.isIE      = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
	this.isMozilla = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
	this.isNS      = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
	this.isFirefox = (ua.indexOf('firefox') != - 1);
}

var slideshow_id = 0;

function SlideShow(slideshow_container_id, width, height, images, links)
{
	this.current_image = 0;
	this.images = images;
	this.links = links;
	this.anim1 = "anim1"+slideshow_id;
	this.anim2 = "anim2"+slideshow_id;
	this.link1 = "link1"+slideshow_id;
	slideshow_id++;
	this.speed = 5000;
	this.fading = false;
	this.fade_id = 0;
	this.opacity = 0;
	this.display_time = 0;
	
	for (var i=0; i<images.length; i++)
		document.write('<img src="'+images[i]+'" alt="" style="display:none;" />');

	first_link = '';
	if (links && links.length > 0 && links[0] != "")
		first_link = 'href="'+links[0]+'"';
		
	var out = '<a id="'+this.link1+'" '+first_link+'><div class="slideshow" id="'+this.anim1+'" style="display:none;width:'+width+'px; height:'+height+'px; background-image: url('+images[0]+');"><div id="'+this.anim2+'" style="width:'+width+'px; height:'+height+'px;"></div></div></a>';	
	document.getElementById(slideshow_container_id).innerHTML = out;	
	document.getElementById(this.anim1).style.display = "block";
	
	var thisObject = this;
	window.setInterval(function() { thisObject.handleTimer() }, 50);
}

SlideShow.prototype.handleTimer = function()
{
//	this.debug(this.display_time);
	// if fading, then change the opacity of the slide that's fading in
	// and stop fading once we've reached 100
	if (this.fading)
	{
		var o = document.getElementById(this.fade_id);
		if (this.opacity <= 100)
			setOpacity(o, this.opacity);

		if (this.opacity < 100)
			this.opacity += 4;
		else
			this.fading = false;
	}
	// otherwise advance the time that the slide is being displayed
	// and start fading once it reaches the maximum
	else
	{
		this.display_time += 50;
		if (this.display_time >= this.speed)
			this.nextImage();
	}
}

SlideShow.prototype.debug = function(text)
{
	var o = document.getElementById("slideshow_debug_id");
	if (o)
		o.innerHTML = text;
}

SlideShow.prototype.gotoImage = function(n)
{
	this.opacity = 100;
	this.fadeToImage(n);
}

//	this.debug("gotoImage("+n+") "); 
SlideShow.prototype.fadeToImage = function(n)
{
	if (n >= 0 && n < this.images.length)
	{
		var img1 = this.images[this.current_image];
		this.current_image = n;
		var img2 = this.images[this.current_image];
		var o1 = document.getElementById(this.anim1);
		var o2 = document.getElementById(this.anim2);
		setOpacity(o2, 0);
		o1.style.background = "url('"+img1+"')";
		o2.style.background = "url('"+img2+"')";
		this.fade_id = this.anim2;
		this.fading = true;
		this.display_time = 0;
		var link1 = document.getElementById(this.link1);
		if (this.links && this.links.length > this.current_image && this.links[this.current_image] != "")
			link1.href = this.links[this.current_image];
	}
}

SlideShow.prototype.nextImage = function()
{
	var n = this.current_image + 1;
	if (n >= this.images.length)
		n = 0;
	this.opacity = 0;
	this.fadeToImage(n);
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	obj.style.KHTMLOpacity = opacity/100; // Safari<1.2, Konqueror
	obj.style.MozOpacity = opacity/100; // Older Mozilla and Firefox
	obj.style.opacity = opacity/100; // Safari 1.2, newer Firefox and Mozilla, CSS3
}

function showMovie(name) {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="fullscreen" align="middle" height="255" width="320">');
	document.write('<param name="allowScriptAccess" value="sameDomain">');
	document.write('<param name="movie" value="movieplayer.swf">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="salign" value="tl">');
	document.write('<param name="bgcolor" value="#000000">');
	document.write('<param name="FlashVars" value="vidpath='+name+'">');
	document.write('<embed src="movieplayer.swf" flashvars="vidpath='+name+'" quality="high" salign="tl" name="fullscreen" bgcolor="#000000" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" align="middle" height="255" width="320">');
	document.write('</object>');
}


