﻿var imagematrix = new Array();
var imagealt = new Array();
var imageurl = new Array();
var cururl = new Array();

var imagesetsel = 0;
var imagedir = "images/products_images/";
var maxset = 0;

var currdisplayimage = '';

function ChangeNextProductView() {

    if (document.getElementById('nextproductview').value != '') {

        if (currdisplayimage == '') {
            currdisplayimage = document.images.displayproductimage.src;
            document.images.displayproductimage.src = document.getElementById('nextproductview').value;
        }
        else {
            document.images.displayproductimage.src = currdisplayimage;
            currdisplayimage = '';
        }

    }
}

function forwardslide() {
    ++imagesetsel;
    if (imagesetsel > maxset) imagesetsel = 0;
    document.images.image01.src = imagedir + imagematrix[imagesetsel * 3];
    document.images.image02.src = imagedir + imagematrix[imagesetsel * 3 + 1];
    document.images.image03.src = imagedir + imagematrix[imagesetsel * 3 + 2];

    document.images.image01.alt = imagealt[imagesetsel * 3];
    document.images.image02.alt = imagealt[imagesetsel * 3 + 1];
    document.images.image03.alt = imagealt[imagesetsel * 3 + 2];

    document.images.image01.title = imagealt[imagesetsel * 3];
    document.images.image02.title = imagealt[imagesetsel * 3 + 1];
    document.images.image03.title = imagealt[imagesetsel * 3 + 2];

    cururl[0] = imageurl[imagesetsel * 3];
    cururl[1] = imageurl[imagesetsel * 3 + 1];
    cururl[2] = imageurl[imagesetsel * 3 + 2];

    document.getElementById('SelectedProd0').getAttribute('value', cururl[0]);
    document.getElementById('SelectedProd1').value = cururl[1];
    document.getElementById('SelectedProd2').value = cururl[2];
    document.getElementById('ProductPageNo').value = imagesetsel;

}

function previousslide() {
    --imagesetsel;
    if (imagesetsel < 0) imagesetsel = maxset;
    document.images.image01.src = imagedir + imagematrix[imagesetsel * 3];
    document.images.image02.src = imagedir + imagematrix[imagesetsel * 3 + 1];
    document.images.image03.src = imagedir + imagematrix[imagesetsel * 3 + 2];

    document.images.image01.alt = imagealt[imagesetsel * 3];
    document.images.image02.alt = imagealt[imagesetsel * 3 + 1];
    document.images.image03.alt = imagealt[imagesetsel * 3 + 2];

    document.images.image01.title = imagealt[imagesetsel * 3];
    document.images.image02.title = imagealt[imagesetsel * 3 + 1];
    document.images.image03.title = imagealt[imagesetsel * 3 + 2];

    cururl[0] = imageurl[imagesetsel * 3];
    cururl[1] = imageurl[imagesetsel * 3 + 1];
    cururl[2] = imageurl[imagesetsel * 3 + 2];

    document.getElementById('SelectedProd0').setAttribute('value',cururl[0]);
    document.getElementById('SelectedProd1').value = cururl[1];
    document.getElementById('SelectedProd2').value = cururl[2];
    document.getElementById('ProductPageNo').value = imagesetsel;

}

function changestylebig(iImageNo) {

    switch (iImageNo) {
        case 1:
            document.images.image01.height = "150";
            document.images.image01.width = "150";
            break;
        case 2:
            document.images.image02.height = "150";
            document.images.image02.width = "150";
            break;

        case 3:
            document.images.image03.height = "150";
            document.images.image03.width = "150";
            break;

        default:
            break;
    }

}

function changestylenormal(iImageNo) {
    switch (iImageNo) {
        case 1:
            document.images.image01.height = "100";
            document.images.image01.width = "100";
            break;
        case 2:
            document.images.image02.height = "100";
            document.images.image02.width = "100";
            break;

        case 3:
            document.images.image03.height = "100";
            document.images.image03.width = "100";
            break;

        default:
            break;
    }
}

function displayproduct(iImageNo) {

    document.getElementById('SelectedProdNo').setAttribute('value',cururl[iImageNo]);
    //alert(document.getElementById('SelectedProdNo').value);
    //document.aspnetForm.action = "displayproduct.aspx";
    if (cururl[iImageNo] != 'blank') {
        document.aspnetForm.submit();
    }


}

function changeImages() {
    if (document.getElementById('pageid').value != changeImages.arguments[0]) {

        if (document.images && (preloadFlag == true)) {
            for (var i = 0; i < changeImages.arguments.length; i += 2) {
                document[changeImages.arguments[i]].src = changeImages.arguments[i + 1];
            }
        }
    }
}

function setImageSrc() {
    var imgs = document.images;
    document[setImageSrc.arguments[0]].src = setImageSrc.arguments[1];

} 

// initialisation for index page

function defaultfeaturedproducts() {

    allproducts();

    imagesetsel = document.getElementById('ProductPageNo').value;
   
    --imagesetsel;
   
    forwardslide();
    
    //document.images.image01.src = imagedir + imagematrix[0];
    //document.images.image02.src = imagedir + imagematrix[1];
    //document.images.image03.src = imagedir + imagematrix[2];

    //document.images.image01.alt = imagealt[0];
    //document.images.image02.alt = imagealt[1];
    //document.images.image03.alt = imagealt[2];
    
   // cururl[0] = imageurl[0];
    //cururl[1] = imageurl[1];
    //cururl[2] = imageurl[2];

    //document.getElementById('SelectedProd0').value = cururl[0];
    //document.getElementById('SelectedProd1').value = cururl[1];
    //document.getElementById('SelectedProd2').value = cururl[2];
   


}

function xallproducts() {
    
    imagematrix[0] = '01.gif';
    imagematrix[1] = '02.gif';
    imagematrix[2] = '03.gif';
    imagematrix[3] = '04.gif';
    imagematrix[4] = '05.gif';
    imagematrix[5] = '06.gif';

    imagealt[0] = 'Sanremo Amalfi';
    imagealt[1] = 'Sanremo Capri';
    imagealt[2] = 'Sanremo Milano';
    imagealt[3] = 'Sanremo Milano LX';
    imagealt[4] = 'Sanremo Verona Tall';
    imagealt[5] = 'Sanremo Verona TCS';

    imageurl[0] = '01';
    imageurl[1] = '02';
    imageurl[2] = '03';
    imageurl[3] = '04';
    imageurl[4] = '05';
    imageurl[5] = '06';

    maxset = imagematrix.length / 3 - 1;

}

function allproducts() {

    imagealt = new Array();
    imagematrix = new Array();
    imageurl = new Array();
    
    var allPartList = document.getElementById("partlist").value;
    imageurl = allPartList.split('|');

    var allPartNameList = document.getElementById("partnamelist").value;
    imagealt = allPartNameList.split('|');

    for (i = 0; i < imageurl.length; i++) {
        imagematrix[i] = imageurl[i] + '.png';
    }

    var reminder = imagematrix.length % 3;
    if (reminder > 0 ) {
        for (i = 0; i < (3 - reminder ) ; i++) {
            imagealt[imagematrix.length] = '';
            imageurl[imagematrix.length] = 'blank';
            imagematrix[imagematrix.length] = 'blank.png';
        }
    }
    
    maxset = imagematrix.length / 3 - 1;

}

function initmain() {

   
    
    defaultfeaturedproducts();

    // setImageSrc('btnHome', 'images/btnhome_over.jpg');
    
    var MyElement = document.getElementById("maincontainer");
    if (MyElement.style.backgroundImage) {
        document.getElementById("maincontainer").style.backgroundImage = 'url(images/mainpagecontainer.jpg)';

    }
}

function initproduct() {

    defaultfeaturedproducts();
            
}

