﻿// Feature Show javascript

var FadeInProgress = false;
var AutomaticRotation = false;

function FeatureShowHideItem( ItemIdToHide ) {
    document.getElementById( ItemIdToHide ).style.display = "none";
}

function FeatureShowShowItem( ItemIdToShow ) {
    document.getElementById( ItemIdToShow ).style.display = "block";
}

function GoToNextFeature ( FromFeatureId, CalledByAutoRotator ) {

    // ignore click if a fade is in progress
    if ( FadeInProgress ) return false;
    
    // ignore automatic rotation if set to false
    if ( !AutomaticRotation && CalledByAutoRotator ) return false;
    
    // turn off auto rotating if user clicks
    if ( !CalledByAutoRotator ) AutomaticRotation = false;

    // assign vars
    if ( FromFeatureId == document.getElementById( "MaxFeatureSlides" ).value ) {
        ToFeatureId = 1;
    } else {
        ToFeatureId = FromFeatureId + 1;
    }
                    
    // prevent click interruptions
    FadeInProgress = true;
    
    // perform fade transition
    FadeTransition( "FeatureSlide" + FromFeatureId, "FeatureSlide" + ToFeatureId );
    
    if(FromFeatureId == document.getElementById( "MaxFeatureSlides" ).value)
    {
        startTheLoop();
    }    
}

function GoToPreviousFeature ( FromFeatureId ) {

    // ignore click if a fade is in progress
    if ( FadeInProgress ) return false;
    
    // ensure auto rotating is off
    AutomaticRotation = false;
    
    // assign vars
    if ( FromFeatureId == 1 ) {
        ToFeatureId = document.getElementById( "MaxFeatureSlides" ).value;
    } else {
        ToFeatureId = FromFeatureId - 1;
    }
                    
    // prevent click interruptions
    FadeInProgress = true;
    
    // perform fade transition
    FadeTransition( "FeatureSlide" + FromFeatureId, "FeatureSlide" + ToFeatureId );

}

function FeatureShowSetOpacity( obj, value ) 
{
    obj.style.opacity = value/10;
    obj.style.filter = "alpha(opacity=" + value*10 + ")";
}

function FeatureShowCancelFade() {
    FadeInProgress = false;
}

function FadeTransition( TransitionFromItem, TransitionToItem ) {

    FadeInProgress = true;
    
    // fade out old
    FeatureShowSetOpacity( document.getElementById( TransitionFromItem ), 9.99 );
    setTimeout( "FeatureShowSetOpacity( document.getElementById( '" + TransitionFromItem + "' ), 8 )", 75 );
    setTimeout( "FeatureShowSetOpacity( document.getElementById( '" + TransitionFromItem + "' ), 6 )", 150 );
    setTimeout( "FeatureShowSetOpacity( document.getElementById( '" + TransitionFromItem + "' ), 4 )", 225 );
    setTimeout( "FeatureShowSetOpacity( document.getElementById( '" + TransitionFromItem + "' ), 2 )", 300 );
    setTimeout( "FeatureShowSetOpacity( document.getElementById( '" + TransitionFromItem + "' ), 0 )", 375 );

    setTimeout( "FeatureShowHideItem( '" + TransitionFromItem + "' )", 450 );
    setTimeout( "FeatureShowShowItem( '" + TransitionToItem + "' )", 450 );

    // fade in new
    FeatureShowSetOpacity( document.getElementById( TransitionToItem ), 0 );
    setTimeout( "FeatureShowSetOpacity( document.getElementById( '" + TransitionToItem + "' ), 2 )", 525 );
    setTimeout( "FeatureShowSetOpacity( document.getElementById( '" + TransitionToItem + "' ), 4 )", 600 );
    setTimeout( "FeatureShowSetOpacity( document.getElementById( '" + TransitionToItem + "' ), 6 )", 675 );
    setTimeout( "FeatureShowSetOpacity( document.getElementById( '" + TransitionToItem + "' ), 8 )", 750 );
    setTimeout( "FeatureShowSetOpacity( document.getElementById( '" + TransitionToItem + "' ), 9.99 )", 825 );

    setTimeout( "FeatureShowCancelFade()", 825 );
  
}
