/* Global Items */
$(document).ready(function() {


	// fontAvailable
    if($.fontAvailable('Arial Narrow')) {
		$("body").addClass("hasArialNarrow");
    }


	// hover switch
	$("input[type='image']").rolloverSubmit();


	// firsts & lasts
	//$("#globalNav li:first-child a").addClass("first");
	//$("#globalNav li:last-child").addClass("last");
	//$("#utilityNav li:last-child").addClass("last");
	//$("#footer li:last-child").addClass("last");
	//$("#interiorNav li.listParent ul li:first-child").addClass("first");
	//$("#rightCol .sideBlock:first-child").addClass("sideBlock-clipped");

	$("#interiorNav li.listParent.active a").addClass("activeAndParent");


	// form selectors
	$(".sideBlock input[type='text']").addClass("textInput");
	$(".sideBlock input[type='image']").addClass("imageInput");


	// let's light up the globalNav
	var curCategory = $("body").attr("id");
	$("#globalNav #link_"+curCategory).addClass("active");


	// If you're hovering over a nav link, kill its neighbor's little notch.
	$("#globalNav li").mouseover(function() {
		$(this).next().addClass("noNotch");
	}).mouseout(function(){
		$(this).next().removeClass("noNotch");
	});
	// And if a nav link is ever "active," then kill its neighbor's notch right off the bat.
	$("#globalNav li.active, #globalNav li.active-trail").next().addClass("noNotch");
	$("#globalNav li.active, #globalNav li.active-trail").mouseout(function() {
		$(this).next().addClass("noNotch");
	});
	
	
	// handmade carousel
	$('#homeCarousel .bbnav').html($("#homeCarouselImages img").length + ' items ... next');
	/*
	var car_images = $("#homeCarouselImages img");
	var car_index = 0;
	$("#homeCarouselImages img:not(:first-child)").css("opacity", 0);
	function goto_next() {
		$(car_images[car_index]).animate({'opacity':0}, 750);
		car_index += 1; // increment the current image by one
		if (car_index >= car_images.length) car_index = 0; // but if it's the last one, take us back to the first one
		$(car_images[car_index]).animate({'opacity': 1}, 750); // bring to visibility
	}
	setInterval(goto_next, 1500);
	*/
	
	$('#billboardz .item-list ul').cycle({
	    fx: 'fade',
	    timeout: 0,
	    next: '#billboardz .pagination .next',
	    prev: '#billboardz .pagination .previous',
	    pager: '#billboardz .pagination .pager',
	    pagerAnchorBuilder: function(index, element) {
	        var first = (index == 0)?"active":"";
            return '<li id="pager'+index+'" class="'+first+'"><a href="#">' + (index+1) + '</a></li>';
        },
        pagerClick: function(index, element) {
            $("#billboardz .pagination .pager li").removeClass('active');
            $("#billboardz .pagination .pager #pager"+index).addClass('active');
        },
        prevNextClick: function(isNext, index, element) {
            $("#billboardz .pagination .pager li").removeClass('active');
            $("#billboardz .pagination .pager #pager"+index).addClass('active');
        }
    });

    $('#block-menu-primary-links li a.active').wrapInner('<span>');

    //investment panels

    var activate_investment_panel = function(section_id) {
        $('#investment-links a').removeClass('active');
        $('#investment-links #'+section_id+" a").addClass('active');
        $('.investment_panel').css('display', 'none');
        $('.'+section_id).css('display','block');
    }
    activate_investment_panel('overview');
    $('#investment-links li').click(function(e) {
        e.preventDefault();
        activate_investment_panel(this.id);
    });
    $('#investment-links').css('display', 'block');

    //add floatleft class to floated images
    $("p img").each(function(){
        if ($(this).css('float') === 'left')
            $(this).addClass('floatleft');
    });

});
