﻿function loadCarouselItems(e, iCat) {
    // reset the tab images
    jQuery('#templateTabs img').each(function() {
        jQuery(this).attr('src', jQuery(this).attr('offsrc'));
        jQuery(this).attr('clickstate', 'inactive');
    });
    jQuery(e).attr('clickstate', 'active');
    jQuery(e).attr('src', jQuery(e).attr('onsrc'));
    jQuery(e).attr('osrc', jQuery(e).attr('onsrc'));

    jQuery.ajax({
        type: 'POST',
        url: '/resources/DesignDIYWS.asmx/GetCategoryTemplates',
        data: 'sCatID=' + iCat,
        contentType: 'application/x-www-form-urlencoded',
        dataType: 'xml',
        success: function(msg) {
            // Do something interesting here.
            parseCarouselItems(msg);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert('There was an error loading your selection.');
        }
    });
}


function parseCarouselItems(msg) {
    if (oCarousel != undefined) {
        oCarousel.reset();
        var iSize = parseInt(jQuery(msg).find('total').text());
        oCarousel.size(iSize);
        jQuery('image', jQuery(msg)).each(function(i) {
            var sItem = getCarouselItem(jQuery(this));
            oCarousel.add(i, sItem);
            //getCarouselItem(jQuery(this))
        });
        oCarousel.reload();
    }
}

function getCarouselItem(node) {
    var sImg = node.attr('src');
    var sDesc = node.attr('desc');
    var sTitle = node.attr('name');
    var sID = node.attr('id');
    var sURL = node.attr('url');
    return '<div><a href="' + sURL + '"><img src="' + sImg + '" alt="' + sDesc + '" /></a></div><div><a href="' + sURL + '">' + sTitle + '</a></div>';
}
