﻿//Set to false if the picture scrolling should stop
var p_doPictureScroll = true;
//Used to page sure that page load only starts the scroling once
//Otherwise the scrolling speeds up after every postback because
//multiple timers are started
var p_doStartScrolling = true;
var p_lastPictureIndex = -1;
var p_maxPictureIndex = 3;

function pageLoad() {
    initPictureGallery();
    if (p_doStartScrolling && p_maxPictureIndex > 0) {
        window.setTimeout(scrollPictures, 3000);
        p_doStartScrolling = false;
    }
}

function onShowProductDetails() {
    $get("divProductPictures").style.display = 'none';
    $get("divProductDetails").style.display = 'block';
}

function onShowProductPictures() {
    $get("divProductPictures").style.display = 'block';
    $get("divProductDetails").style.display = 'none';
}

function onBackToHome(){
    location.href = '/V2/Color/ColorHome.aspx';
}

function showFullSizePicture(pictureURL) {
    $get("imgFullsizePicture").src = pictureURL;
    $get("divFullSizePicture").style.display = 'inline';
    p_doPictureScroll = false;
}

function hidePicture(pictureURL) {
    $get("divFullSizePicture").style.display = 'none';
}

function stopPictureScroll() {
    p_doPictureScroll = false;
}


function scrollPictures() {
    if (p_doPictureScroll && p_maxPictureIndex > 0) {
        var displayIndex;
        
        if (p_lastPictureIndex > 0) {
            displayIndex = p_lastPictureIndex + 1
            if (displayIndex > p_maxPictureIndex) {
                displayIndex = 1
            }
        }
        else {
            displayIndex = 1;
        }
                    
        showPicture(displayIndex, false);
        window.setTimeout(scrollPictures, 5000);
    }
}

function showPicture(pictureIndex, stopScrolling) {
    if (p_lastPictureIndex > 0 ) {
        $get("thumbnail" + p_lastPictureIndex).style.display = 'none';
        $get("link" + p_lastPictureIndex).className = '';
    }   
    $get("thumbnail" + pictureIndex).style.display = 'block';     
    $get("link" + pictureIndex).className = 'selected';
    p_lastPictureIndex = pictureIndex;
    
    if (stopScrolling) {
        p_doPictureScroll = false;
    }
}

