// remap jQuery to $
(function($) {
    $.fn.equalColumnHeight = function() {
        var tallest = 0;
        this.each(function() {
            if ($(this).height() > tallest) {
                tallest = $(this).height();
            }
        });
        return this.each(function() {
            $(this).height(tallest);
        });
    };
    $.fn.slideShow = function() {
        //Set Default State of each portfolio piece
        $(".paging").show();
        $(".paging a:first").addClass("active");

        // Get the size of the images and quantity
        // width
        var imageWidth = $("#slides").width();

        var imageHeight = $("#slides").height();

        // how many images to display
        var imageSum = $("#slides img").size();
        //var imageReelWidth = imageWidth * imageSum;

        //Adjust the image reel to its new size
        //$("#slides").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
            var image_reelPosition = triggerID * imageHeight; //Determines the distance the image reel needs to slide

            $(".paging a").removeClass('active'); //Remove all active class
            $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

            //Slider Animation
            $("figure").animate({
                        top: -image_reelPosition
                    }, 500);
        };

        //Rotation + Timing Event
        rotateSwitch = function() {
            play = setInterval(function() { //Set timer - this will repeat itself every 3 seconds
                $active = $('.paging a.active').next();
                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 (3 seconds)
        };

        rotateSwitch(); //Run function on launch

        //On Hover
        $("#slides a").hover(function() {
            clearInterval(play); //Stop the rotation
        }, function() {
            rotateSwitch(); //Resume rotation
        });

        //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
            return false; //Prevent browser jump to link anchor
        }); // End Slide show
    };
})(window.jQuery);


// usage: log('inside coolFunc',this,arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function() {
    log.history = log.history || [];   // store logs to an array for reference
    log.history.push(arguments);
    if (this.console) {
        console.log(Array.prototype.slice.call(arguments));
    }
};


// catch all document.write() calls
(function(doc) {
    var write = doc.write;
    doc.write = function(q) {
        log('document.write(): ', arguments);
        if (/docwriteregexwhitelist/.test(q)) write.apply(doc, arguments);
    };
})(document);



