//jQuery: adding a new function property to the jQuery.fn - self executing function (closure)
(function( $ ){
    $.fn.preventDoubleSubmit = function () {
        // there's no need to do $(this) because "this" is already a jquery object
        // $(this) would be the same as $($('#element'));
        var alreadySubmitted = false;
        return this.submit(function () {
            var $this = $(this);
            if (alreadySubmitted){
                return false;
            }
            else {
                $this.find(":submit").attr('disabled', 'disabled').attr('value', '...');
                alreadySubmitted = true;
            }
        });
    };

})( jQuery );


//jQuery: execute
$(document).ready(function(){
    // do stuff when DOM is ready

    // assign the ColorBox event to elements
    $("a[rel='gallery']").colorbox({
        transition:"none",
        width:"90%",
        height:"90%",
        slideshow:true,
        slideshowAuto:false,
        maxWidth:'95%',
        maxHeight:'95%',
        scalePhotos:true,
        title: function(){
            var strtitle = $(this).attr('title');
            var url = $(this).attr('href');
            return strtitle+'<br /><a href="'+url+'" target="_blank">Original</a>';
        }
    });

    //Prevent double submit with jQuery
    $('form').preventDoubleSubmit();

});



/******************************************************
Window tools
===========================
Copyright (c) 2000 by mars69 (mars69@people.cz)
*******************************************************/
var PopupWindow = null;
var pop_win_params = "fullscreen=no,directories=no,history=no,location=no,menubars=no,menubar=no,resizable=yes,scrollbars=yes,statusbars=yes,status=no,titlebar=yes,toolbar=no";

function ClosePopupWindow()
{
    if (PopupWindow != null) PopupWindow = PopupWindow.close();
    //if (typeof(PopupWindow) == "object") PopupWindow.close();
    return PopupWindow;
}
function ImageWindow( theImageURL, i_width, i_height, s_title, s_descript ) {
    ClosePopupWindow();
    if (s_descript != null) {
        i_height = i_height + 50;
    }
    PopupWindow = window.open("", "", "left=10,top=10,width="+i_width+",height="+i_height+","+pop_win_params+"");
    with (PopupWindow.document) {
        open();
        writeln("<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
        writeln("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
        writeln("<head><title>"+ s_title +"</title>");
        writeln("<style type=\"text/css\">body {margin:0; padding:0; font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; font-size: 12px; border-color: #999999; background: white; color: black; text-align: center;}</style>");
        writeln("</head>");
        writeln("<body style=\"margin:0; padding:0;\">");
        write("<div><a href=\"#\" onclick=\"window.close()\"><img style=\"border: none;\" src=\""+ theImageURL +"\" alt=\"close\" /></a>");
        if (s_descript != null) {
            write("<p>"+ s_descript +"</p>");
        }
        writeln("</div>");
        writeln("</body></html>");
        close();
        }
    PopupWindow.focus();
    return PopupWindow;
}

