// JScript source code
(function($) {
    $.fn.zoomMe = function(options) {


        $("#project_of_the_day").append('<div id="zoom"><div id="closer"></div>  <div id="zoom_content"></div> </div>');

        var zooming = false;
        var zoom = $("#zoom");
        var content = $("#zoom_content");
        var closer = $("#closer");


        $('html').click(function(e) { if ($(e.target).parents('#zoom:visible').length == 0) hide(); });

        $("#closer").click(hide);

        $(document).keyup(function(event) {
            if (event.keyCode == 27 && $('#zoom:visible').length > 0) hide();
        });


        this.each(function(i) {

            $(this).click(show);

        });

        return this;

        function show() {

            if (zooming) return false
            zooming = true;

            var base = $(this);


            var item = $(this).children(".information");

            var width = $(window).width();
            var height = $(window).height();
            var offset = $(this).offset();
            var window_width = { 'width': width, 'height': height, 'x': offset.left, 'y': offset.top }

            zoom.hide();
            content.html(item.html());


            var width = zoom.outerWidth()
            var height = zoom.outerHeight();
            var w = window_width;
            var baseWidth = base.outerWidth()
            var baseHeight = base.outerHeight();

            var newLeft = ((w.x) + (baseWidth / 2)) - width / 2;
            var newTop = ((w.y) + (baseHeight / 2)) - (height / 2);





            if (newTop <= 25) newTop = 25;
            if (newLeft <= 25) newLeft = 25;

            //if (w.y > w.height) newTop = w.height - height/2;


            closer.css({

                top: -15 + "px",
                left: (width - 20) + "px"

            })


            zoom.css({

                position: "absolute",
                top: newTop + "px",
                left: newLeft + "px"

            })



            //	zoom.fadeIn(500);


            zoom.animate({

                top: newTop + "px",
                left: newLeft + "px",
                opacity: "show"



            }, 500);




            return false

        }

        function hide() {

            zoom.fadeOut();
            zooming = false;
            return false;

        }


        function next(base) {

            var next = base.next(".feature");
            var info = next.children(".information")
            content.html(info.html());

        }





        // return this.each(function() {
        // 	
        // 	$(this).click(show);
        // 	
        // 	
        // 	
        // 	
        // })





    }


})(jQuery);