﻿jQuery(document).ready(function() {

loadPlaylist("CD985CB24CC1C9F9");

    selectTab(1);

});

function selectTab(num) {
    $("#subnav a").removeClass("selected");
    $(".subnav_0" + num).addClass("selected");

    //$("#subcontent").hide();
    $(".content_01").hide();
    $(".content_02").hide();
    $(".content_03").hide();
    $(".content_04").hide();
    $(".content_05").hide();
    $("#content .content_0" + num).show();

    if (num == 1) {
        $("#player").slideDown(800, function() {

            loadVideoInformation("lsYPF1L2Tdk", true);

        });

    } else {
        $('#flashplayer').html('');
        $("#player").slideUp(800);
    }

    if (num == 3) {

       // selectBoard(0);

    }
}

function selectBoard(num) {
    $(".boardnav a").removeClass("selected");
    $(".board_0" + num).addClass("selected");
    $("#ACTIVECAST-LT").html('');
    if (num == 0) {

        LoadActiveCastThreads("computerlaptop", 3);
        LoadActiveCastThreads("software", 3);
        LoadActiveCastThreads("add-ons", 3);
        LoadActiveCastThreads("homeoffice", 3);

    } else if (num == 1) {

        LoadActiveCastThreads("computerlaptop", 12);
    } else if (num == 2) {

        LoadActiveCastThreads("software", 12);
    } else if (num == 3) {

        LoadActiveCastThreads("add-ons", 12);
    } else if (num == 4) {

        LoadActiveCastThreads("homeoffice", 12);
    }
}

function loadVideoInformation(vid, autoplay) {
    var flashvars = { vid: vid, autoplay: autoplay };
    var params = { wmode: "opaque" };
    var attributes = {};
    $.get("/Projects/HowtoVideo/Ajaxrespond.aspx?src=ytVideo&lang=FR&vid=" + vid + "&autoplay=" + autoplay, function(xml) {
        var tempOutput;
        swfobject.embedSWF("/Projects/HowtoVideo/Assets/yt_player_480x400.swf",
                "flashplayer",
                "480", "400",
                "9.0.0", "",
                flashvars, params, attributes);
        $(xml).find("media-category").each(function() {
            var fscName, fscID
            if ($(this).text().substr(0, 3) == "fsc") {
                fscName = $(this).text().substr(3);
                $(".author a").text(fscName);

            } else if ($(this).text().substr(0, 3) == "fid") {
                fscID = $(this).text().substr(3);
                $(".author a").attr("href", "http://www.forumfutureshop.ca/futureshop/profile?user.id=" + fscID);
            }
        });

        $(".views").html("<strong>Visonnements :</strong> " + $(xml).find("yt-statistics:first").attr("viewCount"));

        var tempKeywords = $(xml).find("media-keywords:first").text().replace(/ /g, "").split(",");
        $(".keywords:first").html('<strong>Mots-clés:</strong> ');
        for (i = 0; i < tempKeywords.length; i++) {
            if (tempKeywords[i].substr(0, 3) == "tid") {
            } else if (tempKeywords[i].substr(0, 3) == "cat") {
            } else if (tempKeywords[i].substr(0, 3) == "sku") {
            } else {
                $(".keywords:first").append('<a href="#video_top">' + tempKeywords[i] + '</a> ');
            }
        };
        $(".description").text($(xml).find("media-description:first").text());
        $(".elink input").val("http://www.futureshop.ca/Projects/HowtoVideo/default.aspx?lang=FR&v=" + vid);
        $(".embed input").val("<object width='634' height='414'><param name='movie' value='http://www.futureshop.ca/Projects/HowToVideo/Assets/vplayer_embed.swf?langid=FR&vid=" + vid + "'></param><embed src='http://www.futureshop.ca/Projects/HowToVideo/Assets/vplayer_embed.swf?langid=FR&vid=" + vid + "' type='application/x-shockwave-flash' width='634' height='414'></embed></object>");
        $('div.VideoDetail').hide();
        $(".videotitle:first").text($(xml).find("media-title").text());
    });
}


function loadPlaylist(pid) {
    $.get("/Projects/HowtoVideo/Ajaxrespond.aspx?src=ytPlaylist&lang=EN&pid=" + pid, function(xml) {
    var tempOutput;
    tempOutput = $('<ul class="playlist">');
    $(xml).find("entry").each(function() {
        tempOutput.append(tempList = $('<li class="video">'));
        tempList.append(tempLink = $('<a href="#video_top" onClick="loadVideoInformation(\'' + $(this).find("yt-videoid:first").text() + '\',\'true\')">'));
        tempLink.append('<img src="' + $(this).find("media-thumbnail:first").attr("url") + '" alt="">');
        tempLink.append('<br>');
        tempLink.append($('<span class="title">').html($(this).find("title:first").text()));
        tempList.append($('<span class="views">').html("Visonnements : " + $(this).find("yt-statistics:first").attr("viewCount")));
    });

    tempOutput.append('<span class="clear">');
    $("#playList").html(tempOutput);
        alignHeight();
    });
}

function alignHeight() {
    $("#content #playList .video").height(170);
}

function LoadActiveCastThreads(board, num)
{
        LITHIUM.ActiveCast.getLatestThreads(board, { maxNumberOfMessages: num, numSubjectWords: 150, numBodyWords: 0 });
    
}
