﻿var jQueryScriptOutputted = false;
var itemList;

loadCSS("http://legacy.myskin.com/Content/BlogChannel/Blidget/jquery.jcarousel.css");
loadCSS("http://legacy.myskin.com/Content/BlogChannel/Blidget/skinBC.css");


var str = [""];
str.push("<img src='http://legacy.myskin.com/Images/BlogChannel/Blidget/Blidget3.png' alt='' class='header' />");
str.push("<div id='blidget' style='background:url(http://legacy.myskin.com/Images/BlogChannel/Blidget/blidget-background.jpg) no-repeat #fff;width:180px;height:421px;padding:10px;margin-top: -7px;' class='jcarousel-skin-tango'>");
str.push("<ul id='mycarousel' style='height:420px;'></ul>");
str.push("</div>");
document.write(str.join(''));
initJQuery();

function initJQuery() {
    if (typeof (jQuery) == 'undefined') {
        if (!jQueryScriptOutputted) {
            document.write("<script type=\"text/javascript\" src=\"http://legacy.myskin.com/Scripts/jquery-1.3.2.min.js\"></script>");
            jQueryScriptOutputted = true;
        }
        setTimeout("initJQuery()", 500);
    } else {
        jQuery(function() {
            jQuery.getScript("http://legacy.myskin.com/Scripts/jquery.jcarousel.js", function() {
                jQuery.getScript("http://legacy.myskin.com/Scripts/jsclass.js", function() {
                    var obj = new JSONscriptRequest("http://legacy.myskin.com/BlogChannel/BlidgetData");
                    obj.buildScriptTag();
                    obj.addScriptTag();
                });
            });
        });
    }
}

function BD(res) {
    itemList = jQuery(res).children('li');
    jQuery("#mycarousel").jcarousel({
        scroll: 1, wrap: "circular", auto: 5, animation: 500,
        itemVisibleInCallback: { onBeforeAnimation: mycarousel_itemVisibleInCallback },
        initCallback: mycarousel_initCallback,
        itemVisibleOutCallback: { onAfterAnimation: mycarousel_itemVisibleOutCallback }
    });
}

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, itemList.length);
    carousel.add(i, mycarousel_getItemHTML(itemList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
    carousel.remove(i);
};

function mycarousel_getItemHTML(item) {
    return jQuery(item).html();
};

function mycarousel_initCallback(carousel) {
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(10);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(10);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function loadCSS(location) {
    var fileref = document.createElement("link");
    fileref.setAttribute("rel", "stylesheet");
    fileref.setAttribute("type", "text/css");
    fileref.setAttribute("href", location);
    document.getElementsByTagName("head")[0].appendChild(fileref);
}
