/*
* Two part script. The first part writes out banner images onto the page.
* The second starts when the document is loaded and cycles those images randomly.
*/
document.write("<div class='banner'>"); // Write .banner div.

// Write out whatever images to the document.

// Advertising Banners

image(
"http://www.imvu.com/catalog/web_landing.php?p=power&userId=1326737",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/DR/ClubDarkness_468x60-2_JDWhiskey-1.gif",
"Club Darkness - Join Us in 3D",
"Club Darkness - join Us in 3D",
"0",
null, null);

image(
"http://www.fwebtraffic.com/?rid=1267370",
"_blank",
"http://www.fwebtraffic.com/images/fwebtraffic468x60-1.jpg",
"1,000,000 (One Million) Visitors Free",
"1,000,000 (One Million) Visitors Free",
"0",
null, null);

image(
"http://www.dreamscaperadio.com/hosting",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/DR/DR-Hosting-Sun.gif",
"Dreamscape Web Site and Shoutcast Hosting",
"Dreamscape Web Site and Shoutcast Hosting",
"0",
null, null);

image(
"http://www.extremerestraints.com/home.html?a=extremedreams",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/XR1.jpg",
"Extreme Dreams Adult Toy Store",
"Extreme Dreams Adult Toy Store",
"0",
null, null);

image(
"http://www.extremerestraints.com/home.html?a=extremedreams",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/XTRRST.jpg",
"Extreme Dreams Adult Toy Store",
"Extreme Dreams Adult Toy Store",
"0",
null, null);

image(
"http://adultfriendfinder.com/go/p420425c",
"_blank",
"http://adserver.adultfriendfinder.com/banner.cgi?lfrom=uk",
"Adult Freind Finder",
"Adult Freind Finder",
"0",
null, null);

image(
"http://www.GothicMatch.com/i/af18023480",
"_blank",
"http://images.GothicMatch.com/gm/fbanner2.gif",
"Gothic Match",
"Gothic Match",
"0",
null, null);

image(
"http://clicks.toteme.com/?p=21&pp=1&s=36993&g=262",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/VGirl-01.png",
"Strippers on your desktop",
"Strippers on your desktop",
"0",
null, null);

image(
"http://clicks.toteme.com/?p=21&pp=1&s=36993&g=262",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/VGirl-02.png",
"Strippers on your desktop",
"Strippers on your desktop",
"0",
null, null);

image(
"http://clicks.toteme.com/?p=21&pp=1&s=36993&g=262",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/VGirl-03.png",
"Strippers on your desktop",
"Strippers on your desktop",
"0",
null, null);

image(
"http://refer.ccbill.com/cgi-bin/clicks.cgi?CA=927615-0000&PA=1874782",
"_blank",
"http://www.bangme.net/bannergfx/notaboutsex.gif",
"Its Not ABout Sex",
"Its Not ABout Sex",
"0",
null, null);

image(
"http://refer.ccbill.com/cgi-bin/clicks.cgi?CA=927615-0000&PA=1874782",
"_blank",
"http://www.bangme.net/bannergfx/bangmecutout.jpg",
"Its Not ABout Sex",
"Its Not ABout Sex",
"0",
null, null);

image(
"http://www.bangme.net/refer.aspx?uid=562920",
"_blank",
"http://www.bangme.net/bannergfx/notaboutsex.gif",
"Its Not ABout Sex",
"Its Not ABout Sex",
"0",
null, null);

image(
"http://www.bangme.net/refer.aspx?uid=562920",
"_blank",
"http://www.bangme.net/bannergfx/bangmecutout.jpg",
"Its Not ABout Sex",
"Its Not ABout Sex",
"0",
null, null);

image(
"http://www.thesoundadviceproject.com/",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/SAP_Full.gif",
"The Sound Advice Project",
"The Sound Advice Project",
"0",
null, null);

// Radio Shows

image(
"http://www.myspace.com/theautopsyreport",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/AutopsyReportBanner.jpg",
"The Autopsy Report on MySpace",
"The Autopsy Report on MySpace",
"0",
null, null);

image(
"http://www.wyldsideradio.com",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/wyldside/wyldsidelogo6.jpg",
"Wyldside Radio - Crank It Up And Rip The Knob Off !",
"Wyldside Radio - Crank It Up And Rip The Knob Off !",
"0",
null, null);

// DJ Sites

image(
"http://www.jenmas.com",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/JenMas-Hard2TheCore.gif",
"JenMas Hard 2 The Core",
"JenMas Hard 2 The Core",
"0",
null, null);

// Band Banners

image(
"http://www.myspace.com/signal",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/bands/Signal.jpg",
"Signal on MySpace",
"Signal on MySpace",
"0",
null, null);

image(
"http://www.fourandtwentyelders.com/",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/bands/420.png",
"4&20 Elders",
"4&20 Elders",
"0",
null, null);

image(
"http://www.sonicsyndicate.com",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/bands/SonicSyndacate.jpg",
"Sonic Syndicate",
"Sonic Syndicate",
"0",
null, null);

image(
"http://www.myspace.com/sickfaceband",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/bands/Sickface.png",
"Sickface on MySpace",
"Sickface on MySpace",
"0",
null, null);

image(
"http://www.myspace.com/nextpage2",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/bands/NextPage.jpg",
"Next Page on MySpace",
"Next Page on MySpace",
"0",
null, null);

image(
"http://www.groovhead.net",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/bands/grooveheadlogo.gif",
"Groovehead",
"Groovehead",
"0",
null, null);

image(
"http://www.forevergypsy.com/",
"_blank",
"http://i198.photobucket.com/albums/aa2/djtbone001a/banners/bands/ForeverGypsy.png",
"Forever Gypsy",
"Forever Gypsy",
"0",
null, null);

image(
"http://www.myspace.com/thekeroseneman",
"_blank",
"http://i248.photobucket.com/albums/gg161/grimmworks/kerosenebanner2.jpg",
"The Kerosene Man on MySpace",
"The Kerosene Man on MySpace",
"0",
"468", "60");

//End banner List

document.write("</div>"); // Close div.

// Writes an <img> tag wrap inside a <a>. Pass null for default values.
function image(href, target, src, title, alt, border, width, height) {
    href = quote('href', href);
    target = quote('target', target);
    src = quote('src', src); // Use the quote function to format each attribute.
    title = quote('title', title);
    alt = quote('alt', alt);
    border = quote('border', border);
    width = quote('width', width);
    height = quote('height', height);

     // Set as invisble. The script will show them.
    var style = quote('style', 'display: none;');
    
    // Concat the <img> tag and write it out to the document.
    document.write('<a' + href + target + '>');
    document.write('<img' + src + title + alt + width + height + border + style + '/>');
    document.write('</a>');
}

// Takes a key value pair and formats it like (space)key='value'(space) for html attributes.
function quote(attribute, value) {
    if (value && attribute) // Only if null wasn't passed.
        return " " + attribute + "='" + value + "'" + " ";

    return ''; // Return blank if null was passed.
}

/*
* Second part of script. Should only run once.
*/

// Check pinstance.
if (!pinstance) {
    var pinstance = true;
    var minutes = 1; // How many minutes between updates.
    var currentbanner = 0; // Banner to change next.
    var banners; // jQuery selection of .banner divs
    
    // When document is loaded.
    $(document).ready(function () {
        banners = $('.banner'); // Select .banner divs.
        changeBanners(banners); // Change banners to bring up first images.
        setInterval('updateNext()', (1000 * 60) * minutes); // Now update every now and then.
    });
}

// Updates the currentbanner.
function updateNext () {
    // Select current banner and change it.
    changeBanners(banners.eq(currentbanner));
    
     // Cycle to next banner.
    currentbanner = (currentbanner + 1) % banners.length;
}

// Takes a jquery selection of banners and updates them.
function changeBanners (banners) {
    // $().each() the entire selection.
    banners.each(function (index) {
        // Find the hidden images inside this .banner.
        var hidden = $(this).find('img:hidden');
        
        // If no images there's nothing to do.
        if (hidden.length == 0) return; 
        
         // Pick a hidden image.
        var nextimage = hidden.eq(Math.ceil(Math.random() * hidden.length) - 1);
        $(this).find('img:visible').hide(); // Hide the visible one.
        nextimage.show(); // Show the next one.
    });
}