/* scripts used by AirTime Products */
/************************************/

/* Alert if under construction--override variable in XHTML */
var underConstruction = false ; // turn this false to disable
function devStart(){
  if ( underConstruction ) alert( "This site is currently under construction and may not operate as expected. \r\rContent is still being added. We'll be up and flying soon!" ) ;
  return true ;
}

/* Get available height in browser for content */
function getWindowHeight() {
	var windowHeight = 0;
	 if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

/* Get available width in browser for content */
function getWindowWidth() {
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}

/* hack to force content panel to extend exactly to bottom of client area */
function panelResize() {
  var newWidth = getWindowWidth() ;
  var theHTML = document.getElementsByTagName( 'html' );
  if ( theHTML.length ) theHTML[0].style.overflow = newWidth < 770 ? 'auto' : 'hidden' ;

  var newHeight = getWindowHeight() - 5 ;  // allow for border 
  if ( newWidth < 770 ) newHeight -= 16 ;
  var thePanel = document.getElementById( 'panel' );
  var theContent = document.getElementById( 'content' );
  thePanel.style.visibility = 'hidden' ;
  thePanel.style.height = ( newHeight ) + 'px' ;
  theContent.style.height = ( newHeight - 138 ) + 'px' ;
  thePanel.style.visibility = 'visible' ;
  
  return true ;
}

/* stop IE from flickering background graphics */
function IEKillCache(){
	try {
		document.execCommand("BackgroundImageCache",false,true) ;
	} catch( err ){} ;
}
if ( window.attachEvent ) window.attachEvent( "onload", IEKillCache ) ;

/* Dropdown menu credit to Son of Suckerfish copyright Patrick Griffiths, 2003-2007.
http://www.htmldog.com/articles/suckerfish/dropdowns/  
Only attach if IE */

var sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if ( window.attachEvent ) window.attachEvent( "onload", sfHover ) ;

/* Move the flyer across the banner */
var flyerTimer = 0 ;
var flyerPos = 300 ;
var flyerIncr = 6 ;
var flyerObj = null ;

var flyerShift = function() {
	if ( 0 < ( flyerPos -= flyerIncr )) {
        flyerObj.style.visibility = "hidden" ;
		flyerObj.style.marginLeft = flyerPos + "px" ;
        flyerObj.style.visibility = "visible" ;
	}
	else {
		clearInterval( flyerTimer ) ;
	}
}

var flyerInit = function() {
	flyerObj = document.getElementById( "banner" ) ;
	var pos = flyerObj.offsetLeft ;
	flyerObj = document.getElementById( "bannerflyer" ) ;
	if ( flyerObj.offsetLeft - pos > flyerPos ) { // IE5
		flyerPos /= 2 ;
		flyerIncr /= 2 ;
	}
	flyerTimer = setInterval( flyerShift, 40 ) ;
}

/* unobtrusively start other event handler(s) */
function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
addEvent( window, 'load', panelResize ) ;
addEvent( window, 'resize', panelResize ) ;
addEvent( window, 'load', devStart );
addEvent( window, 'load', flyerInit ) ;

/* Display feature, highlight item */
function showFeature( e, img ) {
	var o = document.getElementById( "featurelist" ) ;
	var offsetTop = o.offsetTop +1 ; /*Peter changed to +1 to line up with top of feature */
	o = o.getElementsByTagName( "li" ) ;
	for ( var i = 0 ; i < o.length ; i++ ) {
		if ( o[i].className == "featureactive" ) o[ i ].className = "featureinactive" ;
	}
	
	if ( !e ) e = window.event ;
	if ( e ) {
		o = e.target || e.srcElement ;
		if ( o.nodeType == 3 ) o = o.parentNode ; // weird Safari
		o.className = "featureactive" ;
		offsetTop = o.offsetTop - offsetTop ;
	}
	else offsetTop = 0 ;
	
	o = document.getElementById( "feature" ) ;
	o.style.visibility = "hidden" ;
	o.style.marginTop = offsetTop + "px" ;
	o.src = 'assets/' + img ;
	o.style.visibility = "visible" ;
	
}

/* Feature list rollovers for IE -- load it only on page */
var featHover = function() {
	var featEls = document.getElementById( "featurelist" ).getElementsByTagName( "li" );
	for ( var i=0; i<featEls.length; i++ ) {
		if ( featEls[i].className == "featureactive" || featEls[i].className == "featureinactive"  ) {
			featEls[i].onmouseover = function() {
				this.className += " feathover";
			}
			featEls[i].onmouseout = function() {
				this.className = this.className.replace(new RegExp(" feathover\\b"), "");
			}
		}
	}
}

/* Standard footer text updates automatically */
function footerText() {
  var today = new Date() ;
  document.writeln( 
    "Copyright &copy; Airtime Products " + today.getFullYear() + " - All Rights Reserved." ) ;
  document.write(
    "&nbsp;&nbsp;&nbsp;Page updated:&nbsp;"+document.lastModified ) ;
}


