var I_THUMBNAILS_WIDTH = 100;
var I_THUMBNAILS_HEIGHT = 69;
var S_GALLERY_CONTENT_AREA_ID;

var bRecordScroll = "";

var WEB_ADS = {
                "SearchFromGallery":        602399,
                "SearchFromHome":           602409,
                "SearchFromSearch":         602411,
                "SearchFromDownload":       602407,
                "CalloutImpressionGallery": 601869,
                "CalloutImpressionHome":    601981,
                "CalloutImpressionSearch":  601982,
                "CalloutLinkGallery":       602403,
                "CalloutLinkHome":          601398,
                "CalloutLinkSearch":        601397,
                "CalloutButtonGallery":     601868,
                "CalloutButtonHome":        601979,
                "CalloutButtonSearch":      601980
            };

$(window).addEvent("domready", function(e)
{
    // Attach rating stars script to the gallery
    // starRate & rateContent are in the gallery.js file
    var aStars = $$("#RatingStars img");
    for(var i=0; i<aStars.length; i++)
    {
        aStars[i].onmouseover = function(){ starRate(this, "empty", "full"); }
        aStars[i].onmouseout = function(){ starRate(this, "full", "empty"); }
    }
    
    // Remove focus from the search text box,
    // to enable the focus behavior of hiding and showing the "Search the Gallery" text
    var oSearch = $$(".txtSearch")[0];    
    if(oSearch)    
        SetSearchColor(oSearch,sSearchDefault); 
        
    addBorder();
    addContentHover();
});

function openAsPopup(oLink, iOWidth, iOHeight)
{
    var iWidth = iOWidth || 640;
    var iHeight = iOHeight || 480;
    
    window.open(oLink.href, "_blank", "width=" + iWidth + ", height=" + iHeight);
}

function openSafeShoppingPopup(oLink)
{
    openAsPopup(oLink, 960, 638);
}

function addContentHover()
{
    var aThumbs = $$("ul.thumbs li a.thumb");
    
    aThumbs.addEvent("mouseenter", function(event){
        if (this.getElements(".dho").length == 0)
        {
            var sTitle = "";
            var oTitleElement = this.getElements("img[AutoID]");
            if (oTitleElement.length == 0)
            {
                oTitleElement = this.getElements("img[AutoId]");
                if (oTitleElement.length > 0)
                {
                    sTitle = oTitleElement[0].title;
                }
            }
            else
            {
                sTitle = oTitleElement[0].title;
            }
            var o = new Element("span", {"class": "dho"});
                o.innerHTML = "&#160;";
                o.title = sTitle;
            this.appendChild(o);
        }
    });
    aThumbs.addEvent("mouseleave", function(event){
        var dho = this.getElements(".dho");
        if (dho.length > 0)
        {
            dho = dho[0];
            dho.parentNode.removeChild(dho);
        }
    });
}

function addRoundCorners()
{
    var aRounded = $$(".rounded, .GeneralButton");
    for(var i=0; i<aRounded.length; i++)
    {
        var oLeft = document.createElement("span");
            oLeft.className = "left";
            oLeft.innerHTML = "&#160;";
        var oRight = document.createElement("span");
            oRight.className = "right";
            oRight.innerHTML = "&#160;";
        
        aRounded[i].insertBefore(oLeft, aRounded[i].firstChild);
        aRounded[i].insertBefore(oRight, aRounded[i].firstChild);
    }
    
    var aSystemButtons = $$(".GetButton");
    for(var i=0; i<aSystemButtons.length; i++)
    {
        if(aSystemButtons[i].className.indexOf("GetButtonVersion") == -1)
        {
            var oRight = document.createElement("span");
                oRight.className = "right";
                oRight.innerHTML = "&#160;";
            
            aSystemButtons[i].insertBefore(oRight, aSystemButtons[i].firstChild);
        }
    }
}

// Record the user's scrolling activity
window.addEvent("scroll",function(e){ //var e = e || event;   
    if(bRecordScroll == "")
        decideIfRecordScroll();
    
    var iScrollY = (bRecordScroll)? document.documentElement.scrollTop : 0;
    document.cookie = "sT=" + iScrollY + "; path=/";
    
    if (navigator.appName.indexOf("Microsoft") == -1)
    {
        if(document.documentElement.scrollTop == 0)
        {
            window.scrollBy(0, 1);
        }
    }
});

function Trim(sString)
{
   return  sString.replace(/^\s+/, '').replace(/\s+$/, '');
}


// Record the scrolling activity only if the user is in the Preview page
function decideIfRecordScroll()
{
    bRecordScroll = ($$(".PreviewPage").length > 0);
}


function aa()
{
    var x = $$("#" + S_SPECIAL_ADS_DIV + " div");
    for (var i=0;i<x.length;i++)
    {
        try 
        {
            var f = new String();
            var o;

            f = x[i].id;
            f = f.substring(0,f.length-2);
            o = $(f);
            if(!o)
                o = $$("." + f)[0];

            if (Trim(o.innerHTML) == "") 
                o.innerHTML = x[i].innerHTML;
        }    
        catch(ex){}
    }
    
    var aPlayButtons = $$("#gallerycontent .notifiers .thumbs li a.thumb .play");
    for(var i=0; i<aPlayButtons.length; i++)
    {
        var oParent = aPlayButtons[i].parentNode;
        var oPlay = aPlayButtons[i].cloneNode(true);
        
        oParent.removeChild(aPlayButtons[i]);
        oParent.appendChild(oPlay);
    }
}

// function showHide(oObject)
// Toggles display of the object
function showHide(oObject)
{
    oObject.style.display = (oObject.style.display == "block")? "none" : "block";
}

// When right-clicking on a link, this function adds the webad to the link's href.
// If the link is outbound, it changes it to the counter page (/redir/?id=XXX).
function attachWebAdToLink(oLink, bToCounter)
{
    var sWebAd = oLink.getAttribute("wa");
    var sNewHref = oLink.href;
    
    oLink.setAttribute("oHref", oLink.href);
    
    if(bToCounter)
        sNewHref = $$("input.hdnWebAdCounterUrl")[0].value + "?";
    else
        sNewHref += (oLink.href.indexOf("?") == -1)? "?" : "&";
    
    oLink.href = sNewHref + "id=" + sWebAd;
}

// When closing the context menu the link's href need to change back to what it was.
function removeWebAdFromLink(oLink)
{
    if(oLink.getAttribute("oHref") != null)
        oLink.href = oLink.getAttribute("oHref");
}

// function searchBoxEvents(oInput, sDefaultValue)
// Replaces the value of the input with the default value if blank
function searchBoxEvents(oInput, sDefaultValue)
{
    var sValue = oInput.value;
    if(sValue == sDefaultValue)
        oInput.value = "";
    else
        if(sValue == "")
            oInput.value = sDefaultValue;
}

// Counts the given webad
function CountWebAd(WebAd)
{
    ajaxRequest(WebAd);
} 

// Calls "count.aspx" using xmlhttp
function ajaxRequest(WebAd)
{ 
    var sUrl = "/" + S_SITE_LANG + "/redir/default.aspx?no_redir=true&id="+WebAd+"&rand="+ Math.random().toString(); 
    var oRequest = new createXMLHttpRequest();
    oRequest.open("GET", sUrl, false);
    oRequest.send(null); 
} 

// Returns a cross-browser XmlHttp object
function createXMLHttpRequest()
{
    try
    {
        return new XMLHttpRequest();
    }catch(e){}

    var aTypes = new Array('Microsoft.XMLHTTP','MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP');

    for (var i = 0; i < aTypes.length; i++)
    {
        try
        {
            return new ActiveXObject(aTypes[i]);
        }catch(e){} 
    }
    
    return false;
}

// Closes the Demo Movie. This function gets called from the flash itself.
function closeDemoMovie()
{
    var oCloser = $$(".peoplealsolikedbutton");
    if (oCloser.length > 0)
        showDemoMovie(oCloser[0]);
    else
        closeCallout();
}

/* Callout */
// Opens the "Install IncrediMail First" floating div in the Gallery
function contentDownloadCallout(sContentDownloadLink, sImagePath)
{
    var oCallout = document.createElement("div");
        oCallout.id = "GalleryCallout";
        
    var sCalloutHtml = "";
    
    try
    {
        sCalloutHtml = S_CALLOUT_HTML;
    }
    catch(ex)
    {
        sCalloutHtml = '' +
                        '<h5>Oops!</h5>' +
                        '<div class="content">' + 
                            '<p>To enjoy all of IncrediMail\'s free content, you <br />must first have IncrediMail installed on your computer.</p>'+
                            '<a href="/' + S_SITE_LANG + '/download.aspx?product=installer" class="GetButton" style="margin: 15px auto;" onclick="CountWebAd(\'%WebAdButton%\'); window.setTimeout(closeCallout, 1000);">Click here to install IncrediMail - FREE<span>&#160;</span></a>' +
                            '<p>If you already have IncrediMail installed, <br /><a href="#" onclick="downloadContent(\'%sContentDownloadLink%\'); closeCallout(); CountWebAd(\'%WebAdLink%\'); return false;">click here to continue.</a></p>' +
                            '' +
                            '<i' + '' + 'mg src="%sImagePath%images/callout_x' + '' + '.gif" alt="Close" class="closex" onclick="closeCallout();" />' +
                        '</div>';
    }
        
    sCalloutHtml = sCalloutHtml.replace("%sContentDownloadLink%", sContentDownloadLink);
    sCalloutHtml = sCalloutHtml.replace("%WebAdButton%", getCalloutWebAd("button"));
    sCalloutHtml = sCalloutHtml.replace("%WebAdLink%", getCalloutWebAd("link"));
    sCalloutHtml = sCalloutHtml.replace("%sImagePath%", sImagePath);
    
    oCallout.innerHTML = sCalloutHtml;
    
    closeCallout();
    oCallout.style.visibility = "hidden";
    document.body.appendChild(oCallout);
    
    var oDimObject = $$(".gthumbs");
    var iScrollTop = window.getScrollTop();
    
    if (oDimObject.length > 0)
    {
        oDimObject = oDimObject[0];
        
        oCallout.style.top = ((iScrollTop < 100)? 350 : window.getScrollTop() + 200) + "px";
        oCallout.style.left = oDimObject.getLeft() + Math.round((oDimObject.offsetWidth - oCallout.offsetWidth)/2) + "px";
    }
    else
    {
        oCallout.style.top = (document.documentElement.clientHeight - oCallout.offsetHeight)/2 + iScrollTop + "px";
        oCallout.style.left = (document.documentElement.clientWidth - oCallout.offsetWidth)/2 + "px";
    }
    
    oCallout.style.visibility = "";
    
    var sDoc = window.location.href;
    var iImpWebAd = -1;
    if (sDoc.indexOf("gallery") != -1)
        iImpWebAd = WEB_ADS["CalloutImpressionGallery"];
    if (sDoc.indexOf("home") != -1)
        iImpWebAd = WEB_ADS["CalloutImpressionHome"];
    if (sDoc.indexOf("search") != -1)
        iImpWebAd = WEB_ADS["CalloutImpressionSearch"];
    
    CountWebAd(iImpWebAd);
}

function downloadContent(sContentUrl)
{
    if (sContentUrl.indexOf("http://") != -1)
    {
        window.location = sContentUrl;
    }
    else
    {
        var oIframe = document.createElement('iframe');
            oIframe.src = sContentUrl;
            oIframe.style.width = 0;
            oIframe.style.height = 0;
        
        document.body.appendChild(oIframe);
    }
}

function getCalloutWebAd(sType)
{
    var sDoc = window.location.href;
    if (sType == "link")
    {
        if (sDoc.indexOf("gallery") != -1)
            return WEB_ADS["CalloutLinkGallery"];
        if (sDoc.indexOf("home") != -1)
            return WEB_ADS["CalloutLinkHome"];
        if (sDoc.indexOf("search") != -1)
            return WEB_ADS["CalloutLinkSearch"];
    }
    else if(sType == "button")
    {
        if (sDoc.indexOf("gallery") != -1)
            return WEB_ADS["CalloutButtonGallery"];
        if (sDoc.indexOf("home") != -1)
            return WEB_ADS["CalloutButtonHome"];
        if (sDoc.indexOf("search") != -1)
            return WEB_ADS["CalloutButtonSearch"];
    }
}

// Opens the Screenshots and skins callouts (floating image)
function showCallout(oImageCaller, sImage, sRootImagePath, sTitle, sContent)
{
    var sImagePath = sRootImagePath;
    
    var oCallout = document.createElement("div");
        oCallout.id = "Callout";
    
    var sTitle = sTitle || oImageCaller.parentNode.getElementsByTagName("h2")[0].innerHTML;
    var oDownloadMenu = $$(".DownloadMenu")[0];
    
    var sShadow = "";
    
    if(navigator.userAgent.indexOf("MSIE 6.0") != -1 && navigator.userAgent.indexOf("MSIE 7") == -1)
        sShadow = "src='" + sImagePath + "images/pix." + "" + "gif' style=\"filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + sImagePath + "images/callout_shadow_big.png');\"";
    else
        sShadow = "src='" + sImagePath + "images/callout_shadow_big." + "" + "png'";
    
    if(sImagePath.charAt(sImagePath.length - 1) != "/")
        sImagePath += "/";
    if(sImagePath.indexOf("http://") == -1)
        sImagePath = "http://" + sImagePath;
    
    if(sImage.indexOf("http://") == -1)
        sImage = sImagePath + sImage;
    
    if (sContent == undefined || sContent == "")
    {
        sContent = "<i" + "" + "mg src='" + sImage + "' class='screenshot' id='MainImage' /> ";
    }
    
    oCallout.innerHTML = 
            "<div class='bg'>" +
                "<h5>" + sTitle + "</h5>" +
                "<div class='content'>" +
                    sContent +
                    "<i" + "" + "mg src='" + sImagePath + "images/callout_x" + "" + ".gif' alt='Close' class='closex' onclick='closeCallout();' />" +
                    "<div class='bottomclose'>" +
                        "<i" + "" + "mg src='" + sImagePath + "download/screenshots/popup_close" + "" + ".gif' onclick='closeCallout();' />" +
                    "</div>" +
                "</div>" +
            "</div>";
    
    closeCallout();
    document.body.appendChild(oCallout);
    oCallout.style.top = window.getScrollTop() + 100 + "px";
    oCallout.style.left = ((document.body.offsetWidth / 2) - (oCallout.offsetWidth / 2)) + "px";
    
    var oTopLeft = new Element("img", {src: sImagePath + "images/callout_top_left.gif", 'class': "corner top left"});
    var oTopRight = new Element("img", {src: sImagePath + "images/callout_top_right.gif", 'class': "corner top right"});
    var oBottomRight = new Element("img", {src: sImagePath + "images/callout_bottom_right.gif", 'class': "corner bottom right"});
    var oBottomLeft = new Element("img", {src: sImagePath + "images/callout_bottom_left.gif", 'class': "corner bottom left"});
    
    if ($("MainImage"))
    {
        $("MainImage").onload = function(e){
                                    if(this.offsetHeight % 2 == 0)
                                    {
                                        oCallout.insertBefore(oTopLeft, oCallout.firstChild);
                                        oCallout.insertBefore(oTopRight, oCallout.firstChild);
                                        oCallout.insertBefore(oBottomRight, oCallout.firstChild);
                                        oCallout.insertBefore(oBottomLeft, oCallout.firstChild);
                                    }
                                    else
                                    {
                                        oCallout.appendChild(oTopLeft);
                                        oCallout.appendChild(oTopRight);
                                        oCallout.appendChild(oBottomRight);
                                        oCallout.appendChild(oBottomLeft);
                                    }
                                }
    }
    else
    {
        oCallout.appendChild(oTopLeft);
        oCallout.appendChild(oTopRight);
        oCallout.appendChild(oBottomRight);
        oCallout.appendChild(oBottomLeft);
    }
    // Makes the frame draggable
    new Drag.Move(oCallout);
}

function showMovieCallout(sSrc, sTitle)
{
    var sMovie = S_IMAGE_PATH + sSrc;
    
    showCallout("", "", S_IMAGE_PATH, sTitle, "<div id='tmpMovie'>&#160;</div>");
    
    var so = new SWFObject(S_IMAGE_PATH + "/preview/loader.swf", "contentpreview", "553", "296", "8", "");
        so.addVariable("demo_name", sMovie);
        so.addVariable("wmode", "transparent");
        so.addVariable("allowScriptAccess", "always");
        so.write("tmpMovie");
}

// Closes the callout frame
function closeCallout()
{
    if($("Callout") != undefined)
    {
        $("Callout").innerHTML = "";
        $("Callout").parentNode.removeChild($("Callout"));
    }
    
    if($("GalleryCallout") != undefined)
    {
        $("GalleryCallout").innerHTML = "";
        $("GalleryCallout").parentNode.removeChild($("GalleryCallout"));
    }
}
/* ------ */

/* Search */
// On focus and blur replaces the default text with a blank string, and vice versa
function replaceSearchText(oInput, sDefaultText)
{
    if(oInput.value == sDefaultText)
    {
        oInput.value = "";
        oInput.style.color = "#000000";
    }
    else
    {
        if(oInput.value == "")
        {
            oInput.value = sDefaultText;
            oInput.style.color = "";
        }
        else
            oInput.style.color = "#000000";
    }
}

function SetSearchColor(oInput, sDefaultText)
{
    if(oInput.value == sDefaultText)
        oInput.style.color = '';
    else
        oInput.style.color = '#000000';
                          
}

// Checks if the key pressed in the search textbox is Enter, submits it if so
function autoSubmitSearch(e, bSubmit)
{
    var e = e || event;
    
    if(e.keyCode == 13 || bSubmit)
    {
        doSearch("", true);
        return false;
    }
    
    return true;
}

// Validates and submits the search
function doSearch(sDefaultText, bFromEnter)
{
    var sQuery = $$(".txtSearch")[0].value;
    var sQueryLocation = "";
    
    if (window.location.href.indexOf("/gallery/") != -1)
        sQueryLocation = "g";
    else if (window.location.href.indexOf("home.aspx") != -1)
        sQueryLocation = "h";
    else if (window.location.href.indexOf("search.aspx") != -1)
        sQueryLocation = "s";
    else if (window.location.href.indexOf("download/") != -1)
        sQueryLocation = "d";
    
    if (sQuery.replace(/%20/g,"") == "" || sQuery == sDefaultText)
    {
        $$(".txtSearch")[0].focus();
    }
    else
    {
        if (bFromEnter)
        {
            switch (sQueryLocation)
            {
                case "g":   CountWebAd(WEB_ADS["SearchFromGallery"]); break;
                case "h":   CountWebAd(WEB_ADS["SearchFromHome"]); break;
                case "s":   CountWebAd(WEB_ADS["SearchFromSearch"]); break;
                case "d":   CountWebAd(WEB_ADS["SearchFromDownload"]); break;
            }
        }
        
        document.location.href = "/" + S_SITE_LANG + "/search.aspx?q=" + encodeURIComponent(sQuery) + "&l=" + sQueryLocation;
    }
    
    return false;
}
/* ------ */

/* Header */
function LoadBackgrouds(sBodyBackgroudImageUrl)
{
    if (sBodyBackgroudImageUrl != "")
    {
        document.body.style.backgroundImage = "url('" + sBodyBackgroudImageUrl + "')";
        document.body.style.backgroundRepeat = "repeat-x";
    }
}
/* ------ */

// Goes over all the images defined in the aThumbs = $$("") code,
// and resizes them according to the I_THUMBNAILS_WIDTH and I_THUMBNAILS_HEIGHT variables.
// The iamges should only be resized if LARGER, that's why simple css width and height can't be used.
function resizeContentThumbnails()
{
    if(S_GALLERY_CONTENT_AREA_ID == undefined || $(S_GALLERY_CONTENT_AREA_ID).className.indexOf("skins") == -1)
    {
        var aThumbs = $$(".thumb img, .collections div a img");
        
        for(var i=0; i<aThumbs.length; i++)
        {
            if(!aThumbs[i].hasClass("play"))
            {
                //window.setTimeout("resizeImage('" + aThumbs[i].id + "', " + I_THUMBNAILS_WIDTH + ", " + I_THUMBNAILS_HEIGHT + ", true)", 500);
                aThumbs[i].onload = function(e){ resizeImage(this, I_THUMBNAILS_WIDTH, I_THUMBNAILS_HEIGHT, true); }
                aThumbs[i].src = aThumbs[i].src;
            }
        }
    }
    
    var oAnimationPreview = $$(".AnimationsPreview img")[0];
    if(oAnimationPreview)
    {
        //window.setTimeout("resizeImage('" + oAnimationPreview.id + "', 290, 190, false)", 100);
        oAnimationPreview.onload = function(e){ resizeImage(this, 290, 190, false); }
        oAnimationPreview.src = oAnimationPreview.src;
    }
    
    var oPreview = $$(".EcardsPreview img, .LettersPreview img")[0];
    if(oPreview)
    {
        //window.setTimeout("resizeImage('" + oPreview.id + "', 300, 207, false)", 100);
        oPreview.onload = function(e){ resizeImage(this, 300, 207, false); }
        oPreview.src = oPreview.src;
    }
}

function resizeImage(oImage, iWidth, iHeight, isBlock)
{
    var oImage = $(oImage);
    if(oImage.offsetWidth > iWidth)
    {
        oImage.style.width = iWidth + "px";
        if(isBlock)
            oImage.style.display = "block";
    }
    if(oImage.offsetHeight > iHeight)
    {
        oImage.style.height = iHeight + "px";
        if(isBlock)
            oImage.style.display = "block";
    }
}

function selectByValue(oSelect, sValue)
{
    for (var i=0; i < oSelect.options.length; i++)
    {
        if (oSelect.options[i].value == sValue)
        {
            oSelect.selectedIndex = i;
            break;
        }
    }
}

function matchElementsHeights(aIds)
{
    var iMaxHeight = -1;
    var iMaxBottomHeight = 0;
    
    for(var i=0; i<aIds.length; i++)
    {
        if ($(aIds[i]))
        {
            iMaxHeight = Math.max(iMaxHeight, $(aIds[i]).offsetHeight);
            
            var sParentId = $(aIds[i]).parentNode.id;
            if (sParentId != "")
            {
                var oBuyNow = $$("#" + sParentId + " .buynow")[0];
                
                if (oBuyNow)
                    iMaxBottomHeight = Math.max(iMaxBottomHeight, oBuyNow.offsetHeight);
            }
        }
    }
    
    for(var i=0; i<aIds.length; i++)
    {
        if ($(aIds[i]))
        {
            var iBottomAdd = 0;
            
            var sParentId = $(aIds[i]).parentNode.id;
            if (sParentId != "")
            {
                var oBuyNow = $$("#" + sParentId + " .buynow")[0];
                if (oBuyNow)
                    iBottomAdd = iMaxBottomHeight - oBuyNow.offsetHeight;
            }
            
            if ($(aIds[i]).offsetHeight <= iMaxHeight + iBottomAdd)
                $(aIds[i]).style.height = (iMaxHeight + iBottomAdd) + "px";
        }
    }
    
    return iMaxHeight;
}

function bb()
{    
    var oScrollTo = $$(".hdnScrollPosition")[0];
    if(oScrollTo && oScrollTo.value != 0)
        window.scrollTo(0, oScrollTo.value);
    else
        if(document.documentElement.scrollTop == 0)
            window.scrollTo(0, 1);
}

function showWebAds()
{
    var oDiv = document.createElement("div");
        oDiv.id = "oO";
        oDiv.style.position = "absolute";
        oDiv.style.zIndex = "1000";
        oDiv.style.background = "#eee";
        oDiv.style.border = "3px double #aaa";
        oDiv.style.padding = "5px";
        
        oDiv.innerHTML = '<div style="padding: 4px 2px; margin-bottom: 5px; font-weight: bold; background: #f6f6f6; font-size: 1.2em;">Element:</div>' +
                            '<table>' +
                                '<tr>' +
                                    '<td>Id: </td>' +
                                    '<td id="oOId">N/A</td>' +
                                '</tr>' +
                                '<tr>' +
                                    '<td>Auto Id:&#160;&#160;&#160;</td>' +
                                    '<td id="oOAId">N/A</td>' +
                                '</tr>' +
                                '<tr><td colspan="2">&#160;</td></tr>' +
                                '<tr>' +
                                    '<td>WebAd: </td>' +
                                    '<td id="oOWA">N/A</td>' +
                                '</tr>' +
                            '</table>';
    
    document.body.insertBefore(oDiv, document.body.firstChild);
    
    $(document.body).addEvent("mousemove", whichElement);
}

function addBorder()
{
    var adivs = $$(".borderBox");
    for(var i=0; i<adivs.length; i++)
    {
        var imgTl = new Element('span',{'class':'a tl'});
        var imgTr = new Element('span',{'class':'a tr'});
        var imgBl = new Element('span',{'class':'a bl'});
        var imgBr = new Element('span',{'class':'a br'});
          
                   
       adivs[i].appendChild( imgTl);
       adivs[i].appendChild( imgTr);
       adivs[i].appendChild( imgBl);
       adivs[i].appendChild( imgBr);
    }
    
 }      

function addToFavorites()
{
    if (document.all)
        window.external.AddFavorite(location.href, document.title);
    else if (window.sidebar)
        window.sidebar.addPanel(document.title, location.href, "")
}

function whichElement(event)
{
    var o = (event.srcElement)? event.srcElement : event.target;
    
    if (o.parentNode.tagName.toLowerCase() == "a")
    {
        o = o.parentNode;
    }
    
    if (o.tagName.toLowerCase() == "a")
    {
        var iTop = ((window.pageYOffset)? window.pageYOffset : document.documentElement.scrollTop) + event.clientY + 15;
        
        $("oO").style.display = "block";
        
        if (iTop + $("oO").offsetHeight > document.body.offsetHeight)
            iTop -= $("oO").offsetHeight;
        
        $("oO").style.top =  iTop + "px";
        
        $("oO").style.left = event.clientX + 15 + "px";
        
        $("oOId").innerHTML = (o.id)? o.id : "N/A";
        $("oOWA").innerHTML = (o.getAttribute("wa"))? "<b>" + o.getAttribute("wa") + "</b>" : "N/A";
        $("oOAId").innerHTML = (o.getAttribute("AutoID"))? "<b>" + o.getAttribute("AutoID") + "</b>" : "N/A";
        
        if (o.onclick != null)
        {
            var s = "" + o.onclick;
            if (s.indexOf("CountWebAd") != -1)
            {
                s = s.replace(/"/g, "'");
                s = s.substring(s.indexOf("CountWebAd") + 12, s.indexOf("')", s.indexOf("CountWebAd") + 12));
                $("oOWA").innerHTML = "<b>" + s + "</b>";
            }
        }
    }
    else
    {
        $("oO").style.display = "none";
    }
}

/**
 * SWFObject v1.5.1: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept == "undefined") var deconcept = {};
if(typeof deconcept.util == "undefined") deconcept.util = {};
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = {};
deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = {};
	this.variables = {};
	this.attributes = [];
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
		if (!deconcept.unloadSet) {
			deconcept.SWFObjectUtil.prepUnload = function() {
				__flash_unloadHandler = function(){};
				__flash_savedUnloadHandler = function(){};
				window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
			}
			window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
			deconcept.unloadSet = true;
		}
	}
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', false);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	useExpressInstall: function(path) {
		this.xiSWFPath = !path ? "expressinstall.swf" : path;
		this.setAttribute('useExpressInstall', true);
	},
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name] || "";
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name] || "";
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = [];
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs[variablePairs.length] = key +"="+ variables[key];
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ (this.getAttribute('style') || "") +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs();
			for(var i=0; i<pairs.length; i++) {
			    swfNode += ' ' + (pairs[i].split("="))[0] + '="' + (pairs[i].split("="))[1] + '"';
			}
			pairs = pairs.join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ (this.getAttribute('style') || "") +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			
			var pairs = this.getVariablePairs();
			for(var i=0; i<pairs.length; i++) {
			    swfNode += '<param name="' + (pairs[i].split("="))[0] + '" value="' + (pairs[i].split("="))[1] + '" />';
			}
			pairs = pairs.join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
//				document.write("player v: "+ counter);
				PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
			} catch (e) {
				axo = null;
			}
		}
	} else { // Win IE (non mobile)
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if (param == null) { return q; }
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i = objects.length - 1; i >= 0; i--) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
/* add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;