﻿$(document).ready(function () {

    $('.slide-out-div').tabSlideOut({
        tabHandle: '.handle',                       //class of the element that will become your tab
        pathToTabImage: '/images/pop_eversion.png', //path to the image for the tab *required*
        imageHeight: '150px',                       //height of tab image *required*
        imageWidth: '62px',                         //width of tab image *required*    
        tabLocation: 'left',                        //side of screen where tab lives, top, right, bottom, or left
        speed: 300,                                 //speed of animation
        action: 'hover',                            //options: 'click' or 'hover', action to trigger animation
        topPos: '200px',                            //position from the top/ use if tabLocation is left or right
        leftPos: '20px',                            //position from left/ use if tabLocation is bottom or top
        fixedPosition: true                         //options: true makes it stick(fixed position) on scroll
    });


    //Navigation menu using hoverIntent

    $(".nav_menu_main").hover(function () {
        $(this).addClass("menu_hover");
    }, function () {
        $(this).removeClass("menu_hover");
    });

    $('ul.nav_menu li').hoverIntent(function () {
        $('ul', this).slideDown(150);
    }, function () {
        $('ul', this).slideUp(150);
    });

    $('#popout_image').hover(function () {
        $('#popout_image a img').fadeIn("slow").attr('src', '/images/eversion_cover_colour.png');
    }, function () {
        $('#popout_image a img').fadeIn("slow").attr('src', '/images/eversion_cover_bnw.png');
    });

});

//js hack to change calendar background colour
$(document).ready(function () {
    $(".CalendarHeader").parent().css('background-color', '#006699');
});


//Code for "story rotator" on default page
$(document).ready(function () {

    $(".paging").show();
    $(".paging a: first").addClass("active");

    var stextWidth = 405;
    var stextSum = $(".stext_reel div").size();
    var stextReelWidth = stextWidth * stextSum;

    var imageWidth = $(".window").width();
    var imageSum = $(".image_reel img").size();
    var imageReelWidth = imageWidth * imageSum;

    $(".image_reel").css({ 'width': imageReelWidth });
    $(".stext_reel").css({ 'width': stextReelWidth });

    //Paging  and Slider Function
    rotate = function () {
        var triggerID = $active.attr("rel") - 1; //Get number of times to slide
        var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide
        var stext_reelPosition = triggerID * stextWidth;

        $(".paging a").removeClass('active'); //Remove all active class
        $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

        //Slider Animation
        $(".image_reel").animate({
            left: -image_reelPosition
        }, 500, 'swing');

        $(".stext_reel").fadeOut("fast").animate({
            left: -stext_reelPosition
        }, 500, function () {
            $(this).fadeIn("fast");
        });
    };

    //Rotation  and Timing Event
    rotateSwitch = function () {
        play = setInterval(function () { //Set timer
            $active = $('.paging a.active').next(); //Move to the next paging
            if ($active.length === 0) { //If paging reaches the end...
                $active = $('.paging a:first'); //go back to first
            }
            rotate(); //Trigger the paging and slider function
        }, 7000); //Timer speed in milliseconds (7 seconds)
    };

    rotateSwitch(); //Run function on launch

    //On Hover
    $(".image_reel").hover(function () {
        clearInterval(play); //Stop the rotation
    }, function () {
        rotateSwitch(); //Resume rotation timer
    });

    $(".stext_reel div").hover(function () {
        clearInterval(play); //Stop the rotation
    }, function () {
        rotateSwitch(); //Resume rotation timer
    });

    //On Click
    $(".paging a").click(function () {
        $active = $(this); //Activate the clicked paging
        //Reset Timer
        clearInterval(play); //Stop the rotation
        rotate(); //Trigger rotation immediately
        rotateSwitch(); // Resume rotation timer
        return false; //Prevent browser jump to link anchor
    });

    //topicheader random colour

    $(document).ready(function () {

        var colours = ["#5179D6", "#66CC66", "#EF2F41", "#FFC700", "#61BDF2", "#FF7900", "#7588DD", "#2F5E8C", "#07BACE", "#BAE55C", "#BA1871", "#FFFFCC", "#BDE6FC", "#C7C7C7", "#ADA8FF", "#2FA675"];

        $(".topicheader").each(function (i) {
            $(this).css('border-top', '3px solid ' + colours[i % colours.length]);
        });
    });



});





