$(function() {
    $("#tweetContainer").tweet({
        avatar_size: 32,
        count: 2,
        username: ["bcdesign1"],
        loading_text: "Loading...",
        refresh_interval: 60,
        template: "{avatar}{text}{time}{join}"
    });
    $(".fancybox").fancybox({
        overlayShow:false
    });

    var bannerPref = $.cookie("bannerPref");
    var currentBanner = "big";

    $("#uparrow").click(function() {
        if (currentBanner == "big") {
            $("#banners").css("height", "auto");
            $(".smallBanner").show();
            $(".bigBanner").hide();
            $("img", this).attr("src", "/img/arrow-270-medium.png");
            currentBanner = "small";
            $.cookie("bannerPref", "small", { expires: 7, path: '/'});
        }
        else {
            $("#banners").css("height", "300px");
            $(".smallBanner").hide();
            $(".bigBanner").show();
            $("img", this).attr("src", "/img/arrow-090-medium.png");
            currentBanner = "big";
            $.cookie("bannerPref", "big", { expires: 7, path: '/'});
        }
        return false;
    });
    if (bannerPref == "small") {
        $("#uparrow").click();
    }

   $("#mainMenu li:has(ul)").hoverIntent({
        timeout: 100,
        over: function () {
            var current = $('.submenu', this);
            $(this).find(".submenu").css({"left": $(">a", this).position().left+"px"});
            current.fadeIn(400);
        },
        out: function () {
            var current = $('.submenu', this);
            current.fadeOut(200);
        }
    });

    /*
     *
     *======SLIDESHOW==========
     *
     **/

    var i,tot,interval;

    $("#bannerMenu a").click(function(e) {
        if (e.clientX) {
            clearInterval(interval);
        }
        if (!$(this).hasClass("active")) {
            $("#bannerMenu a.active").removeClass("active");
            $(this).addClass("active");
            $("#banners div.banner:visible").hide();
            $($(this).attr("href")).fadeIn();
        }
        return false;
    });

    i = 0;
    tot = $("#bannerMenu a").size();
    interval = window.setInterval(function() {
        i = i<0 ? tot-1: (i>=tot ? 0: i);
        $("#bannerMenu a").eq(i).click();
        i++;
    }, 8000);
    $("#bannerMenu a").eq(0).click();

});
