/*
 * My Javascript
 * by Jinny Yu - mainly for iphone
 */


function iPhoneAlert() {
if((navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.match(/iPod/i))||(navigator.userAgent.match(/iPod/i))||(navigator.userAgent.match(/iPad/i))) {
document.getElementById('FlashDetect').innerHTML = "<div id=\"slideshow\"><div class=\"active\"><a href=\"http://www.ensco.com/about-ensco/Annual-Report.htm\"><img src=\"UserFiles/Image/iPhoneFlashSubstitutes/ensco_home_1ar.jpg\" width=\"950\" height=\"280\" border=\"0\" /></a></div><div><a href=\"http://www.ensco.com/security\"><img src=\"UserFiles/Image/iPhoneFlashSubstitutes/ensco_home_2security.jpg\" width=\"950\" height=\"280\" border=\"0\" /></a></div><div><a href=\"http://www.ensco.com/rail-technologies\"><img src=\"UserFiles/Image/iPhoneFlashSubstitutes/ensco_home_3rail.jpg\" width=\"950\" height=\"280\" border=\"0\" /></a></div><div><a href=\"http://www.ensco.com/avionics\"><img src=\"UserFiles/Image/iPhoneFlashSubstitutes/ensco_home_4avionics.jpg\" width=\"950\" height=\"280\" border=\"0\" /></a></div><div><a href=\"http://www.ensco.com/weather-decision-support\"><img src=\"UserFiles/Image/iPhoneFlashSubstitutes/ensco_home_5weather.jpg\" width=\"950\" height=\"280\" border=\"0\" /></a></div><div><a href=\"http://www.ensco.com/aerospace\"><img src=\"UserFiles/Image/iPhoneFlashSubstitutes/ensco_home_6aerospace.jpg\" width=\"950\" height=\"280\" border=\"0\" /></a></div></div>";
    }
}


function slideSwitch() {
    var $active = $('#slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

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

$(function() {
    setInterval( "slideSwitch()", 5000 );
});
