// Add sfhover to enable the menus to work on IE6 (which does not support the li:hover pseudo class)
// Deliberately not using JQuery for this to extend support back to IE 5.5
sfHover = function() {
  if (document.getElementById("nav")) {
    var sfEls = document.getElementById("nav").getElementsByTagName("li");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
            // Added code here to add a special extra class to the top menu items
            // this is so that we can swap the hover images on IE6.
            // If the class names change then this code will need to change too
            if      (this.className == "popupmenu-products")  { this.className += " products-sfhover";  }
            else if (this.className == "popupmenu-buynow")    { this.className += " buynow-sfhover";    }
            else if (this.className == "popupmenu-support")   { this.className += " support-sfhover";   }
            else if (this.className == "popupmenu-corporate") { this.className += " corporate-sfhover"; }
            this.className+=" sfhover";
        };
        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
            this.className=this.className.replace(new RegExp(" products-sfhover\\b"), "");
            this.className=this.className.replace(new RegExp(" buynow-sfhover\\b"), "");
            this.className=this.className.replace(new RegExp(" support-sfhover\\b"), "");
            this.className=this.className.replace(new RegExp(" corporate-sfhover\\b"), "");
        };
        sfEls[i].ontouchstart=function() { this.className = "sfhover"; };
        sfEls[i].ontouchend=function() { this.className = ""; };
    }
  }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function setupFAQPage() {
       $('#blueant-faq').show();
       $('dd').hide();
       $('dt').click( function(){    $(this).next().toggle("fast");      });
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// Define variables used in browser detection in Flash code
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

/* START Index Page Rollover and Slideshow Code */

function rolloverSwitch(wrapperID, newProduct) {

    var $active = $('#' + wrapperID + ' a.active');
    var $next = $('#' + newProduct);
    // Only do the switch if the last active class is NOT present
    // if it is then we are still running a previous animation
    var $currentactive = $('#' + wrapperID + ' a.last-active');

    if ( $currentactive.length == 0 && !$next.is(".active") ) {
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 300, function() {
            $active.removeClass('active last-active');
        });
    }
}

/* END Index Page Rollover and Slideshow Code */

/* START jQuery Cookies */

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/* END jQuery Cookies */

/* START: Auto grow text areas (primarily implemented for mobile devices, but used for all versions of the site */
$(document).ready(function(){ 
    $("textarea").keyup(function(e){ grow(this); }); 
    $("textarea").css("overflow","hidden");
});
function grow(textarea) {
	var TEXTAREA_LINE_HEIGHT = 5;
	var newHeight = textarea.scrollHeight;
	var currentHeight = textarea.clientHeight;
	if (newHeight > currentHeight) {
	textarea.style.height = newHeight + 5 * TEXTAREA_LINE_HEIGHT + 'px';
	}
}

/* END: Auto grow text areas */
