/* 
 * This file contains functions that use js/jquery to format each page,
 * with effects like fade-ins, etc.
 */


/***
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

//Global variable to allow stopping of the slideshow whenever you go to a different page
var slideShowInterval = null;

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

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

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

    // uncomment the 3 lines below to pull the images in random order
    /*
    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');
    });
}

/***
* End Slideshow Function
***/


/***
* Below are my functions
*
***/

//this function delegates page formatting to correct function
function formatPage(loadMePath)
{
    if (loadMePath == 'content/portal.php')
    {      
        $('#pageFooter').hide();
        portalFormat();
    }
    else
    {
        clearInterval(slideShowInterval); //this might break it 999
        $('#contentPane').hide();
        formatSubPage(loadMePath);
    }
    return;
}

//this function formats/fades elements on a given sub page
function formatSubPage(loadMePath)
{
	$('#navMenu').hide();
	$('#holiday-menu-banner-con').hide(); //new, remove if doesn't work
    $('#contentPane').hide();

    //move the logo up
    $("#logoWrap").fadeIn(700, function(){
        $("#logoWrap").animate({
            "margin-top": "50px"
        }, "slow", function() {
            $('#navMenu').fadeIn(400);
        });
    });
	
    $('#contentPane, #pageFooter').fadeIn(400);

    //fade in all images with class='fadeMeIn' at once after they load
    $('.fadeMeIn').imagesLoaded(function() {
        $('.fadeMeIn').fadeIn(700);
    });

    var pattern = /menu.php/gi;
    if (loadMePath.toString().match(pattern))
    {
        //if the following fails, just try .load (and remove the 'this' argument)
        $('img.firstSlides').imagesLoaded(function() {
            $('#slideshow').fadeIn(700, function(){
                clearInterval(slideShowInterval); //stops the slideshow from running whenever you load a different page
                slideShowInterval = setInterval( "slideSwitch()", 5000 );
            });
        });
    }

    $(".sals-fancybox").fancybox({
        'width'             : 282,
        'height'            : 395,
        'padding'           : 0,
        'margin'            : 0,
        'scrolling'         : 'no',
        'transitionIn'      : 'none',
        'transitionOut'     : 'none',
        'type'              : 'iframe'
    });

    $(".sals-image-fancybox").fancybox({
        'padding'           : 0,
        'margin'            : 0,
        'scrolling'         : 'no',
        'transitionIn'      : 'none',
        'transitionOut'     : 'none',
        'type'              : 'image'
    });

    /*
    pattern = /tour.php/gi;
    if (loadMePath.toString().match(pattern))
    {
        $('#coin-slider').coinslider({
            width: 800,
            height: 400
        });
    }
*/
    return;
}

//This function fades in the elements on the portal page
function portalFormat()
{
    //enable the filmstrip
    $("div#makeMeScrollable").smoothDivScroll({
        autoScroll: "onstart",
		autoScrollDirection: "backandforth",
        autoScrollStep: 1,
        autoScrollInterval: 120,
        visibleHotSpots: "always"
    });


    //fade in the logo
    $("#logoWrap").fadeIn(700, function(){
        $("#logoWrap").animate({
            "margin-top": "100px"
        }, "slow");
    });

    $(".color").hide();
    
    //fade colors on mouseover
    //note: color img sits underneath (negative z-index), so we fade gray out to show color
    $(".portal-block").hover(
       
        function () {
            $(".color", this).fadeIn(500);
            $(this).find("a").css({
                'color':'white'
            });            
        },
        function () {
            $(".color", this).fadeOut(150);
            $(this).find("a").css({
                'color':'gray'
            });
        }
        );


    /*
    //fade colors in on mouseover
    $(".switched_images > div").bind("mouseenter mouseleave", function(event) {
        
        if (event.type == 'mouseenter')
        {
            //on mouse enter, fade out the gray one (color sits underneath)
            $("img#"+event.originalTarget.id).fadeOut(500);
        }
        if (event.type == 'mouseleave')
        {
            //on mouse enter, fade in the gray one
            $("img#"+event.originalTarget.id).fadeIn(150);
        }
    });
*/

    return;
}
