﻿/* Maximum of 3 slides */

var currSlide = 0;
var currLink;
var fadeDuration = 500;
var slideDuration = 8000;
var timer;
var slides = ["http://www.bdcsoft.com/Content/Images/home-2.png", "http://www.bdcsoft.com/Content/Images/home-1.png", "http://www.bdcsoft.com/Content/Images/home-3.png"];
var slidesAlt = ["Is custom software too expensive?", "Featured Case Study: ABC Coin - See how BDC helped to improve workflow automation and communication via web and mobile applications.", "Check out the new developer blog!"];
var links = ['articles/is-custom-software-expensive/', 'case-studies/abc/', 'http://blog.bdcsoft.com/Developer-Blog'];

$(function () {
    preload(slides);

    getNewSlide();  // run on load
    StartTimer();

    $('#action-links div').click(function () {
        switch ($(this).attr('id')) {
            case "contact-link":
                window.location = "/contact-us/";
                break;
            case "email-link":
                window.location = "mailto:hello@bdcsoft.com";
                break;
            case "phone-link":
                window.location = "tel:2142838903";
                break;
            case "services-link":
                window.location = "/services/";
                break;
            default:
                break;
        }
    });
});

function preload(images) {
    $(images).each(function () {
        $("<img/>")[0].src = this;
    });
}

function switchSlide() {
    $('#fadeimagecontainer img').fadeTo(fadeDuration, 0, function () {
        getNewSlide();
    });
}

function getNewSlide() {    
    $('#fadeimagecontainer img').attr('src', slides[currSlide]).attr('alt', slidesAlt[currSlide]).fadeTo(fadeDuration, 1);
    $('#fadeimagecontainer a').attr('href', links[currSlide]);

    // 3 slides max
    if (currSlide == 2) {
        currSlide = 0;
        currLink = 0;
    }
    else {
        currSlide += 1;
        currLink += 1;
    }
}

function StartTimer() {
    timer = self.setInterval("switchSlide()", slideDuration);
}
