var http_root = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'route2.pe.ca/';
var image_root = http_root + "media/images/";

var quoteTimer;
var quoteIdx = 1;
var quotes = new Array();
quotes[0] = '                                <p>Our experiences with Route2 have been very prompt and professional. The quality of their work speaks for itself.</p>' + "\n" + '                                <p class="from">~ <span class="author">Mike Thususka</span><br />Director of Economic Development<br /><a href="http://city.summerside.pe.ca/" title="City of Summerside">City of Summerside</a></p>';
quotes[1] = '                                <p>[the system] is very accessible, user friendly, easy to operate and [support] service, if there is ever issues, is prompt and without hassle. Repairs seem to be addressed as soon as possible.</p>' + "\n" + '                                <p class="from">~ <span class="author">Katy Baker</span><br />Marketing Events Officer<br /><a href="http://innovationpei.com/" title="Innovation PEI">Innovation PEI</a></p>';
quotes[2] = '                                <p>When there is a problem with our ticketing system, Route2 responds promptly and stays on the job until the issue is resolved. They are reliable, accessible, knowledgeable and courteous, always.</p>' + "\n" + '                                <p class="from">~ <span class="author">Mary Dennis</span><br />Director of Operations<br /><a href="http://harbourfronttheatre.com/" title="Harbourfront Theatre">Harbourfront Theatre</a></p>';
quotes[3] = '                                <p>Our I.T. is in use by the members twenty four hours a day, seven days a week and we absolutely need the systems working 100%. The team at Route 2 are capable, available and effective when we need them. I\'m glad to have them a phone call away.</p>' + "\n" + '                                <p class="from">~ <span class="author">Chief Dave Poirier</span>, Chief of Police<br />Summerside Police Services<br /><a href="http://city.summerside.pe.ca/" title="City of Summerside">City of Summerside</a></p>';
quotes[4] = '                                <p>I am very happy with the prompt service this fall from Route 2 for bringing WiFi to Brookvale Winter Activity Park.</p>' + "\n" + '                                <p class="from">~ <span class="author">Allan Matters</span><br />Superintendant of Operations<br /><a href="http://brookvaleskipark.com/" title="Brookvale Provincial Ski Park">Brookvale Provincial Ski Park</a></p>';
quotes[5] = '                                <p>Since I know next to nothing about computers, the staff at Route2 have been very patient and understanding</p>' + "\n" + '                                <p class="from">~ <span class="author">Jean Yorke</span><br />High Speed Plus Customer</p>';

var bannerTimer;
var bannerIdx = 1;
var banners = new Array();
banners[0] = "R2B7.jpg";
banners[1] = "R2B5.jpg";
banners[2] = "R2B4.jpg";
banners[3] = "R2B2.jpg";

var emailFilter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;

function init() {
    preloadImages();

    quoteTimer = setInterval( "quoteRotate(false)", 9000 );
    bannerTimer = setInterval( "bannerRotate(false)", 8500 );
}

function preloadImages() {
    if(document.images) {
        preload_image = new Image();
        for(i = 0; i < banners.length; i++) {
            preload_image.src = image_root + banners[i];
        }
    }
}

function quoteRotate(quickly) {
    div = new Element('div').update(quotes[quoteIdx]);
    div.addClassName('whiteBG');
    div.style.height = '220px';
    
    $('quote-front').update(div);

    if(quickly) {
        duration = 0.25;
    } else {
        duration = 1.25;
    }

    new Effect.Appear('quote-front', {
        duration: duration,
         afterFinish: function() {
            $('quote-back').update(div);
            $('quote-front').style.display = "none";
            quoteIdx++;
            if(quoteIdx == quotes.length) {
                quoteIdx = 0;
            }
        }
    });
}


function quoteSelect(direction) {
    clearInterval(quoteTimer);

    if("previous" == direction) {
        quoteIdx--;
        quoteIdx--;
    }
    if(quoteIdx < 0) {
        quoteIdx += quotes.length;
    }

    if(quoteIdx == quotes.length) {
        quoteIdx = 0;
    }

    quoteRotate(true);
    quoteTimer = setInterval("quoteRotate()", 9000);
}

function bannerRotate(quickly) {
    $('banner-image-front').src = image_root + banners[bannerIdx];

    if(bannerIdx == 0) {
        $("banner-control-3").removeClassName('current')
    } else {
        $("banner-control-" + (bannerIdx - 1)).removeClassName('current');
    }
    $("banner-control-" + bannerIdx).addClassName('current');

    if(quickly) {
        duration = 0.25;
    } else {
        duration = 1.25;
    }

    new Effect.Appear('banner-image-front', {
        duration: duration,
        afterFinish: function() {
            $('banner-image-back').src = $('banner-image-front').src;
            $('banner-image-front').style.display = "none";
            bannerIdx++;
            if(bannerIdx == banners.length) {
                bannerIdx = 0;
            }
        }
    });
}

function bannerSelect(idx) {
    clearInterval(bannerTimer);
    for(idy = 0; idy < banners.length; idy++) {
        $("banner-control-" + idy).removeClassName("current");
    }
    bannerIdx = idx;
    bannerRotate(true);
    bannerTimer = setInterval("bannerRotate()", 6500);
}

function go( uri ) {
    if( uri.substr( 0, 4 ) == 'http' ) {
        document.location = uri;
    } else {
        document.location = http_root + uri;
    }
}

