﻿
$(document).ready(function() {
    //$('ul.jd_menu').jdMenu({autoHide:true});

    if ($("#top_admin_link").length) {
        $("#headlines_box ul:eq(1)").more({ boardIds: '5', full: true });
    }

    $("#news_box > ul").more({ boardIds: '58', showDate: true });
    $("#facstaff_box > ul").more({ boardIds: '57' });
    $("#environment_box > ul").more({ boardIds: '123' });
    $("#gifts_box > ul").more({ boardIds: '777' });

    $("#student_center_general > ul").more({ boardIds: '56', category: 'ga' });
    $("#student_center_intern > ul").more({ boardIds: '56', category: 'io' });
    $("#student_center_events > ul").more({ boardIds: '56', category: 'ea' });
    $("#student_center_volunteer > ul").more({ boardIds: '56', category: 'vo' });

    $("#community_events_general > ul").more({ boardIds: '333', category: 'oth' });
    $("#community_events_alumni > ul").more({ boardIds: '333', category: 'alu' });

    $.tabs("cal_tabs_container");
    $.tabs("student_center_tabs_container");
    $.tabs("community_events_box");

    doFooterLayout();

    $('#weather_box').jWeather({ url: "GetXML.aspx?getUrl=http://www.weather.gov/data/current_obs/KBUY.xml" });

    $(".webcam", "#web_cams_photos").click(function() {
        window.open($(this).attr("href"), "Elon University Web Cam", "status=0,toolbar=0,height=530,width=670");
        return false;
    });

    $("#right_box").css("position", "relative").css("top", "0px"); // to fix the cache FF 2nd load bug with the right column being below the page on slow connections...
});

window.onload = function() {
    var firstId = $("#full_headlines > li:first").find("a:first").getUrlParam("id");

    var topImgObj = $("#top_image");
    var origW = topImgObj.width();
    var origH = topImgObj.height();

    topImgObj.wrap($('<div id="top_image_area" style="float: left; overflow: hidden; margin-right: 5px; margin-bottom: 5px; width: ' + origW + 'px;"></div>'));

    $.get("xml.ashx", { id: firstId }, function(data) {
        $("img", data).each(function() {
            if ($(this).attr("position") != "-1") {
                var imgId = $(this).attr("id");
                $("#top_image_area").append('<img alt="" src="Image.ashx?id=' + imgId + '&w=210&h=125&q=70&ab=true"/>');
            }
        });

        if ($("#top_image_area img").size() > 1) {
            $("#top_image_area").append('<img alt="" id="copy_img" src="Image.ashx?id=' + topImgObj.getUrlParam("id") + '&w=210&h=125&q=70&ab=true"/>');

            $('#top_image_area').cycle({
                delay: 2200,
                speed: 300,
                height: "125px",
                before: function() {
                    $(this).css({ left: '50%', marginLeft: -$(this).width() / 2 });
                    //$(this).css({top: '50%', marginTop: -$(this).height()/2}); // vertical align
                }
            });
        }

        $('#top_image_area').height(origH + 10);
    });
};

function doFooterLayout() {
    var leftH = $("#left_box").height();
    var rightH = $("#right_box").height();

    setFooterWidth(leftH, rightH);

    $("#headlines_box img").load(function() {
        leftH = $("#left_box").height();
        rightH = $("#right_box").height();

        setFooterWidth(leftH, rightH);
    });
}

function setFooterWidth(leftH, rightH) {
    //if (leftH < rightH)
    //{
    $("#static_info").attr("style", "width: 564px;");
    $("#static_info ul").attr("style", "");
    //}
    //else
    //{
    //$("#static_info").attr("style", "width: 97%;");
    //}
}
