var ckm = {};
ckm.Entry = Class.create();
ckm.Entry.prototype = {
    initialize: function() {
    },
    
    init: function() {
        // click event question
        Event.observe($('post_info'), 'click', this.openAnswerSlide);

        // permalink
        var hash = location.hash.replace('#', '');
        if (hash) {
            this.openAnswer(hash);
        }
        individualArchivesOnLoad(commenter_name)
    }, 

    openAnswer: function(id) {
        Element.show('mt_comment');
        Event.stopObserving($('post_info'), 'click', ckm.entry_.openAnswerSlide);
        Event.observe($('post_info'), 'click', ckm.entry_.closeAnswerSlide);
    },
    
    openAnswerSlide: function(id) {
//alert(id)
//        Element.show('mt_comment');
    	new Effect.SlideDown("mt_comment", {
    		duration: 0.8 //,
// commented out cause wont work well in ie6... 
//    		afterFinishInternal: function(effect) {
//        Element.show('comment_form');
//    		    alert($('mt_comment').innerHTML);
//                alert(Element.getStyle($('comment_form'), 'visibility'));
//                Event.stopObserving($('post_info'), 'click', ckm.entry_.openAnswerSlide);
//                Event.observe($('post_info'), 'click', ckm.entry_.closeAnswerSlide);
//    		}
    	});

        Event.stopObserving($('post_info'), 'click', ckm.entry_.openAnswerSlide);
        Event.observe($('post_info'), 'click', ckm.entry_.closeAnswerSlide);

    },

    closeAnswerSlide: function() {
    	new Effect.SlideUp("mt_comment", {
    		duration: 0.5 //,
//    		afterFinishInternal: function(effect) {
//                Element.hide('mt_comment');
////                Event.stopObserving($('post_info'), 'click', ckm.entry_.closeAnswerSlide);
////                Event.observe($('post_info'), 'click', ckm.entry_.openAnswerSlide);
//    		}
    	});
        Event.stopObserving($('post_info'), 'click', ckm.entry_.closeAnswerSlide);
        Event.observe($('post_info'), 'click', ckm.entry_.openAnswerSlide);
    	
    }
    
}

// overridden greybox

GB_showImage  = function(caption, url, callback_fn) {
    var options = {
        width: 600,
        height: 450,
        type: 'image',

        fullscreen: false,
        center_win: true,
        caption: caption,
        overlay_click_close: true,
        callback_fn: callback_fn
    }


    var win = new GB_Gallery(options);
    var intVar = win.show(url);

    return intVar;
}

GB_hide = function() {
    GB_CURRENT.hide();
    $('GB_close_btn').remove();
}

GB_Gallery.prototype.setWindowPosition = function() {
    var page_size = AJS.getWindowSize();
    var left = ((page_size.w - this.width)/2)-13;
    AJS.setLeft(this.g_window, left);


    if(!this.center_win) {
        AJS.setTop(this.g_window, AJS.getScrollTop());
    }
    else {
        var fl = ((page_size.h - this.height) /2) - 20 + AJS.getScrollTop();
              
        if(fl < 0)
            fl = 0;
        AJS.setTop(this.g_window, fl);
    }

   //se close button
    if (!$('GB_close_btn')) {
       new Insertion.Before('GB_window', '<div id="GB_close_btn"><img src="/js/greybox/g_close.gif" /></div>');
       Event.observe('GB_close_btn', 'click', GB_hide, false);
    }

       var top = 50;
//       if (top<0) {top=0;}
       var left = parseInt(Element.getStyle('GB_window', 'left', 10)) + 
         parseInt(Element.getStyle($$('.GB_frame')[0], 'width', 10)) + 50;
//             alert(parseInt(Element.getStyle($$('.GB_frame')[0], 'width', 10)))
       $('GB_close_btn').setStyle({'left': left+'px', 'top': top + 'px', 'z-index': 100} );

}

ckm.entry_ = new ckm.Entry;
Event.observe(window, 'load', ckm.entry_.init.bindAsEventListener(ckm.entry_), false);

