/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[15,15]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 200;    // maximum image size.

if (document.getElementById || document.all){
document.write('<div id="trailimageid" style="position:absolute;visibility:hidden;left:200px;top:200px;z-index:110">');document.write('</div>');
}

function gettrailobj(){
if (document.getElementById && document.getElementById("trailimageid"))
return document.getElementById("trailimageid").style
else if (document.all)
return document.all.trailimagid.style
}

function gettrailobjnostyle(){
if (document.getElementById && document.getElementById("trailimageid"))
return document.getElementById("trailimageid")
else if (document.all)
return document.all.trailimagid
}

function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showtrail(imagename,type,client,campaign,width,height,format,length){
    if(type == 'video') {
        if(width <= 0) {
            width = 250;
        }
        if(height > 0) {
            var factor = width / 260;
            if(factor != 0) {
                var new_height = height / factor;
                if(new_height > 100) {
                    height = new_height;
                }
                else {
                    height = 100;
                }
            }
            else {
                width = 260;
                height = 100;
            }
        }
        else {
            height = 100;
        }
        width = 260;
    }

    if (height > 0){
        currentimageheight = height;
    }


    document.onmousemove=followmouse;

    var newHTML =  '<table border="1" width="250" cellpadding="4" cellspacing="0" bgcolor="#EEEEEE">';
  newHTML = newHTML + '<tr><td width="100%" valign="top">';
      newHTML = newHTML + '<table class="thin" width="250">';
        newHTML = newHTML + '<tr><td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">';
              newHTML = newHTML + '<tr><td width="100%"><p align="center">';

                if(type=='photo') {
                newHTML = newHTML + '<div align="center" style="padding: 0px 0px 0px 0px;"><img src="' + imagename + '" border="0"></div>';
                newHTML = newHTML + '</td></tr><tr><td width="100%" bgcolor="#000000">';
                  newHTML = newHTML + '<table border="1" width="100%" cellpadding="2"><tr>';
                      newHTML = newHTML + '<td width="100%"><font face="Arial" size="1">'+client+'</font>';
                      newHTML = newHTML + '<br><font face="Arial" size="1">' +campaign+ '</font>';
                       newHTML = newHTML + '<br><font face="Arial" size="1">' +format+ '</font>';
                  newHTML = newHTML + '</table></td></tr>';
            newHTML = newHTML + '</table></td></tr></table></td></tr>';
                
                  }
                  
                if(type=='video') {
                        temp = '<div align="center" style="padding: 0px 0px 0px 0px; background-color: black;">'
                                 +'     <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+width+'" height="'+height+'" id="myplayer" align="middle">'
                                 +'     <param name="allowScriptAccess" value="always" />'
                                 +'     <param name="movie" value="http://publiccontent.s3.amazonaws.com/items/itemMovie/playerOLD.swf" />'
                                 +'     <param name="quality" value="high" />'
                                 +'     <param name="bgcolor" value="#FFFFFF" />'
                                 +'      <param name="FlashVars" value=file='+imagename+'&autostart=true&displayclick=none&repeat=always&controlbar=over"='+imagename+'" />'
                                 +'     <embed FlashVars=file='+imagename+'&autostart=true&displayclick=none&repeat=always&controlbar=over"='+imagename+'" src="http://publiccontent.s3.amazonaws.com/items/itemMovie/playerOLD.swf" LOOP="true" quality="medium" bgcolor="#000000" width="'+width+'" height="'+height+'" name="player" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
                                 +'     </object>'
                                 +'</div>';
                                 
                   /*temp = '<div align="center" style="padding: 0px 0px 0px 0px; background-color: black;">'
                           + fnSwf(imagename,width,height) 
                           + '</div>';*/

                   newHTML += temp;

newHTML = newHTML + '</td></tr><tr><td width="100%" bgcolor="#FFFFFF">';
                  newHTML = newHTML + '<table border="0" width="100%" cellpadding="2"><tr>';
                  newHTML = newHTML + '<td width="100%"><font face="Arial" size="1" color="blue" style="font-weight: bold">'+client+'</font>';
                      newHTML = newHTML + '<br><font face="Arial" size="1">' +campaign+ '</font>';
                       newHTML = newHTML + '<br><font face="Arial" size="1">' +format+ '</font>';
                        newHTML = newHTML + '<br><font face="Arial" size="1" color="gray">' +length+ '</font>';
                  newHTML = newHTML + '</table></td></tr>';
            newHTML = newHTML + '</table></td></tr></table></td></tr>';
              }

                if(type=='audio') {
                        temp = '<div align="center" style="padding: 0px 0px 0px 0px; background-color: white;">'
                                 +'     <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="0" height="0" id="myplayer" align="middle">'
                                 +'     <param name="allowScriptAccess" value="sameDomain" />'
                                 +'     <param name="movie" value="mediaplayer.swf" />'
                                 +'     <param name="quality" value="high" />'
                                 +'     <param name="bgcolor" value="#000000" />'
                                 +' <param name="FlashVars" value="file='+imagename+'" /> '
                                 +'     <embed FlashVars="file='+imagename+'" src="mediaplayer.swf" quality="high" bgcolor="#000000" width="0" height="0" name="myplayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
                                 +'     </object>'
                                 +'</div>';

                   newHTML += temp;

    newHTML = newHTML + '</td></tr><tr><td width="100%" bgcolor="#FFFFFF">';
                  newHTML = newHTML + '<table border="0" width="100%" cellpadding="2"><tr>';
                      newHTML = newHTML + '<td width="100%"><font face="Arial" size="1">'+client+'</font>';
                      newHTML = newHTML + '<br><font face="Arial" size="1">' +campaign+ '</font></td></tr>';
                  newHTML = newHTML + '</table></td></tr>';
            newHTML = newHTML + '</table></td></tr></table></td></tr>';
  newHTML = newHTML + '<tr><td width="100%" valign="top"><font face="Arial" size="1" color="#FFFFFF"><br></font></td>';
  newHTML = newHTML + '</tr></table>';

                }


        gettrailobjnostyle().innerHTML = newHTML;

        gettrailobj().visibility="visible";

}

function fnSwf(fname,width,height){
    
    var so = new SWFObject("mediaplayer.swf", "mp1", width, height, '7', "#ffffff");
        so.addParam("allowScriptAccess","always");
        so.addParam("allowFullScreen","true");
        so.addParam("wmode", "window");
        so.addParam("scale", "noscale");
        so.addVariable("file", "'"+fname+"'");
        so.addVariable("width", width);
        so.addVariable("height", height);
        so.addVariable("theme", "mediaplayer.swf");
        so.addVariable("repeat", "1");
        so.addVariable("autostart", "1");
        so.addVariable("image", "");
        so.addVariable("volume", "50");
        so.addVariable("scaleonresize", "none");
        so.addVariable("top_caption", " ");
        so.addVariable("bottom_caption", " ");
        so.addVariable("v", getQueryParamValue("v"));
        so.write("trailimageid");  
}

function hidetrail(){
    gettrailobj().visibility="hidden"
    gettrailobjnostyle().innerHTML=""
    document.onmousemove=""
    gettrailobj().left="-500px"

}

function followmouse(e){

    var xcoord=offsetfrommouse[0]
    var ycoord=offsetfrommouse[1]

var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
    var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)
    //if (document.all){
    //    gettrailobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
    //} else {
    //    gettrailobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
    //}

    if (typeof e != "undefined"){
        if (docwidth - e.pageX < 300){
            xcoord = e.pageX - xcoord - 286; // Move to the left side of the cursor
        } else {
            xcoord += e.pageX;
        }
        if (docheight - e.pageY < (currentimageheight + 110)){
            ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
        } else {
            ycoord += e.pageY;
        }

    } else if (typeof window.event != "undefined"){
        if (docwidth - event.clientX < 300){
            xcoord = event.clientX + truebody().scrollLeft - xcoord - 286; // Move to the left side of the cursor
        } else {
            xcoord += truebody().scrollLeft+event.clientX
        }
        if (docheight - event.clientY < (currentimageheight + 110)){
            ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
        } else {
            ycoord += truebody().scrollTop + event.clientY;
        }
    }

    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
    var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

    gettrailobj().left=xcoord+"px"
    gettrailobj().top=ycoord+"px"

}



// call hidetrail once just to init things
// this prevents the first video from showing in the upper left momentarily in IE
//hidetrail();