function enableBanners()
{
    var b = document.getElementById('banners');
    if (b != null)
    {
	try {
	    b.style.display = null;
	}
	catch (e)
	{
	    b.style.display = 'block';
	}
    }
}
addWindowOnload(enableBanners);

var banners = {
    addyou: [
	{
	    created: '2009-03-14',
	    active: true,
	    image: '/images/banners/sponsor.png',
	    link: 'nyheter.vikbolandets-ryttarforening.se/staticpages/index.php?page=sponsor',
	    width: '120px',
	    height: '60px'
	}
    ],
    folksam1: [
	{
	    created: '2006-06-04',
	    active: false,
	    image: '/images/banners/120x60_faraMedHast.gif',
	    link: 'www.folksam.se/forsakring/djur/hast/hastslap.htm',
	    width: '120px',
	    height: '60px'
	},
	{
	    created: '2006-06-04',
	    active: false,
	    image: '/images/banners/120x60_hastfolk.gif',
	    link: 'www.hastfolk.se',
	    width: '120px',
	    height: '60px'
	},
	{
	    created: '2006-06-04',
	    active: false,
	    image: '/images/banners/120x60_krangliga.gif',
	    link: 'www.forsakring/djur/hast/index.htm',
	    width: '120px',
	    height: '60px'
	}
    ],
    folksam2: [
	{
	    created: '2006-06-04',
	    active: false,
	    image: '/images/banners/120x60_godaRad.gif',
	    link: 'www.folksam.se/forskaring/djur/hast/index.htm',
	    width: '120px',
	    height: '60px'
	},
	{
	    created: '2006-06-04',
	    active: false,
	    image: '/images/banners/120x60_hastsaker.gif',
	    link: 'www.folksam.se/idrott/hastsaker.htm',
	    width: '120px',
	    height: '60px'
	},
	{
	    created: '2006-06-04',
	    active: false,
	    image: '/images/banners/120x60_ombud.gif',
	    link: 'www.folksam.se/forsakring/djur/ombud.htm',
	    width: '120px',
	    height: '60px'
	}
    ],
    avantia: [
	{
	    created: '2009-05-23',
	    active: true,
	    image: '/images/banners/avantia.gif',
	    link: 'www.avantiafritid.se',
	    width: '125px',
	    height: '80px'
        }
    ],
    hastkliniken: [
	{
	    created: '2009-09-11',
	    active: true,
	    image: '/images/banners/hastkliniken.png',
	    link: 'www.hastkliniken.se',
	    width: '120px',
	    height: '60px'
        }
    ],
    kings: [
	{
	    created: '2009-03-14',
	    active: true,
	    image: '/images/banners/kings.png',
	    link: 'www.kingshastsport.se',
	    width: '120px',
	    height: '155px'
	},
	{
	    created: '2009-03-14',
	    active: true,
	    image: '/images/banners/kings.png',
	    link: 'www.kingshastsport.se',
	    width: '120px',
	    height: '60px',
	    xpos: '0px',
	    ypos: '-95px'
	},
	{
	    created: '2009-03-14',
	    active: true,
	    image: '/images/banners/kings.png',
	    link: 'www.kingshastsport.se',
	    width: '120px',
	    height: '75px',
	    xpos: '0px',
	    ypos: '-20px'
	}
    ],
    hippson: [
	{
	    created: '2007-05-04',
	    active: false,
	    image: 'http://www.hippson.se/cldocpart/33750.gif',
	    link: 'www.hippson.se',
	    width: '120px',
	    height: '255px'
	},
	{
	    created: '2007-05-04',
	    active: false,
	    image: 'http://www.hippson.se/cldocpart/33750.gif',
	    link: 'www.hippson.se',
	    width: '120px',
	    height: '30px',
	    xpos: '0px',
	    ypos: '-125px',
	    style: 'border:0px solid black;'
	},
	{
	    created: '2007-05-04',
	    active: false,
	    image: 'http://www.hippson.se/cldocpart/33750.gif',
	    link: 'www.hippson.se',
	    width: '120px',
	    height: '105px',
	    xpos: '0px',
	    ypos: '-150px',
	    style: 'border:0px solid black;'
	},
	{
	    created: '2007-05-04',
	    active: false,
	    image: 'http://www.hippson.se/cldocpart/33750.gif',
	    link: 'www.hippson.se',
	    width: '120px',
	    height: '155px',
	    xpos: '0px',
	    ypos: '0px',
	    style: 'border:0px solid black;'
	}
    ]
}

var ads = { 
    opera: [
	{
	    created: '2007-05-04',
	    active: true,
	    image: 'http://promote.opera.com/buttons/official/120x60/png-8/120x60noads.png',
	    link: 'www.opera.com/',
	    title: 'Get Opera!',
	    width: '120px',
	    height: '60px'
	}
    ],
    firefox: [
	{
	    created: '2007-05-04',
	    active: true,
	    image: 'http://sfx-images.mozilla.org/affiliates/Buttons/125x50/takebacktheweb_125x50.png',
	    link: 'www.getfirefox.com/',
	    title: 'Get Firefox!',
	    width: '125px',
	    height: '50px',
	    style: 'border:1px solid black;'
	},
	{
	    created: '2007-05-04',
	    active: false,
	    image: 'http://media.revver.com/broadcast/23838/thumbs/thumb_default.jpg',
	    link: 'firefoxflicks.com/flick/?id=23838',
	    title: 'Valid XHTML 1.0!',
	    width: '120px',
	    height: '90px',
	    style: 'border:1px solid black;'
	}
    ],
    thunderbird: [
	{
	    created: '2007-05-04',
	    active: true,
	    image: 'http://sfx-images.mozilla.org/affiliates/thunderbird/reclaimyourinbox_small.png',
	    link: 'www.getthunderbird.com/',
	    title: 'Get Thunderbird!',
	    width: '125px',
	    height: '80px',
	    style: 'border:1px solid black;'
	}
    ],
    w3validator: [
	{
	    created: '2007-05-04',
	    active: false,
	    image: 'http://www.w3.org/Icons/valid-xhtml10',
	    link: 'validator.w3.org/check?uri=referer',
	    title: 'Valid XHTML 1.0!',
	    width: '88px',
	    height: '31px'
	}
    ]
}

function addBanners(banners)
{
    var list = new Array();
     
    for (var group in banners)
	list.push(banners[group]);
    
    list.sort(function (a, b) { return Math.random() - 0.5; });
    
    for (var i = 0; i < list.length; ++i)
    {
	list[i].sort(function (a, b) { return b.active - a.active; });
	
	var active = 0;
	
	while (active < list[i].length && list[i][active].active)
	    ++active;

	var index = Math.floor(Math.random() * active);

//	alert(active + ' ' + index);

        var showAll = false;
        if (showAll)
            for (var j = 0; j < list[i].length; ++j)
	        addBanner(list[i][j]);
        else
	    addBanner(list[i][index]);
    }
}

function addBanner(item)
{
    if (!item.active)
	return;

    var xpos = item.xpos || 'left';
    var ypos = item.ypos || 'top';
    
    var style = ("background: transparent url('" +
		 item.image +
		 "') no-repeat scroll " +
		 xpos + " " + ypos +
		 "; width: " +
		 item.width +
		 "; height: " +
		 item.height +
		 "; margin: 5px; cursor: pointer;");

    if (item.style)
	style += item.style;// + 'border:2px solid black;';

    var title = item.title || item.link;
    
    document.write('<a href="http://' +
		   item.link +
		   '" target="_blank"><div class="" title="' +
		   title +
		   '" style="' +
		   style +
		   '"></div></a>');
}

