function initPage() {

}

function roundaboutNavigate(item, name, logo, desc, url, quicklink) {
    var $item = $(item);
    if ($item.hasClass('roundabout-in-focus')) {
        //window.location.href = url;
        $('#brand-roundabout-popup').css("display", "block");
        var brandHtml = "test";
        $('#brand-roundabout-popup #brand-popup-logo').attr("src", logo);
        
        $('#brand-roundabout-popup #brand-popup-desc').html(desc);

        $('#brand-roundabout-popup #brand-popup-link').text("Go to the " + name + " website");
        $('#brand-roundabout-popup #brand-popup-link').attr("href", url);

        $('#brand-roundabout-popup #brand-popup-link-about').text("More about " + name);
        $('#brand-roundabout-popup #brand-popup-link-about').attr("href", quicklink);

        $('#brand-roundabout').css("visibility", "hidden");
    }
}

function roundaboutClosePopup() {
    $('#brand-roundabout-popup').css("display", "none");
    $('#brand-roundabout').css("visibility", "visible");
}

if (window.addEventListener)
    window.addEventListener("load", initPage, false);
else if (window.attachEvent)
    window.attachEvent("onload", initPage);


var brandsRoundaboutLoaded = false;

var brandRoundAboutStartedAnimation = false;
var brandRoundAboutFinishedAnimation = false;

$(document).ready(function () {

    /*
    var $portfolio = $('#industries-portfolio ul.main'),
    $slider = $('#industries-slider');

    var moved = false,
    dir = 0,
    newval = 0;

    var $pItems = $('> li', $portfolio),
    $firstPItem = $pItems.filter(':first'),
    liWidth = $firstPItem.width(),
    iconWidth = 40;

    var ulWidth = (liWidth * $pItems.length) + 90;
    $portfolio.width(ulWidth);
    $slider.width(47 * ($pItems.length));

    var handleOffset = 0;
    var sliderMax = ulWidth - (liWidth * 4);

    var portPosition = 0,
    multiplier = ($pItems.length / 100) + 1;
    if (portPosition) {
    $portfolio.css('left', '-' + (portPosition * multiplier) + 'px');
    }
    $slider.slider({
    min: 0,
    max: sliderMax,
    value: portPosition,
    slide: function (ev, ui) {
    if (sliderMax > ui.value * multiplier) {
    $portfolio.css('left', '-' + (ui.value * multiplier) + 'px');
    }
    },
    stop: function (ev, ui) {
    if (sliderMax > ui.value * multiplier) {
    var animateTo = ui.value * multiplier;
    } else {
    var animateTo = sliderMax;
    $slider.slider('value', animateTo - handleOffset);
    }
    $portfolio.animate({
    'left': '-' + animateTo + 'px'
    }, 300, 'linear', function () {
    // $.cookie('portPosition', animateTo - handleOffset);
    });
    }
    });

    $portfolio.find('li').hover(function () {
    $(this).addClass('active');
    }, function () {
    $(this).removeClass('active');
    }).click(function () {
    location.href = $('a', this).attr('href');
    });

    */




    $("#large_slider").cycle({
        slideExpr: '.large_slide',
        fx: 'fade',
        speed: 1000,
        timeout: 4000,
        pause: 1,
        pauseOnPagerHover: 1,
        next: '#large_next',
        prev: '#large_prev'
    });

    $("#large_pause").click(function (e) {
        e.preventDefault();
        $('#large_slider').cycle('pause');
    });

    $("#large_play").click(function (e) {
        e.preventDefault();
        $('#large_slider').cycle('resume');
    });

    $("#inner_slider").cycle({
        slideExpr: '.quad',
        fx: 'scrollLeft',
        speed: 300,
        timeout: 0,
        pause: 1,
        pauseOnPagerHover: 1,
        next: '#inner_next',
        prev: '#inner_prev'
    });

    $(".investor_center_button").mouseover(function () {
        HideAllPanels();
        $(".large_panel").css("visibility", "visible");
        $(".investor_slide").slideDown();
    });

    $(".careers_center_button").mouseover(function () {
        HideAllPanels();
        $(".large_panel").css("visibility", "visible");
        $(".careers_center").slideDown();
    });

    $(".custom_solutions_button").mouseover(function () {
        HideAllPanels();
        $(".large_panel").css("visibility", "visible");
        $(".customer_solutions_slide").slideDown();
    });

    $(".gd_way_button").mouseover(function () {
        HideAllPanels();
        $(".large_panel").css("visibility", "visible");
        $("#large_slider").css("visibility", "visible");
    });

    $(".our_brands_button").mouseover(function () {
        HideAllPanels();
        $(".large_panel").css("visibility", "visible");
        $(".brands_slide").slideDown();
        loadBrandRoundabout();

    });

    $('#brand-roundabout li').focus(function (e) {
        brandRoundAboutFinishedAnimation = true;

        brandRoundAboutStartedAnimation = false;

    }).blur(function (e) {
        brandRoundAboutStartedAnimation = true;

    });


    /*
    $(".banner, .large_slider_thumbnail").mouseout(function () {
    console.log("mouseout");
    console.log(this);
    return false;
    });

    $(".banner").mouseover(function () {
    console.log("mouseover");
    console.log(this);
    return false;
    });*/



});

function HideAllPanels() {
    if (!(brandRoundAboutStartedAnimation && !brandRoundAboutFinishedAnimation)) {
        $(".large_panel").stop(true, true);
        $(".large_panel").hide();
        $("#large_slider").css("visibility", "hidden");
    }
}

function loadBrandRoundabout() {

    if (!brandsRoundaboutLoaded) {

        brandsRoundaboutLoaded = true;

        $('#brand-roundabout').roundabout({
            shape: 'circle',
            childSelector: 'img',
            startingChild: 33,
            btnNext: '#brand-roundabout-next',
            btnPrev: '#brand-roundabout-prev',
            minOpacity: 0.1, // invisible!
            minScale: 0.1 // tiny!
        });

        $('#brand-roundabout').roundabout_setTilt(-15);
    }
}

$(function () {
    if ($('#brands-carousel-small').size() > 0) {
        $('#brands-carousel-small').jcarousel();

        var width = 0;
        $('#brands-carousel-small li').each(function (index, item) {
            width += $(item).width();
        });

        if ((width - $('#brands-carousel-small').width()) > 100) {

            $('#brands-carousel-small').width(width);
        }
    }

});

$(function () {
    if ($('#industries-carousel').size() > 0) {
        $('#industries-carousel').jcarousel();

        var width = 0;
        $('#industries-carousel li').each(function (index, item) {
            width += $(item).width();
        });

        if ((width - $('#industries-carousel').width()) > 100) {

            $('#industries-carousel').width(width);
        }
    }

});
