﻿var baseCoverPath = "assets/images/cover/";

function setCover(objSelected,iType) {
    switch (iType) {
        case 1:
            {
                document.getElementById("button2").className = "";
                objSelected.className = "bold";
                document.getElementById("cover").src = baseCoverPath + "cover_front.png";
                break;
            }
        case 2:
            {
                document.getElementById("button1").className = "";
                objSelected.className = "bold";
                document.getElementById("cover").src = baseCoverPath + "cover_back.png";
                break;
            }
    }
}

$(document).ready(function () {
    var animating_land = false;
    if ($(".showCaseContainer").length) { $.groupShowCase(); }

    //RON EDIT
    if ($("#landenlijst").length > 0) {
        $("#landenlijst li .details .email").each(function () {
            var email = $(this).html();
            $(this).html("<a href='mailto:" + email + "'>" + email + "</a>");
        });

        $("#landenlijst li .details .website").each(function () {
            var website = $(this).html();
            $(this).html("<a href='" + website + "'>" + website + "</a>");
            $(this).find("a").attr("target", "_blank");
        });

        $("#landenlijst li").click(function () {
            if (!animating_land) {
                animating_land = true;
                var clicked = $(this);
                if ($(".active_land").length == 1) {
                    if (!$(clicked).hasClass('active_land')) {

                        $(".active_land").find(".details").slideUp(300, function () {
                            $('.active_land').removeClass('active_land');
                            $(clicked).find(".details").slideDown(300, function () {
                                $(clicked).addClass('active_land');
                                animating_land = false;
                            });


                        });
                    } else {
                        animating_land = false;
                    }
                } else {
                    $(clicked).find(".details").slideDown(300, function () {
                        $(clicked).addClass('active_land');
                        animating_land = false;
                    });

                }
            }
        });
    }
    //EIND RON EDIT

    if ($("a[rel=example_group]").length > 0) { $("a[rel=example_group]").fancybox(); }

    if ($(".tweet").length > 0) {
        $(".tweet").tweet({
            username: ["@JulienSkins"],
            join_text: "auto",
            avatar_size: 32,
            count: 3,
            auto_join_text_default: "",
            loading_text: "loading tweets..."
        });
    }
});

(function($) {

    $.groupShowCase = function() {
        //Set Default State of each portfolio piece
        var activeSlide = 0;
        $(".showCasePaging").show();
        $(".showCasePaging a.prev").hide();

        //Get size of images, how many there are, then determin the size of the image reel.
        var imageWidth = $(".showCaseContainer").width();
        var imageSum = $(".image_reel img").size();
        var imageReelWidth = imageWidth * imageSum;

        //Adjust the image reel to its new size
        $(".image_reel").css({ 'width': imageReelWidth });

        //Paging + Slider Function
        rotate = function() {
            var triggerID = activeSlide; //Get number of times to slide
            var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

            //alert(activeSlide + " # " + $(".image_reel a").length);
            if (activeSlide == 0) { $(".showCasePaging a.prev").hide(); }
            else { $(".showCasePaging a.prev").show(); }
            if (activeSlide == ($(".image_reel a").length-1)) { $(".showCasePaging a.next").hide(); }
            else { $(".showCasePaging a.next").show(); }

            //Slider Animation
            $(".image_reel").animate({
                left: -image_reelPosition
            }, 500);

        };

        //Rotation + Timing Event
        rotateSwitch = function() {
            play = setInterval(function() { //Set timer - this will repeat itself every 3 seconds
                activeSlide = activeSlide + 1;
                if (activeSlide === $(".image_reel a").length) { //If paging reaches the end...
                    activeSlide = 0; //go back to first
                }
                rotate(); //Trigger the paging and slider function
            }, 6000); //Timer speed in milliseconds (3 seconds)
        };

        rotateSwitch(); //Run function on launch

        //On Hover
        $(".image_reel a").hover(function() {
            clearInterval(play); //Stop the rotation
        }, function() {
            rotateSwitch(); //Resume rotation
        });

        //On Click
        $(".showCasePaging a").click(function() {
            switch ($(this).attr("class")) {
                case "next": { activeSlide = activeSlide + 1; break; }
                case "prev": { activeSlide = activeSlide - 1; break; }
            }
            if (activeSlide === $(".image_reel a").length) { //If paging reaches the end...
                activeSlide = 0; //go back to first
            }
            //Reset Timer
            clearInterval(play); //Stop the rotation
            rotate(); //Trigger rotation immediately
            rotateSwitch(); // Resume rotation
            return false; //Prevent browser jump to link anchor
        });
    };

})(jQuery)

