﻿// 
var isTimerOn = false;
var currentDemo = 1;
var demoCount = 10;
var timeOut;
var demoIdPrefix = 'leftreason';

window.onload = initPage;   
     
function initPage() {        
    startTimer();
    startTimer1();
    
    if (!Silverlight.isInstalled("2.0"))
        startTimer2();
}

function startTimer() {        
    if (!isTimerOn) {               
        startDemo();
    }
}

function startDemo() {
    isTimerOn = true;
    var stopTimer = false;
    
    showHideDemo(currentDemo, 'none');
    
    if (currentDemo == demoCount) {
        currentDemo = 1;
        stopTimer = true;
    }
    else
        currentDemo++;
       
    showHideDemo(currentDemo, 'block');
    
    timeOut = setTimeout("startDemo()", 2000);
    
    if(stopTimer) {
        stopDemo();
        setTimeout("jumpDemo(+1)", 2000);
    }
}

function jumpDemo(jump) {
    if (jump > 0) {
        startDemo();
        stopDemo();
    }
    else {
        stopDemo();
        showHideDemo(currentDemo, 'none');
        currentDemo = currentDemo - 2;

        if (currentDemo == 0)
            currentDemo = demoCount;
        else if (currentDemo < 0)
            currentDemo = (demoCount - 1);
            
        startDemo();
        stopDemo();
    }
}

function showHideDemo(demoId, showHide) {        
    imgObj = document.getElementById(demoIdPrefix + demoId);
    imgObj.style.display = showHide;
}

function stopDemo() {
    clearTimeout(timeOut);
    isTimerOn = false;
}

// second player

var isTimerOn1 = false;
var currentDemo1 = 1;
var demoCount1 = 10;
var timeOut1;
var demoIdPrefix1 = 'rightreason';

function startTimer1() {        
    if (!isTimerOn1) {               
        startDemo1();
    }
}

function startDemo1() {
    isTimerOn1 = true;
    var stopTimer1 = false;
            
    showHideDemo1(currentDemo1, 'none');
    
    if (currentDemo1 == demoCount1) {
        currentDemo1 = 1;
        stopTimer1 = true;
    }
    else
        currentDemo1++;
    
    showHideDemo1(currentDemo1, 'block');
    
    timeOut1 = setTimeout("startDemo1()", 2000);
    
    if(stopTimer1) {
        stopDemo1();
        setTimeout("jumpDemo1(+1)", 2000);
    }
        
}

function jumpDemo1(jump) {
    if (jump > 0) {        
        startDemo1();
        stopDemo1();
    }
    else {
        stopDemo1();
        showHideDemo1(currentDemo1, 'none');
        currentDemo1 = currentDemo1 - 2;

        if (currentDemo1 == 0)
            currentDemo1 = demoCount1;
        else if (currentDemo1 < 0)
            currentDemo1 = (demoCount - 1);
        
        startDemo1();
        stopDemo1();
    }
}

function showHideDemo1(demoId, showHide) {        
    imgObj = document.getElementById(demoIdPrefix1 + demoId);
    imgObj.style.display = showHide;
}

function stopDemo1() {
    clearTimeout(timeOut1);
    isTimerOn1 = false;
}



// laptops

var isTimerOn2 = false;
var currentDemo2 = 1;
var demoCount2 = 7;
var timeOut2;
var demoIdPrefix2 = 'laptop';

function startTimer2() {
    if (!isTimerOn2) {
        startDemo2();
    }
}

function startDemo2() {
    isTimerOn2 = true;
    var stopTimer2 = false;

    showHideDemo2(currentDemo2, 'none');

    if (currentDemo2 == demoCount2) {
        currentDemo2 = 1;
        stopTimer2 = true;
    }
    else
        currentDemo2++;

    showHideDemo2(currentDemo2, 'block');

    timeOut2 = setTimeout("startDemo2()", 2000);

//    if (stopTimer2) {
//        stopDemo2();
//        setTimeout("jumpDemo2(+1)", 2000);
//    }

}

function jumpDemo2(jump) {
    if (jump > 0) {
        startDemo2();
        stopDemo2();
    }
    else {
        stopDemo2();
        showHideDemo2(currentDemo2, 'none');
        currentDemo2 = currentDemo2 - 2;

        if (currentDemo2 == 0)
            currentDemo2 = demoCount2;
        else if (currentDemo2 < 0)
            currentDemo2 = (demoCount2 - 1);

        startDemo2();
        //stopDemo2();
    }
}

function showHideDemo2(demoId, showHide) {
    imgObj = document.getElementById(demoIdPrefix2 + demoId);
    imgObj.style.display = showHide;
}

function stopDemo2() {
    clearTimeout(timeOut2);
    isTimerOn2 = false;
}