
var runSlideShow = true;

function start_slideshow(start_frame, end_frame, delay) {
    setTimeout(switch_slides(start_frame, start_frame, end_frame, delay), delay);
}

function switch_slides(frame, start_frame, end_frame, delay) {
    return (function() {
        if (runSlideShow) {
            Effect.Fade('pic' + frame);
            if (frame == end_frame) {
                frame = start_frame;
            } else {
                frame = frame + 1;
            }
            setTimeout("Effect.Appear('pic" + frame + "');", 100);
        }
        setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay + 1000);
    })
}

function setContentMargin(leftElem, contentElem, gap) {
    var w = Element.getWidth($(leftElem)) + gap;
    var marg = w + "px";
    var adds = $('google-adds');
    if (adds == null) {
        $(contentElem).setStyle({
            marginLeft:marg
        });
    }
    else {
        $(contentElem).setStyle({
            marginLeft:marg,
            marginRight:'120px'
        });
    }

}

function showPicture(bigId,bigSrc,bigWidth,bigHeight,title){
    var w = Element.getWidth(document.body);
    var h = Element.getHeight(document.body);

    var viewportWidth  = document.viewport.getWidth();
    var viewportHeight = document.viewport.getHeight();
    
    var vpoffsets = document.viewport.getScrollOffsets();

    var left = vpoffsets[0];
    if(viewportWidth > bigWidth) {
        left = left + Math.round((viewportWidth - bigWidth)/2);
    }

    var top = vpoffsets[1];
    if(viewportHeight > bigHeight) {
        top = top + Math.round((viewportHeight - bigHeight)/2);
    }

    if(h < top + bigHeight) {
        h = top + bigHeight + 30;
    }

    var overlay = $('overlay');

    overlay.setStyle({
        width:w + "px",
        height:h + "px",
        display:'inline'
    });

    var frontpic = $('frontpic');
    if (frontpic == null) {
        frontpic = new Element('img').setStyle({
            position: 'absolute',
            top:top + "px",
            left:left + "px",
            backgroundColor:'#000000',
            border:'thin solid white',
            zIndex:11,
            display:'none'
        });
        frontpic.writeAttribute({
            id:'frontpic',
            src:bigSrc
        });
        frontpic.observe('click', closePicture);
        document.body.insert(frontpic);        
    }
    else {
        frontpic.writeAttribute({
            src:bigSrc
        });
        frontpic.setStyle({
            top:top + "px",
            left:left + "px"
        });
    }

    var frontinfo = $('frontinfo');
    if (frontinfo == null) {
        frontinfo = new Element('div').writeAttribute({
            id:'frontinfo'
        });

        document.body.insert(frontinfo);
    }
    var conttop = top + bigHeight - 30;
    frontinfo.setStyle({
        position: 'absolute',
        top:conttop + "px",
        left:left + "px",
        backgroundColor:'#000000',
        color:'#ffffff',
        zIndex:12,
        display:'none',
        width: bigWidth + "px",
        height: '30px'
    });

    frontinfo.innerHTML = '<span>' + title + '</span>';


    setTimeout("Effect.Appear('frontpic',{duration:0.5});", 1000);
    if(title != null && title.length > 0) {
        setTimeout("Effect.Appear('frontinfo',{duration:0.5, to:0.5});", 1500);
    }

}

function closePicture() {
$('overlay').setStyle({
        display:'none'
    });
    $('frontinfo').setStyle({
            display:'none'
        });

    Effect.Fade($('frontpic'),{duration:0.3});
}



function pictureFocus(smallImageId) {
    var contStr = smallImageId + '_div'; 
    var cont = $(smallImageId + '_div');
    var simg = $(smallImageId + '_frame');
    var dias = $('dias');
    var paragraph = $('paragraph');
    var body = $('body');
    var bodyHeight = Element.getHeight(body);

    var offset = Element.cumulativeOffset(simg);
    var left = offset.left + Element.getWidth(simg);

    var right = Element.cumulativeOffset(dias).left + Element.getWidth(dias) - 120;
    var top = offset.top + 0;
    var w = right - left;
    var h = Element.getHeight(simg);


    cont.setStyle({
        left:left + "px",
        top:top + "px",
        width: w + "px",
        height:h + "px",
        display:'block'
    });

    simg.setStyle({
        backgroundColor:'#207020'
    });

    paragraph.setStyle({
        display:'none'
    });

    body.setStyle({
        height:bodyHeight + "px"
    });
};
function pictureUnfocus(smallImageId) {
    $(smallImageId + '_div').setStyle({
        display:'none'
    });
    $(smallImageId + '_frame').setStyle({
        backgroundColor:'transparent'
    });
//                setTimeout('showParagraph();',500);
    $('paragraph').setStyle({
        display:'block'
    });

}
