$(document).ready(function () {
    initBanner();
    initBannerAutoFade();
    initNavigation();
    initServicesAccordion();
    initWhatWeProvide();
    initEventsHome();
    initLoadEvents();
    initMagazineSlideshow();
    initFormValidationSuccess();
    initServicesOpenTabs();
    initSubNavigationStates();
    initContactMaps();
    initVideoHover();
	initVideos();
	
    ie6PNGFix();
    jQuery.preloadImages = function () {
        for (var i = 0; i < arguments.length; i++) {
            jQuery("<img>").attr("src", arguments[i]);
        }
    }
    $.preloadImages('uploads/images/accordion_arrow_on.gif','uploads/images/success_return.gif','uploads/images/px_events_arrow_over.gif','uploads/images/px_arrow_01a.gif', 'uploads/images/nav_left_corner_on_1.gif', 'uploads/images/nav_right_corner_on_1.gif', 'uploads/images/nav_left_corner_on.gif', 'uploads/images/nav_right_corner_on.gif', 'uploads/images/hero_btn_01_new.png', 'uploads/images/hero_btn_01_active.png', 'uploads/images/hero_btn_02_new.png', 'uploads/images/hero_btn_02_active.png', 'uploads/images/hero_btn_03_new.png', 'uploads/images/hero_btn_03_active.png', 'uploads/images/hero_btn_04_new.png', 'uploads/images/hero_btn_04_active.png', 'uploads/images/hero_btn_05_new.png', 'uploads/images/hero_btn_05_active.png', 'uploads/images/hero_btn_06_new.png', 'uploads/images/hero_btn_06_active.png', 'uploads/images/hero_btn_07_new.png', 'uploads/images/hero_btn_07_active.png', 'uploads/images/hero_btn_08_new.png', 'uploads/images/hero_btn_08_active.png', 'uploads/images/hero_btn_09_new.png', 'uploads/images/hero_btn_09_active.png', 'uploads/images/hero_btn_10_new.png', 'uploads/images/hero_btn_10_active.png', 'uploads/images/headings/fil_e-commerce_1.gif', 'uploads/images/headings/fil_design_1.gif', 'uploads/images/headings/fil_marketing_1.gif', 'uploads/images/headings/fil_store_1.gif', 'uploads/images/headings/fil_e-learning_1.gif', 'uploads/images/headings/fil_managed_seervices_1.gif', 'uploads/images/headings/lnav_e-commerce_1.gif', 'uploads/images/headings/lnav_marketing_services_1.gif', 'uploads/images/headings/lnav_multi_channel_1.gif', 'uploads/images/headings/lnav_store_1.gif', 'uploads/images/headings/lnav_e-learning_1.gif', 'uploads/images/headings/lnav_managed_services_1.gif', 'uploads/images/nav_about_us_1.gif', 'uploads/images/nav_cutomers_1.gif', 'uploads/images/nav_get_in_touch.gif', 'uploads/images/nav_home_1.gif', 'uploads/images/nav_media_centre_1.gif', 'uploads/images/nav_services_solutions.gif');
    
    if ($.browser.msie && $.browser.version === '6.0') {
        $('body').addClass('ie6');
    }
    var fadeHeight = $('#wallpaper').height();
    if ($('body').hasClass('home')) {
        fadeHeight = fadeHeight + 40;
        $('#subnav-fade').css({ 'height': fadeHeight + 'px' });
    }
    else if ($('body').hasClass('services'))
    {
        fadeHeight = fadeHeight + 250;
        $('#subnav-fade').css({ 'height': fadeHeight + 'px' });    
    }
    else {
        $('#subnav-fade').css({ 'height': fadeHeight + 'px' });
    }
    $('div.map-directions').hide();   
    if ($('#tweet').length != 0)
    {
        $("#tweet").tweet({
            username: "BTFresca",
            join_text: "auto",
            avatar_size: 32,
            count: 1,
            auto_join_text_default: "we said,", 
            auto_join_text_ed: "we",
            auto_join_text_ing: "we were",
            auto_join_text_reply: "we replied to",
            auto_join_text_url: "we were checking out",
            loading_text: "loading tweets..."
        });
        $("#tweet-expedite").tweet({
            username: "BTExpedite",
            join_text: "auto",
            avatar_size: 32,
            count: 1,
            auto_join_text_default: "we said,", 
            auto_join_text_ed: "we",
            auto_join_text_ing: "we were",
            auto_join_text_reply: "we replied to",
            auto_join_text_url: "we were checking out",
            loading_text: "loading tweets..."
        });        
    } 
});

function initEnableJSProperties() {
    /*$('#services .module-header div.services-home ul li a:eq(0)').css({ 'background-color': '#ea1684' });
    $('#services .service:eq(0)').css({
        'display': 'block'
    });
    if ($('body').hasClass('home')) {
        $('#services li a img:eq(0)').attr('src', 'uploads/images/serv_multi-channel_on.gif');
        $('#services li a:eq(0)').addClass('changed');
    }
    else
    {
    }*/
    $('#paging p').remove();
    $('ul.remove').remove();
    $('div.remove').remove();

    var cookieValue = $.cookie('sequenceCount');
    if ($('body').hasClass('home')) {
        if (cookieValue != null) {

            $('.Banner' + cookieValue).addClass('active').fadeIn();
            cookieValue = cookieValue - 1;

            $('#paging a').removeClass('active');
            $('#paging a:eq(' + cookieValue + ')').addClass('active');

            if ($.browser.msie && $.browser.version === '6.0') {
                $('#paging a:eq(' + (cookieValue) + ')').addClass('active' + (cookieValue + 1));
            }
            else {
                if (cookieValue >= 10) {
                    $('#paging a:eq(' + (cookieValue) + ')').css('backgroundImage', 'url(uploads/images/hero_btn_' + (cookieValue + 1) + '_active.png)');
                }
                else {
                    $('#paging a:eq(' + (cookieValue) + ')').css('backgroundImage', 'url(uploads/images/hero_btn_0' + (cookieValue + 1) + '_active.png)');
                }
            }
        }
        else {
            $('#paging a.first').addClass('active1');
            $('div.slide-container div:first').addClass('active');
            $('#paging a:first').addClass('active');
            $('#page div.slide-container div:visible').hide();
            $('#page div.slide-container div:eq(0)').show();
        }
    }
    
    $('a.right img').hide();
    $('.withScript #main-banner').remove();
}

function initBanner() {
    $('#paging a').click(function () {
        var pageUrl = $(this).attr('href');
        $('#paging a').each(function () {
            var sequence = $(this).html();
            $(this).removeClass('active' + sequence);
            if ($.browser.msie && $.browser.version === '6.0') {
            }
            else {
                if (sequence >= 10) {
                    $(this).css('backgroundImage', 'url(uploads/images/hero_btn_' + sequence + '_new.png)');
                }
                else {
                    $(this).css('backgroundImage', 'url(uploads/images/hero_btn_0' + sequence + '_new.png)');
                }
            }
        });

        var sequence = $(this).html();
        if ($('#page div.slide-container div:visible').hasClass(pageUrl)) {
            if ($.browser.msie && $.browser.version === '6.0') {
                $(this).addClass('active' + sequence);
            }
            else {
                if (sequence >= 10) {
                    $(this).css('backgroundImage', 'url(uploads/images/hero_btn_' + sequence + '_active.png)');
                }
                else {
                    $(this).css('backgroundImage', 'url(uploads/images/hero_btn_0' + sequence + '_active.png)');
                }
            }
        }
        else {
            if ($.browser.msie && $.browser.version === '6.0') {
                $(this).addClass('active' + sequence);
            }
            else {
                if (sequence >= 10) {
                    $(this).css('backgroundImage', 'url(uploads/images/hero_btn_' + sequence + '_active.png)');
                }
                else {
                    $(this).css('backgroundImage', 'url(uploads/images/hero_btn_0' + sequence + '_active.png)');
                }
            }
            var currentDiv = $(this).attr('href');

            $('#page div.slide-container div:visible').fadeOut();
            $('#page div.slide-container .' + currentDiv).fadeIn();
        }
        return false;
    });

    $('#paging a').each(function () {
        var sequenceNo = $(this).html();

        var pageUrl = $(this).attr('href');           
        
        $.ajax({
            url: 'index.php?page=' + pageUrl,
            cache: false,
            success: function (html) {
                $('#page div.slide-container div.' + pageUrl).append(html);
                initEnableJSProperties();
            }
        });
    });
}

var imageCounter = 1;

function initBannerAutoFade() {
    if ($('body').hasClass('home')) {
        interval = setInterval('autoFade();', 5000);

        var cookieValue = $.cookie('sequenceCount');

        if (cookieValue != null) {
            imageCounter = cookieValue;
        }
        $('#paging a').click(function () {
            clearInterval(interval);
        });
    }
}

function autoFade() {

    var currentImage = $('div.slide-container div.active');
    var currentCount = $('#paging a.active');
    var cookieValue = $.cookie('sequenceCount');

    if ($.browser.msie && $.browser.version === '6.0') {
        currentCount.addClass('active' + imageCounter);
    }
    else {
        if (imageCounter >= 10) {
            $('#paging a.active').css({ 'backgroundImage': 'url(uploads/images/hero_btn_' + imageCounter + '_new.png)' });
        }
        else {
            $('#paging a.active').css({ 'backgroundImage': 'url(uploads/images/hero_btn_0' + imageCounter + '_new.png)' });
        }
    }
    
    $('#page div.slide-container div:visible').fadeOut();
    currentImage.fadeOut();

    if (imageCounter > 10) {
        imageCounter = 1;
    }
    
    if (currentImage.next().length == 0) {
        currentCount.removeClass('active');
        currentCount.removeClass('active' + imageCounter);
        $('div.slide-container div:first').fadeIn().addClass('active');
        
        imageCounter = 1;
        
        if ($.browser.msie && $.browser.version === '6.0') {
            $('#paging a:first').addClass('active' + imageCounter);
            $('#paging a:first').addClass('active');
        }
        else {
            $('#paging a:first').css({ 'backgroundImage': 'url(uploads/images/hero_btn_0' + imageCounter + '_active.png)' }).addClass('active');
        }
    }
    else {
        imageCounter++;
        currentCount.removeClass('active');
        currentCount.next().addClass('active');
        
        if ($.browser.msie && $.browser.version === '6.0') {
            currentCount.removeClass('active' + (imageCounter - 1));
            currentCount.next().addClass('active' + imageCounter);
        }
        else {
            if (imageCounter >= 10) {
                currentCount.next().css({ 'backgroundImage': 'url(uploads/images/hero_btn_' + imageCounter + '_active.png)' });
            }
            else {
                currentCount.next().css({ 'backgroundImage': 'url(uploads/images/hero_btn_0' + imageCounter + '_active.png)' });
            }
        }
        currentImage.removeClass('active');
        currentImage.next().addClass('active');
        currentImage.next().fadeIn();
    }

    $('#paging a').click(function () {
        var newSequence = $(this).attr('href').substring(6, 9);

        $('#paging a').removeClass('active');
        $(this).addClass('active');
        $('div.slide-container div').removeClass('active');
        $('div.slide-container div:eq(' + newSequence + ')').addClass('active');
        imageCounter = newSequence;
    });

    $('#navigation a').click(function () {
        $.cookie('sequenceCount', imageCounter);
    }); 
}  

var PopupStatus = 0;

function initNavigation() {
    initNavigationHover();
    initServicesNavigation();
    initDropdownNavigation();
    $('img.nav-arrow').css({
        'display': 'inline'
    });
    $('#navigation ul#main-navigation li.drop a img').css({
        'padding': '16px 12px 15px 28px'
    })  
}

function initNavigationHover() {
    $('#navigation ul#main-navigation li a').hover(
        function () {
            if ($(this).hasClass('click-active') || $(this).hasClass('current')) {
            }
            else {
                var navImage = $(this).parent().find('img.nav-arrow');
                var hoverState = $(this).find('img').attr('src').replace(/.gif/g, '_1.gif');
                $(this).find('img').attr('src', hoverState);

                if (navImage.length == 0) {
                }
                else {
                    navImage.attr('src', 'uploads/images/px_arrow_01b.gif')
                }
            }
        },
        function () {
            if ($(this).hasClass('click-active') || $(this).hasClass('current')) {
            }
            else {
                var navImage = $(this).parent().find('img.nav-arrow');

                if ($(this).attr('id') == 'home') {
                    $('#navigation').find('img.nav-left').attr('src', 'uploads/images/nav_left_corner.gif');
                }
                if ($(this).attr('id') == 'getintouch') {
                    $('#navigation').find('img.nav-right').attr('src', 'uploads/images/nav_right_corner.gif');
                }

                var hoverOffState = $(this).find('img').attr('src').replace(/_1.gif/g, '.gif');
                $(this).find('img').attr('src', hoverOffState);

                if (navImage.length == 0) {
                }
                else {
                    navImage.attr('src', 'uploads/images/px_arrow_01a.gif');
                }
            }
        }
    );

    if ($('.home a#home').length == 1) {
        var currentPage = $('.home a#home');
        currentPage.addClass('current');
        currentPage.parent().css({
            'backgroundImage': 'url(uploads/images/nav_on_bg.gif)',
            'backgroundRepeat': 'repeat-x',
            'backgroundPosition': '0 -2px'
        });
        $('.home #navigation .nav-left').attr('src', 'uploads/images/nav_left_corner_1.gif');
    }   
    if ($('.services a#services-solutions').length == 1) {
        var currentPage = $('.services a#services-solutions');
        currentPage.addClass('current');
        currentPage.parent().css({
            'backgroundImage': 'url(uploads/images/nav_on_bg.gif)',
            'backgroundRepeat': 'repeat-x',
            'backgroundPosition': '0 -2px'
        });
    }
    if ($('.customers a#customers').length == 1) {
        var currentPage = $('.customers a#customers');
        currentPage.addClass('current');
        currentPage.parent().css({
            'backgroundImage': 'url(uploads/images/nav_on_bg.gif)',
            'backgroundRepeat': 'repeat-x',
            'backgroundPosition': '0 -2px'
        });
    }
    if ($('.media a#media').length == 1) {
        var currentPage = $('.media a#media');
        currentPage.addClass('current');
        currentPage.parent().css({
            'backgroundImage': 'url(uploads/images/nav_on_bg.gif)',
            'backgroundRepeat': 'repeat-x',
            'backgroundPosition': '0 -2px'
        });
    }
    if ($('.about a#about').length == 1) {
        var currentPage = $('.about a#about');
        currentPage.addClass('current');
        currentPage.parent().css({
            'backgroundImage': 'url(uploads/images/nav_on_bg.gif)',
            'backgroundRepeat': 'repeat-x',
            'backgroundPosition': '0 -2px'
        });
    }  
    if ($('.get-in-touch a#getintouch').length == 1) {
        var currentPage = $('.get-in-touch a#getintouch');
        currentPage.addClass('current');
        currentPage.parent().css({
            'backgroundImage': 'url(uploads/images/nav_on_bg.gif)',
            'backgroundRepeat': 'repeat-x',
            'backgroundPosition': '0 -2px'
        });
        $('.get-in-touch #navigation .nav-right').attr('src', 'uploads/images/nav_right_corner_1.gif');
    }           
}

function initServicesNavigation() {
    $('#services .module-header div.services-home ul li a').click(function () {

        if ($(this).parent().hasClass('section')) {
        }
        else {
            if ($(this).hasClass('changed')) {
            }
            else {
                var newImage = $(this).find('img').attr('src').replace(/.gif/g, '_on.gif');

                $(this).parent().parent().find('img').each(function () {
                    var oldImage = $(this).attr('src').replace(/_on.gif/g, '.gif');
                    $(this).attr('src', oldImage);
                });

                $(this).find('img').attr('src', newImage);
                $(this).parent().parent().find('a').css({ 'background': 'none' });
                $(this).css({ 'background-color': '#ea1684' });
            }
            $(this).parent().parent().find('.changed').removeClass('changed');
            $(this).addClass('changed');
        }
        return false;
    });
    $('#services .module-header div.services-home ul li.section').click(function () {
        return false;
    });
}

function initDropdownNavigation() {
    $('a#services-solutions').hover(function () {

        $('#navigation ul#main-navigation li a').removeClass('click-active');
        $(this).addClass('click-active');

        $('#paging').css({ 'z-index': '0' });

        var navImage = $(this).parent().find('img.nav-arrow');
        navImage.attr('src', 'uploads/images/px_arrow_01b.gif')

        $(this).parent().css({
            'height': '55px'
        });

        $('li.drop').css({
            'background':'url(uploads/images/nav_drop_bg.gif)',
            'backgroundRepeat':'no-repeat',
            'backgroundPosition':'left bottom'
        });

        if (PopupStatus == 0) {
            $('#subnav-fade').css({
                'opacity': '0.7'
            });
            $('#navigation').css({
                'z-index': '11',
                'position': 'relative'
            });
            $('#footer').css({
                'z-index': '2',
                'position': 'relative'
            });
            $('#subnav-fade').fadeIn('slow');
            $('#services-subnav').fadeIn('slow');
            PopupStatus = 1;
        }
        else {
            $('#services-subnav').fadeIn();
        }
    });
    initClosePopup();
}



function initContactHome() {
    initClosePopup();
}

function initClosePopup() {   
    $('#subnav-fade').hover(function() {
        
        if ($('#getintouch-subnav div.error').length == 1 || $('#getintouch-subnav div.error_message').length == 1) {
        }
        else
        {    
            if (PopupStatus == 1) {
                $('#subnav-fade').fadeOut('slow');
                $('#services-subnav').fadeOut('slow');
                PopupStatus = 0;
            }
    
            if ($('.services a#services-solutions').length == 1) {
                var navImageStatic = $('.services a#services-solutions').parent().find('img.nav-arrow');
    
                navImageStatic.attr('src', 'uploads/images/px_arrow_01a.gif');
                $('.services a#services-solutions').parent().css({
                    'backgroundImage': 'url(uploads/images/nav_on_bg.gif)',
                    'backgroundRepeat': 'repeat-x',
                    'backgroundPosition':'0 -2px',
                    'background-color': 'transparent'
                });
            }
            else {
                var navImage = $('#navigation ul#main-navigation li a#services-solutions').parent().find('img.nav-arrow');
                navImage.attr('src', 'uploads/images/px_arrow_01a.gif');
    
                $('a#services-solutions .services-image').attr('src', 'uploads/images/nav_services.gif');
    
                $('#navigation ul#main-navigation li a#services-solutions').parent().css({
                    'backgroundImage': 'none',
                    'background': 'none',
                    'height': '53px'
                });
            }     
        }
    });
}

function initServicesAccordion() {
    initAccordionFunction();
}

function initAccordionFunction() {
    if ($('body').hasClass('news') || $('body').hasClass('media')) {
    }
    else {
        $('#accordion h3 a.trigger').click(function () {
            var key = $(this).attr('href').substring(1);
            key = jQuery.trim(key);
            
            if ($(this).attr('href') == '#accordion25' || $(this).attr('href') == 'index.php?page=elearning')
            {
                // Do nothing.
            }
            else {
                if ($(this).parent().parent().find('a.trigger').hasClass('link-active'))
                {
                    //var imageChangeOff = $('img.active-image').attr('src').replace(/_1.gif/g, '_0.gif');
                    //$('img.active-image').attr('src', imageChangeOff);
                    
                    var oldTrigger = $('.link-active').find('img').attr('src').replace(/_on.gif/g, '.gif');
                    $('.link-active').find('img').attr('src', oldTrigger);
                    
                    $('.link-active').parent().removeClass('active-bg');
                    //$('img.active-image').removeClass('active-image');
                    $('#accordion').find('.link-active').removeClass('link-active');
                }
                
                if ($(this).parent().parent().find('.' + key).hasClass('shown')) 
                {
                    $(this).removeClass('accordion-on');
                    $(this).parent().parent().find('.' + key).slideUp().removeClass('shown');
                    
                    //var imageChangeOff = $(this).parent().find('img.section').attr('src').replace(/_1.gif/g, '_0.gif');
                    //$(this).parent().find('img.section').attr('src', imageChangeOff);
                }
                else {
                    $(this).parent().addClass('active-bg');
                    
                    var newTrigger = $(this).find('img').attr('src').replace(/.gif/g, '_on.gif');
                    $(this).find('img').attr('src', newTrigger);
                    $(this).parent().parent().find('.accordion-on').removeClass('.accordion-on');
                    $(this).addClass('link-active');
                    $(this).addClass('accordion-on');
                    $(this).parent().parent().find('.shown').removeClass('shown').slideUp();
                    $(this).parent().parent().find('.' + key).addClass('shown').slideDown();
                  
                    //$(this).parent().find('img.section').addClass('active-image');
                    //var imageChangeOn = $(this).parent().find('img.section').attr('src').replace(/_0.gif/g, '_1.gif');
                    //$(this).parent().find('img.section').attr('src', imageChangeOn);
                }
            return false;
            }
        });
    }
}

function ie6PNGFix() {
    if ($.browser.msie && $.browser.version == '6.0') {
        $.each($(".png"), function () {
            var sizingMethod = "crop";
            if ($(this).is(".scalePng")) {
                var sizingMethod = "scale";
            }
            $(this).wrap("<span class='pngWrap'></span>");
            var test = $(this).parent();
            $(this).parent(".pngWrap").css({
                "display": "block",
                "width": $(this).width(),
                "height": $(this).height(),
                "background-image": "none",
                "filter": "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + $(this).attr("src") + "',sizingMethod='" + sizingMethod + "')"
            });
            $(this).css('display', 'none');
        });
    }
}

function initEventsHome() {
    $('div.module-content div.event a').hover(
        function () {
            $(this).css({
                'background': 'url(uploads/images/px_events_arrow_over.gif)',
                'backgroundRepeat': 'no-repeat',
                'background-position': '302px 12px',
                'background-color': '#6a6a6a'
            });
        },
        function () {
            $(this).css({
                'background': 'url(uploads/images/px_events_arrow.gif)',
                'backgroundRepeat': 'no-repeat',
                'background-position': '302px 12px',
                'background-color': 'transparent'
            });
        }
    );
    $('.news #accordion div.event a').hover(
        function () {
            $(this).css({
                'background-color': '#6a6a6a'
            });
        },
        function () {
            $(this).css({
                'background-color': 'transparent'
            });
        }
    );
}

function initWhatWeProvide() {
    $('#services .module-header div.services-home ul li a').click(function () {
        var tab = $(this).attr('href').substring(1);
        $('#services .module-content').stop().scrollTo('.' + tab, 800);
        return false;
    });
}

function initLoadEvents() {
    $('.news #blog-module-content #accordion div').hide();
    $('.news #blog-module-content #accordion div:eq(0)').show();
    $('.news #blog-module-content #accordion div:eq(1)').show();
    $('.news #blog-module-content #accordion div:eq(2)').show();
    $('.news #blog-module-content #accordion div:eq(3)').show();

    var counter = 0;
    var visibleCount = 0;
    $('.news #blog-module-content #accordion div').each(function () {
        if ($(this).is(':visible')) {
            visibleCount++;
        }
        else {
            counter++;
        }
        if (counter <= 4) {
            $(this).addClass('slide');
            $('div.module-footer').hide();
        }
        else {

        }
    });

    $('.news #blog .module-footer a.load-more').click(function () {

        $('div.slide').slideDown('slow');
        
        var slideCount = 0;
        
        $('div.slide').each(function() {
           slideCount++;
        });
        
        if (visibleCount === slideCount)
        {
            $('div.module-footer').hide();
        }
        else
        {
            $.scrollTo('+=300px', 800);   
        }
        
        return false;
    });
}

function initMagazineSlideshow() {

    var slideshowWidth = 0;
    var divCount = 0;
    var scrollCount = 0;

    $('div.magazine').each(function () {
        slideshowWidth += 140;
        divCount++;
        $(this).addClass('mag' + divCount);
    });

    if ($.browser.msie && $.browser.version === '6.0') {
        slideshowWidth = slideshowWidth + 22;
        $('div.print-slideshow').css({
            'width': slideshowWidth + 'px'
        });
    }
    else {
        $('div.print-slideshow').css({
            'width': slideshowWidth + 'px'
        });
    }

    $('div.magazine-scroll-left a.left').click(function () {
        if (scrollCount == 0) {

        }
        else {
            $('a.left img').fadeOut();
            scrollCount--;
        }
        if (scrollCount == 0) {
            $('a.left img').fadeIn();
        }
        if (divCount - 4 == scrollCount) {
            $('a.right img').fadeIn()
        }
        else {
            $('a.right img').fadeOut();
        }
        if ($.browser.msie && $.browser.version === '6.0') {
            $('div.print-slideshow-container').stop().scrollTo('-=142px', 800);
        }
        else {
            $('div.print-slideshow-container').stop().scrollTo('-=140px', 800);
        }
        return false;
    });

    $('div.magazine-scroll-right a.right').click(function () {
        if (divCount - 4 == scrollCount) {

        }
        else {
            $('a.right img').fadeOut();
            scrollCount++;
        }
        if (divCount - 4 == scrollCount) {
            $('a.right img').fadeIn();
        }
        if (scrollCount == 0) {
            $('a.left img').fadeIn();
        }
        else {
            $('a.left img').fadeOut();
        }

        if ($.browser.msie && $.browser.version === '6.0') {
            $('div.print-slideshow-container').stop().scrollTo('+=142px', 800);
        }
        else {
            $('div.print-slideshow-container').stop().scrollTo('+=140px', 800);
        }
        return false;
    });
}

var count = 0;

function initFormValidationSuccess() {

    if ($('#getintouch-subnav div.error').length == 1 || $('#getintouch-subnav div.error_message').length == 1) {
        $('#subnav-fade').css({
            'opacity': '0.7'
        });

        $('#navigation').find('img.nav-right').attr('src', 'uploads/images/nav_right_corner_1.gif');
        $('#navigation').find('img.get-image').attr('src', 'uploads/images/nav_get_in_touch_1.gif');
        $('a#getintouch').addClass('click-active');

        $('.nav-getintouch').css({
            'backgroundImage': 'url(uploads/images/nav_on_bg.gif)',
            'backgroundRepeat': 'repeat-x',
            'background-color': '#1B1B1B',
            'backgroundPosition':'0 -2px',
            'height': '55px'
        });

        $('#getintouch-subnav').fadeIn();
        $('#subnav-fade').fadeIn();

        $('div.contactform div input').css({
            'position': 'relative',
            'top': '-16px'
        });
        $('div.submit input').css({
            'top': '6px'
        });
        $('#paging').css({
            'z-index':'0'
        });
        
        var backLink = '<div class="back-link"><a href="javascript: history.go(-1)">< Go back to the previous page</a></div>';
        $('#getintouch-subnav div.error').append(backLink);        
    }
    else
    {
    }

    if ($('div.success').length == 1) {

        var popupContent = $('div.success');
        var popupShadow = $('div.success-shadow');
        var documentHeight = $(document).height();
        var windowHeight = $(window).height();
        var widowWidth = $(window).width();

        popupShadow.css({
            'opacity': '0.8',
            'height': documentHeight + 'px',
            'width': widowWidth + 'px'
        });
        popupShadow.show();

        popupContent.detach();
        popupContent.appendTo('div.success-container');

        var popupMarginWidth = widowWidth - 300;
        popupMarginWidth = popupMarginWidth / 2;

        var popupMarginHeight = windowHeight - 300;
        popupMarginHeight = popupMarginHeight / 2;

        $('div.success-container').css({
            'opacity': '1',
            'margin-left': popupMarginWidth + 'px',
            'margin-top': popupMarginHeight + 'px'
        });

        $('div.success-container').show();
    }
    else {
    }

}

function initServicesOpenTabs() {
    if ($('body').hasClass('services')) {
        $('a#services-solutions').click(function () {
            $.cookie('activeClick', '');
        });
        $('.services div#accordion div.accordion2 a').click(function () {
            $.cookie('activeClick', 'multichannel');
        });
        $('.services div#accordion h3:eq(0) a.accordion-page').click(function () {
            $.cookie('activeClick', 'multichannel');
        });        
        $('.services div#accordion div.accordion6 a').click(function () {
            $.cookie('activeClick', 'store');
        });
        $('.services div#accordion h3:eq(1) a.accordion-page').click(function () {
            $.cookie('activeClick', 'store');
        });        
        $('.services div#accordion div.accordion10 a').click(function () {
            $.cookie('activeClick', 'supply');
        });
        $('.services div#accordion h3:eq(2) a.accordion-page').click(function () {
            $.cookie('activeClick', 'supply');
        });                
        $('.services div#accordion div.accordion14 a').click(function () {
            $.cookie('activeClick', 'managed');
        });
        $('.services div#accordion h3:eq(3) a.accordion-page').click(function () {
            $.cookie('activeClick', 'managed');
        });                
        $('.services div#accordion div.accordion18 a').click(function () {
            $.cookie('activeClick', 'ecommerce');
        });
        $('.services div#accordion h3:eq(4) a.accordion-page').click(function () {
            $.cookie('activeClick', 'ecommerce');
        });                
        $('.services div#accordion div.accordion25 a').click(function () {
            $.cookie('activeClick', 'elearning');
        });
        $('.services div#accordion h3:eq(5) a.accordion-page').click(function () {
            $.cookie('activeClick', 'elearning');
        });       
        $('.services div#accordion a.elearning').click(function () {
            $.cookie('activeClick', 'elearning');
        });         
    }   
    if ($('body').hasClass('home')) {
        $('.home div#services-home-container div.multichannel a').click(function () {
            $.cookie('activeClick', 'multichannel');
        });
        $('.home div#services-home-container div.store a').click(function () {
            $.cookie('activeClick', 'store');
        });
        $('.home div#services-home-container div.supply a').click(function () {
            $.cookie('activeClick', 'supply');
        });
        $('.home div#services-home-container div.managed a').click(function () {
            $.cookie('activeClick', 'managed');
        });
        $('.home div#services-home-container div.ecommerce a').click(function () {
            $.cookie('activeClick', 'ecommerce');
        });
        $('.home div#services-home-container div.elearning a').click(function () {
            $.cookie('activeClick', 'elearning');
        });                                                       
    } 
    
    $('#services-subnav a.ecommerce').click(function () {
        $.cookie('activeClick', 'ecommerce');
    });
    $('#footer .footer-links a.ecommerce').click(function () {
        $.cookie('activeClick', 'ecommerce');
    });
    $('#services-subnav ul:eq(0) a').click(function () {
        $.cookie('activeClick', 'multichannel');
    });
    $('#footer .footer-links ul:eq(0) a').click(function () {
        $.cookie('activeClick', 'multichannel');
    });    
    $('#services-subnav a.marketing').click(function () {
        $.cookie('activeClick', 'marketing');
    });
    $('#footer .footer-links a.marketing').click(function () {
        $.cookie('activeClick', 'marketing');
    });         
    $('#services-subnav ul:eq(1) a').click(function () {
        $.cookie('activeClick', 'store');
    });
    $('#footer .footer-links ul:eq(1) a').click(function () {
        $.cookie('activeClick', 'store');
    });    
    $('#services-subnav a.multichannel').click(function () {
        $.cookie('activeClick', 'multichannel');
    });
    $('#footer .footer-links a.multichannel').click(function () {
        $.cookie('activeClick', 'multichannel');
    });     
    $('#services-subnav ul:eq(2) a').click(function () {
        $.cookie('activeClick', 'supply');
    });
    $('#footer .footer-links ul:eq(2) a').click(function () {
        $.cookie('activeClick', 'supply');
    });    
    $('#services-subnav a.store').click(function () {
        $.cookie('activeClick', 'store');
    });
    $('#footer .footer-links a.store').click(function () {
        $.cookie('activeClick', 'store');
    });        
    $('#services-subnav ul:eq(3) a').click(function () {
        $.cookie('activeClick', 'managed');
    });
    $('#footer .footer-links ul:eq(3) a').click(function () {
        $.cookie('activeClick', 'managed');
    });    
    $('#services-subnav a.elearning').click(function () {
        $.cookie('activeClick', 'elearning');
    });
    $('#footer .footer-links a.elearning').click(function () {
        $.cookie('activeClick', 'elearning');
    });        
    $('#services-subnav a.managed').click(function () {
        $.cookie('activeClick', 'managed');
    });
    $('#footer .footer-links a.managed').click(function () {
        $.cookie('activeClick', 'managed');
    });     
    $('#services-subnav ul:eq(4) a').click(function () {
        $.cookie('activeClick', 'ecommerce');
    });
    $('#footer .footer-links ul:eq(4) a').click(function () {
        $.cookie('activeClick', 'ecommerce');
    });          
    $('#services-subnav a.supply').click(function () {
        $.cookie('activeClick', 'supply');
    });
    $('#footer .footer-links a.supply').click(function () {
        $.cookie('activeClick', 'supply');
    });      

    if ($('body').hasClass('services')) {
        if ($.cookie('activeClick') == 'ecommerce') {
            var newImage = $('.services div#accordion h3:eq(4) span a img.section').attr('src').replace(/_0.gif/g, '_1.gif');
            var newArrow = $('.services div#accordion h3:eq(4) a.trigger span img').attr('src').replace(/.gif/, '_on.gif');
            $('.services div#accordion h3:eq(4) span a img.section').attr('src', newImage);
            $('.services div#accordion h3:eq(4) a.trigger span img').attr('src', newArrow);
            $('.services div#accordion h3:eq(4)').addClass('active-bg');
            $('.services div#accordion h3:eq(4) a.trigger').addClass('link-active');
            $('.services div#accordion h3:eq(4) span a.accordion-page img').addClass('active-image');
            $('.services div#accordion h3:eq(4) a').addClass('accordion-on');
            $('.services div#accordion div.accordion18').addClass('shown').slideDown();
        }
        /*else if ($.cookie('activeClick') == 'marketing') {
            var newImage = $('.services div#accordion h3:eq(6) span a img.section').attr('src').replace(/_0.gif/g, '_1.gif');
            var newArrow = $('.services div#accordion h3:eq(6) a.trigger span img').attr('src').replace(/.gif/, '_on.gif');
            $('.services div#accordion h3:eq(6) span a img.section').attr('src', newImage);
            $('.services div#accordion h3:eq(6) a.trigger span img').attr('src', newArrow);
            $('.services div#accordion h3:eq(6)').addClass('active-bg');
            $('.services div#accordion h3:eq(6) a.trigger').addClass('link-active');
            $('.services div#accordion h3:eq(6) span a.accordion-page img').addClass('active-image');
            $('.services div#accordion h3:eq(6) a').addClass('accordion-on');
            $('.services div#accordion div.accordion27').addClass('shown').slideDown();
        }*/
        else if ($.cookie('activeClick') == 'multichannel') {
            var newImage = $('.services div#accordion h3:eq(0) span a img.section').attr('src').replace(/_0.gif/g, '_1.gif');
            var newArrow = $('.services div#accordion h3:eq(0) a.trigger span img').attr('src').replace(/.gif/, '_on.gif');
            $('.services div#accordion h3:eq(0) span a img.section').attr('src', newImage);
            $('.services div#accordion h3:eq(0) a.trigger span img').attr('src', newArrow);
            $('.services div#accordion h3:eq(0)').addClass('active-bg');
            $('.services div#accordion h3:eq(0) a.trigger').addClass('link-active');
            $('.services div#accordion h3:eq(0) span a.accordion-page img').addClass('active-image');
            $('.services div#accordion h3:eq(0) a').addClass('accordion-on');
            $('.services div#accordion div.accordion2').addClass('shown').slideDown();
        }
        else if ($.cookie('activeClick') == 'store') {
            var newImage = $('.services div#accordion h3:eq(1) span a img.section').attr('src').replace(/_0.gif/g, '_1.gif');
            var newArrow = $('.services div#accordion h3:eq(1) a.trigger span img').attr('src').replace(/.gif/, '_on.gif');
            $('.services div#accordion h3:eq(1) span a img.section').attr('src', newImage);
            $('.services div#accordion h3:eq(1) a.trigger span img').attr('src', newArrow);
            $('.services div#accordion h3:eq(1)').addClass('active-bg');
            $('.services div#accordion h3:eq(1) a.trigger').addClass('link-active');
            $('.services div#accordion h3:eq(1) span a.accordion-page img').addClass('active-image');
            $('.services div#accordion h3:eq(1) a').addClass('accordion-on');
            $('.services div#accordion div.accordion6').addClass('shown').slideDown();
        }
        else if ($.cookie('activeClick') == 'elearning') {
            var newImage = $('.services div#accordion h3:eq(5) span a img.section').attr('src').replace(/_0.gif/g, '_1.gif');
            $('.services div#accordion h3:eq(5) span a img.section').attr('src', newImage);
        }
        else if ($.cookie('activeClick') == 'managed') {
            var newImage = $('.services div#accordion h3:eq(3) span a img.section').attr('src').replace(/_0.gif/g, '_1.gif');
            var newArrow = $('.services div#accordion h3:eq(3) a.trigger span img').attr('src').replace(/.gif/, '_on.gif');
            $('.services div#accordion h3:eq(3) span a img.section').attr('src', newImage);
            $('.services div#accordion h3:eq(3) a.trigger span img').attr('src', newArrow);
            $('.services div#accordion h3:eq(3)').addClass('active-bg');
            $('.services div#accordion h3:eq(3) a.trigger').addClass('link-active');
            $('.services div#accordion h3:eq(3) span a.accordion-page img').addClass('active-image');
            $('.services div#accordion h3:eq(3) a').addClass('accordion-on');
            $('.services div#accordion div.accordion14').addClass('shown').slideDown();           
        }
        else if ($.cookie('activeClick') == 'supply') {
            var newImage = $('.services div#accordion h3:eq(2) span a img.section').attr('src').replace(/_0.gif/g, '_1.gif');
            var newArrow = $('.services div#accordion h3:eq(2) a.trigger span img').attr('src').replace(/.gif/, '_on.gif');
            $('.services div#accordion h3:eq(2) span a img.section').attr('src', newImage);
            $('.services div#accordion h3:eq(2) a.trigger span img').attr('src', newArrow);
            $('.services div#accordion h3:eq(2)').addClass('active-bg');
            $('.services div#accordion h3:eq(2) a.trigger').addClass('link-active');
            $('.services div#accordion h3:eq(2) span a.accordion-page img').addClass('active-image');
            $('.services div#accordion h3:eq(2) a').addClass('accordion-on');
            $('.services div#accordion div.accordion10').addClass('shown').slideDown();
        }
    }
}

function initSubNavigationStates() {
    initCustomersNavigationStates();
    initServicesNavigationStates();
}

function initCustomersNavigationStates() {
    var customerTitle = $('.customers #services .module-header span').html();
    
    $('.customers #accordion ul.customers-accordion li a').each(function() {   
        if ($(this).html() === customerTitle)
        {
            $(this).css({'color':'#fff'});
        }
    });
}

function initServicesNavigationStates() {
    var customerTitle = $('.services #services .module-header h1').html();
    
    $('.services #accordion div p a').each(function() {   
        var currentCustomer = $(this).html().replace(/- /g, '');
        
        if (currentCustomer === customerTitle)
        {
            $(this).css({'color':'#fff'});
        }
    });
}

function initContactMaps() {
    $('a.view-map-link').click(function() {
        $(this).next().slideToggle();
        return false;
    });
}

function initVideoHover() {
	var move = 0;
	var zoom = 1;
	//On mouse over those thumbnail
	$('.videoHolder .Videos .VidHold .Video').hover(function() {
		
		//Set the width and height according to the zoom percentage
		width = $('.videoHolder .Videos .VidHold .Video').width() * zoom;
		height = $('.videoHolder .Videos .VidHold .Video').height() * zoom;
		
		//Move and zoom the image
		$(this).find('img').stop(false,true).animate({'width':width, 'height':height, 'top':move, 'left':move}, {duration:200});
		
		//Display the caption
		$(this).find('div.caption').stop(false,true).fadeIn(200);
	},
	function() {
		//Reset the image
		$(this).find('img').stop(false,true).animate({'width':$('.videoHolder .Videos .VidHold .Video').width(), 'height':$('.videoHolder .Videos .VidHold .Video').height(), 'top':'0', 'left':'0'}, {duration:100});	

		//Hide the caption
		$(this).find('div.caption').stop(false,true).fadeOut(200);
	});
}

function initVideos() {
    initVideoLoad();
    initVideoContent();
}

function initVideoLoad() {
    $('a.video-load').click(function() {
        var documentHeight = $(document).height();
        var documentWidth = $(document).width();
        var video = $(this).attr('href');
        var videoTitle = $(this).attr('title');
        
        documentHeight = documentHeight - $('div#video-popup').height();
        documentWidth = documentWidth - $('div#video-popup').width();
        documentHeight = documentHeight / 2;
        documentWidth = documentWidth / 2;
        
        var so = new SWFObject('uploads/player.swf','mpl','470','320','9');
        so.addParam('allowfullscreen','true');
        so.addParam('allowscriptaccess','always');
        so.addParam('wmode','opaque');
        so.addVariable('file',video);
        so.write('mediaspace');          
        
        $('div.video-title').empty();
        $('div.video-title').append(videoTitle);
        
        $('div.success-shadow').css({
            'opacity':'0.9',
            'width': $(document).width() + 'px',
            'height': $(document).height() + 'px'
        }).fadeIn();
        
        $('div#video-popup').css({
            'top': documentHeight + 'px',
            'left': documentWidth + 'px'
        }).fadeIn();
		
		$('body').scrollTo( $('#video-popup'));
        
        return false;
    });    

    $('div#video-popup a.close').click(function() {
       $('div.success-shadow').fadeOut();
       $('div#video-popup').fadeOut(); 
       return false;
    });
	
	
}

function initVideoContent() {

}