//template 6 from template 2 functions galery

var t6imageCount = 0; // how many images
var t6Uncover = 1;  // which image to uncover first
var t6uncoverPosition = 240; // first position
var t6uncoverSpeed = 500;   // animation speed
var t6uncoverSpeedIncreaseBy = 55;    // after each uncover image speed shoud increase
var t6moveUncoverTextTo =215;   // first position for text

function template6script() {
    var sectionName = 'section'+ (inSection+1);
    var slideName = 'slide' + (inSlide +1);
    console.log("function template6script(); sectionName=" +sectionName + "; slideName=" +slideName);
    
    var images = doContent[sectionName][slideName]['images']
    //var image4 = doContent[sectionName][slideName]['images']['image4'];
    
    var i = 0;
    for (image in images) {
        i++;   // count images
        console.log("image" +image);
        $('#' + sectionName+slideName).append('<div id="' +sectionName+slideName+'image' + i + '">' +images[image]+'</div>');
    }
    t6imageCount = i;
    
    $('#' + sectionName+slideName).append('<div class="control" id="' +sectionName+slideName+'uncover"></div>');
    $('#' + sectionName + slideName + 'uncover')
        .css({
            "position":"absolute",
            "display":"block",
            "width":"65px",
            "height":"65px",
            "top":"175px",
            "left":"47px",
            "background":" url(img/uncover_down.png) no-repeat 50% 50%",   
            "z-index": "4"
        })
        .bind('click', function(){ t6ShowImages(); });
}

function t6moveUncoverButton(button) {
    console.log('t6uncoverPosition = ' +t6uncoverPosition);
    console.log('t6uncoverSpeedIncreaseBy = ' +t6uncoverSpeedIncreaseBy);
    $(button).animate(
		{'top' : t6uncoverPosition},
		t6uncoverSpeed,
		function() {// Animation complete.
		}
    );
    t6uncoverPosition += t6uncoverSpeedIncreaseBy;
}

function t6UncoverImage(image) {
    $(image)
        .css({
            "position":"absolute",
            "top":"-100px",
            "left":"119px",
            "z-index": "3"
        });
    $(image).animate(
        {'top' : t6moveUncoverTextTo},
        t6uncoverSpeed,
        function() {// Animation complete.
        }
    );
    t6moveUncoverTextTo +=t6uncoverSpeedIncreaseBy;
}


function t6ShowImages() {
    console.log("function template6ShowImage()");
    var sectionName = 'section'+ (inSection+1);
    var slideName = 'slide' + (inSlide+1);
    
    var button = '#' + sectionName + slideName + 'uncover';
    var image = '#' + sectionName+slideName+'image';
    
    if (t6imageCount==t6Uncover) { 
        console.log("Last image is: "+t6Uncover);
        t6uncoverPosition = 1000;
		
        t6uncoverSpeed = 2000; // slow disapiering of buton.
		t6moveUncoverButton(button);
		setTimeout(function() { $(button).remove(); }, 1300);   
    }
    else{
        t6moveUncoverButton(button);        
    }
    var i=1;
    for (i; i<t6imageCount+1; i++) {
        if (t6Uncover == i) {
            console.log("Uncovering image: "+i);
            t6UncoverImage(image+i);
        }
    }
    t6Uncover++;
}