var stopstatus        = 0;
var slideshowspeed    = 5000;
var crossfadeduration = 3;
var picturefiles      = new Array ();
var picturetexts      = new Array ();
var picturetimeout    = 0;
var nextpictureindex  = 0;
var curpictureindex   = nextpictureindex;
var numpictures       = 0;
var preloadedpictures = new Array ();

function ConfirmDeleteComment ()
{
    return (confirm ("Bist Du sicher, dass Du diesen Kommentar löschen willst?"));
}

function DeleteImage (thelink)
{
    if (confirm ("Bist Du sicher, dass Du dieses Bild löschen willst?"))
        location.href = thelink;
}

function EnablePictureUploadForm (theform)
{
    document.getElementById ("pictureuploadform").title.focus ();
}

function EndPictureSlideShow ()
{
    stopstatus = 1;
}

function MakePicturePopup (thesrcfile, thetitle, thewidth, theheight)
{
    pgwindow = window.open ("", "Galerie", "toolbar=0,location=0,directories=0,status=1,menubar=0,resizable=1,width=" + thewidth + ",height=" + theheight);
    pgwindow.document.write ("<head><title>" + thetitle + "<\/title>");
    pgwindow.document.write ("<script language=\'javascript\'>");
    pgwindow.document.write ("var isnetscape = (navigator.appName == \'Netscape\' ? true : false);");
    pgwindow.document.write ("function ResizePopupWindow () {");
    pgwindow.document.write ("var width = (isnetscape ? window.innerWidth : document.body.clientWidth);");
    pgwindow.document.write ("var height = (isnetscape ? window.innerHeight : document.body.clientHeight);");
    pgwindow.document.write ("width = document.images [0].width - width;");
    pgwindow.document.write ("height = document.images [0].height - height;");
    pgwindow.document.write ("window.resizeBy (width, height);");
    pgwindow.document.write ("self.focus();");
    pgwindow.document.write ("}");
    pgwindow.document.write ("<\/script>");
    pgwindow.document.write ("<\/head>");
    pgwindow.document.write ("<body topmargin=\'0\' marginheight=\'0\' leftmargin=\'0\' marginwidth=\'0\' onload=\'ResizePopupWindow ();\'><img src=\'" + thesrcfile + "\' border=\'0\' hspace=\'0\' vspace=\'0\' \/><\/body>");
    pgwindow.document.close ();
    pgwindow.moveTo(0,0);
}

function PreLoadPicture (index)
{
    if (picturefiles [index] != "") {
        window.status = "Loading : " + picturefiles [index];
        preloadedpictures [index] = new Image ();
        preloadedpictures [index].src = picturefiles [index];
        picturefiles [index] = "";
        window.status = "";
    }
}

function RunPictureSlideShow ()
{
    if (stopstatus != "1") {
        if (document.all) {
            document.images.SlideShow.style.filter = "blendTrans(duration=2)";
            document.images.SlideShow.style.filter = "blendTrans(duration=crossfadeduration)";
            document.images.SlideShow.filters.blendTrans.Apply ();
        }
        document.images.SlideShow.src = preloadedpictures [nextpictureindex].src;
        if (document.all)
            document.images.SlideShow.filters.blendTrans.Play ();
        curpictureindex = nextpictureindex;
        nextpictureindex = nextpictureindex + 1;
        if (nextpictureindex > numpictures - 1)
            nextpictureindex = 0;
        document.getElementById ("imagedescription").firstChild.nodeValue = picturetexts [curpictureindex];
        picturetimeout = setTimeout ("RunPictureSlideShow ()", slideshowspeed);
        PreLoadPicture (nextpictureindex);
    }
}

function ValidatePictureCommentForm (theform)
{
    var elems = [
        new CFormValidator ("comment"         , true , null , null, "Bitte gib Deinen Kommentar ein."     ),
        new CFormValidator ("captcha_response", true , null , null, "Bitte gib den Code aus dem Bild ein.")
    ];
    return (CForm.Validate (elems));
}

function ValidatePictureSend2FriendForm (theform)
{
    var elems = [
        new CFormValidator ("send2friendemail", true, CFormValidator.IsValidEMailAddress, null, "Bitte gib die E-Mail-Adresse Deines Freundes ein.")
    ];
    return (CForm.Validate (elems));
}

function ValidatePictureUploadForm (theform)
{
    var elems = [
        new CFormValidator ("title", true , null , null, "Bitte gib einen Titel ein."     ),
        new CFormValidator ("catid", true , null , null, "Bitte wähle eine Kategorie aus.")
    ];
    if (document.getElementById ("filename") !== null)
        elems.push (new CFormValidator ("filename", true , null , null, "Bitte wähle eine Datei aus."));
    return (CForm.Validate (elems));
}

