﻿$(document).ready(function() {

    //assign li hover class for IE6
    $("li").hover(
          function() {
              $(this).addClass('hover');
          },
          function() {
              $(this).removeClass('hover');
          }
        );
});



var imageIndex = 0;
var imageFolder = '../css/images/banners-large/';
var rotationTime = 1000;
var rotationInterval = 6000;

var Images = new Array(9);


Images[0] = ["banners-brightidea.jpg", "banners-brightidea-left.jpg", "banners-brightidea-right.jpg", "/business-perspective/startups-and-vc-fuelled-initiatives",
                                "<h2>Got a bright idea?</h2><p>Kiandra specialises in green field start-up and venture capital fuelled websites and software development</p>"]; //bright idea


    Images[1] = ["banners-freshchange.jpg", "banners-freshchange-left.jpg", "banners-freshchange-right.jpg", "/business-perspective/a-fresh-change",
                                "<h2>Get a fresh change</h2><p>The right IT people looking after the right IT solutions</p>"]; //fresh change

    Images[2] = ["banners-software.jpg", "banners-software-left.jpg", "banners-software-right.jpg", "/business-perspective/radically-boost-your-bottom-line",
                                "<h2>Custom software</h2><p>The last piece of the IT puzzle that radically boosts your bottom line.</p>"]; //custom software

    Images[3] = ["banners-mac.jpg", "banners-mac-left.jpg", "banners-mac-left.jpg", "/products-and-technologies/apple-solutions",
                                "<h2>Got Mac? Want Mac? We have it covered.</h2><p>Kiandra are experts at Mac and Windows integration and deliver quality, cross-platform solutions.</p>"]; //apple-mac

    Images[4] = ["banners-green.jpg", "banners-green-left.jpg", "banners-green-right.jpg", "/business-perspective/green-it",
                            "<h2>Thinking of green IT?</h2><p>Talk to us about virtualisation and environmentally responsible technology</p>"]; //green it

    Images[5] = ["banners-certified.jpg", "banners-certified-left.jpg", "banners-certified-right.jpg", "/business-perspective/it-partner-experience-and-certification",
                            "<h2>Certified</h2><p>We hold certifications and extensive experience in all leading technologies and solutions</p>"]; //certified

    Images[6] = ["banners-remoteaccess.jpg", "banners-remoteaccess-left.jpg", "banners-remoteaccess-right.jpg", "/products-and-technologies/remote-access",
                            "<h2>Out of the office?</h2><p>Kiandra's secure remote access solutions enable you to work easily from anywhere</p>"]; //out of office

    Images[7] = ["banners-emailarchiving.jpg", "banners-emailarchiving-left.jpg", "banners-emailarchiving-right.jpg", "/products-and-technologies/automated-email-archiving",
                            "<h2>Email Archiving</h2><p>Kiandra partners with Symantec to provide industry leading email and content archiving</p>"]; //email archive

    Images[8] = ["banners-projectrecovery.jpg", "banners-projectrecovery-left.jpg", "banners-projectrecovery-right.jpg", "/software-solutions/project-recovery",
                            "<h2>Development project gone off the rails?</h2><p>Kiandra's emergency project recovery services will get you back on track</p>"]; //development off rails

    Images[9] = ["banners-lineup.jpg", "banners-lineup-left.jpg", "banners-lineup-right.jpg", "/products-and-technologies",
                       "<h2>Impressive Lineup</h2><p>Kiandra's product knowledge and experience ensures you get the right solution.</p>"]; //impressive lineup


    var rotateBanner = function() {

        var nextImage = getNextImageId();
        
        //set background images for first rotation
        $("#banner-wrapper-back").css("background-image", "url(" + imageFolder + Images[nextImage][0] + ")");
        $("#banner-left-back").css("background-image", "url(" + imageFolder + Images[nextImage][1] + ")");
        $("#banner-right-back").css("background-image", "url(" + imageFolder + Images[nextImage][2] + ")");

        //set onclick
        $('#banner-wrapper').unbind('click');

        $("#banner-wrapper").bind('click', function() {
            document.location = getCurrentUrl();
        });

        //run again in 6 seconds
        setTimeout("rotateImages()", rotationInterval);

    }
    var rotateImages = function() {


    
        //increment image index
    imageIndex = getNextImageId();

    var nextImageIndex = getNextImageId();
       
       // $("#banner-wrapper-back").css("display", "inline")

        //set text
        // setText(Images[imageIndex][5]);

        //swap images
        $("#banner-wrapper").stop().animate({
            opacity: 0
        },
        rotationTime,
        function() {

            //set front div to what is currently in background and set front div back to visible
            $("#banner-wrapper")
                    .css("background-image", "url(" + imageFolder + Images[imageIndex][0] + ")")
                    .css("opacity", 1);
                      
            //run again
            setTimeout("rotateImages()", rotationInterval);

            //set background image in 1 second after opacity finishes (prevent ficker issue)
            setTimeout("setBackground(" + nextImageIndex + ")", 1000);
        });

        $("#banner-left").stop().animate({
            opacity: 0
        },
        rotationTime,
        function() {

            //set front div to what is currently in background and set front div back to visible
            $("#banner-left")
                    .css("background-image", "url(" + imageFolder + Images[imageIndex][1] + ")")
                    .css("opacity", 1);

            $("#banner-left-back").css("background-image", "url(" + imageFolder + Images[nextImageIndex][1] + ")");

        });

        //set front div to what is currently in background and set front div back to visible
        $("#banner-right").stop().animate({
            opacity: 0
        },
        rotationTime,
        function() {

            $("#banner-right")
                       .css("background-image", "url(" + imageFolder + Images[imageIndex][2] + ")")
                        .css("opacity", 1);


            $("#banner-right-back").css("background-image", "url(" + imageFolder + Images[nextImageIndex][2] + ")");
        });

      
}

var setBackground = function(index) {
    $("#banner-wrapper-back").css("background-image", "url(" + imageFolder + Images[index][0] + ")");


}

var getCurrentUrl = function() {
    return Images[imageIndex][3];
}

var getNextImageId = function() {

    var nextImage = imageIndex;

    //get next image
    nextImage++;

    if (nextImage >= Images.length) {
        //reset array
        nextImage = 0;
    }

    return nextImage;
}

