var fbtitle;
var fbplugin;

var fbdownloadProgress = 0;
var dl0Progress = 0;
var dl1Progress = 0;
var dl2Progress = 0;
var dl3Progress = 0;
var dl4Progress = 0;
var dl5Progress = 0;
var dl6Progress = 0;
var dlaProgress = 0;

var dl0Download;
var dl1Download;
var dl2Download;
var dl3Download;
var dl6Download;
var dlaDownload;

var fullProgress = 200;
var dl0Token1, dl0Token2;
var dl1Token1, dl1Token2;
var dl2Token1, dl2Token2;
var dl3Token1, dl3Token2;
var dl4Token1, dl4Token2;
var dl5Token1, dl5Token2;
var dl6Token1, dl6Token2;
var dlaToken1, dlaToken2;


function createfbtitle()
{
  if (Silverlight.isInstalled("1.0")) {
    Silverlight.createObject(
        "fbtitle.xaml",                  // Source property value.
        document.getElementById("flashbackTitle"),                  // DOM reference to hosting DIV tag.
        "flashbackTitle",         // Unique plug-in ID value.
        {                               // Per-instance properties.
            width:'100%',                // Width of rectangular region of 
                                        // plug-in area in pixels.
            height:'135',               // Height of rectangular region of 
                                        // plug-in area in pixels.
            inplaceInstallPrompt:true, // Determines whether to display 
                                        // in-place install prompt if 
                                        // invalid version detected.
            background:'#00D6D6D6',       // Background color of plug-in.
            isWindowless:'true',       // Determines whether to display plug-in 
                                        // in Windowless mode.
            framerate:'24',             // MaxFrameRate property value.
            version:'1.0'               // Silverlight version to use.
        },
        {
            onError:null,               // OnError property value -- 
                                        // event handler function name.
            onLoad:onfbtitleLoaded      // OnLoad property value -- 
                                        // event handler function name.
        },
        null);                          // Context value -- event handler function name.
  } else {
    //silverlight not installed
    document.getElementById("flashbackTitle").innerHTML = '<div class="topLeft0">'+String.fromCharCode(13)+'<div class="topLeft1"><img src="images/?i/f1.png" alt=" " /></div>'+String.fromCharCode(13)+'<div class="topLeft2"><img src="images/?i/f2.png" alt=" " /></div>'+String.fromCharCode(13)+'<div class="topLeft3"><img src="images/?i/f3.png" alt=" " /></div>'+String.fromCharCode(13)+'</div>'+String.fromCharCode(13)+'<div class="topRight0">'+String.fromCharCode(13)+'<div class="topRight1"><img src="images/?i/f4.png" alt=" " /></div>'+String.fromCharCode(13)+'<div class="topRight2"><img src="images/?i/f5.png" alt=" " /></div>'+String.fromCharCode(13)+'<div class="topRight3"><img src="images/?i/f6.png" alt=" " /></div>'+String.fromCharCode(13)+'</div>'+String.fromCharCode(13)+'<div class="logo"><img src="images/?fblogo.jpg" alt="Flashback Entertainment" /><br /></div>';
  }
}

function fbonResized(sender, eventArgs)
{
  fbtitle.findName("progressBarBox")["Canvas.Left"] = (fbplugin.Content.ActualWidth / 2) - 110;
  fbtitle.findName("progressBar")["Canvas.Left"] = (fbplugin.Content.ActualWidth / 2) - 100;
  fbtitle.findName("flashbackLogo")["Canvas.Left"] = (fbplugin.Content.ActualWidth / 2) - 161;
  fbtitle.findName("topLeft0")["Canvas.Left"] = 0 - 50;
  fbtitle.findName("topLeft0Image")["Canvas.Left"] = fbtitle.findName("topLeft0")["Canvas.Left"] + 3;
  fbtitle.findName("topLeft1")["Canvas.Left"] = (((fbplugin.Content.ActualWidth - 20) / 2) / 3) - 40;
  fbtitle.findName("topLeft1Image")["Canvas.Left"] = fbtitle.findName("topLeft1")["Canvas.Left"] + 3;
  fbtitle.findName("topLeft2")["Canvas.Left"] = ((((fbplugin.Content.ActualWidth - 20) / 2) / 3) * 2) - 40;
  fbtitle.findName("topLeft2Image")["Canvas.Left"] = fbtitle.findName("topLeft2")["Canvas.Left"] + 3;
  fbtitle.findName("topRight0")["Canvas.Left"] = fbplugin.Content.ActualWidth - 78
  fbtitle.findName("topRight0Image")["Canvas.Left"] = fbtitle.findName("topRight0")["Canvas.Left"] + 2.5
  fbtitle.findName("topRight1")["Canvas.Left"] = fbplugin.Content.ActualWidth - 50 - (((fbplugin.Content.ActualWidth - 20) / 2) / 3) - 40;
  fbtitle.findName("topRight1Image")["Canvas.Left"] = fbtitle.findName("topRight1")["Canvas.Left"] + 2.5;
  fbtitle.findName("topRight2")["Canvas.Left"] = fbplugin.Content.ActualWidth - 50 - ((((fbplugin.Content.ActualWidth - 20) / 2) / 3) * 2) - 40;
  fbtitle.findName("topRight2Image")["Canvas.Left"] = fbtitle.findName("topRight2")["Canvas.Left"] + 2.5;

}

function fbtitleLoaded(sender, args) {


//  fbtitle.findName("flashbackLogo").Source = "images/?fblogo.jpg";
  fbtitle.findName("flashbackLogo")["Canvas.Left"] = (fbplugin.Content.ActualWidth / 2) - 161;
  fbtitle.findName("flashbackLogo").Visibility = "Visible";

//  fbtitle.findName("topLeft0").Source = "images/?i/new_title_back_trans.png,png";
//  fbtitle.findName("topLeft0Image").Source = "images/?i/f1.png,png";
  fbtitle.findName("topLeft0")["Canvas.Left"] = 0 - 50
  fbtitle.findName("topLeft0Image")["Canvas.Left"] = fbtitle.findName("topLeft0")["Canvas.Left"] + 3
  fbtitle.findName("topLeft0").Visibility = "Visible";
  fbtitle.findName("topLeft0Image").Visibility = "Visible";
  
//  fbtitle.findName("topLeft1").Source = "images/?i/new_title_back_trans.png,png";
//  fbtitle.findName("topLeft1Image").Source = "images/?i/f3.png,png";
  fbtitle.findName("topLeft1")["Canvas.Left"] = (((fbplugin.Content.ActualWidth - 20) / 2) / 3) - 40;
  fbtitle.findName("topLeft1Image")["Canvas.Left"] = fbtitle.findName("topLeft1")["Canvas.Left"] + 3;
  fbtitle.findName("topLeft1").Visibility = "Visible";
  fbtitle.findName("topLeft1Image").Visibility = "Visible";8
  
//  fbtitle.findName("topLeft2").Source = "images/?i/new_title_back_trans.png,png";
//  fbtitle.findName("topLeft2Image").Source = "images/?i/f2.png,png";
  fbtitle.findName("topLeft2")["Canvas.Left"] = ((((fbplugin.Content.ActualWidth - 20) / 2) / 3) * 2) - 40;
  fbtitle.findName("topLeft2Image")["Canvas.Left"] = fbtitle.findName("topLeft2")["Canvas.Left"] + 3;
  fbtitle.findName("topLeft2").Visibility = "Visible";
  fbtitle.findName("topLeft2Image").Visibility = "Visible";

//  fbtitle.findName("topRight0").Source = "images/?i/new_title_back_trans.png,png";
//  fbtitle.findName("topRight0Image").Source = "images/?i/f5.png,png";
  fbtitle.findName("topRight0")["Canvas.Left"] = fbplugin.Content.ActualWidth - 78
  fbtitle.findName("topRight0Image")["Canvas.Left"] = fbtitle.findName("topRight0")["Canvas.Left"] + 3
  fbtitle.findName("topRight0").Visibility = "Visible";
  fbtitle.findName("topRight0Image").Visibility = "Visible";

//  fbtitle.findName("topRight1").Source = "images/?i/new_title_back_trans.png,png";
//  fbtitle.findName("topRight1Image").Source = "images/?i/f6.png,png";
  fbtitle.findName("topRight1")["Canvas.Left"] = fbplugin.Content.ActualWidth - 50 - (((fbplugin.Content.ActualWidth - 20) / 2) / 3) - 40;
  fbtitle.findName("topRight1Image")["Canvas.Left"] = fbtitle.findName("topRight1")["Canvas.Left"] + 3;
  fbtitle.findName("topRight1").Visibility = "Visible";
  fbtitle.findName("topRight1Image").Visibility = "Visible";8

//  fbtitle.findName("topRight2").Source = "images/?i/new_title_back_trans.png,png";
//  fbtitle.findName("topRight2Image").Source = "images/?i/f4.png,png";
  fbtitle.findName("topRight2")["Canvas.Left"] = fbplugin.Content.ActualWidth - 50 - ((((fbplugin.Content.ActualWidth - 20) / 2) / 3) * 2) - 40;
  fbtitle.findName("topRight2Image")["Canvas.Left"] = fbtitle.findName("topRight2")["Canvas.Left"] + 3;
  fbtitle.findName("topRight2").Visibility = "Visible";
  fbtitle.findName("topRight2Image").Visibility = "Visible";

}

function onfbtitleLoaded(plugin, userContext, sender) {

  fbtitle = sender;
  fbplugin = sender.getHost();
  
  fbplugin.content.onResize = fbonResized;
  fbonResized(sender, "");
  
//   download the images
  var dl0Download = fbplugin.createObject('downloader');

  dl0Token1 = dl0Download.addEventListener('downloadProgressChanged', dl0Downloading);
  dl0Token2 = dl0Download.addEventListener('completed', dl0Downloaded);
  dl0Download.open('GET', 'images/?fblogo.jpg');
  dl0Download.send();

  dl1Download = fbplugin.createObject('downloader');

  dl1Token1 = dl1Download.addEventListener('downloadProgressChanged', dl1Downloading);
  dl1Token2 = dl1Download.addEventListener('completed', dl1Downloaded);
  dl1Download.open('GET', 'images/?i/f1.png,png');
  dl1Download.send();

  dl2Download = fbplugin.createObject('downloader');

  dl2Token1 = dl2Download.addEventListener('downloadProgressChanged', dl2Downloading);
  dl2Token2 = dl2Download.addEventListener('completed', dl2Downloaded);
  dl2Download.open('GET', 'images/?i/f2.png,png');
  dl2Download.send();

  dl3Download = fbplugin.createObject('downloader');

  dl3Token1 = dl3Download.addEventListener('downloadProgressChanged', dl3Downloading);
  dl3Token2 = dl3Download.addEventListener('completed', dl3Downloaded);
  dl3Download.open('GET', 'images/?i/f3.png,png');
  dl3Download.send();

  dl4Download = fbplugin.createObject('downloader');

  dl4Token1 = dl4Download.addEventListener('downloadProgressChanged', dl4Downloading);
  dl4Token2 = dl4Download.addEventListener('completed', dl4Downloaded);
  dl4Download.open('GET', 'images/?i/f4.png,png');
  dl4Download.send();

  dl5Download = fbplugin.createObject('downloader');

  dl5Token1 = dl5Download.addEventListener('downloadProgressChanged', dl5Downloading);
  dl5Token2 = dl5Download.addEventListener('completed', dl5Downloaded);
  dl5Download.open('GET', 'images/?i/f5.png,png');
  dl5Download.send();

  dl6Download = fbplugin.createObject('downloader');

  dl6Token1 = dl6Download.addEventListener('downloadProgressChanged', dl6Downloading);
  dl6Token2 = dl6Download.addEventListener('completed', dl6Downloaded);
  dl6Download.open('GET', 'images/?i/f6.png,png');
  dl6Download.send();

  dlaDownload = fbplugin.createObject('downloader');

  dlaToken1 = dlaDownload.addEventListener('downloadProgressChanged', dlaDownloading);
  dlaToken2 = dlaDownload.addEventListener('completed', dlaDownloaded);
  dlaDownload.open('GET', 'images/?i/new_title_back_trans.png,png');
  dlaDownload.send();

}

function dl0Downloading(sender, args) {

  fbtitle.findName("progressBar").Visibility = 'Visible';
  fbtitle.findName("progressBarBox").Visibility = 'Visible';

  dl0Progress = sender.downloadProgress * 100;

  fbtitle.findName("progressBar").Width = ((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 800) * fullProgress;

}

function dl1Downloading(sender, args) {

  fbtitle.findName("progressBar").Visibility = 'Visible';
  fbtitle.findName("progressBarBox").Visibility = 'Visible';

  dl1Progress = sender.downloadProgress * 100;

  fbtitle.findName("progressBar").Width = ((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 800) * fullProgress;

}

function dl2Downloading(sender, args) {

  fbtitle.findName("progressBar").Visibility = 'Visible';
  fbtitle.findName("progressBarBox").Visibility = 'Visible';

  dl2Progress = sender.downloadProgress * 100;

  fbtitle.findName("progressBar").Width = ((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 800) * fullProgress;

}

function dl3Downloading(sender, args) {

  fbtitle.findName("progressBar").Visibility = 'Visible';
  fbtitle.findName("progressBarBox").Visibility = 'Visible';

  dl3Progress = sender.downloadProgress * 100;

  fbtitle.findName("progressBar").Width = ((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 800) * fullProgress;

}

function dl4Downloading(sender, args) {

  fbtitle.findName("progressBar").Visibility = 'Visible';
  fbtitle.findName("progressBarBox").Visibility = 'Visible';

  dl4Progress = sender.downloadProgress * 100;

  fbtitle.findName("progressBar").Width = ((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 800) * fullProgress;

}

function dl5Downloading(sender, args) {

  fbtitle.findName("progressBar").Visibility = 'Visible';
  fbtitle.findName("progressBarBox").Visibility = 'Visible';

  dl5Progress = sender.downloadProgress * 100;

  fbtitle.findName("progressBar").Width = ((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 800) * fullProgress;

}

function dl6Downloading(sender, args) {

  fbtitle.findName("progressBar").Visibility = 'Visible';
  fbtitle.findName("progressBarBox").Visibility = 'Visible';

  dl6Progress = sender.downloadProgress * 100;

  fbtitle.findName("progressBar").Width = ((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 800) * fullProgress;

}

function dlaDownloading(sender, args) {

  fbtitle.findName("progressBar").Visibility = 'Visible';
  fbtitle.findName("progressBarBox").Visibility = 'Visible';

  dlaProgress = sender.downloadProgress * 100;

  fbtitle.findName("progressBar").Width = ((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 800) * fullProgress;

}

function dl0Downloaded(sender, args) {

  dl0Progress = 100;

  sender.removeEventListener('downloadProgressChanged', dl0Token1);
  sender.removeEventListener('completed', dl0Token2);

  fbtitle.findName("flashbackLogo").SetSource(sender, "");

  if (((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 8) == 100) {
    fbtitle.findName("progressBar").Visibility = 'Collapsed';
    fbtitle.findName("progressBarBox").Visibility = 'Collapsed';
    fbtitleLoaded(fbtitle, '');
    }

}

function dl1Downloaded(sender, args) {

  dl1Progress = 100;

  sender.removeEventListener('downloadProgressChanged', dl1Token1);
  sender.removeEventListener('completed', dl1Token2);

  fbtitle.findName("topLeft0Image").SetSource(sender, "");

  if (((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 8) == 100) {
    fbtitle.findName("progressBar").Visibility = 'Collapsed';
    fbtitle.findName("progressBarBox").Visibility = 'Collapsed';
    fbtitleLoaded(fbtitle, '');
    }

}

function dl2Downloaded(sender, args) {

  dl2Progress = 100;

  sender.removeEventListener('downloadProgressChanged', dl2Token1);
  sender.removeEventListener('completed', dl2Token2);

  fbtitle.findName("topLeft2Image").SetSource(sender, "");

  if (((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 8) == 100) {
    fbtitle.findName("progressBar").Visibility = 'Collapsed';
    fbtitle.findName("progressBarBox").Visibility = 'Collapsed';
    fbtitleLoaded(fbtitle, '');
    }

}

function dl3Downloaded(sender, args) {

  dl3Progress = 100;

  sender.removeEventListener('downloadProgressChanged', dl3Token1);
  sender.removeEventListener('completed', dl3Token2);

  fbtitle.findName("topLeft1Image").SetSource(sender, "");

  if (((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 8) == 100) {
    fbtitle.findName("progressBar").Visibility = 'Collapsed';
    fbtitle.findName("progressBarBox").Visibility = 'Collapsed';
    fbtitleLoaded(fbtitle, '');
    }

}

function dl4Downloaded(sender, args) {

  dl4Progress = 100;

  sender.removeEventListener('downloadProgressChanged', dl4Token1);
  sender.removeEventListener('completed', dl4Token2);

  fbtitle.findName("topRight2Image").SetSource(sender, "");

  if (((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 8) == 100) {
    fbtitle.findName("progressBar").Visibility = 'Collapsed';
    fbtitle.findName("progressBarBox").Visibility = 'Collapsed';
    fbtitleLoaded(fbtitle, '');
    }

}

function dl5Downloaded(sender, args) {

  dl5Progress = 100;

  sender.removeEventListener('downloadProgressChanged', dl5Token1);
  sender.removeEventListener('completed', dl5Token2);

  fbtitle.findName("topRight0Image").SetSource(sender, "");

  if (((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 8) == 100) {
    fbtitle.findName("progressBar").Visibility = 'Collapsed';
    fbtitle.findName("progressBarBox").Visibility = 'Collapsed';
    fbtitleLoaded(fbtitle, '');
    }

}

function dl6Downloaded(sender, args) {

  dl6Progress = 100;

  sender.removeEventListener('downloadProgressChanged', dl6Token1);
  sender.removeEventListener('completed', dl6Token2);

  fbtitle.findName("topRight1Image").SetSource(sender, "");

  if (((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 8) == 100) {
    fbtitle.findName("progressBar").Visibility = 'Collapsed';
    fbtitle.findName("progressBarBox").Visibility = 'Collapsed';
    fbtitleLoaded(fbtitle, '');
    }

}

function dlaDownloaded(sender, args) {

  dlaProgress = 100;

  sender.removeEventListener('downloadProgressChanged', dlaToken1);
  sender.removeEventListener('completed', dlaToken2);

  fbtitle.findName("topLeft0").SetSource(sender, "");
  fbtitle.findName("topLeft1").SetSource(sender, "");
  fbtitle.findName("topLeft2").SetSource(sender, "");
  fbtitle.findName("topRight0").SetSource(sender, "");
  fbtitle.findName("topRight1").SetSource(sender, "");
  fbtitle.findName("topRight2").SetSource(sender, "");

  if (((dl0Progress + dl1Progress + dl2Progress + dl3Progress + dl4Progress + dl5Progress + dl6Progress + dlaProgress) / 8) == 100) {
    fbtitle.findName("progressBar").Visibility = 'Collapsed';
    fbtitle.findName("progressBarBox").Visibility = 'Collapsed';
    fbtitleLoaded(fbtitle, '');
    }

}

