var videoPanel;
var videos = new Array(new Array("dacIntro","Introduction Video"), new Array("payrollCard","Payroll Card Video"), new Array("moneyDesktop","Money Desktop Video"), new Array("dac8Pillars", "Financial Education Video"));
var currentVideo = -1;

function autoTab(value, length, next) {
    if (value.length == length) {
        document.getElementById(next).focus();
    }
}

function init() {
    loadPanels();
    goToVideo("next");
}

//rewrite this to handle displaying videos in panel
function goToVideo(direction) {
    //keep video in allowable range
    if (direction == "next") {
        currentVideo++;
        if (currentVideo > (videos.length - 1)) {
            currentVideo = 0;
        }
    }
    else {
        currentVideo--;
        if (currentVideo < 0) {
            currentVideo = (videos.length - 1);
        }
    }
	//setup video title
	document.getElementById("homePageVideoTitle").innerHTML = videos[currentVideo][1];
    //setup screenshot div
    var videoDiv = document.getElementById("homePageVideo");
    videoDiv.innerHTML = "<a href=\"javascript:showVideo(" + currentVideo + ")\"><img src=\"/images/videoThumbs/" + videos[currentVideo][0] + "Screenshot.jpg\"/></a>";
    document.getElementById("videoIndex").innerHTML = (currentVideo + 1) + " of " + videos.length;
    //setup thumbnails	
    var thumbDiv = document.getElementById("thumbnailStrip");
    var markup = "";
    if (currentVideo == 0) {
        markup += "<a href=\"javascript:showVideo(" + currentVideo + ")\"><img src=\"/images/videoThumbs/" + videos[0][0] + ".jpg\"  class=\"thumbNailSelected\"/></a>";
        markup += "<a href=\"javascript:showVideo(" + (currentVideo + 1) + ")\"><img src=\"/images/videoThumbs/" + videos[1][0] + ".jpg\"  class=\"thumbNail\"/></a>";
        markup += "<a href=\"javascript:showVideo(" + (currentVideo + 2) + ")\"><img src=\"/images/videoThumbs/" + videos[2][0] + ".jpg\"  class=\"thumbNail\"/></a>";
        document.getElementById("previousVideoLink").style.display = "none";
        document.getElementById("nextVideoLink").style.display = "";
    }
    else if (currentVideo == (videos.length - 1)) {
        markup += "<a href=\"javascript:showVideo(" + (currentVideo - 2) + ")\"><img src=\"/images/videoThumbs/" + videos[currentVideo - 2][0] + ".jpg\"  class=\"thumbNail\"/></a>";
        markup += "<a href=\"javascript:showVideo(" + (currentVideo - 1) + ")\"><img src=\"/images/videoThumbs/" + videos[currentVideo - 1][0] + ".jpg\"  class=\"thumbNail\"/></a>";
        markup += "<a href=\"javascript:showVideo(" + currentVideo + ")\"><img src=\"/images/videoThumbs/" + videos[currentVideo][0] + ".jpg\"  class=\"thumbNailSelected\"/></a>";
        document.getElementById("previousVideoLink").style.display = "";
        document.getElementById("nextVideoLink").style.display = "none";
    }
    else {
        markup += "<a href=\"javascript:showVideo(" + (currentVideo - 1) + ")\"><img src=\"/images/videoThumbs/" + videos[currentVideo - 1][0] + ".jpg\"  class=\"thumbNail\"/></a>";
        markup += "<a href=\"javascript:showVideo(" + currentVideo + ")\"><img src=\"/images/videoThumbs/" + videos[currentVideo][0] + ".jpg\"  class=\"thumbNailSelected\"/></a>";
        markup += "<a href=\"javascript:showVideo(" + (currentVideo + 1) + ")\"><img src=\"/images/videoThumbs/" + videos[currentVideo + 1][0] + ".jpg\"  class=\"thumbNail\"/></a>";
        document.getElementById("previousVideoLink").style.display = "";
        document.getElementById("nextVideoLink").style.display = "";
    }
    thumbDiv.innerHTML = markup;
}

function loadPanels() {
    videoPanel = new YAHOO.widget.Panel("videoPanel", {
        width: "800px",
        height: "410px",
        visible: false,
        constraintoviewport: true,
        fixedcenter: true,
        draggable: false,
        close: true,
        modal: true
    });
    videoPanel.hideEvent.subscribe(function() {
        document.getElementById("panelVideoDiv").innerHTML = "";
    });
    videoPanel.render();
}

function selectInfoItem(item) {
    var id = item.id;
    for (var i = 0; i < 7; i++) {
        if (id != "info" + i) {
            document.getElementById("info" + i).className = "notSelected";
            document.getElementById("info" + i + "Text").style.display = "none";
        }
    }
    item.className = "selected";
    document.getElementById(id + "Text").style.display = "";
}

function setupThumbs(elementId) {

}

function showFaq(faqItem) {
    var id = faqItem.id;
    var count = 0;
    var tags = document.getElementsByTagName("strong");
    for (var i = 0; i < tags.length; i++) {
        var tagName = tags[i].getAttribute("name");
        if (tagName == "faqHeader") {
            count++
        }
    }
    for (var i = 0; i < count; i++) {
        if (document.getElementById("faq" + i + "Content") != null) {
            document.getElementById("faq" + i + "Content").style.display = "none";
        }
    }
    document.getElementById(id + "Content").style.display = "";
}

function showVideo(index) {
    var videoDiv = document.getElementById("panelVideoDiv");
    videoDiv.innerHTML = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0\" width=\"640\" height=\"360\" id=\"panelVideo\" align=\"middle\">" +
    "<param name=\"allowScriptAccess\" value=\"sameDomain\" />" +
    "<param name=\"allowFullScreen\" value=\"false\" />" +
    "<param name=\"movie\" value=\"video/" +
    videos[index][0] +
    ".swf\" />" +
    "<param name=\"quality\" value=\"high\" />" +
    "<param name=\"bgcolor\" value=\"#e4eff5\" />" +
    "<param name=\"wmode\" value=\"opaque\">" +
    "<embed src=\"/video/" +
    videos[index][0] +
    ".swf\" wmode=\"opaque\" quality=\"high\" bgcolor=\"#e4eff5\" width=\"640\" height=\"360\" name=\"panelVideo\" align=\"middle\" allowScriptAccess=\"sameDomain\" allowFullScreen=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer\" />" +
    "</object>";
    videoPanel.show();
}
