// JavaScript file for SweetBriar  9 Feb 09
// for tabs etc, using sliding panel span technique drew-scientific conor may 05
//  9 Feb 09  conor  change text display technique to 'visibility' (was 'display'), also add pictures
// 16 Feb 09  conor  sweet23js.js  add accomm picture
// 20 Feb 09  conor  sweetbriar10js  remove scroller (not wanted)

var selectedTab;        		// the tab button
var oldSpan, thisSpan;          // the text content, actually divs here not spans
var normalColor = "#8ED18E";
var overColor = "#C0FFC0";
var selectedColor = "#DDAA00";

if (document.images){ 
}
	
function tabInit(){
		if (document.getElementById) {
			// select, highlight and display tab 1
			selectedTab = document.getElementById('button1div');
			oldSpan = document.getElementById('tab1div');
			selectedTab.style.backgroundColor = selectedColor; 
			
			// just initialising the opacity property. necessary if going to use it. 
			oldSpan.style.opacity = 1.0;    // FF
			oldSpan.style.filter = "alpha(opacity=100)"; // IE
		}
}

function toggleTab(myTab, currSpan) {        
		if (document.getElementById) {
			thisSpan = document.getElementById(currSpan);
			//alert("toggleTab = " + thisSpan);
			if (thisSpan == oldSpan) {   // if click the displayed Tab again, do nothing
				window.status = '';
				return false
			}
			if (oldSpan) {
				oldSpan.style.visibility = "hidden"; // undisplay old Tab content, if defined 
				selectedTab.style.backgroundColor = normalColor; // un-highlight old tab
				window.status = '';
			}
			myTab.style.backgroundColor = selectedColor; // highlight tab
			window.status = '';
			
			// display new Tab text 
			thisSpan.style.visibility = "visible";   //(oldstyle, instant)
			
			// new style ( fade in from 0% to 100%, over 2msecs, at 25 'frames' per sec)
			FadeOpacity(currSpan, 0, 100, 2000, 25);
			
			oldSpan = thisSpan;
			selectedTab = myTab;
			return false
		}
		else {
			return true
		}
	}
	
function mOver (myTab) {   // highlight tab when mouse over
			//myTab.style.backgroundImage = "url(img/tabsgrey3.gif)";
			myTab.style.backgroundColor = overColor;
			window.status = '';
}
	
function mOut (myTab) {    // on mouse out, set tab to selected or normal
			if (myTab == selectedTab) {
				myTab.style.backgroundColor = selectedColor;
			}
			else {
				myTab.style.backgroundColor = normalColor;
			}
			window.status = '';
}


// from AKXL.net   Aug 07
// to change opacity of object via javascript, multibrowser

function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps)
{
	var steps = Math.ceil(fps * (time / 1000));
	var delta = (toOpacity - fromOpacity) / steps;
	
	FadeOpacityStep(elemId, 0, steps, fromOpacity, delta, (time / steps));
}

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, delta, timePerStep)
{
    SetOpacity(document.getElementById(elemId), Math.round(parseInt(fromOpacity) + (delta * stepNum)));

    if (stepNum < steps)
        setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ");", timePerStep);
}

function SetOpacity(elem, opacityAsInt)
{
	var opacityAsDecimal = opacityAsInt;
	
	if (opacityAsInt > 100)
		opacityAsInt = opacityAsDecimal = 100; 
	else if (opacityAsInt < 0)
		opacityAsInt = opacityAsDecimal = 0; 
	
	opacityAsDecimal /= 100;
	if (opacityAsInt < 1)
		opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
	
	elem.style.opacity = opacityAsDecimal;
	elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}

