//document.unload=unloadDocument
window.onload=initialize

function initialize()
{
//    var placeholder = document.getElementById("search-advertisement");
//    if(placeholder != null)
//    {
//        writeWelcomeMovie(placeholder);
//    }
}

// We should show a icon on top of the movie that states that the movie is musted
function mute(qtMovie)
{
    qtMovie.SetVolume(0);
}

function unmute(qtMovie, volume)
{
    qtMovie.SetVolume(volume);
}

function mouseOverThumbNail(image, width, height)
{
    image.width = width
    image.height = height
}

function mouseExitsThumbNail(image)
{
    image.width = 100
    image.height = 100
}

function unloadDocument()
{
    //alert("Test Unload")
}

// TODO: When the video is muted we show an icon above the movie to indication
//       that the sound is muted.
//
// TODO: The database needs to contain the movie URL, movie kind (QuickTime, 
//       Flash), volumne, possibly start location.
function getWelcomeMovie()
{
    //var tag = ""
    
    var num =  Math.random() * 10
    if(Math.round(num) > 5)
    {
        var tag = "<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' "
        tag += "           codebase='http://www.apple.com/qtactivex/qtplugin.cab'"
        tag += "           width='640' height='288'"
        tag += "           id='movie'"
        tag += "           onmouseover='unmute(document.movie, 1000);return false'"
        tag += "           onMouseOut='mute(document.movie);return false'>"
        tag += "           <param name='src' value='http://images.apple.com/movies/paramount/beowulf/beowulf-tlr1_h.640.mov' />"
        tag += "           <param name='controller' value='false'/>"
        tag += "           <param name='autoplay' value='true' />"
        tag += "           <param name='loop' value='true' />"
        tag += "           <param name='href' value='http://www.beowulfmovie.com/' />"
        tag += "           <param name='volume' value='0' />"
        tag += "           <param name='enablejavascript' value='true'/>"
        tag += "           <embed src='http://images.apple.com/movies/paramount/beowulf/beowulf-tlr1_h.640.mov'"
        tag += "                  width='640'"
        tag += "                  height='288'"
        tag += "                  controller='false'"
        tag += "                  autoplay='true'"
        tag += "                  loop='true'"
        tag += "                  volume='0'"
        tag += "                  href='http://www.beowulfmovie.com/'"
        tag += "                  enablejavascript='true'"
        tag += "                  name='movie'"
        tag += "                  onmouseover='mute(document.movie);return false'"
        tag += "                  onMouseOut='unmute(document.movie, 1000);return false'/>"
        tag += "</object>"
        document.write(tag)
    }
    else
    {
        
        var tag = "<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B'"
        tag += "        codebase='http://www.apple.com/qtactivex/qtplugin.cab'"
        tag += "        width='359' height='300'"
        tag += "        id='movie'"
        tag += "        onmouseover='unmute(document.movie, 100);return false'"
        tag += "        onMouseOut='mute(document.movie);return false'>"
        tag += "        <param name='src' value='http://www.dexigner.com/detail/files/13611.mov' />"
        tag += "        <param name='controller' value='false'/>"
        tag += "        <param name='autoplay' value='true' />"
        tag += "        <param name='loop' value='true' />"
        tag += "        <param name='href' value='http://www.beowulfmovie.com/' />"
        tag += "        <param name='volume' value='0' />"
        tag += "        <param name='enablejavascript' value='true'/>"
        tag += "        <embed src='http://www.dexigner.com/detail/files/13611.mov'"
        tag += "               width='359'"
        tag += "               height='300'"
        tag += "               controller='false'"
        tag += "               autoplay='true'"
        tag += "               loop='true'"
        tag += "               volume='0'"
        tag += "               href='http://www.beowulfmovie.com/'"
        tag += "               enablejavascript='true'"
        tag += "               name='movie'"
        tag += "               onmouseover='mute(document.movie);return false'"
        tag += "               onMouseOut='unmute(document.movie, 100);return false'/>"
        tag += "</object>"
        document.write(tag)
      
    }
}

function getSponserLinks()
{
    document.write("<div class='sponsers'>")
    /*
    var tag = "<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' "
        tag += "           codebase='http://www.apple.com/qtactivex/qtplugin.cab'"
        tag += "           width='259' height='200'"
        tag += "           id='sponser1'"
        tag += "           onblur='alert('test');'"
        tag += "           onmouseover='unmute(document.sponser1, 50);return false'"
        tag += "           onMouseOut='mute(document.sponser1);return false'>"
        tag += "           <param name='src' value='http://screeningroom0.boardsmag.com/commercials/20061005.hondacivic2.mov?103750=95291' />"
        tag += "           <param name='controller' value='false'/>"
        tag += "           <param name='autoplay' value='true' />"
        tag += "           <param name='loop' value='true' />"
        tag += "           <param name='href' value='http://automobiles.honda.com/' />"
        tag += "           <param name='volume' value='0' />"
        tag += "           <param name='enablejavascript' value='true'/>"
        tag += "           <param name='scale' value='ToFit' />"
        tag += "           <embed src='http://screeningroom0.boardsmag.com/commercials/20061005.hondacivic2.mov?103750=95291'"
        tag += "                  width='259'"
        tag += "                  height='200'"
        tag += "                  controller='false'"
        tag += "                  autoplay='true'"
        tag += "                  loop='true'"
        tag += "                  volume='0'"
        tag += "                  href='http://automobiles.honda.com/'"
        tag += "                  enablejavascript='true'"
        tag += "                  scale='ToFit'"
        tag += "                  name='sponser1'"
        tag += "                  onblur='alert('test');'"
        tag += "                  onmouseover='mute(document.sponser1);return false'"
        tag += "                  onMouseOut='unmute(document.sponser1, 50);return false'/>"
        tag += "</object>"
        tag += "<div class='caption'>"
        tag += "Honda Civic"
        tag += "</div>"
        document.write(tag)
     */   
    var tag2 = "<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' "
        tag2 += "           codebase='http://www.apple.com/qtactivex/qtplugin.cab'"
        tag2 += "           width='259' height='200'"
        tag2 += "           id='sponser2'"
        tag2 += "           onmouseover='unmute(document.sponser2, 500);return false'"
        tag2 += "           onMouseOut='mute(document.sponser2);return false'>"
        tag2 += "           <param name='src' value='http://pdl.stream.aol.com/netscape/us/video/2007/01/Netscape-Ford_Super_Duty_Super_Bowl_commercial_clip_No_2_dl.mov' />"
        tag2 += "           <param name='controller' value='false'/>"
        tag2 += "           <param name='autoplay' value='true' />"
        tag2 += "           <param name='loop' value='true' />"
        tag2 += "           <param name='href' value='http://automobiles.honda.com/' />"
        tag2 += "           <param name='volume' value='0' />"
        tag2 += "           <param name='enablejavascript' value='true'/>"
        tag2 += "           <param name='scale' value='ToFit' />"
        tag2 += "           <embed src='http://pdl.stream.aol.com/netscape/us/video/2007/01/Netscape-Ford_Super_Duty_Super_Bowl_commercial_clip_No_2_dl.mov'"
        tag2 += "                  width='259'"
        tag2 += "                  height='200'"
        tag2 += "                  controller='false'"
        tag2 += "                  autoplay='true'"
        tag2 += "                  loop='true'"
        tag2 += "                  volume='0'"
        tag2 += "                  href='http://automobiles.honda.com/'"
        tag2 += "                  enablejavascript='true'"
        tag2 += "                  scale='ToFit'"
        tag2 += "                  name='sponser2'"
        tag2 += "                  onmouseover='mute(document.sponser2);return false'"
        tag2 += "                  onMouseOut='unmute(document.sponser2, 100);return false'/>"
        tag2 += "</object>"
        tag2 += "<div class='caption'>"
        tag2 += "Ford Trucks"
        tag2 += "</div>"
        
        document.write(tag2)
    
    document.write("<div class='sponsers'>")
    
    window.onblur = function()
    {
        //alert("Me Me Me")
        document.sponser1.Stop()
        document.sponser2.Stop()
        //alert("Stopped Movies")
    }
}
