var tZoomLoaded;

function SwapHeaderImages(iImage)
{
	document.getElementById("topliving").src = "images/top_living.gif";
	document.getElementById("topdining").src = "images/top_dining.gif";
	document.getElementById("toppassion").src = "images/top_passion.gif";
	document.getElementById("topquality").src = "images/top_quality.gif";
	document.getElementById("topdesign").src = "images/top_design.gif";
	document.getElementById("topheritage").src = "images/top_heritage.gif";
	document.getElementById("toptrust").src = "images/top_trust.gif";
	
	switch (iImage)
	{
		case 1:
			document.getElementById("topliving").src = "images/top_living_on.gif";	
			break;
		case 2:
			document.getElementById("topdining").src = "images/top_dining_on.gif";	
			break;
		case 3:
			document.getElementById("toppassion").src = "images/top_passion_on.gif";	
			break;
		case 4:
			document.getElementById("topquality").src = "images/top_quality_on.gif";	
			break;
		case 5:
			document.getElementById("topdesign").src = "images/top_design_on.gif";	
			break;
		case 6:
			document.getElementById("topheritage").src = "images/top_heritage_on.gif";	
			break;
		default:
			document.getElementById("toptrust").src = "images/top_trust_on.gif";	
			break;
			
	}	
}

var fadeimages=new Array()
//SET IMAGE PATHS. Extend or contract array as needed
fadeimages[0]=["images/header_img_living.jpg", "", ""] //plain image syntax
fadeimages[1]=["images/header_img_dining.jpg", "", ""] //image with link syntax
fadeimages[2]=["images/header_img_passion.jpg", "", ""] //image with link and target syntax
fadeimages[3]=["images/header_img_quality.jpg", "", ""] //image with link and target syntax
fadeimages[4]=["images/header_img_design.jpg", "", ""] //image with link and target syntax
fadeimages[5]=["images/header_img_heritage.jpg", "", ""] //image with link and target syntax
fadeimages[6]=["images/header_img_trust.jpg", "", ""] //image with link and target syntax

var fadeimages2=new Array()
//SET IMAGE PATHS. Extend or contract array as needed
fadeimages2[0]=["images/header_img_living.jpg", "", ""] //plain image syntax
fadeimages2[1]=["images/header_img_dining.jpg", "", ""] //image with link syntax
fadeimages2[2]=["images/header_img_passion.jpg", "", ""] //image with link and target syntax
fadeimages2[3]=["images/header_img_quality.jpg", "", ""] //image with link and target syntax
fadeimages2[4]=["images/header_img_design.jpg", "", ""] //image with link and target syntax
fadeimages2[5]=["images/header_img_heritage.jpg", "", ""] //image with link and target syntax
fadeimages2[6]=["images/header_img_trust.jpg", "", ""] //image with link and target syntax

var fadebgcolor="white"

////NO need to edit beyond here/////////////

var fadearray=new Array() //array to cache fadeshow instances
var fadeclear=new Array() //array to cache corresponding clearinterval pointers

var dom=(document.getElementById) //modern dom browsers
var iebrowser=document.all

function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder){
this.pausecheck=pause
this.mouseovercheck=0
this.delay=delay
this.degree=10 //initial opacity degree (10%)
this.curimageindex=0
this.nextimageindex=1
fadearray[fadearray.length]=this
this.slideshowid=fadearray.length-1
this.canvasbase="canvas"+this.slideshowid
this.curcanvas=this.canvasbase+"_0"
if (typeof displayorder!="undefined")
theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
this.theimages=theimages
this.imageborder=parseInt(borderwidth)
this.postimages=new Array() //preload images
for (p=0;p<theimages.length;p++){
this.postimages[p]=new Image()
this.postimages[p].src=theimages[p][0]
}

var fadewidth=fadewidth+this.imageborder*2
var fadeheight=fadeheight+this.imageborder*2

if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div><div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div></div>')
else
document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>')

if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
this.startit()
else{
this.curimageindex++
setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay)
}
}

function fadepic(obj){
if (obj.degree<100){
obj.degree+=10
if (obj.tempobj.filters&&obj.tempobj.filters[0]){
if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
obj.tempobj.filters[0].opacity=obj.degree
else //else if IE5.5-
obj.tempobj.style.filter="alpha(opacity="+obj.degree+")"
}
else if (obj.tempobj.style.MozOpacity)
obj.tempobj.style.MozOpacity=obj.degree/101
else if (obj.tempobj.style.KhtmlOpacity)
obj.tempobj.style.KhtmlOpacity=obj.degree/100
else if (obj.tempobj.style.opacity&&!obj.tempobj.filters)
obj.tempobj.style.opacity=obj.degree/101
}
else{
clearInterval(fadeclear[obj.slideshowid])
obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
obj.populateslide(obj.tempobj, obj.nextimageindex)
obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
}
}

fadeshow.prototype.populateslide=function(picobj, picindex){
var slideHTML=""
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML='<a href="'+this.theimages[picindex][1]+'" target="'+this.theimages[picindex][2]+'">'
slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">'
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML+='</a>'
picobj.innerHTML=slideHTML
}


fadeshow.prototype.rotateimage=function(){
	//if (this.pausecheck==1) //if pause onMouseover enabled, cache object
	//TW comment the above out
	var cacheobj=this
	if (this.mouseovercheck==1)
		setTimeout(function(){cacheobj.rotateimage()}, 100)
	else if (iebrowser&&dom||dom){
		this.resetit()
		var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
		crossobj.style.zIndex++
		fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"])",50)
		this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
	}
	else{
		var ns4imgobj=document.images['defaultslide'+this.slideshowid]
		ns4imgobj.src=this.postimages[this.curimageindex].src
	}
	this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
	
	SwapHeaderImages(this.curimageindex);

}

fadeshow.prototype.resetit=function(){
this.degree=10
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
if (crossobj.filters&&crossobj.filters[0]){
if (typeof crossobj.filters[0].opacity=="number") //if IE6+
crossobj.filters(0).opacity=this.degree
else //else if IE5.5-
crossobj.style.filter="alpha(opacity="+this.degree+")"
}
else if (crossobj.style.MozOpacity)
crossobj.style.MozOpacity=this.degree/101
else if (crossobj.style.KhtmlOpacity)
crossobj.style.KhtmlOpacity=this.degree/100
else if (crossobj.style.opacity&&!crossobj.filters)
crossobj.style.opacity=this.degree/101
}


fadeshow.prototype.startit=function(){
	var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
	this.populateslide(crossobj, this.curimageindex)
	if (this.pausecheck==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
		var cacheobj=this
		var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid)
		crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
		crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}

	}
		var cacheobj=this
		var crossobjcontainer2=iebrowser? iebrowser["imgPause"] : document.getElementById("imgPause")
		//crossobjcontainer2.onclick=function(){cacheobj.mouseovercheck=1}

		var crossobjcontainer1=iebrowser? iebrowser["imgPlay"] : document.getElementById("imgPlay")
		//crossobjcontainer1.onclick=function(){cacheobj.mouseovercheck=0}

	this.rotateimage()
}

function ValidateForm()
{
	if (document.getElementById('txtyourname').value == '' || document.getElementById('txtfriendsemail').value == '' || document.getElementById('txtyouremail').value == '')
	{
		alert('Please complete ALL fields!');
		return false;
	}
	else if (!echeck(document.getElementById('txtyouremail').value))
	{
		alert('Please enter a valid email address!');
		return false;
	}
	else if (!echeck(document.getElementById('txtfriendsemail').value))
	{
		alert('Please enter a valid email address!');
		return false;
	}
	else
		return true;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}
	
	function LoadTmpHolder(Colour)	{
	
		var flashUrl = '';
		firstTime360 = firstTime360 && (flashUrl.indexOf('.swf') > -1) && (flashUrl.indexOf('blank') < 0)
		if (!firstTime360)
		{
			HideZoomImage();
		}else{
			firstTime360 = false;
		}
		
		var	i
		for (i=0; i < arrMainImage.length; i++) {
			if	(Colour	==	arrMainImage[i][3])
				{
					tmpHolder[0]	=	arrMainImage[i];
				}
		}
		
		if	(arrThumbImage[0] != null)	{
			tmpHolder[1] = arrThumbImage[0];
			};
		if	(arrThumbImage[1] != null)	{
			tmpHolder[2] = arrThumbImage[1];
			};
		if	(arrThumbImage[2] != null)	{
			tmpHolder[3] = arrThumbImage[2];
			};
		if	(arrThumbImage[3] != null)	{
			tmpHolder[4] = arrThumbImage[3];
			};
		if	(arrThumbImage[4] != null)	{
			tmpHolder[5] = arrThumbImage[4];
			};
		if	(arrThumbImage[5] != null)	{
			tmpHolder[6] = arrThumbImage[5];
			};
			
	}

	function ReplaceImageFromThumb(imgThumbIndex) {
		var	tmp1 = tmpHolder[imgThumbIndex];
		var tmp2 = tmpHolder[0];
		
		tmpHolder[0] = tmp1;
		//tmpHolder[imgThumbIndex] = tmp2;				
		
		HideZoomImage();
		PopulateImages();
	}
	
	function PopulateImages(){
		document.getElementById('imgMainImageZoom').src = '';
		if (document.getElementById('imgMainImage') != null)	{
			try{
				if	(tmpHolder[0] != null)	{
					document.getElementById('imgMainImage').src = tmpHolder[0][1];
					};
				/*if	(tmpHolder[1] != null)	{
					document.getElementById('imgThumb1').src = tmpHolder[1][0];
					};
				if	(tmpHolder[2] != null)	{
					document.getElementById('imgThumb2').src = tmpHolder[2][0];
					};
				if	(tmpHolder[3] != null)	{
					document.getElementById('imgThumb3').src = tmpHolder[3][0];
					};*/
			}
			catch(e){}
		};
		
	}

	function ShowZoomImage()	{
		if	(tmpHolder[0] != null)	{
			oZoomImage = new Image();
			oZoomImage.src = tmpHolder[0][2];					
								
			if (document.getElementById) { // DOM 3: IE5+, NS6, Firefox#
			
				document.getElementById("imgMainImage").style.display = "none";
				document.getElementById("dvMainImageZoom").style.display = "block";
				
				document.getElementById("hypZoomPlus").style.display = "none";
				document.getElementById("hypZoomMinus").style.display = "block";
			} else if (document.layers) { // Netscape 4
			
				document.imgMainImage.style.display = "none";
				document.dvMainImageZoom.style.display = "block";
				
				document.hypZoomPlus.style.display = "none";
				document.hypZoomMinus.style.display = "block";
			} else if (document.all) { // IE 4
			
				document.all.imgMainImage.style.display = "none";
				document.all.dvMainImageZoom.style.display = "block";
				
				document.all.hypZoomPlus.style.display = "none";
				document.all.hypZoomMinus.style.display = "block";
			}
		}
		
		if (!oZoomImage.complete) {
			//document.getElementById('dvMainImageZoom').innerHTML = document.getElementById('content_product_loading' ).innerHTML;
			tZoomLoaded = setInterval(checkZoomLoaded,'500');
		} else {
			checkZoomLoaded();
		}
		
	}
		
	function checkZoomLoaded(){
		if (oZoomImage.complete){
			document.getElementById('dvMainImageZoom').innerHTML = '<img id="imgMainImageZoom" src="' + oZoomImage.src + '" />';
			clearTimeout(tZoomLoaded);	
			//the height parameter following is no longer in use	
			enableDrag('dvMainImageZoom', 'imgMainImageZoom', 800, 800);					
		}
	}
	
	function HideZoomImage()	{
		if (document.getElementById) { // DOM 3: IE5+, NS6, Firefox#
			if (document.getElementById("imgMainImage") != null) {document.getElementById("imgMainImage").style.display = "block";};
			document.getElementById("dvMainImageZoom").style.display = "none";
			if (document.getElementById("hypZoomPlus") != null) {document.getElementById("hypZoomPlus").style.display = "block";};
			if (document.getElementById("hypZoomMinus") != null) {document.getElementById("hypZoomMinus").style.display = "none";};
		} else if (document.layers) { // Netscape 4
			if (document.imgMainImage != null) {document.imgMainImage.style.display = "block";};
			document.dvMainImageZoom.style.display = "none";
			if (document.hypZoomPlus != null) {document.hypZoomPlus.style.display = "block";};
			if (document.hypZoomMinus != null) {document.hypZoomMinus.style.display = "none";};
		} else if (document.all) { // IE 4
			if (document.all.imgMainImage != null) {document.all.imgMainImage.style.display = "block";};
			document.all.dvMainImageZoom.style.display = "none";
			if (document.all.hypZoomPlus != null) {document.all.hypZoomPlus.style.display = "block";};
			if (document.all.hypZoomMinus != null) {document.all.hypZoomMinus.style.display = "none";};
		}

	}
	
	//New Window PopUp
	function SmallWin(page) {
		NewLeft = (screen.width - 630) / 2;
		NewTop = (screen.height - 470) / 2;
		window.open(page,"","status=no,scrollbars=yes,resizable=no,width=630,height=570,top="+ NewTop +",left=" + NewLeft);
	}

	function AdjustablePopup(page,resizable,scrollbars,width,height) {
		NewLeft = (screen.width - width) / 2;
		NewTop = (screen.height - height) / 2;
		window.open(page,"","status=no,scrollbars=" + scrollbars + ",resizable=" + resizable + ",width=" + width + ",height=" + height + ",top="+ NewTop +",left=" + NewLeft);
	}

	var mywindow;
	function spawnwindow(url, name, attributes)
	{
		mywindow=window.open(url,name,attributes);
		if (window.focus) {mywindow.focus()}
	}
	//End

	var testemail
	function checkemail(emailtotest){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(emailtotest))
		testemail=true;
	else{
		testemail=false;
	}
	return (testemail);
	}

	//Drag Image Start
	var dragObject  = null;
	var mouseOffset = null;
	var dragContainer = null;

	function getCanvasWidth() { 
	   return document.body.offsetWidth || window.innerWidth; 
	} 

	function getCanvasHeight() { 
	   return document.body.offsetHeight || window.innerHeight; 
	} 

	function makeContainer(item){
		dragContainer = item;
		dragContainer.style.position = 'relative';
		dragContainer.style.overflow = 'hidden';
	}

	function getMouseOffset(target, ev){
		ev = ev || window.event;

		var docPos    = getPosition(target);
		var mousePos  = mouseCoords(ev);

		return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
	}

	function getPosition(obj){
		var left = 0;
		var	top = 0;
		
		if (obj.offsetParent) {

			left += obj.offsetLeft ;
			top += obj.offsetTop;		
			
			while (obj = obj.offsetParent) {
				if (parseInt(obj.style.left)) {
					left -= parseInt(obj.style.left);
					top -= parseInt(obj.style.top);
				}
			}
		}
		return {x:left, y:top};
	}

	function mouseCoords(ev){
		if(ev.pageX || ev.pageY){
			return {x:ev.pageX, y:ev.pageY};
		}
		return {
			x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
			y:ev.clientY + document.body.scrollTop  - document.body.clientTop
		};
	}

	function mouseMove(ev){
		ev           = ev || window.event;
		var mousePos = mouseCoords(ev);
		var targWidth, targHeight, targPos;
		var browseWidth, browseHeight;

		browseWidth		=	getCanvasWidth();
		browseHeight	=	getCanvasHeight();

		if(dragObject){	
			if (dragContainer) {
				targWidth  = parseInt(dragContainer.offsetWidth);
				targHeight = parseInt(dragContainer.offsetHeight);
				if (((mousePos.y - mouseOffset.y) < 0) && ((mousePos.y - mouseOffset.y + dragObject.height) > (targHeight)))	{dragObject.style.top	= (mousePos.y - mouseOffset.y) + 'px';}
				if (((mousePos.x - mouseOffset.x) < 0) && ((mousePos.x - mouseOffset.x + dragObject.width) > (targWidth)))	{dragObject.style.left	= (mousePos.x - mouseOffset.x) + 'px';}
			} else {
				dragObject = null;
			}
			return false;
		}
	}

	function mouseUp(){
			dragObject = null;
	}

	function makeDraggable(item){
		if(!item) return;
		try {item.style.cursor = 'pointer';} catch (e) {} //cursor property breaks IE5.5
		item.onmousedown = function(ev){		
			dragObject  = this;
			dragObject.style.position = 'absolute';
			mouseOffset = getMouseOffset(this, ev);
			return false;
		}
	}

	function enableDrag(spContainer, imgDrag, imgWidth, imgHeight) {

		var dragItem = null;
		var dragCont = null;
		var contW, contH = 0;
		var top, left;
		
		document.onmousemove = mouseMove;
		document.onmouseup   = mouseUp;
		
		dragCont = document.getElementById(spContainer);
		makeContainer(dragCont);

		dragItem = document.getElementById(imgDrag);
		makeDraggable(dragItem);
		dragItem.style.position = 'absolute';
		
		//dragItem.style.height = imgHeight + 'px'; 
		dragItem.style.width = imgWidth + 'px';
		
		dragItem.style.top = -100; 
		dragItem.style.left = -200;
		dragItem.top = 0; 
		dragItem.left = 0;
			
		top = -((parseInt(dragItem.style.height)/2) - (parseInt(dragCont.style.height)/2));
		left = -((parseInt(dragItem.style.width)/2) - (parseInt(dragCont.style.width)/2));
		
		dragItem.style.top = top +'px';
		dragItem.style.left = left+'px';
		
		dragItem.top = dragItem.style.top;
		dragItem.left = dragItem.style.left;
		
		dragItem.alt = 'Click and hold to drag image';	
	}
	//Drag Image End