// JavaScript Document
var visibleDiv = 2;
var invisibleDiv = 1;

function addLoadEvent(func) {
	var oldonload = window.onload;

	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
		if (oldonload) {
			oldonload();
		}
			func();
		}
	}
}

function setMaxHeight150Off(id1,id2) {
	height1 = document.getElementById(id1).offsetHeight;
	height2 = document.getElementById(id2).offsetHeight;
	if (height1 > (height2+150)) {
		document.getElementById(id2).style.height = (height1-150)+'px';
	} else {
		document.getElementById(id1).style.height = (height2+150)+'px';
	}
}

function setMaxHeight(id1,id2) {
	height1 = document.getElementById(id1).offsetHeight;
	height2 = document.getElementById(id2).offsetHeight;
	if (height1 > height2) {
		document.getElementById(id2).style.height = height1+'px';
	} else {
		document.getElementById(id1).style.height = height2+'px';
	}
}

function clearIf(field,string) {
	if(field.value == string) {
		field.value = '';	
	}
}

function setIfBlank(field,string) {
	if(field.value == '') {
		field.value = string;	
	}
}

function displayMenuMain(name) {
	document.getElementById(name+'SubMenu').style.display = 'block';
	if (document.getElementById(name+'But').style.backgroundImage == 'url("/site_cms/assets/images/menuBG.jpg")' || document.getElementById(name+'But').style.backgroundImage == 'url(/site_cms/assets/images/menuBG.jpg)'|| document.getElementById(name+'But').style.backgroundImage == '') {
		document.getElementById(name+'But').style.backgroundImage = 'url("/site_cms/assets/images/menuBGOver.jpg")';
	}
}

function hideMenuMain(name) {
	document.getElementById(name+'SubMenu').style.display = 'none';
	if (document.getElementById(name+'But').style.backgroundImage == 'url("/site_cms/assets/images/menuBGOver.jpg")' || document.getElementById(name+'But').style.backgroundImage == 'url(/site_cms/assets/images/menuBGOver.jpg)') {
		document.getElementById(name+'But').style.backgroundImage = 'url("/site_cms/assets/images/menuBG.jpg")';
	}
}

function subMenuMouseOver(name) {
	document.getElementById(name+'But').style.backgroundImage = 'url("/site_cms/assets/images/subMenuBGOver.png")';
}

function subMenuMouseOut(name) {
	document.getElementById(name+'But').style.backgroundImage = 'url("/site_cms/assets/images/subMenuBG.png")';
}

function subMenuFinalMouseOver(name) {
	document.getElementById(name+'But').style.backgroundImage = 'url("/site_cms/assets/images/subMenuBGFinalOver.png")';
}

function subMenuFinalMouseOut(name) {
	document.getElementById(name+'But').style.backgroundImage = 'url("/site_cms/assets/images/subMenuBGFinal.png")';
}

activeMiniId = 'homeMini1';
canChange = true;
function setActiveMini(id) {
	if (canChange) {
		canChange = false;
		document.getElementById(activeMiniId).className = 'homeMiniMenu';
		document.getElementById(id).className = 'homeMiniMenuActive';
		$('#'+activeMiniId+'Content').fadeOut('slow', function() {
			$('#'+id+'Content').fadeIn('slow', function() {
				canChange = true;	
			})
		 });
		 activeMiniId = id;
	}
}

function galleryBack() {
	if(currentPos != 1) {
		currentPos = currentPos - 1;
		document.getElementById('imageGalleryMenuCount').innerHTML = "<strong>"+currentPos+"</strong> of "+totalCount+" -";
		document.getElementById('imageGalleryTitle').innerHTML = galleryHeadingArray[currentPos];
		var newImage = "url(/site_cms/assets/images/imageGalleryDepot/" + galleryImageArray[currentPos] + ")";
		document.getElementById('imageGalleryLarge'+invisibleDiv).style.backgroundImage = newImage;
		$('#imageGalleryLarge'+invisibleDiv).fadeIn('1200');
		$('#imageGalleryLarge'+visibleDiv).fadeOut('1200');
		var tempStorage = visibleDiv;
		visibleDiv = invisibleDiv;
		invisibleDiv = tempStorage;
	}
}

function galleryForward() {
	if(currentPos != totalCount) {
		currentPos = currentPos + 1;
		document.getElementById('imageGalleryMenuCount').innerHTML = "<strong>"+currentPos+"</strong> of "+totalCount+" -";
		document.getElementById('imageGalleryTitle').innerHTML = galleryHeadingArray[currentPos];
		var newImage = "url('/site_cms/assets/images/imageGalleryDepot/" + galleryImageArray[currentPos] + "')";
		document.getElementById('imageGalleryLarge'+invisibleDiv).style.backgroundImage = newImage;
		$('#imageGalleryLarge'+invisibleDiv).fadeIn('1200');
		$('#imageGalleryLarge'+visibleDiv).fadeOut('1200');
		var tempStorage = visibleDiv;
		visibleDiv = invisibleDiv;
		invisibleDiv = tempStorage;
	}
}

function resizeDiv() 
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	
	myWidth = window.innerWidth;
	
	myHeight = window.innerHeight + window.scrollMaxY;
	myOffset = (window.pageYOffset+50);
	
	/*myHeight = (document.body.offsetHeight>document.body.scrollHeight)? document.body.offsetHeight : document.body.scrollHeight;*/
	
	//+document.body.scrollHeight
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.body.offsetHeight;
	myHeight = document.body.offsetHeight;
	myOffset = (document.documentElement.scrollTop+50);	
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.offsetHeight;
	myHeight = document.body.offsetHeight;
	myOffset = (document.body.scrollTop+50);	
  }
  
 	myHeight= (document.body.offsetHeight>document.body.scrollHeight)? document.body.offsetHeight : document.body.scrollHeight;
	document.getElementById("overlayDiv").style.height=myHeight + "px";
	// if IE 7+, Firefox
	if (typeof document.body.style.maxHeight != "undefined")
	{
		document.getElementById("overlayDiv").style.height=(myHeight+17) + "px";
		if (navigator.appVersion.indexOf("MSIE 7.")==-1) {
			document.getElementById("overlayDiv").style.height=(myHeight) + "px";
		}
	}
	else
	{
		// IE 6 or older
		document.getElementById("overlayDiv").style.height=(myHeight*1.5) + "px";
	}
	
	document.getElementById("overlayDiv").style.width="100%";
	document.getElementById("overlayDiv").style.display="block";
	document.getElementById("overlayContent").style.display="block";
	document.getElementById("overlayContent2").style.display="none";
}

function hideDiv(DivId)
{
    parent.document.getElementById(DivId).style.display = "none";
}	

/* function menuMouseOver(tabName) {
	document.getElementById('headerMenuLeft-'+tabName).className = "headerMenuLeftOver";
	document.getElementById('headerMenuMiddle-'+tabName).className = "headerMenuMiddleOver";
	document.getElementById('headerMenuRight-'+tabName).className = "headerMenuRightOver";
}

function menuMouseOut(tabName) {
	document.getElementById('headerMenuLeft-'+tabName).className = "headerMenuLeft";
	document.getElementById('headerMenuMiddle-'+tabName).className = "headerMenuMiddle";
	document.getElementById('headerMenuRight-'+tabName).className = "headerMenuRight";
}

*/

var globalImg = 1;

function currentImg(direction,totalNum){
	
	if(direction == 'next'){
		if(globalImg < totalNum){
			globalImg++;
			document.getElementById('currentImg').innerHTML = ''+ globalImg +'';
		}

	}else{
		if(globalImg > 1){
			globalImg--;
			document.getElementById('currentImg').innerHTML = ''+ globalImg +'';
		}
	}
}


function flyout(){
	if(document.getElementById('noosaElse').style.display == 'block'){
		document.getElementById('noosaElse').style.display = 'none';
	}else{
		document.getElementById('noosaElse').style.display = 'block';
	}
}



// Copyright (C) 2005-2008 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Re-distribute this code or any part of it.
//     Instead, you may link to the homepage of this code:
//     http://www.php-development.ru/javascripts/dropdown.php
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as part of another product.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind.
// You expressly acknowledge and agree that use of this code is at your own risk.


// ***** Popup Control *********************************************************

// ***** at_show_aux *****

function at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child );
  p.className = parent+'HasMenu';
  
  var top  = (c["at_position"] == "y") ? p.offsetHeight : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth : 0;

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  c.style.visibility = "visible";

}

// ***** at_show *****

function at_show()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);
  
   
   at_show_aux(p.id, c.id);
  clearTimeout(c["at_timeout"]);
}

// ***** at_hide *****

function at_hide()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);
  p.className = this["at_parent"];
  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'",0);
}

// ***** at_click *****

function at_click()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") at_show_aux(p.id, c.id); else c.style.visibility = "hidden";
  return false;
}

// ***** at_attach *****

// PARAMETERS:
// parent   - id of the parent html element
// child    - id of the child  html element that should be droped down
// showtype - "click" = drop down child html element on mouse click
//            "hover" = drop down child html element on mouse over
// position - "x" = display the child html element to the right
//            "y" = display the child html element below
// cursor   - omit to use default cursor or specify CSS cursor name

function at_attach(parent, child, showtype, position, cursor)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);
  var pstyle = p.style;

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  switch (showtype)
  {
    case "click":
      p.onclick     = at_click;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
    case "hover":
	  
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
  }
}

