﻿/////////////////////////
//Javascript for Images
/////////////////////////

var icurscroll=1;
var qcurscroll=1;
var toid = null;
var pstatus = 0;
var pstatusQuote = 0;
var scrollVid = false;
var scrollQuo = false;
var scrollImg = false;

function play() {
    if (pstatus == 0){
    //added this check and moved variables for proper ability to pause
        pause();
    }
    else{
        if (icurscroll == imaxscroll) {
            icurscroll = 1;
            $('iscrollview').style.left = 0;
            changeiScrollCount();
        }
        else {
            nextImage(0,0);
        }
        toid = setTimeout(play,3000);
    }
}

function pause() {
    clearTimeout(toid)
}

function playpause() {
    if (pstatus == 0) {
        pstatus = 1;
        play();
        $('pbutton').update("Pause");
    }
    else {
        pstatus = 0;
        pause();
        $('pbutton').update("Slideshow");
    }
    
}

function prevImage(pause) {
    if (pause && pstatus==1){
    //added this check and moved variables for proper ability to pause
        playpause();
    }
    var cs = eval('icurscroll');
    var maxs = eval('imaxscroll');
    if (cs > 1) {
        if (cs < images1.length && $("image1_" + cs).src.indexOf("/images/loading3.gif") >= 0) {
            $("image1_" + cs).src = images1[cs];
        }
        new Effect.MoveBy('iscrollview',0,300,{duration:0.4,queue:'end'})
        icurscroll--;
        changeiScrollCount();
    }
}

function nextImage(supressEvent,pause) {
    if (pause && pstatus==1){
    //added this check and moved variables for proper ability to pause
        playpause();
    }
    var cs = eval('icurscroll');
    var maxs = eval('imaxscroll');
    if (cs < maxs) {
        if (cs > 0 && $("image1_" + cs).src.indexOf("/images/loading3.gif") >= 0) {
            $("image1_" + cs).src = images1[cs];
        }
        new Effect.MoveBy('iscrollview',0,-300,{duration:0.4,queue:'end'});
        icurscroll++;
        changeiScrollCount();
    }
    if($('pbutton').innerHTML == 'Slideshow')
    {
        if(!scrollImg)
        {
            scrollImg = true;
        }
    }
}

function iScrollTo(idx) {
    var scroll = (idx-1)*-300;
    new Effect.MoveBy('iscrollview',0,scroll,{duration:0.0,queue:'end'});
    icurscroll = idx ;
    changeiScrollCount();
}

function changeiScrollCount(){
    var scrollstatusdiv = $('iscrollstatus');
    if (scrollstatusdiv != null){
        scrollstatusdiv.update("(" + icurscroll + " of " + imaxscroll + ")");
    }
    checkPrevNextImage();
}

function checkPrevNextImage(){
    var curScroll = eval('icurscroll');
    var maxScroll = eval('imaxscroll');
    if ((curScroll == 1 && maxScroll == 1)) {
        if (largeImages){
            $('mediaControlButtons').style.display = "none";
            
        }
        else{
            $('mediaControlsImages').style.display = "none";
        }
    }
    else {
        if (curScroll == 1) {
            $('spanPrevImageEna').style.display = "none";
            $('spanPrevImageDis').style.display = "inline";
        }
        else {
            $('spanPrevImageEna').style.display = "inline";
            $('spanPrevImageDis').style.display = "none";
        }
        if (curScroll == maxScroll) {
            $('spanNextImageEna').style.display = "none";
            $('spanNextImageDis').style.display = "inline";
        }
        else {
            $('spanNextImageEna').style.display = "inline";
            $('spanNextImageDis').style.display = "none";
        }
    }
}

/////////////////////////
//Javascript for 2nd image control
/////////////////////////

var icruscroll2=1;
var toid2 = null;
var pstatus2 = 0;
var scrollImg2 = false;

function play2() {
    if (pstatus2 == 0){
    //added this check and moved variables for proper ability to pause
        pause2();
    }
    else{
        if (icruscroll2 == imaxscroll2) {
            icruscroll2 = 1;
            $('iscrollview2').style.left = 0;
            changeiScrollCount2();
        }
        else {
            nextImage2(0,0);
        }
        toid2 = setTimeout(play2,3000);
    }
}

function pause2() {
    clearTimeout(toid2)
}

function playpause2() {
    if (pstatus2 == 0) {
        pstatus2 = 1;
        play2();
        $('pbutton2').update("Pause");
    }
    else {
        pstatus2 = 0;
        pause2();
        $('pbutton2').update("Slideshow");
    }
    
}

function prevImage2(pause) {
    if (pause && pstatus2==1){
    //added this check and moved variables for proper ability to pause
        playpause2();
    }
    var cs = eval('icruscroll2');
    var maxs = eval('imaxscroll2');
    if (cs > 1) {
        if (cs<images2.length && $("image2_" + cs).src.indexOf("/images/loading3.gif") >= 0) {
            $("image2_" + cs).src = images2[cs];
        }
        new Effect.MoveBy('iscrollview2',0,300,{duration:0.4,queue:'end'})
        icruscroll2--;
        changeiScrollCount2();
    }
}

function nextImage2(supressEvent,pause) {
    if (pause && pstatus2==1){
    //added this check and moved variables for proper ability to pause
        playpause2();
    }
    var cs = eval('icruscroll2');
    var maxs = eval('imaxscroll2');
    if (cs < maxs) {
        if (cs >0 && $("image2_" + cs).src.indexOf("/images/loading3.gif") >= 0) {
            $("image2_" + cs).src = images2[cs];
        }
        new Effect.MoveBy('iscrollview2',0,-300,{duration:0.4,queue:'end'});
        icruscroll2++;
        changeiScrollCount2();
    }
    if($('pbutton2').innerHTML == 'Slideshow')
    {
        if(!scrollImg2)
        {
            scrollImg2 = true;
        }
    }
}

function iScrollTo2(idx) {
    var scroll = (idx-1)*-300;
    new Effect.MoveBy('iscrollview2',0,scroll,{duration:0.0,queue:'end'});
    icruscroll2 = idx ;
    changeiScrollCount2();
}

function changeiScrollCount2(){
    var scrollstatusdiv = $('iscrollstatus2');
    if (scrollstatusdiv != null){
        scrollstatusdiv.update(icruscroll2 + " of " + imaxscroll2);
    }
    checkPrevNextImage2();
}

function checkPrevNextImage2(){
    var curScroll = eval('icruscroll2');
    var maxScroll = eval('imaxscroll2');
    if (curScroll == 1 && maxScroll == 1) {
        $('mediaControlsImages2').style.display = "none";
    }
    else {
        if (curScroll == 1) {
            $('spanPrevImage2Ena').style.display = "none";
            $('spanPrevImage2Dis').style.display = "inline";
        }
        else {
            $('spanPrevImage2Ena').style.display = "inline";
            $('spanPrevImage2Dis').style.display = "none";
        }
        if (curScroll == maxScroll) {
            $('spanNextImage2Ena').style.display = "none";
            $('spanNextImage2Dis').style.display = "inline";
        }
        else {
            $('spanNextImage2Ena').style.display = "inline";
            $('spanNextImage2Dis').style.display = "none";
        }
    }
}

/////////////////////////
//Javascript for Videos
/////////////////////////

var vcurscroll=0;

function prevVideo() 
{
    var cs = eval('vcurscroll');
    var maxs = eval('vmaxscroll');
    if (cs >  0) {
        $('video'+vcurscroll).style.display = 'none'
        vcurscroll--;
        changeVideoCount();
    }
}

function nextVideo() 
{
    var cs = eval('vcurscroll');
    var maxs = eval('vmaxscroll')-1;
    if (cs <  maxs) {
        $('video'+vcurscroll).style.display = 'none'
        vcurscroll++;
        changeVideoCount();
    }
    if(!scrollVid)
    {
        scrollVid = true;
    }
}

function vScrollTo(idx) {
    var maxs = eval('vmaxscroll')-1;
    if (idx > maxs) {
        idx = maxs;
    }
    $('video'+vcurscroll).style.display = 'none';
    vcurscroll = idx;
    changeVideoCount();
}

function changeVideoCount(){
    var scrollstatusdiv = $('vscrollstatus');
    $('video'+vcurscroll).style.display = 'block'
    var cs = eval('vcurscroll')+1;
    var ms = eval('vmaxscroll');
    if (scrollstatusdiv != null){
        scrollstatusdiv.update("(" + cs + " of " + ms + ")");
    }
    checkPrevNextVideo();
}

function checkPrevNextVideo(){
    var curScroll = eval('vcurscroll')+1;
    var maxScroll = eval('vmaxscroll');
    if (curScroll == 1 && maxScroll == 1) {
        $('videoControlButtons').style.display = "none";
        document.writeln('<style type="text/css">#videos_panel * .mediaCaption {margin-top:20px;}</style>');

    }
    else {
        if (curScroll == 1) {
            $('spanPrevVideoEna').style.display = "none";
            $('spanPrevVideoDis').style.display = "inline";
        }
        else {
            $('spanPrevVideoEna').style.display = "inline";
            $('spanPrevVideoDis').style.display = "none";
        }
        if (curScroll == maxScroll) {
            $('spanNextVideoEna').style.display = "none";
            $('spanNextVideoDis').style.display = "inline";
        }
        else {
            $('spanNextVideoEna').style.display = "inline";
            $('spanNextVideoDis').style.display = "none";
        }
    }
}

/////////////////////////
//Javascript for Quotes
/////////////////////////

function playQuote() {
    if (pstatusQuote == 0){
    //added this check and moved variables for proper ability to pause
        pauseQuote();
    }
    else{
        if (qcurscroll == qmaxscroll) {
            qcurscroll = 1;
            $('qscrollview').style.left = 0;
            changeqScrollCount();
        }
        else {
            nextQuote(0,0);
        }
        toid = setTimeout(playQuote,4000);
    }
}

function pauseQuote() {
    clearTimeout(toid)
}

function playpauseQuote() {
    if (pstatusQuote == 0) {
        pstatusQuote = 1;
        playQuote();
        $('pbuttonQuote').update("Pause");
    }
    else {
        pstatusQuote = 0;
        pauseQuote();
        $('pbuttonQuote').update("Slideshow");
    }
}

function prevQuote(pause) {
    if (pause && pstatusQuote==1){
    //added this check and moved variables for proper ability to pause
        playpauseQuote();
    }
    var cs = eval('qcurscroll');
    var maxs = eval('qmaxscroll');
    if (cs >  1) {
        new Effect.MoveBy('qscrollview',0,300,{duration:0.4,queue:'end'})
        qcurscroll--;
        changeqScrollCount();
    }
}

function nextQuote(supressEvent,pause) {
    if (pause && pstatusQuote==1){
    //added this check and moved variables for proper ability to pause
        playpauseQuote();
    }
    var cs = eval('qcurscroll');
    var maxs = eval('qmaxscroll');
    if (cs  <  maxs) {
        new Effect.MoveBy('qscrollview',0,-300,{duration:0.4,queue:'end'});
        qcurscroll++;
        changeqScrollCount();
    }
    if($('pbuttonQuote').innerHTML == 'Slideshow')
    {
        if(!scrollQuo)
        {
            scrollQuo = true;
        }
    }
}

function qScrollTo(idx) {
    var scroll = (idx-1)*-300;
    new Effect.MoveBy('qscrollview',0,scroll,{duration:0.0,queue:'end'});
    qcurscroll = idx;
    changeqScrollCount();
}

function changeqScrollCount(){
    var scrollstatusdiv = $('qscrollstatus');
    if (scrollstatusdiv != null){
        scrollstatusdiv.update("(" + qcurscroll + " of " + qmaxscroll + ")");
    }
    checkPrevNextQuote();
}

function checkPrevNextQuote(){
    var curScroll = eval('qcurscroll');
    var maxScroll = eval('qmaxscroll');
    if (curScroll == 1 && maxScroll == 1) {
        $('mediaControlsQuotes').style.display = "none";
    }
    else {
        if (curScroll == 1) {
            $('spanPrevQuoteEna').style.display = "none";
            $('spanPrevQuoteDis').style.display = "inline";
        }
        else {
            $('spanPrevQuoteEna').style.display = "inline";
            $('spanPrevQuoteDis').style.display = "none";
        }
        if (curScroll == maxScroll) {
            $('spanNextQuoteEna').style.display = "none";
            $('spanNextQuoteDis').style.display = "inline";
        }
        else {
            $('spanNextQuoteEna').style.display = "inline";
            $('spanNextQuoteDis').style.display = "none";
        }
    }
}