
document.write('<style type="text/css"> ');
document.write(' ');
document.write('#flash {width: 465px; margin: 0; clear: both; padding-top: 8px;}');
document.write('</style>');

var gVideoCount = 1;

document.write('<div class="video-module">');
document.write('<div class="clear"><div class="label-module" style="float:left">VIDEO&nbsp;</div>');
document.write('<div style="float:right;padding-right:5px">');
document.write('<a href="##" onclick="GetPreviousSet(); return false;" ><img id="GetPrevious" src="http://assets.imediaconnection.com/images/graphics/bt-back.gif" border="0" style="margin-right:6px" alt="previous" title="previous" /></a> <img id="videoimgdot1" /> <img id="videoimgdot2" /> <img id="videoimgdot3" /> <a href="##" onclick="GetNextSet(); return false;"><img src="http://assets.imediaconnection.com/images/graphics/bt-forward.gif" id="GetNext" border="0" alt="next" title="next"/></a></div></div>');	

for (i = 1; i <= gVideoCount; i++)
{
    document.write('<div class="video-icon-active" id="video' + i + '">');
    document.write('<a href="##" onmouseover="showactive(' + i + ');" onclick="showvideo(' + i + ');">');
    document.write('<img id="image' + i + '" style="margin-right:0" border="0" alt="Video title" title="Video title"/></a></div>');
}

// document.write('<br class="clear"/>');		
document.write('<div style="font-size:11px;">');
document.write('<div class="video-module-title">');
document.write('<a href="##" onclick="ShowCurrentVideo();" id="videotitle"></a></div>');
document.write('<div id="videoteaser" style="color:#000"></div>');
// document.write('<div id="ispotlogo" style="height:11px; margin-top:10px;"></div>');
document.write('</div>');
document.write('</div>');



    

    var curVideoID;
    var xmlHttpvideo = false;
    var curSet = 1; //first set of videos
    var showSets = 3; 
    var lastSet = gVideoCount;    //
    var videolist = new Array(gVideoCount);
    var videotype = new Array(gVideoCount);
    var curvideo = 0;
    
    if (videofile.NewDataSet.VideoFile.length / gVideoCount > showSets)    
        videofile.NewDataSet.VideoFile.splice(showSets * gVideoCount, videofile.NewDataSet.VideoFile.length);
    
    for (i = 0; i < gVideoCount; i++)    
        videotype[i] = 2;
    
    LoadFirstSet();
    function LoadFirstSet()
    {
        var jsonxmlHttp = false;
        var jsonvideo="";

        lastSet = videofile.NewDataSet.VideoFile.length / gVideoCount;
        
        for (i = 1; i <= gVideoCount; i++)
        {   
            if (i - 1 < videofile.NewDataSet.VideoFile.length)
            {
                document.getElementById("image" + i).src = "http://www.imediaconnection.com/spot/images/" + videofile.NewDataSet.VideoFile[i - 1].ThumbnailFile;
                videolist[i - 1] = videofile.NewDataSet.VideoFile[i - 1].VideoFile_ID;
                videotype[i - 1] = videofile.NewDataSet.VideoFile[i - 1].VideoType;
            }
        }
       
       getVideo(videolist[0], videotype[0]);       
       showactive(1);
    }
    
    function clearnSelect()
    {
        for (i = 1; i <= gVideoCount; i++)
        {
             document.getElementById ("video" + i).className = "video-icon-active";             
        }
    }
        
    function showactive(seq)
    {
        var dot;
        document.getElementById ("video" + seq).className ="video-icon-active";
        getVideo(videolist[seq-1], videotype[seq-1])
        
        for(i = 1; i <= gVideoCount; i++)
        {
            if (i != seq)
                document.getElementById ("video" + i).className ="video-icon-active";            
        }
        
        if (videotype[seq-1] == 2)
            document.getElementById("ispotlogo").innerHTML="<img alt='iMedia Spot' src='http://assets.imediaconnection.com/images/graphics/logo_imediaspot_sm.gif' title='iMedia Spot'/><span style='color:#999;margin-left:4px;font-size:9px;'>(this is a paid video)</span>"
        else
            // document.getElementById("ispotlogo").innerHTML=" ";
        
        curvideo = seq - 1;
        
        for (i = 1; i <= showSets; i++)
        {   
            dot = document.getElementById("videoimgdot" + i);
            if (dot)
            {
                if (i == curSet)
                    dot.src = "http://assets.imediaconnection.com/images/graphics/dot_red_video_active.gif";
                else
                    dot.src = "http://assets.imediaconnection.com/images/graphics/dot_red_video.gif";
            }
        }
    }
    
    function showvideo(seq)
    {   
        var type = videotype[seq-1];
        var id = videolist[seq-1];
        window.location = "http://www.imediaconnection.com/videoredirect.aspx?VideoID=" + id + "&type=" + type;
    }
    
    function ShowCurrentVideo()
    {   
        var type = videotype[curvideo];
        var id = videolist[curvideo];
      
        window.location = "http://www.imediaconnection.com/videoredirect.aspx?VideoID=" + id + "&type=" + type;
    }
    
    function GetNextSet()
    {
        var startseq = 0;
        
        startseq = 1 + curSet * gVideoCount;
            
        curSet = curSet + 1;
        var videoid;
        
        clearnSelect();
        
        document.getElementById("GetPrevious").src="http://assets.imediaconnection.com/images/graphics/bt-back.gif";
       
        if (curSet > lastSet)
        {   
            curSet = lastSet 
            return;
        }   
        if (curSet == lastSet)
        {    
            document.getElementById("GetNext").src="http://assets.imediaconnection.com/images/graphics/bt-forward.gif";
        }
        else
            document.getElementById("GetNext").src="http://assets.imediaconnection.com/images/graphics/bt-forward.gif";
    
           //lastSet = videofile.NewDataSet.VideoFile.length/3;
            
        for (j = 1; j <= gVideoCount; j++)
        {
            document.getElementById("image" + j).src = "http://www.imediaconnection.com/spot/images/" 
                + videofile.NewDataSet.VideoFile[startseq + j - 2].ThumbnailFile;
            videolist[j - 1] = videofile.NewDataSet.VideoFile[startseq + j - 2].VideoFile_ID;
            videotype[j - 1] = videofile.NewDataSet.VideoFile[startseq + j - 2].VideoType;            
        }
        
        getVideo(videolist[0], videotype[0]);        
        showactive(1);
    }
    
    function GetPreviousSet()
    {
        var startseq = 1;
        clearnSelect();
        var videoid;
        if (curSet == 1)
            return;
        
        if (curSet != 1)
        {
            startseq = (curSet-1)*gVideoCount - gVideoCount;
            curSet = curSet - 1;
        }
        if (curSet == 1)
            document.getElementById("GetPrevious").src="http://assets.imediaconnection.com/images/graphics/bt-back.gif";
        else
            document.getElementById("GetPrevious").src = "http://assets.imediaconnection.com/images/graphics/bt-back.gif";
    
        document.getElementById("GetNext").src="http://assets.imediaconnection.com/images/graphics/bt-forward.gif";
         
        for (j = 1; j <= gVideoCount; j++)
        {
             document.getElementById("image" + j).src = "http://www.imediaconnection.com/spot/images/" 
                + videofile.NewDataSet.VideoFile[startseq + j - 1].ThumbnailFile;
             videolist[j - 1] = videofile.NewDataSet.VideoFile[startseq + j - 1].VideoFile_ID;
             videotype[j - 1] = videofile.NewDataSet.VideoFile[startseq + j - 1].VideoType;
        }
                    
        getVideo(videolist[0], videotype[0]);
        showactive(1);
       
    }
    
    function getVideo(videoID, videoType) { 
        try{
                xmlHttpvideo = new XMLHttpRequest();
           }
           catch(trymicrosoft){
                try{
                    xmlHttpvideo = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(othermicrosoft){
                    try{
                        xmlHttpvideo = new ActiveXObject("Microsoft.XMLHTTP");
                    }
                    catch(failed){
                        xmlHttpvideo = false;
                    }
                }
           }
           
           if(!xmlHttpvideo) {
              alert('Browser does not support HTTP Request')
              return      
           }   
           var url="/spot/GetVideoDetail.aspx"
           url=url+"?videoID=" + videoID + "&typeID="+ videoType
           
           xmlHttpvideo.onreadystatechange=statesChanged 
           xmlHttpvideo.open("GET",url,true)
           xmlHttpvideo.send(null)
    }

    function handleOut()
    {
        //document.getElementById ("videoteaser").innerHTML = "";
    }
	
    function WatchVideo ()
    {
        
    }

    function ShowDetail (videoID, typeID)
    {
      
    }
    
    function statesChanged() { 
        
        if (xmlHttpvideo.readyState==4 || xmlHttpvideo.readyState=="complete") { 
                        
            var videoinfo = xmlHttpvideo.responseText;
            var pos = videoinfo.indexOf("@");
            // var title = "";
            var title = videoinfo.substring(0, pos);
			var teaser = videoinfo.substring(pos+1); 
            if (teaser.length > 130)
            { 
               
                teaser = teaser.substring(0, 130);
                teaser = teaser.substring(0, teaser.lastIndexOf(" "));
                teaser = teaser +  "..."; 
            }     
            document.getElementById("videoteaser").innerHTML = trimAll(teaser);
            document.getElementById("videotitle").innerHTML = "<strong>" + trimAll(title) +"</strong>";
        }   
    }
    
    function trimAll(sString) 
    {
        while (sString.substring(0,1) == ' ')
        {
        sString = sString.substring(1, sString.length);
        }
        while (sString.substring(sString.length-1, sString.length) == ' ')
        {
        sString = sString.substring(0,sString.length-1);
        }
        return sString;
    }    


