﻿if (!FlashDetect.versionAtLeast(10)) {
    $('flash').setStyle('display', '')
    var link = $$('#flash a')[0];
    link.blink = function() { this.style.fontSize = this.style.fontSize == '20px' ? '18px' : '20px'; };
    link.blink.bind(link).periodical(1500);
}


function SetBanners(url, isDirect) {
    // set presentation banners
    if (!cancelPresBanners) {
        var images = $$('div#emailbody img:not([src*=style])').filter(function(img) { return img.getStyle('width').replace('px', '') >= 380; });
        var remainder = images.length % 5;
        var quotient = (images.length - remainder) / 5;
        var len = quotient - 1;
        for (var i = 1; i <= len; i++) {
            var bannerContainer = new Element('div', { id: 'bannerContainer_' + i, styles: { width: '728px', height: '90px', display: 'block', clear: 'both', margin: '10px auto 0 auto'} });
            bannerContainer.inject(images[5 * i - 1], 'after');
            if (isDirect) Banner.createdirect(bannerContainer, url);
            else Banner.create(bannerContainer, url);
        }
    }
    //set text banners - same code as presentation
    $$('div.textbanner').each(function(div) {
        if (isDirect) Banner.createdirect(div, url);
        else Banner.create(div, url);
    });
}

//SwapImages
$$('div#emailbody img[rel=swapimage]').each(function(img) {
    var src = img['src'].split('/');
    img.set('out', src.pop());
    img.set('path', src.join('/') + '/');
    img.addEvent('mouseover', function() { this['src'] = this.get('path') + this.get('over'); ; } .bind(img));
    img.addEvent('mouseout', function() { this['src'] = this.get('path') + this.get('out'); } .bind(img));
});

//Viewers
var lastviews = 0;
var objviewers = $('viewers');
var setViewers = function() {
    var jsonRequest = new Request.JSON({ noCache: true, url: "/handlers/general.ashx", onComplete:
                function(RetVal) {
                    if (RetVal == null || RetVal.views == null) return;
                    if (lastviews == RetVal.views) return;

                    objviewers.set('html', 'אתה הצופה ה-<b>' + RetVal.views + '</b> להיום.').highlight('#ff0');
                    lastviews = RetVal.views;
                }
    }).get({ 'action': 'getviews' });
};
if (objviewers) { setViewers(); setViewers.periodical(5000); }

