﻿objUtils.addEvent(window, "load", addVideoLink);

function addVideoLink(sender, args) {
    var videoDivs = document.getElementsByTagName("VIN");
    var vin, onclickstr;

    var allDivs = document.getElementsByTagName("div");
    var divid;
    for (var i = 0; i < allDivs.length; i++) {
        divid = allDivs[i].id;
        if (divid.substring(0, 4) != "VIN_") continue;
        // else the DIV corresponds to the VIN
        vin = divid.substring(4);
        //onclickstr = "javascript:window.open('http://www.dealervideos.com/vehicle.aspx?vin=" + vin + "','','width=320, height=240')";
        //document.getElementById("VIN_" + vin).innerHTML = '&nbsp;<div id="uwm_' + vin + '"><a href="javascript:void(0)" onclick="' + onclickstr + '"><img src="/AutoDealer/Images/Video_icon.png" alt="Vehicle Video"></a></div>';
        //

        if (document.getElementById("Details_VIN_" + vin)) {
            onclickstr = "<a href='http://www.dealervideos.com/vehicle.aspx?vin=" + vin + "' class='floatbox' data-fb-options='width:320 height:240'  ><img src='/AutoDealer/Images/Video_icon_big.png' alt='Vehicle Video'></a>";
            document.getElementById("Details_VIN_" + vin).innerHTML = '<div id="uwm_' + vin + '">' + onclickstr + '</div>';
        } else {
            onclickstr = "<a href='http://www.dealervideos.com/vehicle.aspx?vin=" + vin + "' class='floatbox' data-fb-options='width:320 height:240'  ><img src='/AutoDealer/Images/Video_icon_small.png' alt='Vehicle Video'></a>";
            document.getElementById("VIN_" + vin).innerHTML = '<div id="uwm_' + vin + '">' + onclickstr + '</div>';
        }
    }
    jquery_ready(); 
    
}

function jquery_ready() {
    jQuery("body").append("<div id=\"uwmDialog\" ><span id=\"uwmSwfObject\"/></div>");
    var d = jQuery("#uwmDialog");
    d.addClass("uwmDialogClass").dialog({ autoOpen: false, draggable: true, width: 350, height: 295, show: "slow", hide: "puff" });
    if (typeof (uwmInit) != "undefined")
        vinArray = uwmInit();
    var vinArray;
    if (typeof (uwmGetVinArray) != "undefined")
        vinArray = uwmGetVinArray();
    else
        vinArray = uwmDefaultGetVinArray();
    uwmCheckAvailability(vinArray);
}