// JavaScript Document

var emoot;

if (!emoot) emoot = {};

if (!emoot.slide) emoot.slide = {};

var current_pi;
var current_pi_display;
var pi_count;
var	islide;
var mslide;
var	pi_prev_in			= 0;
var pi_next_in			= 0;
var	image_folder;
var	image_waiting;
var	playing_flash		= 0;
var	fade_state			= 0;
var ie6					= false /*@cc_on || @_jscript_version < 5.7 @*/;
var	thumbnail_width;
var	thumbnail_count;
var	thumbnail_panel_fade;
var	thumbnail_panel_slide;
var thumbnail_slide_amount;
var thumbnail_slide_x	= 1;
var	thumbnail_slide_y	= 0;
var	plinth_opacity		= 0.5;
var	thumbnails_visible	= false;
var thumbnail_timeout	= 0;
var	in_thumbbar			= 0;
var	is_ie				= /MSIE/.test(navigator.userAgent);
var	thumbnail_fade_enabled	= false;
var	thumbnail_slide_enabled	= true;
var piprevg;
var piprevr;
var piprevo;
var pinextg;
var pinextr;
var pinexto;
var	videob;
var	video_x			= 0;
var	video_y			= 0;
var	video_width		= 200;
var	video_height	= 200;
var	video_path;

function tdh_test(v)
{
	var	ele			= document.getElementById("tdh_test");

	ele.innerHTML	= v;
}

function hilite(a, b)
{ 
	document.getElementById(a).setAttribute('src', b.src);
}

function gup(name)
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );

	if( results == null )
		return "";
	else
		return results[1];
}

function empre(w, h, filename)
{
	var	pim	= new Image(w, h);
	pim.src	= "nav/" + filename + ".gif";
	return pim;
}

function emprejpg(w, h, filename)
{
	var	pim	= new Image(w, h);
	pim.src	= filename;
	return pim;
}

function emrnb(n, rnb)
{
	var	a	= new Array(46, 76, 62, 62, 51);
	var	s	= new Array("red", "normal", "bold");

	return empre(a[n - 1], 11, s[rnb - 1] + n);
}

function show_date()
{
	var	par		= document.getElementById("maincontainer");
	var ele		= document.createElement("div");
	var dt		= new Date();
	var month	= new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

	ele.id			= "date";
	ele.innerHTML	= dt.getDate() + " " + month[dt.getMonth()] + " " + dt.getFullYear();
	par.appendChild(ele);
}

function emootslide(ele, x, y, pmask)
{
	this.current_vtarget	= 0;
	this.current_htarget	= 0;
	this.scroll_timer		= 0;
	this.start_ms			= 0;
	this.hscroll			= 0;
	this.vscroll			= 0;
	this.animation_time		= 0;
	this.current_left		= 0;
	this.current_top		= 0;
	this.element			= ele;
	this.in_out_timer		= 0;
	this.in_sub				= 0;
	this.in_main			= 0;
	this.forwards			= 0;
	this.default_left		= x;
	this.default_top		= y;
	this.mask				= pmask;
	this.move(x, y);
}

emootslide.prototype.move = function(x, y)
{
	var	ele		= document.getElementById(this.element);
	var mask	= document.getElementById(this.mask);

	this.current_left	= x;
	this.current_top	= y;
	
	ele.style.left		= x + "px";
	ele.style.top		= y + "px";

	if (mask && this.default_top)
	{
		mask.style.height	= ((1 - Math.abs(y / this.default_top)) * Math.abs(this.default_top)) + "px";
	}
}

emootslide.prototype.get_now = function()
{
	var	now	= new Date();
	return now.getTime();
}

emootslide.prototype.getms = function()
{
	if (this.start_ms > 0)
	{
		var	now				= this.get_now();
		var	old_start_ms	= this.start_ms;
		
		this.start_ms		= now;
		return (now - old_start_ms);
	}

	return 0;
}

emootslide.prototype.draw_step = function()
{
	var	ms	= this.getms();
	var	ele	= document.getElementById(this.element);

	if (this.hscroll)
	{
		this.current_left	+= this.hscroll * (ms / this.animation_time);

		if ((this.hscroll < 0 && this.current_left < this.current_htarget) || (this.hscroll > 0 && this.current_left > this.current_htarget))
		{
			this.current_left	= this.current_htarget;
			this.hscroll		= 0;
		}

		ele.style.left	= Math.round(this.current_left) + "px";
	}

	if (this.vscroll)
	{
		this.current_top	+= this.vscroll * (ms / this.animation_time);

		if ((this.vscroll < 0 && this.current_top < this.current_vtarget) || (this.vscroll > 0 && this.current_top > this.current_vtarget))
		{
			this.current_top	= this.current_vtarget;
			this.vscroll		= 0;
		}

		var	y	= Math.round(this.current_top);
		
		ele.style.top	= y + "px";

		var	mask	= document.getElementById(this.mask);

		if (mask)
			mask.style.height	= ((1 - Math.abs(y / this.default_top)) * Math.abs(this.default_top)) + "px";
	}

	if (this.hscroll == 0 && this.vscroll == 0)
	{
		clearInterval(this.scroll_timer);
		this.scroll_timer	= 0;
	}
}

emootslide.prototype.starth = function(target, ms)
{
	var	ele	= document.getElementById(this.element);
	this.current_left	= parseFloat(ele.style.left);
	this.current_top	= parseFloat(ele.style.top);

	if (this.scroll_timer)
	{
		clearInterval(this.scroll_timer);
		this.scroll_timer	= 0;
	}

	if (ms == 0)
	{
		this.current_left		= target;
		ele.style.left			= target + "px";
	}
	else
	{
		this.current_htarget	= target;
		this.hscroll			= this.current_htarget - this.current_left;
		this.vscroll			= 0;
		this.start_ms			= this.get_now();
		this.animation_time		= ms;
		var self				= this;
		this.scroll_timer		= setInterval(function(){self.draw_step();}, 20);
	}
}

emootslide.prototype.startv = function(target, ms)
{
	var	ele	= document.getElementById(this.element);
	this.current_left	= parseFloat(ele.style.left);
	this.current_top	= parseFloat(ele.style.top);

	if (isNaN(this.current_left))
		this.current_left	= 0;
		
	if (isNaN(this.current_top))
		this.current_top	= 0;

	if (this.scroll_timer)
	{
		clearInterval(this.scroll_timer);
		this.scroll_timer	= 0;
	}

	if (ms == 0)
	{
		this.current_top		= target;
		ele.style.top			= target + "px";
	}
	else
	{
		this.current_vtarget	= target;
		this.hscroll			= 0;
		this.vscroll			= this.current_vtarget - this.current_top;
		this.start_ms			= this.get_now();
		this.animation_time		= ms;
		var	self				= this;
		this.scroll_timer		= setInterval(function(){self.draw_step();}, 20);
	}
}

emootslide.prototype.starthv = function(targeth, targetv, ms)
{
	var	ele	= document.getElementById(this.element);
	this.current_left	= parseFloat(ele.style.left);
	this.current_top	= parseFloat(ele.style.top);

	if (isNaN(this.current_left))
		this.current_left	= 0;
		
	if (isNaN(this.current_top))
		this.current_top	= 0;

	if (this.scroll_timer)
	{
		clearInterval(this.scroll_timer);
		this.scroll_timer	= 0;
	}

	if (ms == 0)
	{
		this.current_left		= targeth;
		ele.style.left			= targeth + "px";
		this.current_top		= targetv;
		ele.style.top			= targetv + "px";
	}
	else
	{
		this.current_htarget	= targeth;
		this.current_vtarget	= targetv;
		this.hscroll			= this.current_htarget - this.current_left;
		this.vscroll			= this.current_vtarget - this.current_top;
		this.start_ms			= this.get_now();
		this.animation_time		= ms;
		var self				= this;
		this.scroll_timer		= setInterval(function(){self.draw_step();}, 20);
	}
}

emootslide.prototype.trigger_sub_main_out = function()
{
	if (this.in_out_timer != 0)
	{
		clearInterval(this.in_out_timer);
		this.in_out_timer	= 0;
	}

	if (this.in_main == 0 && this.in_sub == 0)
	{
		this.forwards	= 0;
		this.starthv(this.default_left, this.default_top, 200);
	}
}

emootslide.prototype.check_sub_and_main = function()
{
	if (this.in_main == 0 && this.in_sub == 0)
	{
		if (this.in_out_timer != 0)
		{
			clearInterval(this.in_out_timer);
			this.in_out_timer	= 0;
		}

		{
			var self = this;
			this.in_out_timer	= setInterval(function() { self.trigger_sub_main_out(); }, 10);
		}
	}
}

emootslide.prototype.main_in = function()
{
	if (this.forwards != 1)
	{
		this.forwards	= 1;
		this.starthv(0, 0, 200);
	}

	this.in_main = 1;
}

emootslide.prototype.main_out = function()
{
	this.in_main = 0;
	this.check_sub_and_main();
}

emootslide.prototype.sub_in = function()
{
	this.in_sub	= 1;
}

emootslide.prototype.sub_out = function()
{
	this.in_sub = 0;
	this.check_sub_and_main();
}

function emootfade(ele, op)
{
	this.fade_timer			= 0;
	this.start_ms			= 0;
	this.animation_time		= 0;
	this.current_opacity	= 0;
	this.current_target		= 0;
	this.element			= ele;
	this.fade_timer			= 0;
	this.fade				= 0;
	this.set_opacity(op);
}

emootfade.prototype.get_now = function()
{
	var	now	= new Date();
	return now.getTime();
}

emootfade.prototype.getms = function()
{
	if (this.start_ms > 0)
	{
		var	now				= this.get_now();
		var	old_start_ms	= this.start_ms;
		
		this.start_ms		= now;
		return (now - old_start_ms);
	}

	return 0;
}

emootfade.prototype.set_opacity = function(op)
{
	var	ele	= document.getElementById(this.element);

	ele.style.opacity	= op;

	if (is_ie)			// /MSIE/.test(navigator.userAgent))
	{
		ele.style.filter	= "alpha(opacity=" + (op * 100) + ")";
//		ele.style.filter	= "alpha(opacity:" + (op * 100) + ")";
	}

	this.current_opacity	= op;
}

emootfade.prototype.draw_step = function()
{
	var	ms	= this.getms();
	var	ele	= document.getElementById(this.element);

	if (this.fade)
	{
		this.current_opacity	+= this.fade * (ms / this.animation_time);

		if ((this.fade < 0 && this.current_opacity < this.current_target) || (this.fade > 0 && this.current_opacity > this.current_target))
		{
			this.current_opacity	= this.current_target;
			this.fade				= 0;
		}

		this.set_opacity(this.current_opacity);
	}

	if (this.fade == 0)
	{
		clearInterval(this.fade_timer);
		this.fade_timer	= 0;
	}
}

emootfade.prototype.start = function(target, ms)
{
	var	ele	= document.getElementById(this.element);

	if (this.fade_timer)
	{
		clearInterval(this.fade_timer);
		this.fade_timer	= 0;
	}

	if (ms == 0)
	{
		this.current_opacity	= target;
		this.set_opacity(target);
	}
	else
	{
		this.current_target	= target;
		this.fade				= this.current_target - this.current_opacity;
		this.start_ms			= this.get_now();
		this.animation_time		= ms;
		var self				= this;
		this.fade_timer			= setInterval(function(){self.draw_step();}, 20);
	}
}

var	current_promo_image	= -1;
var	current_promo_state	= 0;
var	promo_image_waiting;
var promo_imagefade;
var promo_images;

function fade_promo_now(im, alt, lnk)
{
	var	ele		= document.getElementById("promoimage1");
	var	lele	= document.getElementById("promolink");

	lele.setAttribute("href", lnk);

//	if (ie6)
//	{
//		ele.setAttribute('src', im.src);
//		return;
//	}

	var	ele2	= document.getElementById("promoimage2");

	switch (current_promo_state)
	{
	case 0:
		current_promo_state	= 1;
		ele.alt				= alt;
		ele.setAttribute('src', im.src);
		promo_imagefade.start(0, 0);
		break;
	case 1:
		current_promo_state	= 2;
		ele2.alt			= alt;
		ele2.setAttribute('src', im.src);
		promo_imagefade.start(1, 1000);
		break;
	case 2:
		current_promo_state	= 1;
		ele.alt				= alt;
		ele.setAttribute('src', im.src);
		promo_imagefade.start(0, 1000);
		break;
	}
}

function fadepanel(image_filename, alt, lnk)
{
	this.filename		= image_filename;
	this.alt			= alt;
	this.loaded			= false;
	this.image			= new Image();
	this.complete_timer	= 0;
	this.lnk			= lnk;
}

fadepanel.prototype.onload = function()
{
	if (this.image.complete)
	{
		this.loaded		= true;

		if (this.complete_timer)
		{
			clearInterval(this.complete_timer);
			this.complete_timer	= 0;
		}

		if (promo_image_waiting == this.filename)
			fade_promo_now(promo_images[current_promo_image].image, promo_images[current_promo_image].alt, promo_images[current_promo_image].lnk);
	}
	else
		if (this.complete_timer == 0)
		{
			var self			= this;
			this.complete_timer	= setInterval(function(){self.onload();}, 20);
		}
}

fadepanel.prototype.load_image = function()
{
	if (this.loaded)
		return true;

	var	self			= this;
	this.image.onload	= function () { self.onload(); };
	this.image.src		= "images/" + this.filename + ".jpg";
	return false;
}

function display_next_promo_image()
{
	current_promo_image++;

	if (current_promo_image < 0 || current_promo_image >= promo_images.length)
		current_promo_image	= 0;

	promo_image_waiting	= promo_images[current_promo_image].filename;

	if (promo_images[current_promo_image].load_image())
		fade_promo_now(promo_images[current_promo_image].image, promo_images[current_promo_image].alt, promo_images[current_promo_image].lnk);
}

function start_promo()
{
	promo_imagefade			= new emootfade("promoimage2", 0);
	display_next_promo_image();
	
	setInterval(function(){display_next_promo_image();}, 6000);
}

var		menu_hover_count	= 0;

function check_menu_colours(mi, si, acc)
{
	var		i;

	menu_hover_count	+= acc;

	if (menu_hover_count < 0)
		menu_hover_count	= 0;

	if (acc < 0 && menu_hover_count > 0)
		return;

	for (i = 0; i < artmachine_menu.length; i++)
	{
		var		main_menu_item	= document.getElementById("mm" + i);

		if (i == mi && acc > 0)
			main_menu_item.style.color	= "#ee2025";
		else
			main_menu_item.style.color	= "#000";
	}
}

function menu_item(plabel, ptarget, psub_menu)
{
	this.label			= plabel;
	this.target			= ptarget;
	this.sub_menu		= psub_menu;
	this.slide_effect	= 0;
	this.main_index		= 0;
	this.sub_index		= -1;
}

menu_item.prototype.initialise_submenu = function(container, mi, si, ms)
{
	var		obj	= document.createElement("div");
	var		nwa	= document.createElement("a");	

	obj.className	= "submenu_item";
	nwa.href		= this.target;
	nwa.innerHTML	= this.label;
	nwa.id			= "mm" + mi + "sm" + si;
	obj.appendChild(nwa);

	if (ms == this.label)
	{
		var		arrow	= document.createElement("img");

		arrow.src			= "images/arrow_sub.png";

		arrow.style.position	= "relative";
		arrow.style.display		= "block";
		arrow.style.left		= "190px";
		arrow.style.top			= "-14px";
		obj.appendChild(arrow);
	}

	container.appendChild(obj);
	this.main_index	= mi;
	this.sub_index	= si;
}

menu_item.prototype.menu_check = function()
{
	if (this.slide_effect)
		this.slide_effect.main_in();

//	check_menu_colours(this.main_index, -1, 1);
}

menu_item.prototype.initialise = function(id, mm, ms)
{
	var		ele	= document.getElementById("ammenu");
	var		obj	= document.createElement("div");
	var		nwa	= document.createElement("a");

	obj.className		= "ammenu_main";
	nwa.href			= this.target;
	nwa.innerHTML		= this.label;
	nwa.id				= "mm" + id;
	obj.appendChild(nwa);
	ele.appendChild(obj);
	this.main_index	= id;

	if (mm == this.label)
	{
		var		arrow	= document.createElement("img");

		arrow.src				= "images/arrow_main.png";
		arrow.style.position	= "relative";
		arrow.style.display		= "block";
		arrow.style.left		= "220px";
		arrow.style.top			= "-15px";
		obj.appendChild(arrow);
	}
	else
		ms	= null;

	if (this.sub_menu)
	{
		var		i;
		var		smask_id	= "smask" + id;
		var		smenu_id	= "smenu" + id;
		var		smask		= document.createElement("div");
		var		smenu		= document.createElement("div");
		var		smi;

		smask.className			= "submenu_mask";
		smask.id				= smask_id;
		smenu.className			= "submenu_container";
		smenu.id				= smenu_id;

		for (i = 0; i < this.sub_menu.length; i++)
			this.sub_menu[i].initialise_submenu(smenu, id, i, ms);

		smask.appendChild(smenu);
		ele.appendChild(smask);

		if (ms || mm == this.label)
			smask.style.height	= (this.sub_menu.length * 22) + "px";
		else
			this.slide_effect	= new emootslide(smenu_id, 0, this.sub_menu.length * -22, smask_id);
	}

	var	self			= this;
	nwa.onmouseover		= function() { self.menu_check(); };
}

artmachine_menu	= new Array(	new menu_item( "Home",					"index.html" ),
								new menu_item( "Products",				"products.html",
											  new Array(	new menu_item( "Classic",		"classic.html" ),
															new menu_item( "Mini",			"mini.html" ),
															new menu_item( "Multi-Touch",	"touch.html" ),
															new menu_item( "Kiosk",			"kiosk.html" ),
															new menu_item( "Custom",		"custom.html"),
															new menu_item( "Build your own!",   "diy.html"),
															new menu_item( "Special Needs",	"sneeds.html"))),
								new menu_item( "Purchase / Rental",		"buyrent.html" ),
								new menu_item( "Gallery",				"gallery.html",
											  new Array(	new menu_item( "Subtractive",	"paint.html" ),
															new menu_item( "Additive",		"light.html" ))),
								new menu_item( "Promotional Options",	"promote.html" ),
								new menu_item( "Where in the World?",	"installations.html" ),
								new menu_item( "Videos &amp; Downloads", "downloads.html" ),
								new menu_item( "Contact",				"contact.html" ));

function set_op(ename, op)
{
	var	ele	= document.getElementById(ename);

	ele.style.opacity	= op;

	if(/MSIE/.test(navigator.userAgent))
		ele.style.filter	= "alpha(opacity=" + (op * 100) + ")";
}

function emoot_logo()
{
	var	ele	= document.getElementById("emootlogo");
	var	dt	= new Date;

	ele.innerHTML	= '<a href="http://www.emoot.com"><img src="images/emoot.gif" /></a><div id="copyright">eMoot Limited &copy; ' + dt.getFullYear() + '</div>';
}

function initialise_newsletter()
{
	var	ele	= document.getElementById("newsletter");

	ele.innerHTML	=	'<div id="message"><p>To receive the Art Machine newsletter, please enter your<br /> email address here...</p></div>' + 
						'<input type="text" id="email" size="17" />&nbsp;<input type="button" onclick="signup();" id="submit" value="Sign up"; /></div>';
	document.getElementById("email").focus();
}

function initialise_menu(mm, ms)
{
	var		i;

	for (i = 0; i < artmachine_menu.length; i++)
		artmachine_menu[i].initialise(i, mm, ms);

	show_date();
	emoot_logo();
	initialise_newsletter();
}

function check_pi_arrows()
{
	if (current_pi_display <= 0)
		hilite("piprev", piprevo);
	else
		if (pi_prev_in)
			hilite("piprev", piprevr);
		else
			hilite("piprev", piprevg);

	if (current_pi_display >= (pi_count - 1))
		hilite("pinext", pinexto);
	else
		if (pi_next_in)
			hilite("pinext", pinextr);
		else
			hilite("pinext", pinextg);
}

function fade_image_now(im, alt)
{
	var	ele		= document.getElementById("mainimage");

	if (ie6)
	{
		ele.setAttribute('src', im.src);
		return;
	}

	var	ele2	= document.getElementById("mainimage2");

	switch (fade_state)
	{
	case 0:
		fade_state	= 1;
		ele.alt		= alt;
		ele.setAttribute('src', im.src);
		imagefade.start(0, 0);
		break;
	case 1:
		fade_state	= 2;
		ele2.alt	= alt;
		ele2.setAttribute('src', im.src);
		imagefade.start(1, 250);
		break;
	case 2:
		fade_state	= 1;
		ele.alt		= alt;
		ele.setAttribute('src', im.src);
		imagefade.start(0, 250);
		break;
	}	

	ele				= document.getElementById("maincaption");
	ele.innerHTML	= image_array[current_pi_display].caption;
}

function display_image(i)
{
	var	ele;
	var hline	= document.getElementById("pitop");
	var pnum	= document.getElementById("pagenumber");

	current_pi_display	= i;
	check_pi_arrows();
	check_pi_scroll();

	pnum.innerHTML	= (current_pi_display + 1) + " / " + pi_count;

	mslide.starth(9 + ((current_pi_display - current_pi) * (thumbnail_width + 3)), 150);

	if (playing_flash)
	{
		var	ic				= document.getElementById("iframeid");
		var	fc				= document.getElementById("flashvideo");
		fc.removeChild(ic);
		playing_flash		= false;
	}

	if (image_array[i].alt == "video")
	{
		image_waiting			= "";
		fade_image_now(videob, "");

		var fc					= document.getElementById("flashvideo");
		var ic					= document.createElement("iframe");

		ic.width				= video_width;
		ic.height				= video_height;
		ic.frameborder			= "0";
		ic.id					= "iframeid";
		ic.scrolling			= "no";
		fc.appendChild(ic);
		playing_flash			= true;  

//		if (ie6)  
//			ic.src				= "projects/videos/iemoan.html";
//		else
			ic.src				= video_path + image_array[i].filename + ".html";
	}
	else
	{
		image_waiting	= image_array[i].filename;

		if (image_array[i].load_image())
			fade_image_now(image_array[i].image, image_array[i].alt);
	}

	check_pi_arrows();;
}

function pi_hilite_prev(prev_in)
{
	pi_prev_in	= prev_in;
	check_pi_arrows();
}

function pi_hilite_next(next_in)
{
	pi_next_in	= next_in;
	check_pi_arrows();
}

function check_pi_scroll()
{
	if (pi_count <= thumbnail_count)
		return;

	var	new_pi	= current_pi_display - parseInt(thumbnail_count / 2);

	if (new_pi < 0)
		new_pi	= 0;
	else
		if ((new_pi + thumbnail_count) > pi_count)
			new_pi	= pi_count - thumbnail_count;

	if (new_pi != current_pi)
	{
		current_pi	= new_pi;
		islide.starth(current_pi * -(thumbnail_width + 3), 150);
	}
}

function scroll_pi(dir)
{
	if (dir < 0 && current_pi_display <= 0)
	{
		check_pi_arrows();
		return;
	}

	if (dir > 0 && current_pi_display >= (pi_count - 1))
	{
		check_pi_arrows();
		return;
	}

	display_image(current_pi_display + dir);
}

function imagepanel(image_filename, alt, cap)
{
	this.filename		= image_filename;
	this.alt			= alt;
	this.caption		= cap;
	this.loaded			= false;
	this.image			= new Image();
	this.complete_timer	= 0;
}

imagepanel.prototype.onload = function()
{
	if (this.image.complete)
	{
		this.loaded		= true;

		if (this.complete_timer)
		{
			clearInterval(this.complete_timer);
			this.complete_timer	= 0;
		}

		if (image_waiting == this.filename)
			fade_image_now(this.image, this.alt);
	}
	else
		if (this.complete_timer == 0)
		{
			var self			= this;
			this.complete_timer	= setInterval(function(){self.onload();}, 20);
		}
}

imagepanel.prototype.load_image = function()
{
	if (this.loaded)
		return true;

	var	self			= this;
	this.image.onload	= function () { self.onload(); };
	this.image.src		= image_folder + "/" + this.filename + ".jpg";
	return false;
}

function create_div(id)
{
	var	ele	= document.createElement("div");

	ele.id	= id;
	return ele;
}

function create_a(href, id)
{
	var	ele	= document.createElement("a");

	if (href)
		ele.href	= href;
	else
		ele.href	= "#";

	if (id)
		ele.id	= id;

	return ele;
}

function create_img(src, id)
{
	var	ele	= document.createElement("img");

	if (src)
		ele.src	= src;

	if (id)
		ele.id	= id;

	return ele;
}

function setxy(ele, x, y)
{
	ele.style.left		= x + "px";
	ele.style.top		= y + "px";
}

function setwh(ele, w, h)
{
	ele.style.width		= w + "px";
	ele.style.height	= h + "px";
}

function hide_thumbnails()
{
	if (in_thumbbar > 0)
		return;

	if (thumbnails_visible)
	{
		if (thumbnail_slide_enabled)
			thumbnail_panel_slide.starthv(thumbnail_slide_amount * thumbnail_slide_x, 74 * thumbnail_slide_y, 250);

		if (thumbnail_fade_enabled && !is_ie)
			thumbnail_panel_fade.start(0, 250);
		else
			if (!thumbnail_slide_enabled)
				document.getElementById("ps_outer").style.visibility	= "hidden";

		thumbnails_visible	= false;
	}

	thumbnail_timeout	= 0;
}

function reveal_thumbnails()
{
	if (!thumbnails_visible)
	{
		thumbnails_visible	= true;

		if (thumbnail_slide_enabled)
			thumbnail_panel_slide.starthv(0, 0, 250);

		if (thumbnail_fade_enabled && !is_ie)
			thumbnail_panel_fade.start(1, 150);
		else
			if (!thumbnail_slide_enabled)
				document.getElementById("ps_outer").style.visibility	= "visible";
	}

	if (thumbnail_timeout)
	{
		clearTimeout(thumbnail_timeout);
		thumbnail_timeout	= 0;
	}

	if (in_thumbbar == 0)
		thumbnail_timeout	= setTimeout("hide_thumbnails()", 1000);
}

function thumbbar_in(a)
{
	in_thumbbar	+= a;

	if (in_thumbbar < 0)
		in_thumbbar	= 0;

//	tdh_test(in_thumbbar);

	if (a > 0)
	{
		reveal_thumbnails();
	}
	else
		if (in_thumbbar == 0)
			thumbnail_timeout	= setTimeout("hide_thumbnails()", 1000);
}

function initialise_project_images(image_x, image_y, image_w, image_h, ilist_x, ilist_y, ilist_thumbnails, thumbnail_w, im_folder, frame_filename, cap_x, cap_y, pn_x, pn_y)
{
	var	i;
	var ele;
	var im;
	var id;
	var	ni;
	var	newa;
	var	mc;
	var	name;
	var	swidth;
	var	psouter;
	var	plinth;
	var	xxmslide;
	var	pscontainer;
	var	pstrip;
	var	pilist;
	var	piimages;
	var	aim;
	var	reveal			= function () { reveal_thumbnails(); };
	var	reveal_and_lock	= function () { thumbbar_in(1); };
	var	test_lock_out	= function () { thumbbar_in(-1); };

	piprevg	= empre(23, 58, "piprevg");
	piprevr	= empre(23, 58, "piprevr");
	piprevo	= empre(23, 58, "piprevo");
	pinextg	= empre(23, 58, "pinextg");
	pinextr	= empre(23, 58, "pinextr");
	pinexto	= empre(23, 58, "pinexto");
	videob	= 0;

	video_path		= im_folder + "/";

	mc				= document.getElementById("maincontainer");
	image_folder	= im_folder;

	ele				= create_img(image_folder + "/" + frame_filename, "fancy_frame");
	ele.onmousemove	= reveal;
	mc.appendChild(ele);

	name			= "mainimage";
	thumbnail_width	= thumbnail_w;
	thumbnail_count	= ilist_thumbnails;

	for (i = 0; i < 2; i++)
	{
		ni				= create_img(0, name);
		ni.onmousemove	= reveal;
		setxy(ni, image_x, image_y);
		setwh(ni, image_w, image_h);
		mc.appendChild(ni);
		name			= "mainimage2";
	}

	ele					= create_div("flashvideo");
	ele.onmousemove		= reveal;
	setxy(ele, image_x + video_x, image_y + video_y);
	setwh(ele, video_width, video_height);
	mc.appendChild(ele);

	ele					= create_div("maincaption");
	setxy(ele, cap_x, cap_y);
	mc.appendChild(ele);

	ele					= create_div("pagenumber");
	setxy(ele, pn_x, pn_y);
	mc.appendChild(ele);

	swidth				= (ilist_thumbnails * (3 + thumbnail_w)) + 46;

	pscontainer			= create_div("ps_container");
	setxy(pscontainer, image_x + ilist_x, image_y + ilist_y);
	pscontainer.style.width	= (swidth + 14) + "px";
	thumbnail_slide_amount	= swidth + 14;

	psouter				= create_div("ps_outer");
	setxy(psouter, 0, 0);
	psouter.style.width	= (swidth + 14) + "px";
	plinth				= create_div("ps_plinth");
	plinth.style.width	= (swidth + 14) + "px";
	plinth.onmouseover	= reveal_and_lock;
	plinth.onmouseout	= test_lock_out;
	psouter.appendChild(plinth);

	xxmslide			= create_div("mslide");
	ele					= create_img("nav/hitop.gif", "pitop");
	ele.onmouseover		= reveal_and_lock;
	ele.onmouseout		= test_lock_out;
	xxmslide.appendChild(ele);
	ele					= create_img("nav/hibottom.gif", "pibottom");
	ele.onmouseover		= reveal_and_lock;
	ele.onmouseout		= test_lock_out;
	xxmslide.appendChild(ele);
	psouter.appendChild(xxmslide);

	pstrip				= create_div("portfolio_strip");
	pstrip.onmouseover	= reveal_and_lock;
	pstrip.onmouseout	= test_lock_out;
	pstrip.style.width	= swidth + "px";
	pilist				= create_div("pilist");
	piimages			= create_div("piimages");
	pilist.appendChild(piimages);
	pstrip.appendChild(pilist);

	ele					= create_a();
	ele.onclick			= function () { scroll_pi(-1); };
	ele.onmouseover		= function () { pi_hilite_prev(1); };
	ele.onmouseout		= function () { pi_hilite_prev(0); };
	aim					= create_img("nav/piprevg.gif", "piprev");
	aim.style.left		= (swidth - 46) + "px";
	ele.appendChild(aim);
	pstrip.appendChild(ele);

	ele					= create_a();
	ele.onclick			= function () { scroll_pi(1); };
	ele.onmouseover		= function () { pi_hilite_next(1); };
	ele.onmouseout		= function () { pi_hilite_next(0); };
	aim					= create_img("nav/pinextg.gif", "pinext");
	aim.style.left		= (swidth - 23) + "px";
	ele.appendChild(aim);
	pstrip.appendChild(ele);

	psouter.appendChild(pstrip);
	pscontainer.appendChild(psouter);

	mc.appendChild(pscontainer);

	set_op("ps_plinth", plinth_opacity);

	if (thumbnail_slide_enabled)
		thumbnail_panel_slide	= new emootslide("ps_outer", thumbnail_slide_amount * thumbnail_slide_x, 74 * thumbnail_slide_y);

	if (thumbnail_fade_enabled && !is_ie)
		thumbnail_panel_fade	= new emootfade("ps_outer", 0);
	else
		if (!thumbnail_slide_enabled)
			psouter.style.visibility	= "hidden";

	pi_count	= image_array.length;

	if (pi_count == 0)
	{
		document.getElementById("piprev").style.visibility		= "hidden";
		document.getElementById("pinext").style.visibility		= "hidden";
		document.getElementById("pitop").style.visibility		= "hidden";
		document.getElementById("pibottom").style.visibility	= "hidden";
		return;
	}

	ele	= document.getElementById("pitop");

	for (i = 0; i < 2; i++)
	{
		ele.style.width	= thumbnail_w + "px";
		ele.style.top	= (3 + (i * 65)) + "px";
		ele				= document.getElementById("pibottom");
	}

	for (i = 0; i < pi_count; i++)
	{
		newa				= create_a();
		id					= "pi" + i;
		im					= document.createElement(id);
		im.style.position	= "absolute";
		im.style.left		= 2 + (i * (thumbnail_w + 3)) + "px";
		im.style.top		= "2px";
		ni					= create_img(image_folder + "/" + "thumbs/" + image_array[i].filename + ".jpg");
		ni.onmouseover		= reveal_and_lock;
		ni.onmouseout		= test_lock_out;
		ni.alt				= image_array[i].alt;
		newa.className		= "" + i;
		newa.onclick		= function() { display_image(parseInt(this.className)); };
		im.appendChild(ni);
		newa.appendChild(im);
		piimages.appendChild(newa);

		if (image_array[i].alt == "video" && videob == 0)
			videob	= emprejpg(image_w, image_h, im_folder + "/vframe.jpg");
	}

	islide				= new emootslide("piimages", 0, 0);
	mslide				= new emootslide("mslide", 0, 0);
	current_pi			= 0;
	imagefade			= new emootfade("mainimage2", 0);

	display_image(0);
}

function signup()
{	
	var	em	= document.getElementById("email").value;
	var	ele	= document.getElementById("message");

	var good_email = em.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.sex)|(\.biz)|(\.aero)|(\.coop)|(\.museum)|(\.name)|(\.pro)|(\..{2,2}))$)\b/gi);

	if (good_email)
	{
		document.getElementById("signup").innerHTML		= "<iframe src='http://www.squirtualreality.com/signup.php?e=" + em + "' width='0' height='0' ></iframe>";

		ele.innerHTML	= "<p>&nbsp;<br>Thankyou for registering!<br>&nbsp;</p>";
	}
	else
	{
		ele.innerHTML	= "<p>&nbsp;<br>Please enter a valid email address<br>&nbsp;</p>";
		ele	= document.getElementById("email");
		ele.focus();
	}
}
