
//Function for centering items horizontally
jQuery.fn.centerh = function () {
    this.css("left", ($(window).width() - this.outerWidth()) / 2 + $(window).scrollLeft() + "px");
    return this;
}

//Variables used later on
var PermanentLockObj
var PermanentLockObjSwap
var HoverVisible = false;

//When the document has finished loading
$(document).ready(function () {

    // $("#FlashLogo").centerh();
    //removed in favor of centered table

    //Whenever the window is resized:
    $(window).resize(function () {

        // $("#FlashLogo").centerh();
        //removed in favor of centered table

        BlackBar_Lock(PermanentLockObj, PermanentLockObjSwap);
    });

    //    var option = {
    //        x: 1,
    //        y: 3,
    //        radius: 4,
    //        color: "#808080"
    //    }

    //    $("#PageTitle a.SkinObject").textShadow(option);


    //    var thePage     
    //thePage=unescape(location.href)
    //thePage=thePage.indexOf('?')==-1? thePage.substr(thePage.lastIndexOf('/')+1) : thePage.substring(thePage.lastIndexOf('/')+1,thePage.indexOf('?'))


    switch (thePageTitle) {
        case 'Blog':
            PermanentLockObj = $('#bloglink')
            PermanentLockObjSwap = false;
            BlackBar_Lock(PermanentLockObj, false);
            break;

        case 'Projects':
            PermanentLockObj = $('#projectslink');
            PermanentLockObjSwap = false;
            BlackBar_Lock(PermanentLockObj, false);
            break;

        case 'News':
            PermanentLockObj = $('#newslink')
            PermanentLockObjSwap = false;
            BlackBar_Lock(PermanentLockObj, false);
            break;

        case 'Forums':
            PermanentLockObj = $('#forumslink')
            PermanentLockObjSwap = true;
            BlackBar_Lock(PermanentLockObj, true);
            break;

        case 'Downloads':
            PermanentLockObj = $('#downloadlink')
            PermanentLockObjSwap = true;
            BlackBar_Lock(PermanentLockObj, true);
            break;

        case 'About':
            PermanentLockObj = $('#aboutlink')
            PermanentLockObjSwap = true;
            BlackBar_Lock(PermanentLockObj, true);
            break;

    }

    //    $('.NavLink').hover(
    //    //On Hover
    //    function () {
    //        if (HoverVisible == false) {
    //            $('#BlackBar_Follow').css('display', 'block');
    //        }
    //        HoverVisible = true;
    //        BlackBar_Follow($('#' + this.id));
    //    },
    //    //On exit
    //        function () {
    //            HoverVisible = false;
    //            $('#BlackBar_Follow').css('display', 'none');
    //        });
    //    function BlackBar_Follow(obj) {
    //        var leftval = obj.offset().left;
    //        $('#BlackBar_Follow').css('left', leftval - 32);
    //        /*
    // 
    //        $('#BlackBar_Follow').animate({
    //        left: leftval
    //        }, 'fast', function() {
    //        // Animation complete.
    //        });
    //        */

    //    }

    function BlackBar_Lock(obj, swap) {
        obj.addClass("NavLink_Permanent");
        var leftval = obj.offset().left;
        var rightval = obj.offset().left + obj.outerWidth();
        $('#PageTitle').css('display', 'block');
        $('#BlackBar_Follow_Permanent').css('display', 'block');
        $('#BlackBar_Follow_Permanent').css('left', leftval - 32);
        if (swap == false) {
            $('#PageTitle').css('left', rightval + 32);
        } else {
            $('#PageTitle').css('left', leftval - 3 - $('#PageTitle').outerWidth());
        }
        /*
 
        $('#BlackBar_Follow').animate({
        left: leftval
        }, 'fast', function() {
        // Animation complete.
        });
        */

    }
    //    $('.NewsPostHeader_Title').gradienttext({
    //        colors: ['#FFF', '#C6C6C6'],
    //        style: 'vertical',
    //        shadow: true,
    //        shadow_color: '#000000',
    //        shadow_offset_x: 3,
    //        shadow_offset_x: 3,
    //        shadow_blur: 5
    //    });


    $("a.popup").fancybox();

    $(".imagewrap").wrap("<div class='imagewrap_e'><div class='imagewrap_w'><div class='imagewrap_s'><div class='imagewrap_n'><div class='imagewrap_se'><div class='imagewrap_sw'><div class='imagewrap_ne'><div class='imagewrap_nw'></div></div></div></div></div></div></div></div>");

    $.getJSON("http://twitter.com/statuses/user_timeline/zanmgt.json?callback=?", function (data) {
        $("#twitter_update_zanmgt").html('<a href="http://twitter.com/zanmgt"><span class="Twitter_Rainbow_Header">ZanMgt:&nbsp;&nbsp;</span></a>' + data[0].text);
    });

    $.getJSON("http://twitter.com/statuses/user_timeline/zanmgt_zack.json?callback=?", function (data) {
        $("#twitter_update_zack").html('<a href="http://twitter.com/zanmgt_zack"><span class="Twitter_Rainbow_Header">Zack:&nbsp;&nbsp;</span></a>' + data[0].text);
    });

    $.getJSON("http://twitter.com/statuses/user_timeline/zanmgt_aaron.json?callback=?", function (data) {
        $("#twitter_update_aaron").html('<a href="http://twitter.com/zanmgt_aaron"><span class="Twitter_Rainbow_Header">Aaron:&nbsp;&nbsp;</span></a>' + data[0].text);
    });

    $.getJSON("http://twitter.com/statuses/user_timeline/zanmgt_nathan.json?callback=?", function (data) {
        $("#twitter_update_nathan").html('<a href="http://twitter.com/zanmgt_nathan"><span class="Twitter_Rainbow_Header">Nathan:&nbsp;&nbsp;</span></a>' + data[0].text);
    });

    $.getJSON("http://twitter.com/statuses/user_timeline/zanmgt_micah.json?callback=?", function (data) {
        $("#twitter_update_micah").html('<a href="http://twitter.com/zanmgt_micah"><span class="Twitter_Rainbow_Header">Micah:&nbsp;&nbsp;</span></a>' + data[0].text);
    });

    $.getJSON("http://twitter.com/statuses/user_timeline/zanmgt_gabriel.json?callback=?", function (data) {
        $("#twitter_update_gabriel").html('<a href="http://twitter.com/zanmgt_gabriel"><span class="Twitter_Rainbow_Header">Gabriel:&nbsp;&nbsp;</span></a>' + data[0].text);
    });

    $.getJSON("http://twitter.com/statuses/user_timeline/zanmgt_terah.json?callback=?", function (data) {
        $("#twitter_update_terah").html('<a href="http://twitter.com/zanmgt_terah"><span class="Twitter_Rainbow_Header">Terah:&nbsp;&nbsp;</span></a>' + data[0].text);
    });

    $('.TopRainbowBar marquee').marquee('pointer').mouseover(function () {
        $(this).trigger('stop');
    }).mouseout(function () {
        $(this).trigger('start');
    }).mousemove(function (event) {
        if ($(this).data('drag') == true) {
            this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
        }
    }).mousedown(function (event) {
        $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
    }).mouseup(function () {
        $(this).data('drag', false);
    });
});

