var speed = 30;
var l = 0;
var d = 0;
var i = 0;
var a = 0;
var p = 294;
var toTheLeft;
var toTheRight;
var moveItToTimeout;
var resumeTime;
var resumeTime2;
var timex;
var itHaveMoved;
var ddestination;
var page;
var changeText;
var opacityIncreaseTimeout;
var opacityDecreaseTimeout;
var s = 0;
var t = 0;
var way = 0;
var o = 10;
var notFullOpacity = "TRUE";
var interrupted = "FALSE";
var ccontent;
var lastContent;
var destinationChanged;
var noActionHappened = "TRUE";
var lastActiveItem = null;
var lo = 98;
var loadingScreenInvisible = "FALSE";

//window.onload=function() {
//    if (noActionHappened == "TRUE") {
//    timex = setTimeout('scrollLeft()',1000);
//    }
//}

function hasStopped() {
    clearTimeout(toTheLeft);
    resumeTime = setTimeout('scrollLeft()', 10000);
}

function hasStopped2() {
    clearTimeout(toTheRight);
    resumeTime2 = setTimeout('scrollRight()', 10000);
}

function turnRight() {
    i=0;
    setTimeout('scrollRight()', 2000);   
}

function turnLeft() {
i=0;
setTimeout('scrollLeft()', 2000);
}

function scrollLeft() {

    if (l==0||l==-951||l==-1901||l==-2851||l==-3801||l==-4751) {
        a = l;
        d = a - 950;
        speed = 30;
    }

    if (l > (d - a)/3 + a) {
        document.getElementById('roller').style.left=l+'px';
        l += i;
        i--;
        toTheLeft = setTimeout('scrollLeft()',speed);
    } else if (l < (d - a)/3 + a) {
        document.getElementById('roller').style.left=l+'px';
        l += i;

        if (i < -1 && l < (d - a)/(3) + a - p && l!== d) {
            i++;  
        }

        if(i>=-2 && i <= -1) {
                speed = 5;
            }

        if(l==-951||l==-1901||l==-2851||l==-3801) {
            hasStopped();
        } else if(l==-4751) {
        turnRight();
        } else {
        toTheLeft = setTimeout('scrollLeft()',speed);
        }
    } 
}

function scrollRight() {
        if (l==0||l==-951||l==-1901||l==-2851||l==-3801||l==-4751) {
        a = l;
        d = a + 950;
        speed = 30;
    }

    if (l < (d - a)/3 + a) {
        document.getElementById('roller').style.left=l+'px';
        l += i;
        i++;
        toTheRight = setTimeout('scrollRight()',speed);
    } else if (l > (d - a)/3 + a) {
        document.getElementById('roller').style.left=l+'px';
        l += i;

        if (i > 1 && l > (d - a)/(3) + a + p  && l!== d) {
            i--;
        }

        if(i<=2 && i >= 1) {
                speed = 5;
            }

        if(l==-951||l==-1901||l==-2851||l==-3801) {
            hasStopped2();
        } else if(l==0) {
        turnLeft();
        } else {
        toTheRight = setTimeout('scrollRight()',speed);
        }
    }
    
}

function stopScroll() {
    clearTimeout(toTheLeft);
    clearTimeout(toTheRight);
    clearTimeout(moveItToTimeout);
    clearTimeout(resumeTime);
    clearTimeout(resumeTime2);
    clearTimeout(timex);
    clearTimeout(changeText);
    clearTimeout(opacityIncreaseTimeout);
    clearTimeout(changeText);
}

function moveItTo(target, firstRun) {

    if (firstRun=="TRUE") {
    s = l;
    t = target;
    firstRun = "FALSE";
    i = 0;
    a = 0;
    runOnce = "TRUE";
    speed = 30;
    if (s < t){
    way = (s - t) * (-1);
    } else {
        way = s - t;
    }

    fullWay = way;

    acceleration = fullWay * 0.75;
    deceleration = fullWay * 0.28;
    }

    if (s < t) {

          if (way >= 0) {
            if (way >= acceleration){
                document.getElementById('roller').style.left=l+'px';
                l += i;
                way -= i;
                i++;
                moveItToTimeout = setTimeout('moveItTo()',speed);
            }else if (way <= deceleration){
                document.getElementById('roller').style.left=l+'px';
                
                if (i<5) {
                    speed = 10;
                }

                if (i>1){
                i--;

                }

                l += i;
                way -= i;
                moveItToTimeout = setTimeout('moveItTo()',speed);
            }
            else{
                document.getElementById('roller').style.left=l+'px';
                l += i;
                way -= i;
                moveItToTimeout = setTimeout('moveItTo()',speed);
            }

        }
    
} else {
    if (way >= 0) {
            if (way >= acceleration){
                document.getElementById('roller').style.left=l+'px';
                l -= i;
                way -= i;
                i++;
                
                moveItToTimeout = setTimeout('moveItTo()',speed);
            }else if (way <= deceleration){
                document.getElementById('roller').style.left=l+'px';

                if (i<5) {
                    speed = 10;
                    
                }

                if (i>1){
                i--;
                }

                l -= i;
                way -= i;
                moveItToTimeout = setTimeout('moveItTo()',speed);
            }
            else{
                document.getElementById('roller').style.left=l+'px';
                l -= i;
                way -= i;
                moveItToTimeout = setTimeout('moveItTo()',speed);
            }

        }
     
}

   if (way <= 0 && runOnce =="TRUE") {
    runOnce = "FALSE";
    changeText = setTimeout ('showText(page)', 200);
}

}

function opaciter (incrOrDecr) {
    // pro IECKO filter:alpha(opacity=50);
    if (navigator.appName == 'Microsoft Internet Explorer') {
   if (incrOrDecr == "increase") {
       if (interrupted == "TRUE") {
           o=10;
       }
    interrupted = "FALSE";
    document.getElementById('content_' + ccontent).style.display='block';
    if (o <= 96) {
    document.getElementById('content_' + ccontent).style.filter = "alpha(opacity=" + o + ")";
    } else {
    document.getElementById('content_' + ccontent).style.filter = "alpha(opacity=" + 100 + ")";
    }
    if (o <= 96) {
        o+=4;
    lastContent = ccontent;
    opacityIncreaseTimeout = setTimeout ("opaciter('increase')", 30);
    }
} else if (incrOrDecr == "decrease") {



   if (document.getElementById('content_' + lastContent) != null) {
   interrupted = "TRUE";

   document.getElementById('content_' + lastContent).style.display='block';
   tisk = document.getElementById('content_' + lastContent).style.filter = "alpha(opacity=" + o + ")";
    if (o <= 98 && o > 10) {
        o-=9;
        opacityDecreaseTimeout = setTimeout ("opaciter('decrease')", 20);
    } else {
        document.getElementById('content_' + lastContent).style.filter = "alpha(opacity=" + 0 + ")";
        document.getElementById('content_' + lastContent).style.display='none';
    }
   }



}
    }else {

// pro zbytekkkkkk
   if (incrOrDecr == "increase") {
       if (interrupted == "TRUE") {
           o=10;
       }
    interrupted = "FALSE";
    document.getElementById('content_' + ccontent).style.display='block';
    if (o <= 96) {
    document.getElementById('content_' + ccontent).style.opacity="0." + o;
    } else {
    document.getElementById('content_' + ccontent).style.opacity="1";
    }
    if (o <= 96) {
        o+=4;
    lastContent = ccontent;
    opacityIncreaseTimeout = setTimeout ("opaciter('increase')", 30);
    }
} else if (incrOrDecr == "decrease") {



   if (document.getElementById('content_' + lastContent) != null) {
   interrupted = "TRUE";

   document.getElementById('content_' + lastContent).style.display='block';
   tisk = document.getElementById('content_' + lastContent).style.opacity="0." + o;

    if (o <= 98 && o > 10) {
        o-=9;
        opacityDecreaseTimeout = setTimeout ("opaciter('decrease')", 20);
    } else {
        document.getElementById('content_' + lastContent).style.opacity="0";
        document.getElementById('content_' + lastContent).style.display='none';
    }
   }



}
    }


}

function showText(page) {
    switch (page) {
        case 'ubytovani':
          opaciter("increase");
        break;

        case 'seychely':
          opaciter("increase");
        break;

        case 'aktivity':
          opaciter("increase");
        break;

        case 'fotogalerie':
          opaciter("increase");
        break;

        case 'rezervace':
            opaciter("increase");
        break;

        case 'kontakt':
            opaciter("increase");
        break;
    }
}

function menuActivator(activeItem) {

    switch (activeItem) {
        case 'ubytovani':
            document.getElementById(activeItem).style.backgroundPosition='0 -110';
            lastActiveItem = activeItem;
        break;

        case 'seychely':
            document.getElementById(activeItem).style.backgroundPosition='0 -110';
            lastActiveItem = activeItem;
        break;

        case 'aktivity':
            document.getElementById(activeItem).style.backgroundPosition='0 -110';
            lastActiveItem = activeItem;
        break;

        case 'fotogalerie':
            document.getElementById(activeItem).style.backgroundPosition='0 -110';
            lastActiveItem = activeItem;
        break;

        case 'rezervace':
            document.getElementById(activeItem).style.backgroundPosition='0 -110';
            lastActiveItem = activeItem;
        break;

        case 'kontakt':
            document.getElementById(activeItem).style.backgroundPosition='0 -110';
            lastActiveItem = activeItem;
        break;
    }
}

function menuDeactivator (lastActiveItem) {
        switch (lastActiveItem) {
        case 'ubytovani':
          document.getElementById(lastActiveItem).style.backgroundPosition='0 0';
        break;

        case 'seychely':
          document.getElementById(lastActiveItem).style.backgroundPosition='0 0';
        break;

        case 'aktivity':
          document.getElementById(lastActiveItem).style.backgroundPosition='0 0';
        break;

        case 'fotogalerie':
         document.getElementById(lastActiveItem).style.backgroundPosition='0 0';
        break;

        case 'rezervace':
            document.getElementById(lastActiveItem).style.backgroundPosition='0 0';
        break;

        case 'kontakt':
            document.getElementById(lastActiveItem).style.backgroundPosition='0 0';
        break;
    }
}


function xScrollTo(ddestination) {
    if (ddestination !== page ) {
        stopScroll();
    page = ddestination;
    noActionHappened = "FALSE";
    ccontent = ddestination;
    document.getElementById('content_' + ccontent).style.display='none';
    switch (ddestination) {
        case 'ubytovani':
            if (lastActiveItem != null) {
                menuDeactivator(lastActiveItem);
            }
            menuActivator(ddestination);
            opaciter("decrease");
            setTimeout ("moveItTo(0, 'TRUE')", 5);
        break;
        case 'seychely':
            if (lastActiveItem != null) {
                menuDeactivator(lastActiveItem);
            }
            menuActivator(ddestination);
            opaciter("decrease");
            setTimeout ("moveItTo(-951, 'TRUE')", 5);
        break;
        case 'aktivity':
            if (lastActiveItem != null) {
                menuDeactivator(lastActiveItem);
            }
            menuActivator(ddestination);
            opaciter("decrease");
            setTimeout ("moveItTo(-1901, 'TRUE')", 5);
        break;
        case 'fotogalerie':
            if (lastActiveItem != null) {
                menuDeactivator(lastActiveItem);
            }
            menuActivator(ddestination);
            opaciter("decrease");
            setTimeout ("moveItTo(-2851, 'TRUE')", 5);
        break;
        case 'rezervace':
            if (lastActiveItem != null) {
                menuDeactivator(lastActiveItem);
            }
            menuActivator(ddestination);
            opaciter("decrease");
            setTimeout ("moveItTo(-3801, 'TRUE')", 5);
        break;
        case 'kontakt':
            if (lastActiveItem != null) {
                menuDeactivator(lastActiveItem);
            }
            menuActivator(ddestination);
            opaciter("decrease");
            setTimeout ("moveItTo(-4751, 'TRUE')", 5);
        break;
    }
  }
}
    
// debuger
function vypis(msgs){
document.getElementById('debuger').innerHTML=document.getElementById('debuger').innerHTML+msgs+"<br />";
}

function hideLoadingScreen() {


    if (navigator.appName == 'Microsoft Internet Explorer') {
        document.getElementById('loadingScreen').style.filter = "alpha(opacity=" + lo + ")";
        if (lo <= 100 && lo > 10) {
            lo-=9;
            opacityDecreaseTimeout = setTimeout ("hideLoadingScreen()", 20);
        } else {
            document.getElementById('loadingScreen').style.filter = "alpha(opacity=" + 0 + ")";
            document.getElementById('loadingScreen').style.display='none';
            loadingScreenInvisible = "TRUE";
        }
    } else {

        tisk = document.getElementById('loadingScreen').style.opacity="0." + lo;

        if (lo <= 100 && lo > 10) {
            lo-=9;
            opacityDecreaseTimeout = setTimeout ("hideLoadingScreen()", 20);
        } else {
            document.getElementById('loadingScreen').style.opacity="0";
            document.getElementById('loadingScreen').style.display='none';
            loadingScreenInvisible = "TRUE";
        }
    }

        if (noActionHappened == "TRUE" && loadingScreenInvisible =="TRUE") {
    timex = setTimeout('scrollLeft()',10000);
        }
}

