/**
 * iPhone stuff
 */
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {  
	for (var i=0; i<document.styleSheets.length; i++) {
		if (document.styleSheets[i].href != null && document.styleSheets[i].href.lastIndexOf("iphone") == -1) {
			document.styleSheets[i].disabled = true;
		}
	}
	window.scrollTo(0,1);
}

$(document).ready(function(){
    if($('#feature').length > 0) {
        $('#feature ul li:last').addClass('active');
        setInterval( "slideSwitch()", 6000 );
    }
    handleFlyouts();
    $('div.prog').equalHeights();
    $('div.fac').equalHeights();

    // Facility select
    $('#facility_select select').bind('change', function(e){
        if($(this).val().length > 0) window.location = $(this).val();
    });
});

function handleFlyouts() {
    var config = {    
        sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
        interval: 200, // number = milliseconds for onMouseOver polling interval    
        over: toggleNav, // function = onMouseOver callback (REQUIRED)    
        timeout: 500, // number = milliseconds delay before onMouseOut    
        out: toggleNav // function = onMouseOut callback (REQUIRED)    
    };

    $('#nav_programs').hide();
    $('#nav_programs').appendTo('#nav_9968');
    $('#nav_9968').hoverIntent( config );
}

function toggleNav() {
    $('#nav_9968').toggleClass("over");
    $("#nav_programs").slideToggle("normal");
}

function slideSwitch() {
    var $active = $('#feature ul li.active');
    if ( $active.length == 0 ) $active = $('#feature ul li:last');
    var $next =  $active.prev().length ? $active.prev() : $('#feature ul li:last');

    $active.fadeOut('slow').removeClass('active');
    $next.fadeIn('slow').addClass('active');
}

$.fn.equalHeights = function(px) {
    if(!isIP()) {
    var currentTallest = 0;
    $(this).each(function(i){
        if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
    });
    // for ie6, set height since min-height isn't supported
    if ($.browser.msie && $.browser.version == 6.0) { $(this).css({'height': currentTallest}); }
    $(this).css({'min-height': currentTallest}); 
    return this;
    }
};

function isIP() {
    if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) return true;
    else return false;
}