/*
    Our Dreams Are Different - A Soul of Athens Production
    Version 1.0
    www.soulofathens.com
    
    Author: Ohio Univeristy - School of Visual Communications
    
*/

 function showlayer(layer) {
        var myLayer = document.getElementById(layer);
        if (myLayer.style.display === "none" || myLayer.style.display === "") {
            myLayer.style.display = "block";
        } else {
            myLayer.style.display = "none";
        }
    }

$(document).ready(function() {

    // global image protect on images
    var imgProtect = $('img', '*');

    $(imgProtect).each(function() {

        $(imgProtect).bind("contextmenu", function() {
            return false;
        });

        $(imgProtect).bind("mousedown", function() {
            return false;
        });
		
    });
    // end global image protect


    // variables for image expand
    var img_container;
    var img;


    function sidebar_opacity(e) {

        if ($('.full').length >= 1) {
            $('#sidebar').animate({
                'opacity': '0.4'
            });
        }
        else {
            $('#sidebar').animate({
                'opacity': '1'
            });
        }

    }



    function expand_left_img(e) {
        img_container = jQuery(this);
        img = jQuery(this).find("img");

        if (img_container.hasClass('full')) {
			
            // animate enlarge
            img_container.stop().animate({
                'width': '400px',
                'height': '300px'
            }, 1000);

            img.stop().animate({
                'width': '400px',
                'height': '267px'
            }, 1000);

            // add class for future shrink
            $(img_container).removeClass('full');

            sidebar_opacity();
            return false;
        }


        if (!img_container.hasClass('full')) {
            // animate enlarge
            img_container.stop().animate({
                'width': '900px',
                'height': '600px'
            }, 1000);

            img.stop().animate({
                'width': '900px',
                'height': '600px'
            }, 1000);

            // add class for future shrink
            $(img_container).addClass('full');

            // check for sidebar opacity
            sidebar_opacity();

            return false;
        }

    }

    function expand_right_img(e) {

        img_container = jQuery(this);
        img = jQuery(this).find("img");

        if (img_container.hasClass('full')) {
            // animate enlarge
            img_container.stop().animate({
                'width': '400px',
                'height': '300px',
                'margin-right': '0px'
            }, 1000);


            img.stop().animate({
                'width': '400px',
                'height': '267px'
            }, 1000);

            // add class for future shrink
            $(img_container).removeClass('full');

            // check for sidebar opacity
            sidebar_opacity();

            return false;
        }


        if (!img_container.hasClass('full')) {
            // animate enlarge
            img_container.stop().animate({
                'width': '900px',
                'height': '650px',
                'margin-right': '-300px'
            }, 1000); // -300px margin is for "center" growth
            img.stop().animate({
                'width': '900px',
                'height': '600px'
            }, 1000);

            // add class for future shrink
            $(img_container).addClass('full');

            // check for sidebar opacity
            sidebar_opacity();

            return false;
        }

    }


    function expand_middle_img(e) {

        img_container = jQuery(this);
        img = jQuery(this).find("img");

        if (img_container.hasClass('full')) {

            img_container.stop().animate({
                'width': '600px',
                'height': '400px'
            }, 1000);
            img.stop().animate({
                'width': '600px',
                'height': '400px'
            }, 1000);

            // remove class for future enlarge
            $(img_container).removeClass('full');

            // check for sidebar opacity
            sidebar_opacity();

            return false;
        }


        if (!img_container.hasClass('full')) {
            // animate enlarge
            img_container.stop().animate({
                'width': '900px',
                'height': '600px'
            }, 1000);
            img.stop().animate({
                'width': '900px',
                'height': '600px'
            }, 1000);

            // add class for future shrink
            $(img_container).addClass('full');

            // check for sidebar opacity
            sidebar_opacity();

            return false;
        }


    }

    // inline image listeners
    $('.image-left-container').live('click', expand_left_img);
    $('.image-right-container').live('click', expand_right_img);
    $('.image-middle-container').live('click', expand_middle_img);

    // check for transcript element, add click fn if exists
    if ($(".transcript").length > 0) {
        $(".slider").click(function() {
            $(".transcript").slideToggle("slow");
            $(this).toggleClass("active");
            return false;
        });

    }

    // sidebar IMG next/previous story pager    
    $("#sidebar .previous-story").hover(

    function() {

        $("#next-story").fadeOut(250, function() {
            // check hide
            $("#next-story").hide();

            $("#previous-story").fadeIn(250).css({
                'display': 'block'
            });


        });


    }, function() {

        $("#previous-story").fadeOut(250, function() {

            $("#previous-story").hide();

            $("#next-story").fadeIn(250).css({
                'display': 'block'
            });

        });

    });


    // bottom TEXT next/previous story pager    
    $("#share-pager .previous-story").hover(

    function() {
        $("#prev-story-title").css('visibility', 'visible');
    }, function() {
        $("#prev-story-title").css('visibility', 'hidden');
    });
    $("#share-pager .next-story").hover(

    function() {
        $("#next-story-title").css('visibility', 'visible');
    }, function() {
        $("#next-story-title").css('visibility', 'hidden');
    });


}); // end onReady fn

