//====================
//--Gallery Object--//
//====================
function g_obj(id, x, y, w, h, brgb, indoc, placement)
{
	//define vars
	this.id = id;
	this.x = x;
	this.y = y;
	this.w = w;
	this.h = h;
	this.brgb = brgb;	
	this.indoc = indoc;
	if(indoc!=0)this.placement=placement;
	else placement=0;
	this.picData = Array();
	this.imgSpecData = Array();
	this.pictures = 0;
	this.curPic = 0;
	this.switchDelay = 0;
	this.timer = 0;
	//Define Functions
	this.AddPicture = fn1;
	this.ChangePicture = fn2;
	this.FadePictures = fn3;
	this.Scroll = fn4;
	
	var strphotoObj = "<div id=\""+id+"_1\" valign=\"middle\" style=\"z-index:1;opacity:1;filter:alpha(opacity=100);vertical-align:middle;text-align:center;position:absolute;left:"+x+";top:"+y+";width:"+w+";height:"+h+";background-color:rgb(0,0,0);border-style:solid;border-color:"+brgb+";\"><table width=\"100%\" height=\"100%\"><tr><td id=\""+id+"\"></td></tr></table></div>";
	var strnavObj = "<div id=\""+id+"Nav\" style=\"position:absolute;left:"+x+";top:"+y+";width:"+w+";height:20px;background-color:"+brgb+";border-color:"+brgb+";\"><div style=\"float:right;\"><a href=\"#\" style=\"color:#000000;text-decoration:none;\" onclick=\"docChangeImg('"+id+"','++'); return false;\">\></a></div><div style=\"float:left;\"><a href=\"#\" style=\"color:#000000;text-decoration:none;\" onclick=\"docChangeImg('"+id+"','--'); return false;\">\<</a></div><div id=\""+id+"NavNum\" style=\"text-align:center;\"></div></div>";
	
	var strphotoObj2 = "<div id=\""+id+"_1\" valign=\"middle\" style=\"z-index:1;opacity:1;filter:alpha(opacity=100);vertical-align:middle;text-align:center;width:"+w+";height:"+h+";background-color:rgb(0,0,0);border-style:solid;border-color:"+brgb+";\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" height=\"100%\"><tr><td valign=\"top\" id=\""+id+"\"></td></tr></table></div>";	
	var strnavObj2 = "<div id=\""+id+"Nav\" style=\"width:"+w+";height:20px;background-color:"+brgb+";border-color:"+brgb+";\"><div style=\"float:right;\"><a href=\"#\" style=\"color:#000000;text-decoration:none;\" onclick=\"docChangeImg('"+id+"','++'); return false;\">\></a></div><div style=\"float:left;\"><a href=\"#\" style=\"color:#000000;text-decoration:none;\" onclick=\"docChangeImg('"+id+"','--'); return false;\">\<</a></div><div id=\""+id+"NavNum\" style=\"text-align:center;\"></div></div>";
	
	if(placement==0)
	{
		//Create on page
		document.write(photoObj);
		//Create Nav
		y = y+h;
		document.write(navObj);
	}
	else
	{
		var placeObj = eval(placement);
		placeObj.innerHTML = strphotoObj2 + strnavObj2;
	}
}
//Gallery Functions//
//AddPicture
function fn1(img, w, h)
{
	this.pictures++;
	var idnum = this.pictures;
	var rn = 12;
	var r = 0;
	if(w > this.w)
	{
		r=(h/w);
		w = this.w;
		h = w*r;
		w-=rn;
		h-=rn;
	}
	if(h > this.h)
	{
		r=(w/h);
		h = this.h;
		w = h*r;
		w-=rn;
		h-=rn;
	}
	var cx = this.w/2;
	var cy = this.h/2;
	var pcx = w/2;
	var pcy = h/2;
	cx-=pcx;
	cy-=pcy;
	cx-=(rn/3);cy-=(rn/3);
	var imgdata;
	if(this.placement==0)
		imgdata = "<img id=\"pic"+idnum+"\" src=\""+img+"\" width=\""+w+"\" height=\""+h+"\" style=\"position:absolute;left:"+cx+";top:"+cy+";opacity:0;filter:alpha(opacity=0);\" />";
	else
		imgdata = "<img id=\"pic"+idnum+"\" src=\""+img+"\" width=\""+w+"\" height=\""+h+"\" hspace=\""+cx+"\" vspace=\""+cy+"\" style=\"position:absolute;opacity:0;filter:alpha(opacity=0);\" />";
	this.picData[idnum] = imgdata;
	
	
	//add it to the nav
	var nav = document.getElementById(this.id+"NavNum");
	nav.innerHTML+="<a id=\"but"+idnum+"\" href=\"\" style=\"color:#000000;font:verdana;text-decoration:none;\" onclick=\"docChangeImg('"+this.id+"',"+idnum+");return false;\">&nbsp"+idnum+"&nbsp</a>";
}
//ChangePicture
function fn2(id)
{
	//alert(this.curPic);
	if(this.curPic == this.pictures)id=1;
	if(id==0)id=this.pictures;
	if(this.curPic == id) return;
	if(this.picData[id]==null)return;
	var galobj = document.getElementById(this.id);
	//alert(this.picData[id]);
	
	if(this.curPic==0)
	{
		galobj.innerHTML = this.picData[1];
		var pic = document.getElementById("pic1");
		this.FadePictures(0, id);
		//pic.style.opacity=1;pic.filters.alpha.opacity=100;
		var butobj = document.getElementById('but'+id);
		butobj.style.color="#FFFFFF";
		this.curPic = 1;
		return;
	}
	
	//Manage Picture effect
	galobj.innerHTML = this.picData[this.curPic] + " " + this.picData[id];
	var oldpic = document.getElementById("pic"+this.curPic);
	var newpic = document.getElementById("pic"+id);
	oldpic.style.opacity=1;oldpic.filters.alpha.opacity=100;
	this.FadePictures(this.curPic, id);
	
	//Manage Button effect
	var oldbutobj = document.getElementById('but'+this.curPic);
	if(oldbutobj)oldbutobj.style.color="#000000";
	var butobj = document.getElementById('but'+id);
	butobj.style.color="#FFFFFF";
	this.curPic = id;
}

//FadePictures
function fn3(oldpic, newpic)
{
	if(oldpic!=0) var oldobj = document.getElementById("pic"+oldpic);
	var newobj = document.getElementById("pic"+newpic);
	var t = 0;
	if(newobj.style.opacity<1)
	{
		if(oldpic!=0)
		{
			oldobj.style.opacity=parseFloat(oldobj.style.opacity)-.01;
			oldobj.filters.alpha.opacity=parseInt(oldobj.filters.alpha.opacity, 10)-1;
		}
		newobj.style.opacity=parseFloat(newobj.style.opacity)+.01;
		newobj.filters.alpha.opacity=parseInt(newobj.filters.alpha.opacity, 10)+1;
		t = setTimeout("fn3("+oldpic+","+newpic+");",1);
	}
	else
	{
		clearTimeout(t);
	}
}
//Scroll
function fn4()
{
	var nextpic = this.curPic+1;
	this.ChangePicture(nextpic);
	this.timer = setTimeout(this.id+".Scroll();",this.switchDelay);
}

//Document Oriented Functions
function docChangeImg(objname, picid)
{
	//alert(objname);
	eval("clearTimeout("+objname+".timer);");
	eval(objname+".timer = setTimeout(objname+\".Scroll()\", eval(objname+\".switchDelay\"));");
	if(picid=="++")eval("picid = "+objname+".curPic+1;");
	if(picid=="--")eval("picid = "+objname+".curPic-1;");
	eval(objname+".ChangePicture("+picid+");");
}
function setTime()
{
	var curtime = new Date();
	var curhour = curtime.getHours();
	var curmin = curtime.getMinutes();
	var cursec = curtime.getSeconds();
	var time = "";
	if(curhour == 0) curhour = 12;
	time = (curhour > 12 ? curhour - 12 : curhour) + ":" + curmin + ":" + cursec + " " + (curhour > 12 ? "PM" : "AM");
	var obj = document.getElementById("timer");
	obj.innerHTML = "Current Time: "+time+"";
	t = setTimeout("setTime();", 1000);
}
function sleep(milsec)
{
	var date = new Date();
	var msec = date.getMilliseconds();
	var sec = date.getSeconds();
	var min = date.getMinutes();
	var start_time = msec + (sec*1000) + (min*60*1000);
	while(true)
	{
		var newdate = new Date();
		var fmsec = newdate.getMilliseconds();
		var fsec = newdate.getSeconds();
		var fmin = newdate.getMinutes();
		var end_time = fmsec + (fsec*1000) + (fmin*60*1000);
		if((end_time - start_time) > milsec) break;
	}
}

//OBJECTS
setTime();
var gobj = new g_obj("gobj", 380, 180, 520, 390, "rgb(159,208,81);", 1, "photos");
gobj.switchDelay=10000;
gobj.AddPicture("day-spa-phoenix.jpg", 728, 493);
gobj.AddPicture("day spa in phoenix.jpg", 742, 560);
gobj.AddPicture("spa8.jpg", 745, 490);
gobj.AddPicture("couples-Spa-Massage.jpg", 411, 605);
gobj.AddPicture("spa-wellness.jpg", 405, 601);
gobj.AddPicture("spa12.jpg", 330, 421);
gobj.AddPicture("spa-beauty.jpg", 280, 421);
gobj.AddPicture("sauna.jpg", 243, 419);
gobj.AddPicture("slimming-body-wraps.gif", 182, 287);
gobj.AddPicture("thai-Massage.jpg", 438, 295);
gobj.AddPicture("meditation.jpg", 298, 300);
gobj.AddPicture("make-up-application.jpg", 262, 394);
gobj.AddPicture("ayurvedic-facial.jpg", 254, 393);
gobj.AddPicture("spa-facial-arizona.jpg", 231, 396);
gobj.AddPicture("shirodhara.jpg", 267, 399);
gobj.AddPicture("spa massage.jpg", 345, 398);
gobj.AddPicture("jeanie-Marcelino-Spa-Director.jpg", 309, 409);
gobj.AddPicture("man getting massage.jpg", 375, 409);
gobj.AddPicture("spa3.jpg", 261, 378);
gobj.AddPicture("spa17.jpg", 263, 377);
gobj.AddPicture("rhonda-Allison-Skin-Care.jpg", 299, 374);
gobj.Scroll();
