/*------------------------------------------
|  Core Lib For use with : Chatter - RAC 
|			 (c) kM0ti0n 2005
|
|	web : http://km0ti0n.blunted.co.uk
|  mail : km0ti0n@gmail.com
|  date : 22/01/2006
--------------------------------------------*/


/*Bass Class*/

function Base(){ 
	this.Controls			= (new Controls()).instanceOf();
}

Base.prototype						= new Object();	
Base.prototype.constructor			= Base;
Base.prototype.ClassName			= "Base";
Base.prototype.CSSClass				= "";
Base.prototype.Parent				= null;	
Base.prototype.ParentElement		= null;	
Base.prototype.MultiChildElements	= false;	
Base.prototype.TopElement			= null;	
Base.prototype.IdCounter			= 0;
Base.prototype.Events				= new Array();
Base.prototype.Init					= function (){};
Base.prototype.ToString				= function () {	return this.ClassName;	}
Base.prototype.toString				= function () { return this.ToString();	}
Base.prototype.Dependant			= [];



Base.prototype.PreInit			= function ()
{
	//document.body.onselectstart = function (  ){return false;}	
	this.CSSClass = this.ClassName;
	for( var i = 0; i < this.Events.length; i++)
	{
		this.AddEvent( this.Events[i] );
	}
	this.Base = this.prototype;
}

// Creates and Appends a new element of type tagName to parent
Base.prototype.NewObj = function (tagName, props, parent, text, doc )
{
	var o;
	if (!doc){ doc = document}
	o = doc.createElement(tagName)
	if (props) for (var p in props) o[p]=props[p];
	if (parent) parent.appendChild(o);
	if (text) o.appendChild(doc.createTextNode(text));
	// Adding FindXY functionality to ALL new Objs
	o.FindXY = function ()
	{
		var obj = this, x=0,y=0;
		while (obj!=null)
		{
			x	+=	obj.offsetLeft-obj.scrollLeft;
			y	+=	obj.offsetTop-obj.scrollTop;
			obj	=	obj.offsetParent;
		}
		return {x:x,y:y};
	}
	return o;
}

// Generates a Unique ID for an Element
Base.prototype.NewId = function (cString)
{ 
	if( !cString ) { cString = this.ToString(); }
	this.IdCounter++;
	return cString + this.IdCounter;
}

// Creates a New Event Caller & Handler
Base.prototype.AddEvent = function (cEvent)
{
	var self = this;
	this[cEvent.substring(2)] = new Event(self, cEvent);
	
	var lNew	= true;
	for( var i = 0; i < this.Events.length; i++)
	{
		if( this.Events[i] == cEvent  )
		{
			lNew = false;
		}
	}
	if ( lNew )
	{
		this.Events[this.Events.length] = cEvent;
	}
	self = null;
}

// Clears all Events and remover circular refferences to parent objects;
Base.prototype.Dispose = function ()
{
	this.PreDispose();
	// Insert Custom Class Dispose code here;
	this.PostDispose();
}

Base.prototype.PreDispose = function ()
{
	for( var i = 0; i < this.Events.length; i++)
	{
		this[this.Events[i]] = null;
		this[this.Events[i].substring(2)] = null;
	}
	for( var i = 0; i < this.Controls.length; i++)
	{
		this.Controls[i].Dispose();
		this.Controls[i] = null;
	}
	
}
Base.prototype.PostDispose = function ()
{
	if(this.ParentElement && !this.MultiChildElements)
	{	
		this.ParentElement.innerHTML = "";
	}
	else if( this.TopElement )
	{	
		this.ParentElement.removeChild( this.TopElement );
	}

	this.Parent			= null;	
	this.ParentElement	= null;	
}


// A collection of all the Objects that are Added to the App
function Controls()
{
	this.instanceOf = function ()
	{
		var self = new Array();
		self.Add = function ( oControl )
		{
			if( oControl )
			{	 
				this[this.length] = oControl;
				
				oControl.PreInit();
				oControl.Init();
			}
		}
		return self;
	}
} 

// Event Handler Called from Base.AddEvent("onsomeevent")
// Creates Base.onsomeevent and Base.someevent.Fire(oEvent);
function Event(self, cEvent)	{ this.Self = self; this.cEvent = cEvent; }
Event.prototype					= new Object();
Event.prototype.constructor		= Event;
Event.prototype.Self			= null;
Event.prototype.cEvent			= "";

Event.prototype.Fire			= function (oEvent)
{
	if(this.Self[this.cEvent])
	{
		this.Self[this.cEvent](oEvent);
	}
	else
	{	
		if(this.Self.Parent)
		{
			this.Self.Parent.AddEvent( this.cEvent );
			this.Self.Parent[this.cEvent.substring(2)].Fire(oEvent);
		}
		else
		{
			alert("nothing to do");
		}
	}
}

// Renders png correctly in IE and 
//just renders normal img's for FF
function PNG( imgName, props, parent )
{
	var img = document.createElement( "img" )
	if( window.attachEvent && !window.opera)
	{
		img.src = "images/png.gif";
		img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\"" + imgName + "\", sizingMethod='image');";
	}
	else
	{
		img.src = imgName;
	}
	if (props) for (var p in props) img[p]=props[p];
	img.style.border = "solid 0px";
	return parent.appendChild( img );
}


function AddClass(obj,cName){ KillClass(obj,cName); return obj.className+=(obj.className.length>0?' ':'')+cName; }
function KillClass(obj,cName){ return obj.className=obj.className.replace(new RegExp("^"+cName+"\\b\\s*|\\s*\\b"+cName+"\\b",'g'),''); }
function HasClass(obj,cName){ return (!obj || !obj.className)?false:(new RegExp("\\b"+cName+"\\b")).test(obj.className) }
function RemoveClass(obj,cName){ KillClass(obj,cName) }


Array.prototype.removeItem=function(el){
	// *** Removes an item from the Array by value (not index)
	for (var i=0;i<this.length;i++) if (this[i]==el) this.splice(i,1);
}

Array.prototype.indexOf=function(el){
	for (var i=0;i<this.length;i++) if (this[i]==el) return i;
	return -1;
}


var __cCurrentCursor = "";
function SetCursor( cCursor )
{
	if( !cCursor )
	{		
		RemoveClass(document.documentElement, __cCurrentCursor);
	}
	else
	{
		__cCurrentCursor = cCursor;
		if( !HasClass(document.documentElement, __cCurrentCursor) )
		{
			AddClass(document.documentElement, __cCurrentCursor);
		}
	}
}

function FindXY(obj)
{
	var x=0,y=0;
	while (obj!=null)
	{
		x	+=	obj.offsetLeft-obj.scrollLeft;
		y	+=	obj.offsetTop-obj.scrollTop;
		obj	=	obj.offsetParent;
	}
	return {x:x,y:y};
}

if (typeof Number.prototype.toFixed!='function' || (.9).toFixed()=='0' || (.007).toFixed(2)=='0.00') Number.prototype.toFixed=function(f){
	if (isNaN(f*=1) || f<0 || f>20) f=0;
	var s='',x=this.valueOf(),m='';
	if (this<0){ s='-'; x*=-1; }
	if (x>=Math.pow(10,21)) m=x.toString();
	else{
		m=Math.round(Math.pow(10,f)*x).toString();
		if (f!=0){
			var k=m.length;
			if (k<=f){
				var z='00000000000000000000'.substring(0,f+1-k);
				m=z+m;
				k=f+1;
			}
			var a = m.substring(0,k-f);
			var b = m.substring(k-f);
			m = a+'.'+b;
		}
	}
	if (m=='0') s='';
	return s+m;
}


function renderDate(el, e)
{
	if(XAPDatePicker)
	{
		var evt = e || event;
		evt.src = evt.target || evt.srcElement
		var oPicker = new XAPDatePicker();
		oPicker.ParentElement = el;
		oPicker.Parent = null;
		oPicker.Event = evt; 
	//	oPicker.Target = el; 
		oPicker.Init();
	}
}

function getElementsByClassName(node, classname)
{
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for (var i=0, j=els.length; i<j; i++)
    {
        if(re.test(els[i].className)) { a.push(els[i]); }
    }
    return a;
}

function SetFocus(e, oInput)
{
	e = e || event;
	
	//alert(e.keyCode);
	if ( e.keyCode == 13 ) 
	{
		if (window.event) window.event.cancelBubble = true;
		searchclick(); 
		return false; 
	}
	return true;
}

function searchclick()
{
    if ( document.getElementById("ipSearchBox").value != "" ) { location.href = "searchproducts?SearchText=" + document.getElementById("ipSearchBox").value; }
}	// mozXPath [http://km0ti0n.blunted.co.uk/mozxpath/] km0ti0n@gmail.com
// Code licensed under Creative Commons Attribution-ShareAlike License 
// http://creativecommons.org/licenses/by-sa/2.5/
if( document.implementation.hasFeature("XPath", "3.0") )
{
	XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

		var oNSResolver = this.createNSResolver(this.documentElement)
		var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
		var aResult = [];
		for( var i = 0; i < aItems.snapshotLength; i++)
		{
			aResult[i] =  aItems.snapshotItem(i);
		}
		
		return aResult;
	}
	XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

		var xItems = this.selectNodes(cXPathString, xNode);
		if( xItems.length > 0 )
		{
			return xItems[0];
		}
		else
		{
			return null;
		}
	}

	Element.prototype.selectNodes = function(cXPathString)
	{
		if(this.ownerDocument.selectNodes)
		{
			return this.ownerDocument.selectNodes(cXPathString, this);
		}
		else{throw "For XML Elements Only";}
	}

	Element.prototype.selectSingleNode = function(cXPathString)
	{	
		if(this.ownerDocument.selectSingleNode)
		{
			return this.ownerDocument.selectSingleNode(cXPathString, this);
		}
		else{throw "For XML Elements Only";}
	}

}
/** XHConn - Simple XMLHTTP Interface - brad@xkr.us - 2005-01-24             **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XAP()
{
  var xmlhttp;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest();}
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4) {
        fnDone(xmlhttp); }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

//-----------------------------------------------------------
//
//		Toolbar For FrameWork
//
//		Renders a XAPDataList
//
//		Requires : CoreLib.js, Base.js
//
//-----------------------------------------------------------

function XAPDataList(){}
XAPDataList.prototype					= new Base();
XAPDataList.prototype.constructor		= XAPDataList();
XAPDataList.prototype.ClassName			= "XAPDataList";
XAPDataList.prototype.ePane				= null;
XAPDataList.prototype.DataSource		= null;
XAPDataList.prototype.aSelectedItems	= [];
XAPDataList.prototype.oSelectedItem		= null;
XAPDataList.prototype.DataTextField		= "";
XAPDataList.prototype.DataIdField		= "";
XAPDataList.prototype.MultiSelect		= false;
XAPDataList.prototype.Disabled			= false;


XAPDataList.prototype.Events			= [];

XAPDataList.prototype.Init				= function ()
{
	
}	

XAPDataList.prototype.DataBind			= function ()
{
	if( this.ePane ){ this.ParentElement.removeChild( this.ePane ); }
	
	this.ePane = this.NewObj( "div", {className:'XAPDataList'}, this.ParentElement, "" );
	
	for( var i = 0; i < this.DataSource.length; i++  )
	{
		var Text = "";
		var Id	 = "";
		if( this.DataSource.constructor ==  Array )
		{
			Text	= this.DataSource[i][0];
			Id		= this.DataSource[i][1];
		}
		else
		{
			Text	= this.DataSource[i].getElementsByTagName(this.DataTextField)[0].text;
			Id		= this.DataSource[i].getElementsByTagName(this.DataIdField)[0].text;
		}
		
		var oItem				= new XAPListItem(Text, Id);
		oItem.Parent			= this;
		oItem.ParentElement		= this.ePane;
		this.Controls.Add( oItem );
	}
}

XAPDataList.prototype.onItemSelected	= function ( oItem )
{

	if( !this.MultiSelect )
	{
		if(this.oSelectedItem && !this.MultiSelect)
		{
			this.oSelectedItem.Deselect();
		}
		this.oSelectedItem = oItem;
	}
	else
	{
		var lNew = true;
		for( var i = 0; i < this.aSelectedItems.length; i++ )
		{
			if( this.aSelectedItems[i] == oItem )
			{
				oItem.Deselect();
				lNew = false;
				this.aSelectedItems.removeItem( oItem );
			}
		}
		if( lNew )
		{
			this.aSelectedItems[this.aSelectedItems.length] = oItem;
		}
	}
}

XAPDataList.prototype.Append	= function ( cText, cItemID )
{
	var oItem				= new XAPListItem(cText, cItemID);
	oItem.Parent			= this;
	oItem.ParentElement		= this.ePane;
	this.Controls.Add( oItem );
}

XAPDataList.prototype.Remove	= function ( oItem )
{
	if( !oItem ){ return false; }
	if( !this.MultiSelect )
	{
		if( this.oSelectedItem == oItem )
		{
			this.oSelectedItem.Deselect();
			this.oSelectedItem = null;
		}
	}
	else
	{
		for( var i = 0; i < this.aSelectedItems.length; i++ )
		{
			if( this.aSelectedItems[i] == oItem )
			{
				oItem.Deselect();
				this.aSelectedItems.removeItem( oItem );
			}
		}
	}
	
	var lExist = false;
	for( var i = 0; i < this.Controls.length; i++ )
	{	
		if ( this.Controls[i] == oItem )
		{	
			lExist	= true;
		}
	}
		
	if( !lExist ) { return false; }

	this.Controls.removeItem( oItem );
	this.ePane.removeChild(oItem.oItem);
	
	return true;
}

XAPDataList.prototype.Disable	= function ( )
{
	this.ePane.style.filter = "alpha(opacity=30)";
	this.Disabled = true;
}
XAPDataList.prototype.Enable	= function ( )
{
	this.ePane.style.filter = "alpha(opacity=100)";
	this.Disabled = false;
}
//-----------------------------------------------------------
//
//		Toolbar For FrameWork
//
//		Renders a XAPListItem
//
//		Requires : CoreLib.js, Base.js
//
//-----------------------------------------------------------

function XAPListItem(cText, cItemID){ this.cText = cText; this.cItemID = cItemID; }
XAPListItem.prototype				= new Base();
XAPListItem.prototype.constructor	= XAPListItem();
XAPListItem.prototype.ClassName		= "XAPListItem";
XAPListItem.prototype.oItem			= null;
XAPListItem.prototype.cText			= "";
XAPListItem.prototype.cItemID		= "";

XAPListItem.prototype.Events		= ["onItemSelected"];

XAPListItem.prototype.Init			= function ()
{
	var self = this;
	this.oItem = this.NewObj( "div", {}, this.ParentElement, this.cText );
	this.oItem.onmouseover	= function (){ AddClass(this, "hover");		}
	this.oItem.onmouseout	= function (){ RemoveClass(this, "hover");	}
	this.oItem.onclick		= function ()
	{ 
		if( !self.Parent.Disabled )
		{
			AddClass(this, "selected");  self.ItemSelected.Fire( self ); 
		}
	}	
}	

XAPListItem.prototype.Deselect		= function ()
{
	RemoveClass( this.oItem, "selected" );
}

//-----------------------------------------------------------
//
//		Toolbar For FrameWork
//
//		Renders a XAPDatePicker
//
//		Requires : CoreLib.js, Base.js
//
//-----------------------------------------------------------

function XAPDatePicker(){}; _this = XAPDatePicker.prototype = new Base();
_this				= XAPDatePicker.prototype;
_this.constructor	= XAPDatePicker();
_this.ClassName		= "XAPDatePicker";
_this.ePane			= null;
_this.eTitleBar		= null;
_this.eContentArea	= null;
_this.eStatusBar	= null;
_this.cTitle		= "";
_this.ShowTitleBar	= true;
_this.ShowStatusBar	= true;
_this.Resizable		= false;
_this.DragingWindow	= false;
_this.MousePosition	= [0,0];
_this.XAP			= new XAP();
_this.ChildWindows	= [];
_this.State			= "Windowed";
_this.MinSize		= [0,0];
_this.Modal			= false;
_this.Width			= 200;
_this.Height		= 147;
_this.dDate			= new Date();
_this.StartYear		= 1995;
_this.EndYear		= 2015;
_this.Target		= null;
//_this.Left				= 100;
//_this.Top				= 100;


	

_this.Events		= [];

_this.Init			= function ()
{	
	
	if(this.Modal){this.eModal  = this.NewObj( "div", {className:"XAPDialogModal"}, document.body, "" );}
	var aSel = document.getElementsByTagName("select");
	for( var i=0;i<aSel.length; i++ ){ aSel[i].style.visibility = "hidden"; }
	this.Target = this.Event.src;
	this.cId					= "cclDialog" +  this.Target.name; 
	this.ePane					= this.NewObj( "div", {className:"XAPDialog", id:this.cId}, document.body, "" );
	
	if ( this.Width  != null ) { this.ePane.style.width  = this.Width;}
	if ( this.Height != null ) { this.ePane.style.height = this.Height;}
	this.ePane.style.top    = FindXY(this.Target).y;
	this.ePane.style.left   = FindXY(this.Target).x;
	this.dDate = new Date( this.Event.src.value.split("/")[2], (+this.Event.src.value.split("/")[1]-1), this.Event.src.value.split("/")[0] );
	if ( this.cTitle == null ) { this.cTitle			 = "Select Date";}
	var self = this;

	//this.eTitleBar		= this.NewObj( "div", {className:"XAPTitleBar", CCLIdToDrag:this.cId}, this.ePane, "" );
	//this.eTitle = this.NewObj( "span", {}, this.eTitleBar, this.cTitle );
	
	
	/* Content Area */
	this.eContentHolder	= this.NewObj( "div", {className:"XAPContentHolder"}, this.ePane, "" );
	this.eContentArea	= this.NewObj( "div", {className:"XAPContentArea"}, this.eContentHolder, "" );
	
	var self = this;
				
	this.lnkClose				 = this.NewObj("a", {className:'DialogButton', href:'#'}, this.eContentArea, "X");
	this.lnkClose.onclick        = function (){ self.Dispose(); return false; }
	this.lnkClose.style.position = 'absolute';
	this.lnkClose.style.top		 = '0px';
	this.lnkClose.style.right    = '0px';
	this.lnkClose.style.width	 = '20px';
	this.lnkClose.style.height	 = '20px';
	this.Target.blur();
	
	this.RenderCalender();
}	

_this.RenderCalender = function ()
{		
	var self = this;
	
	this.eSelects = this.NewObj("div", {}, this.eContentHolder, "");
	/*Months*/
	this.eMonth = this.NewObj("select", {}, this.eSelects, "");
	this.NewObj("option", {value:"1"}, this.eMonth, "January");
	this.NewObj("option", {value:"2"}, this.eMonth, "February");
	this.NewObj("option", {value:"3"}, this.eMonth, "March");
	this.NewObj("option", {value:"4"}, this.eMonth, "April");
	this.NewObj("option", {value:"5"}, this.eMonth, "May");
	this.NewObj("option", {value:"6"}, this.eMonth, "June");
	this.NewObj("option", {value:"7"}, this.eMonth, "July");
	this.NewObj("option", {value:"8"}, this.eMonth, "August");
	this.NewObj("option", {value:"9"}, this.eMonth, "September");
	this.NewObj("option", {value:"10"}, this.eMonth, "October");
	this.NewObj("option", {value:"11"}, this.eMonth, "November");
	this.NewObj("option", {value:"12"}, this.eMonth, "December");
	
	/*Years*/
	this.eYear = this.NewObj("select", {}, this.eSelects, "");
	for( var i = this.StartYear; i <= this.EndYear; i++ )
	{
		this.NewObj("option", {value:i}, this.eYear, i);
	}
	
	
	this.eMonth.value = this.dDate.getMonth() + 1;
	this.eMonth.onchange = function()
	{
		self.dDate = new Date( self.dDate.getFullYear() + "/" + this.value + "/" + self.dDate.getDate() );
		self.RenderDays();
	}

	this.eYear.value = this.dDate.getFullYear();
	this.eYear.onchange = function()
	{
		self.dDate = new Date( this.value + "/" + self.dDate.getMonth() + "/" + self.dDate.getDate() );
		self.RenderDays();
	}
	this.eSelects.style.textAlign = "left";
	this.eMonth.style.margin = "5px";
	this.eYear.style.margin = "5px";
	
	this.RenderDays();
}

_this.RenderDays = function ()
{
	var self = this;
	
	if( this.eDays ){ this.eDays.outerHTML = ""; this.eDays = null; }
	this.eDays = this.NewObj("div", {}, this.eContentHolder, "");
	this.eDays.style.width			= "100%";	 
	this.eDays.style.height			= "";	 	 
	
	var table = this.NewObj( "table", {className:"Cal", border:0, cellPadding:0, cellSpacing:0}, this.eDays, "" )
	table.style.width = "100%"
	table.style.border = "solid 0px";
	table.style.borderTop = "solid 1px #d0d0d0";
	var thead = this.NewObj( "thead", {}, table, "" )


	var tr = this.NewObj( "tr", {}, thead, "" );

	tr.style.backgroundColor = "#f0f0f0";
	tr.style.color = "black";
	td = this.NewObj( "td", {}, tr, "M" );
	td.style.borderBottom = "solid 1px #d0d0d0";
	td = this.NewObj( "td", {}, tr, "T" );
	td.style.borderBottom = "solid 1px #d0d0d0";
	td = this.NewObj( "td", {}, tr, "W" );
	td.style.borderBottom = "solid 1px #d0d0d0";
	td = this.NewObj( "td", {}, tr, "T" );
	td.style.borderBottom = "solid 1px #d0d0d0";
	td = this.NewObj( "td", {}, tr, "F" );
	td.style.borderBottom = "solid 1px #d0d0d0";
	td = this.NewObj( "td", {}, tr, "S" );
	td.style.borderBottom = "solid 1px #d0d0d0";
	td = this.NewObj( "td", {}, tr, "S" );
	td.style.borderBottom = "solid 1px #d0d0d0";
	
	var nDaysInMonth  = new Date(this.dDate.getFullYear(), this.dDate.getMonth() + 1, 0).getDate();
	this.dTemp = new Date(this.dDate.getFullYear(), this.dDate.getMonth(), 0);

	var tbody = this.NewObj( "tbody", {}, table, "" )
	tr = this.NewObj( "tr", {}, tbody, "" );
	
	var lFirstWeek = true;
	var nDay = 0;
	var lEOW = false;
	for( var i = 1; i <=42 ; i++  )
	{
		if( lFirstWeek )
		{
			if( i == this.dTemp.getDay() + 1 || i == 7  ){	lFirstWeek = false;	nDay++;	}
		}
		else if( nDay < nDaysInMonth  && !lEOW ){	nDay++;	}
		else	{	nDay = 0;	lEOW = true	}
		
		var cDay = "";
		if( nDay != 0 ){ cDay = nDay; }
		var td = this.NewObj( "td", {}, tr, cDay );
		td.style.backgroundColor="white";
		if( cDay != "" )
		{
			td.day = cDay;
			td.onclick = function (){ self.updateDate(this.day); }
			td.style.cursor = "pointer";
			td.style.color = "#54328D";
			td.style.fontWeight = "bold";
			td.onmouseover = function(){this.style.backgroundColor="#54328D";this.style.color="white";}
			td.onmouseout  = function(){this.style.backgroundColor="white";this.style.color="#54328D";}
		
			if( Math.floor(i/7) == i/7 || Math.floor((i+1)/7) == (i+1)/7 )	
			{	
				// SAT / SUN
				td.style.backgroundColor="#f0f0f0";
				td.onmouseout  = function(){this.style.backgroundColor="#f0f0f0";this.style.color="#54328D";}
			}
			
			if( cDay == this.dDate.getDate() )
			{
				td.style.backgroundColor="#d0d0d0";
				td.onmouseout  = function(){this.style.backgroundColor="#d0d0d0";this.style.color="#54328D";}
				//#54328D
			}
			
			
		}
		
		if( Math.floor(i/7) == i/7  )	{	tr = this.NewObj( "tr", {}, tbody, "" );	}						
	}

}

_this.updateDate = function(nDay)
{
	this.Target.value = nDay + "/" + (+this.dDate.getMonth()+1) + "/" + this.dDate.getFullYear();
	
	if ( this.Target.getAttribute("peerdate") != null )
	{
		document.getElementById(this.Target.getAttribute("peerdate")).value = this.Target.value;
	}
	
	this.Dispose();
}

_this.Blur			= function (cText)
{
	AddClass(this.ePane, "Blured");
	this.ePane.style.zIndex = 900;
}

_this.Dispose = function ()
{
	if(this.Model){this.eModal.outerHTML = "";}
	//this.ePane.outerHTML = "";
	this.ePane.parentNode.removeChild( this.ePane );
	var aSel = document.getElementsByTagName("select"); for( var i=0;i<aSel.length; i++ ){ aSel[i].style.visibility = ""; }
}

_this.ReSize = function()
{
	if ( this.Width  != null ) { this.ePane.style.width  = this.Width;}
	if ( this.Height != null ) { this.ePane.style.height = this.Height;}
	if ( this.Top    != null ) { this.ePane.style.top    = this.Top;}
	if ( this.Left   != null ) { this.ePane.style.left   = this.Left;}	
}

_this.SetTitle = function(cTitle)
{
	if( cTitle ){ this.cTitle = cTitle }
	this.eTitle.innerHTML = cTitle;
}

/*------------------------------------------
|
|  Address Lookup For use with : CRCWeb 
|			 (c) CCL 2006
|
|	web : http://www.companioncomputers.co.uk
|  mail : Andrew@compan.net / km0ti0n@gmail.com
|  date : 06/02/2006
| 
--------------------------------------------*/

function XAPAddressLookup(){}
var _this = XAPAddressLookup.prototype = new XAPDataList();
_this.constructor	= XAPAddressLookup();
_this.ClassName		= "XAPAddressLookup";
_this.XAP			= new XAP();
_this.Events		= [];
_this.address1		= "";
_this.address2		= "";	
_this.address3		= "";
_this.town			= "";
_this.county		= "";
_this.postcode		= "";
_this.aAddress		= [];

_this.Init = function()
{
	var aSel = document.getElementsByTagName("select"); for( var i=0;i<aSel.length; i++ ){ aSel[i].style.visibility = "hidden"; }
	var self = this; 
	window.status = "Looking up Address for Postcode : " + this.cPostCode.toUpperCase();
	this.aAddress = [];
	/* Render ListArea */
	this.ePane = this.NewObj("div", { id:"AddressList" }, this.ParentElement);
	this.NewObj( "p", {}, this.ePane, "Please wait, retrieving list of houses names and address information for the postcode : ");
	this.NewObj( "p", {}, this.ePane, this.cPostCode.toUpperCase() );
	this.NewObj( "img", {src:"../images/Loading.gif"}, this.ePane  );
	var oCords = FindXY( this.oParentElement );
	this.ePane.style.top	= (oCords.y) + "px";
	this.ePane.style.left	= (oCords.x + 80) + "px";
	this.XAP = new XAP();
	if(!this.XAP){ alert("Please upgrade your browser.\nThe technique used on this page is over 5 years old, and as such is common practice.") }
	var fnXAPResult  = function(oXML){ self.RenderList(oXML); }
	this.XAP.connect("addresslookup.asmx/Lookup", "POST", "cPostcode=" + this.cPostCode, fnXAPResult );
	
}

_this.RenderList = function(oXml)
{
	window.status = "Looking up Address for Postcode : FOUND";

	this.ePane.innerHTML = "";
	try{ this.address1	= oXml.responseXML.documentElement.selectSingleNode("//address1/text()").nodeValue;		}catch(e){}
	try{ this.address2	= oXml.responseXML.documentElement.selectSingleNode("//address2/text()").nodeValue;		}catch(e){}
	try{ this.address3	= oXml.responseXML.documentElement.selectSingleNode("//address3/text()").nodeValue;		}catch(e){}
	try{ this.town		= oXml.responseXML.documentElement.selectSingleNode("//town/text()").nodeValue;			}catch(e){}
	try{ this.county	= oXml.responseXML.documentElement.selectSingleNode("//county/text()").nodeValue;		}catch(e){}
	try{ this.postcode	= oXml.responseXML.documentElement.selectSingleNode("//post_code/text()").nodeValue;	}catch(e){}
		
	this.DataSource = oXml.responseXML.documentElement.selectNodes("//address");
	this.DataBind();

}

_this.DataBind = function()
{
	
	window.status = "Looking up Address for Postcode : RENDERING";
	var self = this;
	this.ePane.onselectstart = function(){ return false; }
	for( var i = 0; i < this.DataSource.length; i++  )
	{
		try
		{
			//Build Address			
			var cBuilding = ""; try{ cBuilding = this.DataSource[i].selectSingleNode("building/text()").nodeValue }catch(e){}
			var cSubBuild = ""; try{ cSubBuild = this.DataSource[i].selectSingleNode("subbuild/text()").nodeValue }catch(e){}
			var cNumber   = ""; try{ cNumber   = this.DataSource[i].selectSingleNode("number/text()").nodeValue   }catch(e){}
			var cOrganise = ""; try{ cOrganise = this.DataSource[i].selectSingleNode("organise/text()").nodeValue }catch(e){}
			
			var cAddress = "";
			
			if		( cSubBuild != "" )	{ cAddress += cSubBuild + ", "; }
			if		( cBuilding != "" )	{ cAddress += cBuilding;		}
			else if	( cNumber   != "" ) { cAddress += cNumber;			}
			
			if( cAddress != "" ){ this.aAddress[this.aAddress.length] = cAddress; }
			
		}catch(e){}
	}
	
	this.aAddress.sort();
	for( var i = 0; i < this.aAddress.length; i++  )
	{
		var Text = Id = this.aAddress[i];
		if(this.address2 != ""){	Text += ", " + this.address2; }
		var oItem				= new XAPListItem(Text, Id);
		oItem.Parent			= this;
		oItem.ParentElement		= this.ePane;
		this.Controls.Add( oItem );
		oItem.oItem.oldclick = oItem.oItem.onclick;
		oItem.oItem.onclick = function(){ this.oldclick(); self.PopulateAddress(); }
	}
	window.status = "Please Select an Addrees.";
	
	if( this.aAddress.length == 0 ){ alert("Sorry unable to find Address for the Postcode.\n\nPlease check the postcode you entered\nor fill in the address fields manually."); this.ePane.parentNode.removeChild( this.ePane ); }
}

_this.PopulateAddress = function()
{

	this.ePane.parentNode.removeChild( this.ePane );
	//alert(this.oSelectedItem.cItemID)
	
	// aps replaced below 30.6.2006
//	this.eForm.address1.value	= this.oSelectedItem.cItemID;
//	this.eForm.address2.value	= this.address2;
//	this.eForm.address3.value	= this.address3;
//	this.eForm.town.value		= this.town ;
//	this.eForm.county.value		= this.county;
//	this.eForm.postCode.value	= this.postcode;
//	this.eForm.country.value	= "UK";
	
	
	if ( this.oSelectedItem.cItemID.length > 4 )
	{
		getElementsByClassName(this.oParentElement, "Address1")[0].value = this.oSelectedItem.cItemID;
		getElementsByClassName(this.oParentElement, "Address2")[0].value = this.address2;
		getElementsByClassName(this.oParentElement, "Address3")[0].value = this.address3;
	}
	else
	{
		getElementsByClassName(this.oParentElement, "Address1")[0].value = this.oSelectedItem.cItemID + " " + this.address2;
		getElementsByClassName(this.oParentElement, "Address2")[0].value = this.address3;
	}
	
	getElementsByClassName(this.oParentElement, "Town")[0].value     = this.town;
	getElementsByClassName(this.oParentElement, "County")[0].value   = this.county;
	getElementsByClassName(this.oParentElement, "Postcode")[0].value = this.postcode;


	var aSel = document.getElementsByTagName("select"); for( var i=0;i<aSel.length; i++ ){ aSel[i].style.visibility = ""; }
}

/*----------------------------------------------
|LookupAddress()  
----------------------------------------------*/
var oAddress;
function LookupAddress(eForm, e)
{
	var evt = e || event; 
	evt.src = e.target || e.srcElement;
	var cPostCode =  eForm.postCode.value;
	if( /[A-Za-z]{1,2}\d{1,2}[A-Za-z]? \d[A-Za-z]{2}/.test( cPostCode ) )
	{
		oAddress = new XAPAddressLookup();
		oAddress.eForm = eForm;
		oAddress.evt = evt;
		oAddress.Parent = window;
		oAddress.ParentElement = document.body;
		oAddress.cPostCode = cPostCode
		oAddress.Init();
	}
	else
	{
		alert("Please use a valid UK Postal Code")
	}
}

function LookupAddressFromPostcode(e, cAddressType)
{

	var evt = e || event; 
	evt.src = e.target || e.srcElement;
	var cPostCode =  document.getElementById(aIDs.Postcode).value;
	if( /[A-Za-z]{1,2}\d{1,2}[A-Za-z]? \d[A-Za-z]{2}/.test( cPostCode ) )
	{
		oAddress = new XAPAddressLookup();
		//oAddress.eForm = eForm;
		oAddress.evt = evt;
		oAddress.Parent = window;
		oAddress.ParentElement = document.body;
		oAddress.cPostCode = cPostCode
		oAddress.Init();
	}
	else
	{
		alert("Please use a valid UK Postal Code")
	}
}

function LookUpAddressII(oParentElement, e)
{
	var evt = e || event; 
	evt.src = e.target || e.srcElement;
		
	var cPostCode = getElementsByClassName(oParentElement, "Postcode")[0].value;
	
	if ( /[A-Za-z]{1,2}\d{1,2}[A-Za-z]? \d[A-Za-z]{2}/.test(cPostCode) )
	{
		oAddress                = new XAPAddressLookup();
		oAddress.oParentElement = oParentElement;
		oAddress.evt            = evt;
		oAddress.Parent         = window;
		oAddress.ParentElement  = document.body;
		oAddress.cPostCode      = cPostCode
		oAddress.Init();
	}
	else
	{
		alert("Please use a valid UK Postal Code");
	}
}
  /*this.oMultiSlideShow = new multiSlideShowControl();
	this.aSlideShowVars = [this.aDescPhotos, this.cMediaFolder, this.aImgElements];
	this.oMultiSlideShow.init(this.aSlideShowVars);
	
  this.oMiniSlideShow1 = new miniSlideShowControl();
	this.aSlideShowVars = [this.aDescPhotos1, this.cMediaFolder, document.getElementById("liImg1")];
	this.oMiniSlideShow1.init(this.aSlideShowVars);
	this.oMiniSlideShow1.start();
*/
 ///////////////////// slideShowControl ///////////////

function slideShowControl(){}

var _this = slideShowControl.prototype = new Object();
_this.constructor		= slideShowControl;
_this.player;
_this.parentElement;
_this.aLoadedImages;
_this.aImageUrls;
_this.lPlaying;
_this.lPause;
_this.aImageElements;
_this.cMediaFolder;
_this.lSlideStopped;
_this.nSequenceCount;
_this.oParent;

_this.hBlend;
_this.hStatic;
_this.nStep;
_this.nTime;
_this.nStepSize;
_this.nMaxRange;
_this.nNoOfSteps; 
_this.nStaticTime;
_this.cImageIn;
_this.cImageOut;
_this.nCurIndex;

_this.lBlending;

_this.lOffset

_this.init = function ( aVars, loffset ) {
	
	this.player				= null;
	this.aLoadedImages	= [];
	this.aImageUrls 		= [];
	this.lPlaying			= false;
	this.lPause				= false;
	this.aImageElements	= [];
	this.hBlend				= 0;
	this.hStatic			= 0;
	this.nStep 				= 0;
	this.nTime 				= 1000;
	this.nStepSize 		= 5;
	this.nMaxRange 		= 100;
	this.nNoOfSteps 		= 0; 
	this.nStaticTime		= 2000;
	this.cImageIn			= "";
	this.cImageOut			= "";
	this.nCurIndex			= 0;	
	this.lOffset            = loffset;

	this.aImageUrls 		= aVars[0];
	this.cMediaFolder		= aVars[1];
	this.oParent			= aVars[2];
	this.aDesc				= aVars[3];
	
	this.parentElement	= this.oParent;

	this.nNoOfSteps 		= this.nMaxRange / this.nStepSize;
	
	this.lSlideStopped   = false;
	this.nSequenceCount	= 0;
	
	this.lBlending = false;
	
	this.preloadImages();
}

_this.preloadImages = function () {
	var self = this;
	var lAllImagesLoaded = true;
	for (var nIndex = 0; nIndex < this.aImageUrls.length; nIndex = nIndex + 1) {
		var cImageUrl = this.aImageUrls[nIndex];
		if (!this.aLoadedImages[cImageUrl]) {
			lAllImagesLoaded = false;
			this.aImageElements[cImageUrl] = document.createElement("img");
			this.aImageElements[cImageUrl].onload = function () {
				if ( self.lOffset ) { this.style.marginLeft = (this.width/2)*(-1) + "px"; }
				self.imageLoaded(this)
			}
			this.aImageElements[cImageUrl].id 	= cImageUrl;
			this.aImageElements[cImageUrl].style.filter = "alpha(opacity = 0)";	
			this.aImageElements[cImageUrl].style.opacity = 0;		
			this.aImageElements[cImageUrl].src 	= this.cMediaFolder + cImageUrl;
			nIndex 								= this.aImageUrls.length;
		}		
	}
	if (lAllImagesLoaded) {	
	}
}

_this.imageLoaded = function (eImage) {
		if (!this.lPlaying && !this.lSlideStopped) {
			this.start();
		}
		for ( var i = 0; i < this.aImageUrls.length; i++ ) {
	/*
		  if ( this.aImageUrls[i] == eImage.id )
			{
				if (typeof this.parent.photoButtons.aButtons[i] != "undefined") {
					this.parent.photoButtons.aButtons[i].style.display = "";
					i = this.aImageUrls.length;
				}
			}	*/
		}
		this.aLoadedImages[eImage.id] = true;		
		this.preloadImages();	
}


_this.start = function () {
//
//document.getElementById("ResumeSlideShow").style.display = "none";
	if (!this.lPlaying) {
	  for (var nIndex = 0; nIndex < this.aImageUrls.length; nIndex = nIndex + 1) {
			var cImageUrl = this.aImageUrls[nIndex];
			if (this.aLoadedImages[cImageUrl]) {
				this.nCurIndex = nIndex;
				this.cImageIn = cImageUrl;
				this.parentElement.appendChild(this.aImageElements[cImageUrl])
				this.lPlaying = true;
//				this.parent.photoButtons.render(this.nCurIndex);	
				this.blend();
				nIndex = this.aImageUrls.length;
			}
		}
	}	
	
}


_this.blend = function () {	
	this.lBlending = true;
	var self = this;
	this.nStep++
	if( this.nStep < this.nNoOfSteps ){
		this.aImageElements[this.cImageIn].style.filter = "alpha(opacity = " + (this.nStep * this.nStepSize) + ")";
		this.aImageElements[this.cImageIn].style.opacity = ((this.nStep * this.nStepSize)/100);
		this.hBlend = setTimeout( function () {self.blend()}, this.nTime / this.nNoOfSteps );

		try{		document.getElementById("GalleryCaption").innerHTML = this.aDesc[this.nCurIndex];}catch(e){}

	}
	else {
		this.lBlending = false;
		this.nStep = 0;
		this.aImageElements[this.cImageIn].style.filter = "alpha(opacity = 100)";
		this.aImageElements[this.cImageIn].style.opacity = 1;		
		
		if (this.aImageElements[this.cImageOut] != null) {
			this.aImageElements[this.cImageOut].style.filter = "alpha(opacity = 0)";	
			this.aImageElements[this.cImageOut].style.opacity = 0;		
		}
		if(!this.lPause){
			this.hStatic = setTimeout( function () {self.sequence()}, this.nStaticTime );
		}

//		document.getElementById("GalleryCaption").innerHTML = this.cImageIn;

	}
}

_this.sequence = function () {
	var self = this;	
	var cImageUrl = "";
	if (this.nSequenceCount >= 5) {	
		this.pause();		
//		document.getElementById("ResumeSlideShow").style.display = "";
	}
	else {
		for (var nIndex = 0; nIndex < this.aImageUrls.length; nIndex = nIndex + 1) {
			if(nIndex == this.nCurIndex){
				if (nIndex == this.aImageUrls.length - 1) {
					// restart	
					cImageUrl = this.aImageUrls[0];
					this.nCurIndex = 0;
					this.nSequenceCount = this.nSequenceCount + 1;
				}
				else {
					// step
					cImageUrl = this.aImageUrls[nIndex + 1];				
					this.nCurIndex = nIndex + 1;
				}
//				this.parent.photoButtons.render(this.nCurIndex);	
				nIndex = this.aImageUrls.length;
			}
		}
		if (cImageUrl == "") {
			alert("error");
		}
		else {
			if (this.aLoadedImages[cImageUrl]) {	
				this.cImageOut = this.cImageIn;		
				this.cImageIn = cImageUrl;
				this.aImageElements[this.cImageIn].style.filter = "alpha(opacity = 0)";	
				this.aImageElements[this.cImageIn].style.opacity = 0;		
				this.parentElement.appendChild(this.aImageElements[cImageUrl]);	
				this.blend();
			}
			else {
				this.hStatic = setTimeout( function () {self.sequence()}, this.nStaticTime );
			}		
		}
	}
	
}


_this.finish = function () {
	this.lPlaying      = false;
	this.lSlideStopped = true;
	clearTimeout(this.hBlend);
	clearTimeout(this.hStatic);
	if (this.nStep > 0) {
		this.nStep = this.nNoOfSteps;
	}
}

_this.pause = function () {
	this.lPause = true;
	clearTimeout(this.hStatic);
}			

_this.resume = function () {
	this.nSequenceCount = 0;
//	document.getElementById("ResumeSlideShow").style.display = "none";
	this.lPause = false;
	this.sequence();
}			

_this.show = function(nIndex){
	this.pause();
	//document.getElementById("ResumeSlideShow").style.display = "";
	if( this.aImageUrls[nIndex] && !this.lBlending ){
		this.nCurIndex = nIndex;
		var cImageUrl = this.aImageUrls[nIndex];
		if( this.aLoadedImages[cImageUrl] ){
			this.cImageOut = this.cImageIn;		
			this.cImageIn = cImageUrl;
			this.parentElement.appendChild(this.aImageElements[cImageUrl]);	
//			this.parent.photoButtons.render(this.nCurIndex);	
			this.blend();
		}
		else{	
		}
	}
}

_this.previous = function () {
	if (this.nCurIndex > 0) {
		this.show(this.nCurIndex - 1);
	}
}

_this.next = function () {
	if (this.nCurIndex < this.aImageUrls.length) {
		this.show(this.nCurIndex + 1);
	}
}

_this.resetSequenceCount = function() {
	this.nSequenceCount = 0;	
}

///////////////////// end //////////////////////// 


///////////////////// miniSlideShowControl ///////////////

function miniSlideShowControl(){}

var _this = miniSlideShowControl.prototype = new slideShowControl();
_this.constructor		= miniSlideShowControl;
_this.cRandom;

_this.init = function ( aVars ) {

	this.player				= null;
	this.aLoadedImages	= [];
	this.lPlaying			= false;
	this.lPause				= false;
	this.aImageElements	= [];
	this.hBlend				= 0;
	this.hStatic			= 0;
	this.nStep 				= 0;
	this.nTime 				= 1000;
	this.nStepSize 		= 5;
	this.nMaxRange 		= 100;
	this.nNoOfSteps 		= 0; 
	this.nStaticTime		= 2000;
	this.cImageIn			= "";
	this.cImageOut			= "";
	this.nCurIndex			= 0;	
	this.nSequenceCount	= 0;

/*	this.aImageUrls 		= aVars[0];
	this.cMediaFolder		= aVars[1];
	this.parentElement	= aVars[2];
	*/
	this.nNoOfSteps 		= this.nMaxRange / this.nStepSize;
	
	this.cRandom            = "?rnd=" + new Date().getTime();
	
	this.preloadImages();
}

_this.preloadImages = function () {
	var self = this;
	var lAllImagesLoaded = true;
	for (var nIndex = 0; nIndex < this.aImageUrls.length; nIndex = nIndex + 1) {
		var cImageUrl = this.aImageUrls[nIndex];
		if (!this.aLoadedImages[cImageUrl]) {
			lAllImagesLoaded = false;
			this.aImageElements[cImageUrl] 					= document.createElement("img");
			this.aImageElements[cImageUrl].onload 			= function () {
				self.imageLoaded(this)
			}
			this.aImageElements[cImageUrl].id 				= cImageUrl;
			this.aImageElements[cImageUrl].style.filter 	= "alpha(opacity = 0)";	
			this.aImageElements[cImageUrl].style.opacity = 0;		
			this.aImageElements[cImageUrl].src 				= this.cMediaFolder + cImageUrl + this.cRandom;
			nIndex 													= this.aImageUrls.length;
		}		
	}
	if (lAllImagesLoaded) {	
	}
}

_this.imageLoaded = function (eImage) {
		if (!this.lPlaying && !this.lSlideStopped) {
			this.start();
		}
		this.aLoadedImages[eImage.id] = true;		
		this.preloadImages();	
}

_this.start = function () {
	if (!this.lPlaying) {
		this.nSequenceCount	= 0;
		for (var nIndex = 0; nIndex < this.aImageUrls.length; nIndex = nIndex + 1) {
			var cImageUrl = this.aImageUrls[nIndex];
			if (this.aLoadedImages[cImageUrl]) {
				this.nCurIndex = nIndex;
				this.cImageIn = cImageUrl;
				this.parentElement.appendChild(this.aImageElements[cImageUrl]);
				this.lPlaying = true;
				this.blend();
				nIndex = this.aImageUrls.length;
			}
		}
	}	
}

_this.sequence = function () {
	var self = this;	
	var cImageUrl = "";
	this.nSequenceCount = this.nSequenceCount + 1
	if (this.nSequenceCount > 20) {
		this.finish();	
	}
	else {	
		for (var nIndex = 0; nIndex < this.aImageUrls.length; nIndex = nIndex + 1) {
			if(nIndex == this.nCurIndex){
				if (nIndex == this.aImageUrls.length - 1) {
					// restart	
					cImageUrl = this.aImageUrls[0];
					this.nCurIndex = 0;
				}
				else {
					// step
					cImageUrl = this.aImageUrls[nIndex + 1];				
					this.nCurIndex = nIndex + 1;
				}
				nIndex = this.aImageUrls.length;
			}
		}
		if (cImageUrl == "") {
			alert("error");
		}
		else {
			if (this.aLoadedImages[cImageUrl]) {	
				this.cImageOut = this.cImageIn;		
				this.cImageIn  = cImageUrl;
				this.aImageElements[this.cImageIn].style.filter = "alpha(opacity = 0)";	
				this.aImageElements[this.cImageIn].style.opacity = 0;		
				this.parentElement.appendChild(this.aImageElements[cImageUrl]);	
				this.blend();
			}
			else {
				this.hStatic = setTimeout( function () {self.sequence()}, this.nStaticTime );
			}		
		}
	}
}

_this.finish = function () {
	this.lPlaying      = false;
	this.lSlideStopped = true;
	clearTimeout(this.hBlend);
	clearTimeout(this.hStatic);
}

//////////////////////// end ///////////////////



  /*this.oMultiSlideShow = new multiSlideShowControl();
	this.aSlideShowVars = [this.aDescPhotos, this.cMediaFolder, this.aImgElements];
	this.oMultiSlideShow.init(this.aSlideShowVars);
	
  this.oMiniSlideShow1 = new miniSlideShowControl();
	this.aSlideShowVars = [this.aDescPhotos1, this.cMediaFolder, document.getElementById("liImg1")];
	this.oMiniSlideShow1.init(this.aSlideShowVars);
	this.oMiniSlideShow1.start();
*/
 ///////////////////// slideShowControl ///////////////

function slideShowControlII(){}

var _this = slideShowControlII.prototype = new Object();
_this.constructor		= slideShowControl;
_this.player;
_this.parentElement;
_this.aLoadedImages;
_this.aImageUrls;
_this.lPlaying;
_this.lPause;
_this.aImageElements;
_this.cMediaFolder;
_this.lSlideStopped;
_this.nSequenceCount;
_this.oParent;

_this.hBlend;
_this.hStatic;
_this.nStep;
_this.nTime;
_this.nStepSize;
_this.nMaxRange;
_this.nNoOfSteps; 
_this.nStaticTime;
_this.cImageIn;
_this.cImageOut;
_this.nCurIndex;

_this.lBlending;

_this.lOffset

_this.init = function ( aVars, loffset ) {
	
	this.player				= null;
	this.aLoadedImages	= [];
	this.aImageUrls 		= [];
	this.lPlaying			= false;
	this.lPause				= false;
	this.aImageElements	= [];
	this.hBlend				= 0;
	this.hStatic			= 0;
	this.nStep 				= 0;
	this.nTime 				= 3000;
	this.nStepSize 		= 5;
	this.nMaxRange 		= 100;
	this.nNoOfSteps 		= 0; 
	this.nStaticTime		= 10000;
	this.cImageIn			= "";
	this.cImageOut			= "";
	this.nCurIndex			= 0;	
	this.lOffset            = loffset;

	this.aImageUrls 		= aVars[0];
	this.cMediaFolder		= aVars[1];
	this.oParent			= aVars[2];
	this.aDesc				= aVars[3];
	
	this.parentElement	= this.oParent;

	this.nNoOfSteps 		= this.nMaxRange / this.nStepSize;
	
	this.lSlideStopped   = false;
	this.nSequenceCount	= 0;
	
	this.lBlending = false;
	
	this.preloadImages();
}

_this.preloadImages = function () {
	var self = this;
	var lAllImagesLoaded = true;
	for (var nIndex = 0; nIndex < this.aImageUrls.length; nIndex = nIndex + 1) {
		var cImageUrl = this.aImageUrls[nIndex];
		if (!this.aLoadedImages[cImageUrl]) {
			lAllImagesLoaded = false;
			this.aImageElements[cImageUrl] = document.createElement("img");
			this.aImageElements[cImageUrl].onload = function () {
				if ( self.lOffset ) { this.style.marginLeft = (this.width/2)*(-1) + "px"; }
				self.imageLoaded(this)
			}
			this.aImageElements[cImageUrl].id 	= cImageUrl;
			this.aImageElements[cImageUrl].style.filter = "alpha(opacity = 0)";	
			this.aImageElements[cImageUrl].style.opacity = 0;		
			this.aImageElements[cImageUrl].src 	= this.cMediaFolder + cImageUrl;
			nIndex 								= this.aImageUrls.length;
		}		
	}
	if (lAllImagesLoaded) {	
	}
}

_this.imageLoaded = function (eImage) {
		if (!this.lPlaying && !this.lSlideStopped) {
			this.start();
		}
		for ( var i = 0; i < this.aImageUrls.length; i++ ) {
	/*
		  if ( this.aImageUrls[i] == eImage.id )
			{
				if (typeof this.parent.photoButtons.aButtons[i] != "undefined") {
					this.parent.photoButtons.aButtons[i].style.display = "";
					i = this.aImageUrls.length;
				}
			}	*/
		}
		this.aLoadedImages[eImage.id] = true;		
		this.preloadImages();	
}


_this.start = function () {
//
//document.getElementById("ResumeSlideShow").style.display = "none";
	if (!this.lPlaying) {
	  for (var nIndex = 0; nIndex < this.aImageUrls.length; nIndex = nIndex + 1) {
			var cImageUrl = this.aImageUrls[nIndex];
			if (this.aLoadedImages[cImageUrl]) {
				this.nCurIndex = nIndex;
				this.cImageIn = cImageUrl;
				this.parentElement.appendChild(this.aImageElements[cImageUrl])
				this.lPlaying = true;
//				this.parent.photoButtons.render(this.nCurIndex);	
				this.blend();
				nIndex = this.aImageUrls.length;
			}
		}
	}	
}


_this.blend = function () {	
	this.lBlending = true;
	var self = this;
	this.nStep++
	if( this.nStep < this.nNoOfSteps ){
		this.aImageElements[this.cImageIn].style.filter = "alpha(opacity = " + (this.nStep * this.nStepSize) + ")";
		this.aImageElements[this.cImageIn].style.opacity = ((this.nStep * this.nStepSize)/100);
		this.hBlend = setTimeout( function () {self.blend()}, this.nTime / this.nNoOfSteps );

		try{		document.getElementById("GalleryCaption").innerHTML = this.aDesc[this.nCurIndex];}catch(e){}

	}
	else {
		this.lBlending = false;
		this.nStep = 0;
		this.aImageElements[this.cImageIn].style.filter = "alpha(opacity = 100)";
		this.aImageElements[this.cImageIn].style.opacity = 1;		
		
		if (this.aImageElements[this.cImageOut] != null) {
			this.aImageElements[this.cImageOut].style.filter = "alpha(opacity = 0)";	
			this.aImageElements[this.cImageOut].style.opacity = 0;		
		}
		if(!this.lPause){
			this.hStatic = setTimeout( function () {self.sequence()}, this.nStaticTime );
		}

//		document.getElementById("GalleryCaption").innerHTML = this.cImageIn;

	}
}

_this.sequence = function () {
	var self = this;	
	var cImageUrl = "";
	if (this.nSequenceCount >= 5) {	
		this.pause();		
//		document.getElementById("ResumeSlideShow").style.display = "";
	}
	else {
		for (var nIndex = 0; nIndex < this.aImageUrls.length; nIndex = nIndex + 1) {
			if(nIndex == this.nCurIndex){
				if (nIndex == this.aImageUrls.length - 1) {
					// restart	
					cImageUrl = this.aImageUrls[0];
					this.nCurIndex = 0;
					this.nSequenceCount = this.nSequenceCount + 1;
				}
				else {
					// step
					cImageUrl = this.aImageUrls[nIndex + 1];				
					this.nCurIndex = nIndex + 1;
				}
//				this.parent.photoButtons.render(this.nCurIndex);	
				nIndex = this.aImageUrls.length;
			}
		}
		if (cImageUrl == "") {
			alert("error");
		}
		else {
			if (this.aLoadedImages[cImageUrl]) {	
				this.cImageOut = this.cImageIn;		
				this.cImageIn = cImageUrl;
				this.aImageElements[this.cImageIn].style.filter = "alpha(opacity = 0)";	
				this.aImageElements[this.cImageIn].style.opacity = 0;		
				this.parentElement.appendChild(this.aImageElements[cImageUrl]);	
				this.blend();
			}
			else {
				this.hStatic = setTimeout( function () {self.sequence()}, this.nStaticTime );
			}		
		}
	}
}


_this.finish = function () {
	this.lPlaying      = false;
	this.lSlideStopped = true;
	clearTimeout(this.hBlend);
	clearTimeout(this.hStatic);
	if (this.nStep > 0) {
		this.nStep = this.nNoOfSteps;
	}
}

_this.pause = function () {
	this.lPause = true;
	clearTimeout(this.hStatic);
}			

_this.resume = function () {
	this.nSequenceCount = 0;
//	document.getElementById("ResumeSlideShow").style.display = "none";
	this.lPause = false;
	this.sequence();
}			

_this.show = function(nIndex){
	this.pause();
	//document.getElementById("ResumeSlideShow").style.display = "";
	if( this.aImageUrls[nIndex] && !this.lBlending ){
		this.nCurIndex = nIndex;
		var cImageUrl = this.aImageUrls[nIndex];
		if( this.aLoadedImages[cImageUrl] ){
			this.cImageOut = this.cImageIn;		
			this.cImageIn = cImageUrl;
			this.parentElement.appendChild(this.aImageElements[cImageUrl]);	
//			this.parent.photoButtons.render(this.nCurIndex);	
			this.blend();
		}
		else{	
		}
	}
}

_this.previous = function () {
	if (this.nCurIndex > 0) {
		this.show(this.nCurIndex - 1);
	}
}

_this.next = function () {
	if (this.nCurIndex < this.aImageUrls.length) {
		this.show(this.nCurIndex + 1);
	}
}

_this.resetSequenceCount = function() {
	this.nSequenceCount = 0;	
}

///////////////////// end //////////////////////// 


///////////////////// miniSlideShowControl ///////////////

function miniSlideShowControl(){}

var _this = miniSlideShowControl.prototype = new slideShowControl();
_this.constructor		= miniSlideShowControl;
_this.cRandom;

_this.init = function ( aVars ) {

	this.player				= null;
	this.aLoadedImages	= [];
	this.lPlaying			= false;
	this.lPause				= false;
	this.aImageElements	= [];
	this.hBlend				= 0;
	this.hStatic			= 0;
	this.nStep 				= 0;
	this.nTime 				= 1000;
	this.nStepSize 		= 5;
	this.nMaxRange 		= 100;
	this.nNoOfSteps 		= 0; 
	this.nStaticTime		= 2000;
	this.cImageIn			= "";
	this.cImageOut			= "";
	this.nCurIndex			= 0;	
	this.nSequenceCount	= 0;

/*	this.aImageUrls 		= aVars[0];
	this.cMediaFolder		= aVars[1];
	this.parentElement	= aVars[2];
	*/
	this.nNoOfSteps 		= this.nMaxRange / this.nStepSize;
	
	this.cRandom            = "?rnd=" + new Date().getTime();
	
	this.preloadImages();
}

_this.preloadImages = function () {
	var self = this;
	var lAllImagesLoaded = true;
	for (var nIndex = 0; nIndex < this.aImageUrls.length; nIndex = nIndex + 1) {
		var cImageUrl = this.aImageUrls[nIndex];
		if (!this.aLoadedImages[cImageUrl]) {
			lAllImagesLoaded = false;
			this.aImageElements[cImageUrl] 					= document.createElement("img");
			this.aImageElements[cImageUrl].onload 			= function () {
				self.imageLoaded(this)
			}
			this.aImageElements[cImageUrl].id 				= cImageUrl;
			this.aImageElements[cImageUrl].style.filter 	= "alpha(opacity = 0)";	
			this.aImageElements[cImageUrl].style.opacity = 0;		
			this.aImageElements[cImageUrl].src 				= this.cMediaFolder + cImageUrl + this.cRandom;
			nIndex 													= this.aImageUrls.length;
		}		
	}
	if (lAllImagesLoaded) {	
	}
}

_this.imageLoaded = function (eImage) {
		if (!this.lPlaying && !this.lSlideStopped) {
			this.start();
		}
		this.aLoadedImages[eImage.id] = true;		
		this.preloadImages();	
}

_this.start = function () {
	if (!this.lPlaying) {
		this.nSequenceCount	= 0;
		for (var nIndex = 0; nIndex < this.aImageUrls.length; nIndex = nIndex + 1) {
			var cImageUrl = this.aImageUrls[nIndex];
			if (this.aLoadedImages[cImageUrl]) {
				this.nCurIndex = nIndex;
				this.cImageIn = cImageUrl;
				this.parentElement.appendChild(this.aImageElements[cImageUrl]);
				this.lPlaying = true;
				this.blend();
				nIndex = this.aImageUrls.length;
			}
		}
	}	
}

_this.sequence = function () {
	var self = this;	
	var cImageUrl = "";
	this.nSequenceCount = this.nSequenceCount + 1
	if (this.nSequenceCount > 20) {
		this.finish();	
	}
	else {	
		for (var nIndex = 0; nIndex < this.aImageUrls.length; nIndex = nIndex + 1) {
			if(nIndex == this.nCurIndex){
				if (nIndex == this.aImageUrls.length - 1) {
					// restart	
					cImageUrl = this.aImageUrls[0];
					this.nCurIndex = 0;
				}
				else {
					// step
					cImageUrl = this.aImageUrls[nIndex + 1];				
					this.nCurIndex = nIndex + 1;
				}
				nIndex = this.aImageUrls.length;
			}
		}
		if (cImageUrl == "") {
			alert("error");
		}
		else {
			if (this.aLoadedImages[cImageUrl]) {	
				this.cImageOut = this.cImageIn;		
				this.cImageIn  = cImageUrl;
				this.aImageElements[this.cImageIn].style.filter = "alpha(opacity = 0)";	
				this.aImageElements[this.cImageIn].style.opacity = 0;		
				this.parentElement.appendChild(this.aImageElements[cImageUrl]);	
				this.blend();
			}
			else {
				this.hStatic = setTimeout( function () {self.sequence()}, this.nStaticTime );
			}		
		}
	}
}

_this.finish = function () {
	this.lPlaying      = false;
	this.lSlideStopped = true;
	clearTimeout(this.hBlend);
	clearTimeout(this.hStatic);
}

//////////////////////// end ///////////////////



///////////////////// audioControl /////////////////////

function audioControl(){}

var _this = audioControl.prototype = new Object();

_this.constructor			= audioControl;
_this.player;
_this.paused;
_this.position;
_this.hDelay;
_this.aTracks;
_this.nCurTrack;
_this.cTrackName;
_this.nInterval;
_this.lEnable;
_this.cMediaFolder;
_this.cPlayerId;
_this.lMute;

_this.requestAlert;
_this.swfAudioTrack;
_this.fnPlayAudio;
_this.fnEndAudio;
_this.fnPauseResumeAudio;
_this.fnMuteAudio;
_this.swfAudioPosition;
_this.swfFadeAudioTime;


_this.init = function ( aVars ) {
		
// 	this.swfAudioControl.play(this.cMediaFolder + this.cInitialTrack + ".mp3", 6); // delay is in seconds

	this.requestAlert				= "reqAlt";
	this.swfAudioTrack			= "varAT";
	this.fnPlayAudio				= "fnPA";
	this.fnEndAudio				= "fnEA";
	this.fnPauseResumeAudio		= "fnPRA";
	this.fnMuteAudio				= "fnMA";
	this.swfAudioPosition		= "varAP";
	this.swfFadeAudioTime		= "varFAT";	
	
	this.paused				= false;
	this.position			= 0;
	this.hDelay		 		= 0;
	this.cTrackName		= "";
	this.nInterval			= 0;
	this.lMute				= false;
	
	this.cPlayerId			= aVars[0];
	this.cMediaFolder		= aVars[1];
	this.aTracks			= aVars[2];
	this.nCurTrack			= aVars[3];
	
	var ie = navigator.appName.indexOf("Microsoft") != -1;
//	this.player = (ie) ? window[cPlayerId] : document[cPlayerId];
	if (ie)
	{
		this.player = window[this.cPlayerId];
	
		this.lEnable = true;	
		//this.play(this.nCurTrack, 6);
	}
	else
	{
		this.player = document[this.cPlayerId]
	
		this.lEnable = true;	
		//this.play(this.nCurTrack, 10);
	}


	// this.player = document.getElementById(cPlayerId);	
		
}

_this.rePlay = function (nInterval) {
	this.play(this.nCurTrack, nInterval);
}

_this.play = function (nIndex, nInterval) {	
	var self = this;
	clearTimeout(this.hDelay);
	if (this.lEnable) {
		this.nCurTrack = nIndex;
		this.cTrackName = this.aTracks[nIndex];
		this.nInterval = 1000 * nInterval;
		if (this.nInterval > 0) {
			// hAudioDelay = setTimeout(function() {delayedAudio(cTrackName)}, nInterval); 
			this.hDelay = setTimeout( function () {self.delayedPlay()}, this.nInterval); 
		}
		else {	
			this.assign(this.swfAudioTrack, 	this.cMediaFolder + this.cTrackName + ".mp3");
			this.assign(this.fnPlayAudio, 	true);
			this.assign(this.requestAlert, 	true);
		}
	}
}

_this.delayedPlay = function () {
	clearTimeout(this.hDelay);
	this.assign(this.swfAudioTrack, 	this.cMediaFolder + this.cTrackName + ".mp3");
	this.assign(this.fnPlayAudio, 	true);
	this.assign(this.requestAlert, 	true);
}

_this.stop = function () {
	this.assign(this.fnEndAudio, 					true);
	this.assign(this.requestAlert, 				true);
}

_this.pauseResume	= function () {
	if (this.paused) {
		this.setPosition();
		this.assign(this.fnPauseResumeAudio, 	true);
		this.assign(this.requestAlert, 			true);
		this.paused = false;
	}
	else {
		this.assign(this.fnPauseResumeAudio, 	true);
		this.assign(this.requestAlert, 			true);
		this.paused = true;
	}
}

_this.mute = function (lMute) {
	if (lMute != this.lMute) {
		this.assign(this.fnMuteAudio, 				true);
		this.assign(this.requestAlert, 				true);
		this.lMute = lMute;
	}
}

_this.getPosition = function () {
	// Need to wait after issuing pause request for the variable to be updated by Flash	
	this.position = this.access(this.swfAudioPosition);
	alert(this.position);
}

_this.setPosition = function () {
	this.assign(this.swfAudioPosition, this.position);
}
		
_this.fadeTime = function () {
	this.assign(this.swfFadeAudioTime, 2);
	/*
	This is the time to fade in or out in seconds.
	The fade takes 10 steps over this period.
	The minimum period is 1 second.
	The default period is 5 seconds.
	*/
}

	
_this.assign = function (cVarName, cVarData) {
	this.player.SetVariable("/:" + cVarName, cVarData);			
}
 	
_this.access = function(cVarName) {	
	return this.player.GetVariable("/:" + cVarName);
}

_this.enable = function () {
	this.lEnable = true;	
}

_this.disable = function () {
	this.lEnable = false;	
}

///////////////////// end ////////////////////////


///////////////////// videoControl ///////////////

function videoControl(){}

var _this = videoControl.prototype = new Object();

_this.constructor	= videoControl;
_this.player;
_this.hDelay;
_this.cVideoName;
_this.nInterval;
_this.cPlayerId;
_this.lMute;

_this.requestAlert;
_this.swfVideoName;
_this.fnPlayVideo;
_this.swfVideoStartTime;
_this.fnStopVideo;
_this.fnPauseResumeVideo;
_this.fnMuteVideo;

_this.init = function ( cVar ) {
	
	this.requestAlert				= "reqAlt";
	this.swfVideoName				= "varVN";
	this.fnPlayVideo				= "fnPV";
	this.swfVideoStartTime		= "varVST";
	this.fnStopVideo				= "fnSV";
	this.fnPauseResumeVideo		= "fnPRV";
	this.fnMuteVideo				= "fnMV";
	
	this.cPlayerId 	= cVar;
	this.lMute			= false;
	
	this.hDelay			= 0;
	this.cVideoName	= "";
	this.nInterval		= 0;
	
	var ie = navigator.appName.indexOf("Microsoft") != -1;
	this.player = (ie) ? window[this.cPlayerId] : document[this.cPlayerId];	
	//this.player = document.getElementById(cPlayerId);	
}

_this.play			= function (cVideoName, nInterval) {
	var self = this;
	this.cVideoName = cVideoName;
	this.nInterval = 1000 * nInterval;
	if (this.nInterval > 0) {
		this.hDelay = setTimeout( function () {self.delayedPlay()}, this.nInterval); 
	}
	else {
		this.assign(this.swfVideoName, 	cVideoName);
		this.assign(this.fnPlayVideo, 	true);
		this.assign(this.requestAlert, 	true);
	}
}

_this.delayedPlay = function () {
	clearTimeout(this.hDelay);
	// aps added 13.04.2006
	this.assign(this.swfVideoStartTime, 5); // set to 5 seconds delay - default is also 5 seconds	
	this.assign(this.swfVideoName, 	this.cVideoName);
	this.assign(this.fnPlayVideo, 	true);
	this.assign(this.requestAlert, 	true);
}

_this.stop = function () {
	this.assign(this.fnStopVideo, 				true);
	this.assign(this.requestAlert, 				true);
}

_this.pauseResume	= function () {
	this.assign(this.fnPauseResumeVideo, 		true);
	this.assign(this.requestAlert, 				true);
}

_this.mute = function (lMute) {
	if (lMute != this.lMute) {
		this.assign(this.fnMuteVideo, 				true);
		this.assign(this.requestAlert, 				true);
		this.lMute = lMute;
	}
}

_this.startTime = function () {
	this.assign(this.swfVideoStartTime, 5); // set to 5 seconds delay - default is also 5 seconds	
}

_this.assign = function (cVarName, cVarData) {
	this.player.SetVariable("/:" + cVarName, cVarData);			
}
 	
_this.access = function(cVarName) {	
	return this.player.GetVariable("/:" + cVarName);
}

///////////////////// end ////////////////////////


//////////////////// logoWrapper /////////////////

function logoWrapper(){}

var _this = logoWrapper.prototype = new Object();
_this.constructor		= logoWrapper;
_this.aLogoIds;
_this.aDivElements;
_this.aFlashObjects;
_this.cCurFlashId;

_this.init = function ( aVars ) {
	
	this.aDivElements		= [];
	this.aFlashObjects	= [];
	this.cCurFlashId		= "";
	
	this.aLogoIds = aVars;
	for (var nIndex = 0; nIndex < this.aLogoIds.length; nIndex = nIndex + 1) {
		var cDivId 		= this.aLogoIds[nIndex][0];
		var cFlashId 	= this.aLogoIds[nIndex][1];
		
		this.aDivElements[cFlashId] = document.getElementById(cDivId);
		this.aDivElements[cFlashId].style.display = "none";
		
		this.aFlashObjects[cFlashId] = new logoControl();	
		this.aFlashObjects[cFlashId].init(cFlashId);
		// alert(this.aDivElements[cFlashId].innerHTML);
	}	
}

_this.play = function (cNewFlashId) {
	if (this.cCurFlashId != "") {
		this.aDivElements[this.cCurFlashId].style.display = "none";
	}
	this.aDivElements[cNewFlashId].style.display = "";
	this.aFlashObjects[cNewFlashId].play();
	this.cCurFlashId = cNewFlashId;

}

_this.replay = function () {
	this.aFlashObjects[this.cCurFlashId].play();	
}

//////////////////////// end /////////////////////


///////////////////// logoControl ///////////////

function logoControl(){}

var _this = logoControl.prototype = new Object();
_this.constructor	= logoControl;
_this.player;

_this.init = function (cPlayerId) {
	var ie = navigator.appName.indexOf("Microsoft") != -1;
	this.player = (ie) ? window[cPlayerId] : document[cPlayerId];	
	// this.player = document.getElementById(cPlayerId);	
}

_this.play = function () {	
	this.assign("requestAlert", 	true);
}

_this.assign = function (cVarName, cVarData) {
	try{this.player.SetVariable("/:" + cVarName, cVarData);	}catch(e){}
}
 	
_this.access = function(cVarName) {	
	return this.player.GetVariable("/:" + cVarName);
}

///////////////////// end ////////////////////////


///////////////////// mainControl ///////////////

function mainControl(){}

var _this = mainControl.prototype = new Object();

_this.constructor	= mainControl;

// class objects
_this.swfAudioControl;
_this.swfVideoControl;
_this.galleryControl;
_this.montageControl;
_this.aVideoControlVars;
_this.aAudioControlVars;
_this.aGalleryVars;

// holders for HTML variables
_this.cMediaFolder;
_this.cImageFolder;
_this.cImageHolderID;
_this.aSoundTracks;
_this.nInitialTrack;
_this.cVideoName;
_this.aImages;
_this.aMontages;
_this.cMontageHolderID;
_this.cSectionName;

// other variables
_this.lVideoOn;
_this.lAudioOn;


_this.init = function (	aVars ) {

	// passed from HTML
	this.cMediaFolder			= aVars[0];
	this.cImageFolder			= aVars[1];
	this.cImageHolderID		= aVars[2];
	this.aSoundTracks			= aVars[3];
	this.nInitialTrack		= aVars[4];
	this.cVideoName			= aVars[5];
	this.aImages				= aVars[6];
	this.aMontages				= aVars[7];
	this.cMontageHolderID	= aVars[8];
	this.cSectionName   	= aVars[9];
				
	this.lVideo = false;
	this.lAudioOn = false;

	switch ( this.cSectionName )
	{
		case "Portfolio":
			this.galleryControl = new galleryControl();
			this.galleryControl.parent = this;
			this.aGalleryControlVars = [this.aImages, this.cMediaFolder, this.cImageHolderID];
			this.galleryControl.init(this.aGalleryControlVars, false); 
			
			break;
		case "Product":
			if ( this.aImages.length > 1 )
			{
				this.galleryControl = new galleryControl();
				this.galleryControl.parent = this;
				this.aGalleryControlVars = [this.aImages, this.cMediaFolder, this.cImageHolderID];
				this.galleryControl.init(this.aGalleryControlVars, true); 
			}
			else
			{
				document.getElementById("SingleImage").style.marginLeft = (document.getElementById("SingleImage").width/2)*(-1) + "px";
			}

			this.swfVideoControl = new videoControl();
			this.aVideoControlVars = ["videoPlayer"];
			this.swfVideoControl.init(this.aVideoControlVars); 

			this.swfAudioControl = new audioControl();
			this.swfAudioControl.parent = this;
			this.aAudioControlVars = ["audioPlayer", this.cMediaFolder, this.aSoundTracks, this.nInitialTrack];
			this.swfAudioControl.init(this.aAudioControlVars); 
			break;
	}

	this.montageControl = new montageControl();
	this.montageControl.parent = this;
	this.aMontageControlVars = [this.aMontages, this.cImageFolder, this.cMontageHolderID];
	this.montageControl.init(this.aMontageControlVars);


} ;

_this.htmlStartVideo = function () {
	
	if (this.lAudioOn ) { clearTimeout(this.swfAudioControl.hDelay); }

	this.lVideoOn = true;

	this.swfAudioControl.stop();
	this.swfAudioControl.disable();			
	
	 var oListenText1 = document.getElementById("ListenText1");
	 var oListenText2 = document.getElementById("ListenText2");
     var oListenText3 = document.getElementById("ListenText3");
                
    if ( oListenText1 && document.getElementById("ListenText1").innerHTML == "Stop Track 1" ) { document.getElementById("ListenText1").innerHTML = "Listen to Track 1"; }
    if ( oListenText2 && document.getElementById("ListenText2").innerHTML == "Stop Track 2" ) { document.getElementById("ListenText2").innerHTML = "Listen to Track 2"; }
    if ( oListenText3 && document.getElementById("ListenText3").innerHTML == "Stop Track 3" ) { document.getElementById("ListenText3").innerHTML = "Listen to Track 3"; }
	

	document.getElementById("Gallery").style.display   = "none";
	document.getElementById("VideoArea").style.display = "block";
	
	if ( this.aImages.length > 1 ) { this.galleryControl.pause(); }

	this.swfVideoControl.play(this.cMediaFolder + this.cVideoName, 2); // delay is in seconds	

	document.getElementById("WatchText").innerHTML  = "Stop Video";
	var oListenDiv = document.getElementById("ListenText");
	if ( oListenDiv ) { oListenDiv.innerHTML = "Listen"; }
}

_this.htmlStopVideo = function () {

	clearTimeout(this.swfVideoControl.hDelay);
	
	this.lVideoOn     = false;
	
	this.swfVideoControl.stop();
	this.swfAudioControl.enable();				
		
	document.getElementById("Gallery").style.display   = "block";
	document.getElementById("VideoArea").style.display = "none";
	
	if ( this.aImages.length > 1 ) { this.galleryControl.resume(); }

	document.getElementById("WatchText").innerHTML  = "Watch a Video";
	var oListenDiv = document.getElementById("ListenText");
	if ( oListenDiv ) { oListenDiv.innerHTML = "Listen"; }
}

_this.htmlPlayVideo = function() {
	if ( document.getElementById("WatchText").innerHTML == "Watch a Video" ) {
		this.htmlStartVideo();
	} else {
		this.htmlStopVideo();
	} ;
} ;

_this.htmlPlayTrack = function (nIndex) {
    switch ( nIndex )
    {
        case 0:
            if ( document.getElementById("ListenText1").innerHTML == "Listen to Track 1" )
            {
                if ( this.lVideoOn ) { this.htmlStopVideo(); } ;
                
                var oListenText2 = document.getElementById("ListenText2");
                var oListenText3 = document.getElementById("ListenText3");
                
                if ( oListenText2 && document.getElementById("ListenText2").innerHTML == "Stop Track 2" ) { this.swfAudioControl.stop(); document.getElementById("ListenText2").innerHTML = "Listen to Track 2"; }
                if ( oListenText3 && document.getElementById("ListenText3").innerHTML == "Stop Track 3" ) { this.swfAudioControl.stop(); document.getElementById("ListenText3").innerHTML = "Listen to Track 3"; }
                
		        this.lAudioOn = true;
		        this.swfAudioControl.play(nIndex, 1); // delay is in seconds
		        document.getElementById("ListenText1").innerHTML = "Stop Track 1";	
		        
            }
            else
            {
            	this.lAudioOn = false;
		        this.swfAudioControl.stop(); // delay is in seconds
		        document.getElementById("ListenText1").innerHTML = "Listen to Track 1";
            }
            break;
        case 1:
            if ( document.getElementById("ListenText2").innerHTML == "Listen to Track 2" )
            {
                if ( this.lVideoOn ) { this.htmlStopVideo(); } ;

                var oListenText1 = document.getElementById("ListenText1");
                var oListenText3 = document.getElementById("ListenText3");
                
                if ( oListenText1 && document.getElementById("ListenText1").innerHTML == "Stop Track 1" ) { this.swfAudioControl.stop(); document.getElementById("ListenText1").innerHTML = "Listen to Track 1"; }
                if ( oListenText3 && document.getElementById("ListenText3").innerHTML == "Stop Track 3" ) { this.swfAudioControl.stop(); document.getElementById("ListenText3").innerHTML = "Listen to Track 3"; }
                
		        this.lAudioOn = true;
		        this.swfAudioControl.play(nIndex, 1); // delay is in seconds
		        document.getElementById("ListenText2").innerHTML = "Stop Track 2";	
		        
            }
            else
            {
            	this.lAudioOn = false;
		        this.swfAudioControl.stop(); // delay is in seconds
		        document.getElementById("ListenText2").innerHTML = "Listen to Track 2";
            }
        
            break;
        case 2:
            if ( document.getElementById("ListenText3").innerHTML == "Listen to Track 3" )
            {
                if ( this.lVideoOn ) { this.htmlStopVideo(); } ;
                
                var oListenText1 = document.getElementById("ListenText1");
                var oListenText2 = document.getElementById("ListenText2");
                
                if ( oListenText1 && document.getElementById("ListenText1").innerHTML == "Stop Track 1" ) { this.swfAudioControl.stop(); document.getElementById("ListenText1").innerHTML = "Listen to Track 1";}
                if ( oListenText2 && document.getElementById("ListenText2").innerHTML == "Stop Track 2" ) { this.swfAudioControl.stop(); document.getElementById("ListenText2").innerHTML = "Listen to Track 2"; }
                
		        this.lAudioOn = true;
		        this.swfAudioControl.play(nIndex, 1); // delay is in seconds
		        document.getElementById("ListenText3").innerHTML = "Stop Track 3";	
		        
            }
            else
            {
            	this.lAudioOn = false;
		        this.swfAudioControl.stop(); // delay is in seconds
		        document.getElementById("ListenText3").innerHTML = "Listen to Track 3";
            }

            break;
    }
} ;

_this.htmlPauseResumeSlideShow = function() {
	if ( document.getElementById("SlideShowPauseResume").innerHTML == "pause" )
	{
		this.galleryControl.pause();
		document.getElementById("SlideShowPauseResume").innerHTML = "resume slideshow";
	}
	else
	{
		this.galleryControl.resume();
		document.getElementById("SlideShowPauseResume").innerHTML = "pause";
	}
}

_this.htmlPrevSlide = function() {
	if ( document.getElementById("SlideShowPauseResume").innerHTML == "pause" )
	{
		this.galleryControl.pause();
		document.getElementById("SlideShowPauseResume").innerHTML = "resume slideshow";
	}
	this.galleryControl.previous();
}

_this.htmlNextSlide = function() {
	if ( document.getElementById("SlideShowPauseResume").innerHTML == "pause" )
	{
		this.galleryControl.pause();
		document.getElementById("SlideShowPauseResume").innerHTML = "resume slideshow";
	}
	this.galleryControl.next();
}


/////////////////////// end /////////////////////////


///////////////////// galleryControl ///////////////

function galleryControl(){}

var _this = galleryControl.prototype = new Object();

_this.constructor	= galleryControl;

// class objects
_this.slideShowControl;

// containers for HTML variables
_this.aImages;
_this.cMediaFolder;
_this.cImageHolderID;

// other variables
_this.aSlideShowControlVars;
_this.aUrls;
_this.aDesc;

_this.init = function ( aVars, lOffset ) {
	
	
	this.aImages			= aVars[0];	
	this.cMediaFolder 	= aVars[1]; //  "/Media/"
	this.cImageHolderID 	= aVars[2]; // "Gallery"

	this.aUrls = [];
	this.aDesc = [];
	
	for( var nIndex = 0; nIndex < aImages.length; nIndex = nIndex + 1 ) { 
		this.aUrls[this.aUrls.length] = this.aImages[nIndex].src; 
		this.aDesc[this.aDesc.length] = this.aImages[nIndex].desc; 
	}

	this.slideShowControl = new slideShowControl();
	this.slideShowControl.parent = this;
	this.aSlideShowControlVars = [this.aUrls, this.cMediaFolder, document.getElementById(this.cImageHolderID), this.aDesc];
	this.slideShowControl.init(this.aSlideShowControlVars, lOffset); 

	this.slideShowControl.start();
	
}

_this.start = function () {
	this.slideShowControl.start();
} ;

_this.pause = function () {
	this.slideShowControl.pause();
} ;

_this.resume = function () {
	this.slideShowControl.resume();
} ;

_this.next = function () {
	this.slideShowControl.next();
}	

_this.previous = function () {
	this.slideShowControl.previous();
}	

/////////////////////// end /////////////////////////


///////////////////// montageControl ///////////////

function montageControl(){}

var _this = montageControl.prototype = new Object();

_this.constructor	= montageControl;

// class objects
_this.slideShowControl;

// containers for HTML variables
_this.aImages;
_this.cMediaFolder;
_this.cImageHolderID;

// other variables
_this.aSlideShowControlVars;
_this.aUrls;
_this.aDesc;

_this.init = function ( aVars ) {
	
	
	this.aImages			= aVars[0];	
	this.cMediaFolder 	= aVars[1]; //  "/Media/"
	this.cImageHolderID 	= aVars[2]; // "Montage"

	this.aUrls = [];
	this.aDesc = [];
	
	for( var nIndex = 0; nIndex < this.aImages.length; nIndex = nIndex + 1 ) { 
		this.aUrls[this.aUrls.length] = this.aImages[nIndex].src; 
		this.aDesc[this.aDesc.length] = this.aImages[nIndex].desc; 
	}

	this.slideShowControl = new slideShowControlII();
	this.slideShowControl.parent = this;
	this.aSlideShowControlVars = [this.aUrls, this.cMediaFolder, document.getElementById(this.cImageHolderID), this.aDesc];
	this.slideShowControl.init(this.aSlideShowControlVars); 

	this.slideShowControl.start();

}

_this.start = function () {
	this.slideShowControl.start();
} ;

_this.resume = function () {
	this.slideShowControl.resume();
} ;
	

/////////////////////// end /////////////////////////

function AddProduct(cName, cID)
{
   location.href = '/' + cName + '?AddProduct=' + cID;    
}

/////////////////////////// functions called by HTML ///////////////////

// These functions represent the external interface to the HTML page.

function StartVideo()			{ main ? main.htmlStartVideo() 								: false; }
function StopVideo() 			{ main ? main.htmlStopVideo() 								: false; }
function PlayVideo() 			{ main ? main.htmlPlayVideo() 								: false; }
function PlayTrack(nIndex) 	    { main ? main.htmlPlayTrack(nIndex) 						: false; }
function StartGallery() 		{ main ? main.htmlStartGallery() 							: false; }
function PauseResumeSlideShow() { main ? main.htmlPauseResumeSlideShow()                    : false; }
function PrevSlide()			{ main ? main.htmlPrevSlide()								: false; }
function NextSlide()			{ main ? main.htmlNextSlide()								: false; }

/////////////////////////// end //////////////////////////////////


///////////////////////// main /////////////////////////////////

var main;
var ahtmlVars;

var cMediaFolder 		= "http://www.theeventscompany.co.uk/Media/";  
var cImageFolder 		= "http://www.theeventscompany.co.uk/Images/"; 

window.onload = function() {

	// fn();
	
	main = new mainControl();
	aHtmlVars = new Array();
	try { aHtmlVars.push(cMediaFolder); } 		catch(err) { aHtmlVars.push(""); } ;
	try { aHtmlVars.push(cImageFolder); } 		catch(err) { aHtmlVars.push(""); } ;
	try { aHtmlVars.push(cImageHolderID); } 	catch(err) { aHtmlVars.push(""); } ;
	try { aHtmlVars.push(aSoundTracks); } 		catch(err) { aHtmlVars.push([]); } ;
	try { aHtmlVars.push(nInitialTrack); } 	    catch(err) { aHtmlVars.push(""); } ;
	try { aHtmlVars.push(cVideoName); } 		catch(err) { aHtmlVars.push(""); } ;
	try { aHtmlVars.push(aImages); } 			catch(err) { aHtmlVars.push([]); } ;	
	try { aHtmlVars.push(aMontages); } 			catch(err) { aHtmlVars.push([]); } ;	
	try { aHtmlVars.push(cMontageHolderID); }   catch(err) { aHtmlVars.push(""); } ;
	try { aHtmlVars.push(cSectionName); }       catch(err) { aHtmlVars.push(""); } ;
	main.init(aHtmlVars);

	/*var cHeight1;
	var cHeight2;
	if ( typeof cSectionName == "undefined" )
	{
		cHeight1 = document.getElementById("divMainBody").offsetHeight + 700 + "px";
		cHeight2 = document.getElementById("divMainBody").offsetHeight + 692 + "px";
	}
	else
	{
		if ( cSectionName != null && cSectionName == "Portfolio" )
		{
			cHeight1 = document.getElementById("divPortfolioDesc").offsetHeight + 700 + "px";
			cHeight2 = document.getElementById("divPortfolioDesc").offsetHeight + 692 + "px";
		}
		else
		{
			cHeight1 = document.getElementById("divMainBody").offsetHeight + 700 + "px";
			cHeight2 = document.getElementById("divMainBody").offsetHeight + 692 + "px";
		}
	}
	
	document.getElementById("divOuterLHS").style.height        = cHeight1;
	document.getElementById("divOuterRHS").style.height        = cHeight1;
	document.getElementById("divLHS").style.height             = cHeight1;
	document.getElementById("divRHS").style.height             = cHeight2;
	document.getElementById("divInnerRepeatArea").style.height = cHeight2;*/
	
	
}



