// COMMON FUNCTIONS
function ChangeClass(item, changeClass)
{
item.className = changeClass;
}

function findLinkByHref(href) {
  for (var i=0; i<document.links.length; i++) {
    if (document.links[i].href == href) return i;
  }
  return -1;
}

function changeLinkHref(id,newHref,oldHref) {
  if (document.links.length > 0) {
    if (document.getElementById) {
      document.getElementById(id).href = newHref;
    }
    else if (document.all) {
      document.all[id].href = newHref;
    }
    else {
      var index = findLinkByHref(oldHref);
      if (index > -1)
        document.links[index].href = newHref;
    }
  }
}

/*
	Header Information------------------------------------[Do Not Remove This Header]--
	Title: OO Dom Image Rollover
	Description: This script makes it easy to add rollover/ mousedown 
  	effects to any image on the page, including image submit buttons. Automatically 
  	preloads images as well. Script works in all DOM capable browsers- IE5+, NS6+, 
  	Opera7+.
	
	Legal: Copyright 2005 Adam Smith
	Author Email Address: ibulwark@hotmail.com
	Date Created: June 6, 2005
	Website: Codevendor.com | eBadgeman.com
	Script featured on Dynamic Drive: http://www.dynamicdrive.com
	-----------------------------------------------------------------------------------
*/

function imageholderclass(){
	this.over=new Array();
	this.down=new Array();
	this.src=new Array();
	this.store=store;
	
	function store(src, down, over){
		var AL=this.src.length;
		this.src[AL]=new Image(); this.src[AL].src=src;
		this.over[AL]=new Image(); this.over[AL].src=over;
		this.down[AL]=new Image(); this.down[AL].src=down;
	}
}

var ih = new imageholderclass();
var mouseisdown=0;

function preloader(t){
	for(i=0;i<t.length;i++){
		if(t[i].getAttribute('srcover')||t[i].getAttribute('srcdown')){
			
			storeimages(t[i]);
			var checker='';
			checker=(t[i].getAttribute('srcover'))?checker+'A':checker+'';
			checker=(t[i].getAttribute('srcdown'))?checker+'B':checker+'';
			
			switch(checker){
			case 'A' : mouseover(t[i]);mouseout(t[i]); break;
			case 'B' : mousedown(t[i]); mouseup2(t[i]); break;
			case 'AB' : mouseover(t[i]);mouseout(t[i]); mousedown(t[i]); mouseup(t[i]); break;
			default : return;			
			}
			
			if(t[i].src){t[i].setAttribute("oldsrc",t[i].src);}
		}
	}
}
function mouseup(t){
	var newmouseup;
	if(t.onmouseup){
		t.oldmouseup=t.onmouseup;
		newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("srcover");this.oldmouseup();}

	}
	else{newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("srcover");}}
	t.onmouseup=newmouseup;
}

function mouseup2(t){
	var newmouseup;
	if(t.onmouseup){
		t.oldmouseup=t.onmouseup;
		newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("oldsrc");this.oldmouseup();}
		}
	else{newmouseup=function(){mouseisdown=0;this.src=this.getAttribute("oldsrc");}}
	t.onmouseup = newmouseup;
}

function mousedown(t){
	var newmousedown;
	if(t.onmousedown){
		t.oldmousedown=t.onmousedown;
		newmousedown=function(){if(mouseisdown==0){this.src=this.getAttribute("srcdown");this.oldmousedown();}}
	}
	else{newmousedown=function(){if(mouseisdown==0){this.src=this.getAttribute("srcdown");}}}
	t.onmousedown=newmousedown;
}

function mouseover(t){
	var newmouseover;
	if(t.onmouseover){
		t.oldmouseover=t.onmouseover;
		newmouseover=function(){this.src=this.getAttribute("srcover");this.oldmouseover();}
	}
	else{newmouseover=function(){this.src=this.getAttribute("srcover");}}
	t.onmouseover=newmouseover;
}

function mouseout(t){
	var newmouseout;
	if(t.onmouseout){
		t.oldmouseout=t.onmouseout;
		newmouseout=function(){this.src=this.getAttribute("oldsrc");this.oldmouseout();}
	}
	else{newmouseout=function(){this.src=this.getAttribute("oldsrc");}}
	t.onmouseout=newmouseout;
}

function storeimages(t){
	var s=(t.getAttribute('src'))?t.getAttribute('src'):'';
	var d=(t.getAttribute('srcdown'))?t.getAttribute('srcdown'):'';
	var o=(t.getAttribute('srcover'))?t.getAttribute('srcover'):'';
	ih.store(s,d,o);
}

function preloadimgsrc(){
	if(!document.getElementById) return;
	var it=document.getElementsByTagName('IMG');
	var it2=document.getElementsByTagName('INPUT');
	preloader(it);
	preloader(it2);
}

if(window.addEventListener){window.addEventListener("load", preloadimgsrc, false);} 
else{
	if(window.attachEvent){window.attachEvent("onload", preloadimgsrc);}
	else{if(document.getElementById){window.onload=preloadimgsrc;}}
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// SCROLLER FUNCTIONS
// gives up and down scroll buttons to images, spans, ... named up_name, down_name, respectively.
// will keep the default scroll_box's style overflow if it encounters errors (so make overflow: auto;)

// usage: put this after the scrollbox div:  var div_scroll1 = new TextScroll('div_scroll1', 'scroll_box');
function TextScroll(scrollname, div_name, up_name, down_name)
{
    this.div_name = div_name;
    this.name = scrollname;
    this.scrollCursor = 0;
    this.speed = 5;
    this.timeoutID = 0;
    this.div_obj = null;
    this.up_name = up_name;
    this.dn_name = down_name;

{
        if (document.getElementById) {
            div_obj = document.getElementById(this.div_name);
            if (div_obj) {
                this.div_obj = div_obj;
                this.div_obj.style.overflow = 'hidden';
            }
            div_up_obj = document.getElementById(this.up_name);
            div_dn_obj = document.getElementById(this.dn_name);
            if (div_up_obj && div_dn_obj) {
				div_up_obj.onmouseover = function() { eval(scrollname + ".scrollUp();") };
				div_up_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
				
				div_dn_obj.onmouseover = function() { eval(scrollname + ".scrollDown();") };
				div_dn_obj.onmouseout = function() { eval(scrollname + ".stopScroll();") };
            }
        }
    }

this.stopScroll = function() {
        clearTimeout(this.timeoutID);
    }

this.scrollUp = function() {
        if (this.div_obj) {
            this.scrollCursor = (this.scrollCursor - this.speed) < 0 ? 0 : this.scrollCursor - this.speed;
            this.div_obj.scrollTop = this.scrollCursor;
            this.timeoutID = setTimeout(this.name + ".scrollUp()", 60);
        }
    }

this.scrollDown = function() {
if (this.div_obj) {
this.scrollCursor += this.speed;
this.div_obj.scrollTop = this.scrollCursor;
if (this.div_obj.scrollTop == this.scrollCursor) {
this.timeoutID = setTimeout(this.name + ".scrollDown()", 60);
} else {
this.scrollCursor = this.div_obj.scrollTop;
}
}
}

this.resetScroll = function() {
        if (this.div_obj) {
            this.div_obj.scrollTop = 0;
            this.scrollCursor = 0;
        }
    }
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//<!-- Original:  Nicholas Lupien (smylex@aol.com) -->

//<!-- This script and many more are available free online at -->
//<!-- The JavaScript Source!! http://javascript.internet.com -->

//<!-- Begin
var rand1 = 0;
var useRand = 0;

images = new Array;
images[1] = new Image();
images[1].src = "images/homepics/pic1.jpg";
images[1].alt = "Beach House, Port Fairy";
images[1].title = "Beach House, Port Fairy";
images[2] = new Image();
images[2].src = "images/homepics/pic2.jpg";
images[2].alt = "Beach House, Port Fairy";
images[2].title = "Beach House, Port Fairy";
images[3] = new Image();
images[3].src = "images/homepics/pic3.jpg";
images[3].alt = "Kvadrat Maharam";
images[3].title = "Kvadrat Maharam";
images[4] = new Image();
images[4].src = "images/homepics/pic4.jpg";
images[4].alt = "Private House, Sydney";
images[4].title = "Private House, Sydney";
images[5] = new Image();
images[5].src = "images/homepics/pic5.jpg";
images[5].alt = "Bush Retreat, Hunter Valley";
images[5].title = "Bush Retreat, Hunter Valley";
images[6] = new Image();
images[6].src = "images/homepics/pic6.jpg";
images[6].alt = "Beach House, Port Fairy";
images[6].title = "Beach House, Port Fairy";
images[7] = new Image();
images[7].src = "images/homepics/pic7.jpg";
images[7].alt = "Kvadrat Maharam";
images[7].title = "Kvadrat Maharam";
images[8] = new Image();
images[8].src = "images/homepics/pic8.jpg";
images[8].alt = "Beach House, Torquay";
images[8].title = "Beach House, Torquay";
images[9] = new Image();
images[9].src = "images/homepics/pic9.jpg";
images[9].alt = "Tilbury Hotel";
images[9].title = "Tilbury Hotel";
images[10] = new Image();
images[10].src = "images/homepics/pic10.jpg";
images[10].alt = "Bush Retreat, Hunter Valley";
images[10].title = "Bush Retreat, Hunter Valley";
images[11] = new Image();
images[11].src = "images/homepics/pic11.jpg";
images[11].alt = "Beach Road Hotel ";
images[11].title = "Beach Road Hotel";
images[12] = new Image();
images[12].src = "images/homepics/pic12.jpg";
images[12].alt = "Tilbury Hotel";
images[12].title = "Tilbury Hotel";
images[13] = new Image();
images[13].src = "images/homepics/pic13.jpg";
images[13].alt = "Tilbury Hotel";
images[13].title = "Tilbury Hotel";
images[14] = new Image();
images[14].src = "images/homepics/pic14.jpg";
images[14].alt = " ";
images[14].title = " ";
images[15] = new Image();
images[15].src = "images/homepics/pic15.jpg";
images[15].alt = "Bush Retreat, Hunter Valley";
images[15].title = "Bush Retreat, Hunter Valley";
images[16] = new Image();
images[16].src = "images/homepics/pic16.jpg";
images[16].alt = "Beach House, Torquay";
images[16].title = "Beach House, Torquay";
images[17] = new Image();
images[17].src = "images/homepics/pic17.jpg";
images[17].alt = "Bunk Desk";
images[17].title = "Bunk Desk";
images[18] = new Image();
images[18].src = "images/homepics/pic18.jpg";
images[18].alt = "Signage Entry";
images[18].title = "Signage Entry";
images[19] = new Image();
images[19].src = "images/homepics/pic19.jpg";
images[19].alt = "Beach House, Port Fairy";
images[19].title = "Beach House, Port Fairy";
images[20] = new Image();
images[20].src = "images/homepics/pic20.jpg";
images[20].alt = "Beach House, Port Fairy";
images[20].title = "Beach House, Port Fairy";
images[21] = new Image();
images[21].src = "images/homepics/pic21.jpg";
images[21].alt = "Beach House, Port Fairy";
images[21].title = "Beach House, Port Fairy";
images[22] = new Image();
images[22].src = "images/homepics/pic22.jpg";
images[22].alt = "Desk View";
images[22].title = "Desk View";
images[23] = new Image();
images[23].src = "images/homepics/pic23.jpg";
images[23].alt = "Main Showroom";
images[23].title = "Main Showroom";
images[24] = new Image();
images[24].src = "images/homepics/pic24.jpg";
images[24].alt = "Desking";
images[24].title = "Desking";



function swapPic() {
	var imgnum=Math.floor(Math.random()*(images.length - 1)) + 1;
	document.randimg.src = images[imgnum].src;
	document.randimg.alt = images[imgnum].alt;
	document.randimg.title = images[imgnum].title;
}
//  End -->

var rand1 = 0;
var bgnumber = 0;

// Function for randomly choosing the background and then using that for the rest of the session
function chooseBG(relpath) {
	//check for cookie
	if (readCookie('ffbgcookie') != null) {//if cookie exists, use that bg
		bgnumber = readCookie('ffbgcookie');
	}
	else {//otherwise choose a random bg
		var bgnumber = 4;
		var bgnumber=Math.floor(Math.random()*(bgnumber + 1));
		createCookie('ffbgcookie',bgnumber,0) // set the cookie
	}
	if (bgnumber == 0) {
		bgnumber = 1;
	}
	 document.getElementById("bodyElement").style.backgroundImage = "url('" + relpath + "images/bg/bg" + bgnumber + ".gif')";
	//document.write(bgnumber);
	//document.write('<link REL="stylesheet" href="includes/bg' + bgnumber + '.css" TYPE="text/css">');	
}

function changeNavOpacity(navtype) {
	if (navtype == 'main') {
		ChangeClass(document.getElementById("thenavigationbg"), "navigationbg_over")
	}
	else {
		ChangeClass(document.getElementById("thesubnavigationbg"), "subnavigationbg_over")
	}
}

function changeNavOpacityBack(navtype) {
	if (navtype == 'main') {
		ChangeClass(document.getElementById("thenavigationbg"), "navigationbg")
	}
	else {
		ChangeClass(document.getElementById("thesubnavigationbg"), "subnavigationbg")
	}
}

function toggleLayer(whichLayer)
{
var style2 = document.getElementById(whichLayer).style;
style2.display = style2.display? "":"block";
}

function hideLayerForever(whichLayer)
{
var style2 = document.getElementById(whichLayer).style;
style2.display = "none";
}

function toggleProjectTitle(whichTitle) {
	var newstyle;
	var currentstyle = document.getElementById(whichTitle).className;
	if (currentstyle == "projecttitle_on") {
		newstyle = "projecttitle";
	}
	else {
		newstyle = "projecttitle_on";
	}
	ChangeClass(document.getElementById(whichTitle), newstyle);
}

function showImageNav(currImg, whichTitle) {
	var htmlstring, prevstring, nextstring, prevImg, nextImg, theid, thumbnailstring;
	
	imgArray = eval(whichTitle);
	imgTotal = imgArray.length - 1;
	
	preloadProjectThumbs(whichTitle);
	htmlstring = '';
	prevstring = '<img src="../images/projects/imagenav/imageleft.gif" alt="" width="9" height="29" border="0" name="imageleft" id="imageleft">';
	prevImg = currImg - 1;
	if (prevImg > 0) {
		prevstring = '<a href="javascript:showImageNav(' + prevImg + ',\'' + whichTitle + '\');" onMouseOver="MM_swapImage(\'imageleft\',\'\',\'../images/projects/imagenav/imageleft_over.gif\',1)" onMouseOut="MM_swapImgRestore()">' + prevstring + '</a>';
	}	
	nextstring = '<img src="../images/projects/imagenav/imageright.gif" alt="" width="9" height="29" border="0" name="imageright" id="imageright">';
	nextImg = currImg + 1;
	if (nextImg <= imgTotal) {
		nextstring = '<a href="javascript:showImageNav(' + nextImg + ',\'' + whichTitle + '\');" onMouseOver="MM_swapImage(\'imageright\',\'\',\'../images/projects/imagenav/imageright_over.gif\',1)" onMouseOut="MM_swapImgRestore()">' + nextstring + '</a>';
	}	
	htmlstring = htmlstring + '<img src="../images/projects/imagenav/' + currImg + '.gif" alt="">';
	htmlstring = htmlstring + '<img src="../images/projects/imagenav/imagediv.gif" alt="" width="15" height="29">';
	htmlstring = htmlstring + '<img src="../images/projects/imagenav/' + imgTotal + '.gif" alt="">';
	htmlstring = prevstring + htmlstring + nextstring;
	document.getElementById("projectimagenav").innerHTML = htmlstring;
	document.getElementById("projectimagenav").style.display = "block";
	// change big pic
	document.getElementById('bigpic').src = imgArray[currImg].src;
	document.getElementById('bigpic').alt = imgArray[currImg].alt;
	document.getElementById('bigpic').title = imgArray[currImg].title;
	
	//draw thumbnails
	thumbnailstring = "";
	for (i=2;i<=imgTotal;i++) {
		if (i == currImg) {
			thumbnailstring = thumbnailstring + '<img src="../images/projects/' + whichTitle + '/t/on/' + i + '.jpg" alt="" name="' + whichTitle + i + '" id="' + whichTitle + i + '" border="0"> '
		}
		else {
			thumbnailstring = thumbnailstring + '<a href="javascript:showImageNav(' + i + ',\'' + whichTitle + '\');"><img src="../images/projects/' + whichTitle + '/t/' + i + '.jpg" alt="" name="' + whichTitle + i + '" id="' + whichTitle + i + '" border="0"></a> '
		}
	}
	thumbid = whichTitle + "Thumbs";
	document.getElementById(thumbid).innerHTML = thumbnailstring;
	
	// preload the next image in the sequence
	if (document.images) {
	nextimg = new Image();
	nextno = currImg + 1;
	nextimg.src = imgArray[nextno].src;

	}
}

function preloadProjectThumbs(arrayName) {
	if (document.images) {
		imgArray = eval(arrayName);
		
		var x=2;
		for (x=2; x<imgArray.length; x++)
		{
			nextthumbimg = new Image();
			nextthumbimg.src = '../images/projects/' + arrayName + '/t/on/' + x + '.jpg';
		}
	}

}

//OPACITY FUNCTIONS

function On(element)
{
element.style.opacity=1;
element.filters.alpha.opacity=100;
}

function Off(element)
{
element.style.opacity=0.5;
element.filters.alpha.opacity=50;
}



//NEW SCROLLBAR FUNCTIONS

function init_dw_Scroll() {
    var wndo = new dw_scrollObj('wn', 'lyr1');
    wndo.setUpScrollbar("dragBar", "track", "v", 1, 1);
    wndo.setUpScrollControls('scrollbar');
}

// if code supported, link in the style sheet and call the init function onload
if ( dw_scrollObj.isSupported() ) {
    dw_writeStyleSheet('styles.css')
    dw_Event.add( window, 'load', init_dw_Scroll);
}

