//opens window with color preview
var image
function openWin(image){
    window.open(image, "zoom", "resizable=no, scrollbars=no, location=no, menubar=no, height=500, width=750")
}

//rotating banner of patterns on right side

$('document').ready(function(){
    thisAd = 0;
    thisAdNext = 1
    imgCt = adImages.length;
    rotate();
});

function rotate (){
    if(imgCt != 0) {

        if (thisAd == imgCt){
            thisAd = 0
            thisAdNext = 1
        }
        else if(thisAdNext == imgCt){
            thisAdNext = 0
        }
        var url = '/www/product-images/pattern-external/' + adImages[thisAd]['image'];
        $('#image-banner').css('background-image', 'url(' + url + ')');
        $('#image-banner').css('background-repeat', 'no-repeat')
        $('#image-banner').css('background-position', 'center top')
        $('#adBanner').hide();
        $('#adBannerLink').attr('href', adImages[thisAd]['link']);
        $('#adBanner').attr('src', '/www/product-images/pattern-external/' + adImages[thisAdNext]['image']);
        $('#adBanner').fadeIn(1000 , function(){
            thisAd++
            thisAdNext++
            setTimeout('rotate()', 3 * 1000)
        });



    }
}

function populateColourList(element, targetId) {
    var fabricId = $(element).val();
    var options = '<option value="0">--SELECT--</option>';

    $.getJSON(
        '/admin/fabric/'+fabricId+'/get-colours',
        null,
        function(data) {
            $.each(data, function(i,item){
                options += '<option value="' + item.fabric_colour_id + '">' + item.fabric_colour_name + '</option>';
            })
            $('#'+targetId).html(options);
        }
    )
}

