$(document).ready(function() {
	//bildspel
    //<div id="welcomeImageRotate" class=".welcomeImageRotate" iName="ita-pict" iType="jpg" rotateTime="4000" transitionTime="1500"></div>
    var imgRotate = $(".welcomeImageRotate");
    if (imgRotate.length > 0) {
        imageLoad("#" + imgRotate.attr('id'), imgRotate.attr('iName'), imgRotate.attr('iType'), imgRotate.attr('rotateTime'), imgRotate.attr('transitionTime'), true);
    }
});
var imgList = new Array();
var imgIndex = 0;
function rotateImages(id) {
    var oldImgIndex = imgIndex;
    imgIndex++;
    if (imgIndex >= imgList.length) {
        imgIndex = 0;
    }
    imgList[oldImgIndex].animate({ opacity: 'toggle' }, parseInt(imgList[oldImgIndex].attr("tTime")));
    imgList[imgIndex].animate({ opacity: 'toggle' }, parseInt(imgList[imgIndex].attr("tTime")));
    setTimeout(function() { rotateImages(id) }, parseInt(imgList[imgIndex].attr("rTime")));
}
function imageLoaded(id, img) {
    imgList[imgList.length] = img
    $(id).append(img);
    if (1 == imgList.length) {
        imgList[0].show();
        $(id).css("width", img.outerWidth() + "px");
        $(id).css("height", img.outerHeight() + "px");
    }
    else {
        img.hide();
    }
}
function imageLoad(id, name, ext, rTime, tTime, run) {
    var img = $("<img />");
    img.attr("src", "/shop/assets/shop_images/" + name + imgList.length + "." + ext + "?r=" + Math.random() * 99999);
    img.attr("rTime", rTime);
    img.attr("tTime", tTime);
    img.load(function() {
        imageLoaded(id, $(this));
        if (run) {
            setTimeout(function() { rotateImages(id) }, rTime / 2);
        }
        imageLoad(id, name, ext, rTime, tTime, false);
    });
    img.error(function() {
        //setTimeout(rotateImages,rTime);
    });
}
