﻿$(document).ready(function () {

    //Set Default State of each portfolio piece
    $(".listindex").show();
    $(".listindex a:first").addClass("active");

    //Get size of images, how many there are, then determin the size of the image reel.
    var imageWidth = $(".window").width();
    var imageSum = $(".reel > div").size();
    var imageReelWidth = imageWidth * imageSum;

    //Adjust the image reel to its new size
    $(".reel").css({ 'width': imageReelWidth });

    //Paging + 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

        $(".listindex a").removeClass('active'); //Remove all active class
        $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

        //Slider Animation
        $(".window").animate({
            scrollLeft: image_reelPosition
        }, 800);

    };

    //Rotation + Timing Event
    rotateSwitch = function () {
        play = setInterval(function () { //Set timer - this will repeat itself every 3 seconds
            $active = $('.listindex a.active').next();
            if ($active.length === 0 || $active.is('div')) { //If paging reaches the end...
                $active = $('.listindex a:first'); //go back to first
            }
            rotate(); //Trigger the paging and slider function
        }, 7000); //Timer speed in milliseconds (3 seconds)
    };

    rotateSwitch(); //Run function on launch

    //On Hover
    $(".reel a").hover(function () {
        clearInterval(play); //Stop the rotation
    }, function () {
        rotateSwitch(); //Resume rotation
    });

    //On Click
    $(".listindex a").click(function () {
        $active = $(this); //Activate the clicked paging
        //Reset Timer
        clearInterval(play); //Stop the rotation
        rotate(); //Trigger rotation immediately
        rotateSwitch(); // Resume rotation
        return false; //Prevent browser jump to link anchor
    });

});

$(function () {
    $("img").lazyload();
    $(".window img").lazyload({ container: $('.window') });
    $("#thecontent").children().hide();
    $.fn.fadeSeq = function (e) {
        var d = 0;
        return this.each(function () {
            $(this).delay(d).fadeIn(e * 2);
            d += e;
        });
    }
    $("#thecontent").children().ready().fadeIn(400);
    //$("#logo").hide().fadeIn(800);
});

function doPop(mode, parentFK, info) {
    window.open('/static/edit.aspx?mode=' + mode + '&key=' + parentFK + '&info=' + info, 'editwindow', 'status=0,toolbar=0,location=0,scrollbars=0,height=680,width=500,resizable=0')
}
