// This list builds out all the demo buttons by advertiser name
var oDemoAds = new Hash({
    preroll:     ["holidayinn", "dish", "dove", "degree", "amazon"],
    overlay:     ["maaco", "education", "benjaminplumber", "bigbox", "1408"],
    ingame:      ["holidayinn", "dish", "dove", "degree", "amazon"],
    videobanner: ["degree", "dish", "dove", "holidayinn", "amazon"]
});

function showDemoSection(strShowType)
{
    oDemoAds.each(function(aAds, strAdType) {
        if(strAdType == strShowType)
        {
            $("section_link_" + strAdType).addClass("current");
            $("demo_blurb_" + strAdType).setStyle("display", "block");
            $("demo_buttons_" + strAdType).setStyle("display", "block");
            showDemo(strAdType, aAds[0]);
        }
        else
        {
            $("section_link_" + strAdType).removeClass("current");
            $("demo_blurb_" + strAdType).setStyle("display", "none");
            $("demo_buttons_" + strAdType).setStyle("display", "none");
        }
    });
};

function showDemo(strAdType, strAdvertiser)
{
    var oSwf = new Swiff("/resources/flash/ad_demos/SpotxAdDemo.swf", {
        id: "demo_ad_swf",
        container: $("demo_pane"),
        width: 864,
        height: 637,
        params: {base: "."},
        vars: {
            type: strAdType,
            advertiser: strAdvertiser
        },
        properties: {menu: false}
    });
};

function swapImageHover(oImg, strAd, strState)
{
    if(strState == 'on')
    {
        oImg.src = strAdIconImageDir + "adv_chip_" + strAd + "_on.png";
    }
    else
    {
        oImg.src = strAdIconImageDir + "adv_chip_" + strAd + "_off.png";
    }
};

var strAdIconImageDir = "/images/advertiser_icons/";
window.addEvent("domready", function() {
    oDemoAds.each(function(aAds, strAdType){        
        var oDiv = new Element("div", {
            id: "demo_buttons_" + strAdType
        })
        .setStyle("display", "none");
        $("demo_buttons").grab(oDiv);
        
        aAds.each(function(strAd) {
            // Use a string to add img tags for ie6, was crashing browser using Element class
            var strImg = '<img id="img_' + strAdType + strAd + '" src="' + strAdIconImageDir + 'adv_chip_' + strAd + '_off.png"'
                    + ' onclick="showDemo(\'' + strAdType + '\', \'' + strAd + '\');"'
                    + (!Browser.Engine.trident4
                        ?  ' onmouseover="swapImageHover(this, \'' + strAd + '\', \'on\')" onmouseout="swapImageHover(this, \'' + strAd + '\', \'off\')"'
                        : '')
                    + ' />';
            
            oDiv.innerHTML = oDiv.innerHTML + strImg;
        });
    });
    
    showDemoSection("preroll");
});