
/*
   Copyright 2002 The GoHome Networks, Inc. All rights reserved. No
   reproduction, distribution, or transmission of the copyrighted
   materials at this site is permitted without the written permission
   of The GoHome Networks, unless otherwise specified. MLSWorks,
   BrokerWorks, ActiveListing, and AdTracker are Trademarks of
   The GoHome Networks, Inc.

   ActiveAgent is a registered Service Mark of The GoHome Networks, Inc.
*/

var W3C = (document.getElementById) ? 1 : 0;
var IE = (document.all) ? 1 : 0;
var NS4 = (document.layers) ? 1 : 0;

function OpenSlideURL (destwindow)
{
	if (this.slidesloaded)
	{
		var dest = this.slides[this.currentslide].slideurl;
		if(destwindow && !destwindow.closed && dest)
		{
			destwindow.location = dest;
			destwindow.focus();
			return true;
		}
		else if(dest)
		{
			var targetwindow = window.open(dest, "slide");
			targetwindow.focus();
			return true;
		}
	}
	return false;
}

function AddTag( thename, thevalue )
{
	var newTag = new Object();
	newTag.name = thename;
	newTag.value = thevalue;
	this.tags[this.tags.length] = newTag;
	return newTag;
}

function LoadSlideImage()
{
	this.image.src = this.imageurl;
	this.imageloaded = 1;
}

function Slide(imageurl, slideurl)
{
	this.image = new Image();
	this.imageurl = imageurl;
	this.imageloaded = 0;
	this.slideurl = slideurl;
	this.tags = new Array();
	this.AddTag = AddTag;
	this.LoadImage = LoadSlideImage;
}

function AddSlide(imageurl, slideurl)
{
	var newSlide = new Slide(imageurl, slideurl);
	this.slides[this.slides.length] = newSlide;
	return newSlide;
}

function LoadSlideShow ()
{
	if (this.slides.length)
	{
		this.slides[0].LoadImage();
		if (this.slides.length>1)
		{
			this.slides[1].LoadImage();
		}
		this.slidesloaded = 1;
		this.currentslide = -1;
		return 1;
	}
	return 0;
}

function NextSlide ()
{
	if (!this.slides.length)
		return;
	this.currentslide++;
	if (this.currentslide >= this.slides.length)
		this.currentslide = 0;
	slide = this.slides[this.currentslide];
	if (!slide.imageloaded)
		slide.LoadImage();

	if (W3C || IE || NS4)
	{
		var theimage = document.images[this.imagename];
		if (IE && !this.paused && this.blendDuration)
		{
			theimage.style.filter="blendTrans(duration="+this.blendDuration+")";
			theimage.style.filter="blendTrans(duration=crossFadeDuration)";
			theimage.filters.blendTrans.Apply();
		}
		if (this.updateTags)
		{
			for (i = 0; i < slide.tags.length; i++)
			{
				var thetag = slide.tags[i].name;
				if (W3C)
					document.getElementById(thetag).innerHTML = slide.tags[i].value;
				else if (IE)
					document.all.item(thetag).innerHTML = slide.tags[i].value;
				else if (NS4)
				{
					var theparent = document.layers['PNS'+thetag];
					if (theparent)
					{
						var thechild = theparent.layers['NS'+thetag];
						if (thechild)
						{
							thechild.document.write("<DIV ID='"+thetag+"' STYLE='font-color: black;'>"+slide.tags[i].value+"</DIV>");
							thechild.document.close();
						}
						else
						{
							alert("Missing layer: NS" + thetag);
						}
					}
					else
					{
						alert("Missing layer: PNS" + thetag);
					}
				}
			}
		}
	}

	theimage.src = slide.image.src;
	if (IE && !this.paused && this.blendDuration)
		theimage.filters.blendTrans.Play();

	var nextslide = this.currentslide + 1;
	if (nextslide >= this.slides.length)
		nextslide = 0;
	slide = this.slides[nextslide];
	if (!slide.imageloaded)
		slide.LoadImage();

	if (!this.paused)
		this.timer = setTimeout(this.name + ".Next()", this.switchspeed * 1000);
}

function PrevSlide ()
{
	this.currentslide -= 2;
	if (this.currentslide < -1)
		this.currentslide = this.slides.length - 2;
	this.Next();
}

function RunSlideShow ()
{
	if (!this.slides.length)
		return;
	if (this.paused)
		this.paused = 0;
	else
		clearTimeout(this.timer);

	if (this.playimage.pause)
		UpdateImage(this.playimage.name, this.playimage.pause);
	if (this.stopimage.pause)
		UpdateImage(this.stopimage.name, this.stopimage.pause);

	this.Next();
}

function StopSlideShow ()
{
	if (this.paused)
		return;

	if (this.playimage.play)
		UpdateImage(this.playimage.name, this.playimage.play);
	if (this.stopimage.play)
		UpdateImage(this.stopimage.name, this.stopimage.play);

	clearTimeout(this.timer);
	this.paused = 1;
}

function SetPlayImage(name, playsrc, pausesrc)
{
	this.playimage.name = name;
	if (playsrc)
	{
		this.playimage.play = new Image();
		this.playimage.play.src = playsrc;
	}
	else
		this.playimage.play = 0;
	if (pausesrc)
	{
		this.playimage.pause = new Image();
		this.playimage.pause.src = pausesrc;
	}
	else
		this.playimage.pause = 0;
}

function SetStopImage(name, stopsrc, pausesrc)
{
	this.stopimage.name = name;
	if (stopsrc)
	{
		this.stopimage.stop = new Image();
		this.stopimage.stop.src = stopsrc;
	}
	else
		this.stopimage.play = 0;
	if (pausesrc)
	{
		this.stopimage.pause = new Image();
		this.stopimage.pause.src = pausesrc;
	}
	else
		this.stopimage.pause = 0;
}

function UpdateImage(name, newimage)
{
	document.images[name].src = newimage.src;
}

function SlideShow (name, imagename)
{
	this.name = name;
	this.currentslide = 0;
	this.switchspeed = 5;
	this.blendDuration = 1;
	this.imagename = imagename;
	this.imageWidth = 480;
	this.imageHeight = this.imageWidth / 4 * 3;
	this.imageBorder = 0;
	this.showNoPhoto = 0;
	this.showNav = 0;
	this.updateTags = 0;
	this.slidesloaded = 0;
	this.currentslide = 0;
	this.paused = 1;
	this.timer;
	this.slides = new Array();

	this.OpenSlideURL = OpenSlideURL;
	this.AddSlide = AddSlide;
	this.Load = LoadSlideShow;
	this.Next = NextSlide;
	this.Prev = PrevSlide;
	this.Run = RunSlideShow;
	this.Stop = StopSlideShow;

	this.playimage = new Object();
	this.stopimage = new Object();

	this.SetPlayImage = SetPlayImage;
	this.SetStopImage = SetStopImage;
}
