﻿//credits to http://www.alohatechsupport.net/webdesignmaui/maui-web-site-design/easy_jquery_auto_image_rotator.html
var refreshInterval;
var currId = 0;
var limit=6;
function theRotator() {
    //Set the opacity of all images to 0
//    $('div.rotator ul li').css({ opacity: 0.0 });

//    //Get the first image and display it (gets set to full opacity)
//    $('div.rotator ul li:first').css({ opacity: 1.0 });
    $('div.rotator ul li:first').show();
    currId = 1;
    //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds

    refreshInterval = setInterval('rotate()', 7000);

}

var stoprotate = false;

function setImage(id) {

    clearInterval(refreshInterval);
    
    currId = parseInt(id);

    $('div.rotator ul li').each(function() {
        $(this).hide();
    });


    $('#' + id).fadeIn(200); //.css('display', 'block');
   
    SetButton(id);

    refreshInterval = setInterval('rotate()', 7000);
}

var x = 0;
function SetButton(id) {

    $('#img2').css('display', '');
    $('#img3').css('display', '');
    $('#img4').css('display', '');
    $('#img5').css('display', '');
    $('#img6').css('display', '');
    
    $('div#pagebuttons a').each(function() {
    $(this).removeClass('selectedA');
    
    });
    $('#a' + id).addClass('selectedA');

    if (id == 1 || id == 2)
        $('div.rotator').css('z-index', '999999');
    else $('div.rotator').css('z-index', '-1');

    if (id >= 1 && id <= 3) {

        var isIE = navigator.appVersion;
        if ($('#flashholder').attr('innerHTML').toString().indexOf('fast-howfast.swf') < 1) {
            //$('#newwebsite_notice').css('margin-top', '220px');
            if (navigator.appName == "Microsoft Internet Explorer") {
                if (parseInt(isIE.substr(isIE.indexOf("MSIE") + 4)) == 7)
                    $('#newwebsite_notice').animate({ 'margin-top': '10px' }, function() {
                        $('#newlayer').css('display', 'block');
                    });
                else $('#newwebsite_notice').animate({ 'margin-top': '220px' }, function() {
                    $('#newlayer').css('display', 'block');
                });
            }
            else $('#newwebsite_notice').animate({ 'margin-top': '220px' }, function() {
                $('#newlayer').css('display', 'block');
            });
            $('#flashholder').attr('innerHTML', loadFlash('fast-howfast.swf'));

        }
    }
    else {

        if ($('#flashholder').attr('innerHTML').toString().indexOf('new animation5.swf') < 1) {
            
            $('#newwebsite_notice').animate({ 'margin-top': '150px' }, function() {
                $('#newlayer').css('display', 'none');
            });
            $('#flashholder').attr('innerHTML', loadFlash('new animation5.swf'));
            //$('#newwebsite_notice').css('margin-top','150px');

        }        
    }
   
}

function rotate() {
   

//    //Get the first image

//    var current = ($('div.rotator ul li.show') ? $('div.rotator ul li.show') : $('div.rotator ul li:first'));

    var current = $('div.rotator ul li#' + currId);
    
    current.fadeOut(200); //.hide(1000);
    
    if(currId >= limit)
        currId = 0;

    currId = currId + 1;

    var next = $('div.rotator ul li#' + currId);
//    if (current.length == 0) current = $('div.rotator ul li:first');

//    //Get next image, when it reaches the end, rotate it back to the first image
//    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') : current.next()) : $('div.rotator ul li:first'));
    var id = next.attr('id');
    next.fadeIn(200); //.show(1000)

   
//   
//    //Un-comment the 3 lines below to get the images in random order

//    //var sibs = current.siblings();
//    //var rndNum = Math.floor(Math.random() * sibs.length );
//    //var next = $( sibs[ rndNum ] );


//    //Set the fade in effect for the next image, the show class has higher z-index
//    next.css({ opacity: 0.0 }).addClass('show').animate({ opacity: 1.0 }, 500);
//   
//    //Hide the current image
//    current.animate({ opacity: 0.0 }, 500).removeClass('show');
    
    SetButton(id);
    
};



$(window).load(function() {

var isIE = navigator.appVersion;
if (navigator.appName == "Microsoft Internet Explorer") {
    if (parseInt(isIE.substr(isIE.indexOf("MSIE") + 4)) == 7)
        $('#newwebsite_notice').animate({ 'margin-top': '10px' }, function() {
            $('#newlayer').css('display', 'block');
        });
    else $('#newwebsite_notice').animate({ 'margin-top': '220px' }, function() {
        $('#newlayer').css('display', 'block');
    });
}
else $('#newwebsite_notice').animate({ 'margin-top': '220px' }, function() {
    $('#newlayer').css('display', 'block');
});

$('div.rotator').css('z-index', '999999');
    //Load the slideshow
$('#flashholder').attr('innerHTML', loadFlash('fast-howfast.swf'));
    $('div.rotator ul li').each(function() {
        $(this).css('display', 'none');
    });
    theRotator();
    $('#pagebuttons').css('display', '');

});

function loadFlash(swf) {
   
    var objectflash = ' <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +
             'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' +
             'id="Object1" align="LEFT" width="1100" height="370"> ' +
             '<param name="movie" value="animation/' + swf + '"> ' +
             '<param name="quality" value="high"> ' +
             '<param name="wmode" value="transparent" /> ' +
             '<embed src="animation/' + swf + '" width="1100" height="370" quality="high" ' +
             'wmode="transparent" name="02" align="LEFT" type="application/x-shockwave-flash" ' +
             'pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';

    return objectflash;

}
