// -*- mode: javascript; coding: utf-8 -*-
//
// Copyright 2009, 2010, 2011 Andrej A Antonov <polymorphm@gmail.com>.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

(function () {
    'use strict'
    
    var $ = jQuery
    
    function gallery_item_object (obj, label) {
        var file = $(obj).prop('href')
        
	    open('/cgi-bin/preview?obj=' +
	            encodeURIComponent(file) +
	            ((label!==null)?'&label=' + encodeURIComponent(label):''),
	            '_blank',
	            'width=1000,height=900,resizable=yes,scrollbars=yes')
    }
    
    $('.GalleryItemObject').live('click', function (event) {
        event.preventDefault()
        
        var width = $(this).data('gallery-item-object-window-width')
        var height = $(this).data('gallery-item-object-window-height')
        
        if (width === undefined) {
            width = 1000
        }
        if (height === undefined) {
            height = 900
        }
        
        var file = $(this).prop('href')
        
        open('/cgi-bin/preview?obj=' +
	            encodeURIComponent(file),
	            '_blank',
	            'width='+width+',height='+height+',resizable=yes,scrollbars=yes')
    })
    
    window.gallery_object = gallery_item_object // OBSOLETED FUNCTION NAME
    window.gallery_item_object = gallery_item_object
})()

