$(function(){
	$('html').removeClass('no-js').addClass('js');
    
    if (!supports_input_placeholder()) {
        //PLACEHOLDER NOT SUPPORTED.
        $('input[type="text"], textarea').each(function() {
            
            var placeholder = $(this).attr('placeholder');
            
            $(this).val(placeholder).focus(function() {
                if ($(this).val() == $(this).attr('placeholder'))
                {
                    $(this).val('');
                };
            }).blur(function() {
                if ($(this).val() == '')
                {
                    $(this).val($(this).attr('placeholder'));
                };
            });
        });
    };
    
    //MAKE SURE FOOTER AT THE VERY BOTTOM
    var body_window_difference = $(window).height() - $('body').height();
    if (body_window_difference > 0)
    {
        $('#footer').css({
            'marginTop': body_window_difference+40+'px'
        });
    }
    
    //CYCLE BANNER SLIDES
	if ($("#banner").size()) {
		$("#banner").append("<div id=\"banner_nav\"></div>").cycle({
			fx: "scrollHorz",
			slideExpr: ".slide",
			timeout: 5000,
			speed: 1000,
			pause: 1,
			pager: "#banner_nav"
		});
	};
    
    //MAKE SUMMARY PANELS SAME HEIGHT
    var home_summaries_panel_height = 0;
    $('#home_summaries .panel').each(function() {
        if ($(this).height() > home_summaries_panel_height) {
            home_summaries_panel_height = $(this).height();
        };
    });
    $('#home_summaries .panel').height(home_summaries_panel_height);
    
    //ANIMATE SCROLL FOR HOME PANELS
    if ($('#home_summaries').size())
    {
        
        var home_summaries_button_prev = $('<img />').attr('src', '/images/home-summaries-button-prev.png').attr('id', 'home_summaries_button_prev').click(function() {
            
            if (parseInt($('#home_summaries_inner').css('marginLeft'),10) >= 0)
            {
                return false;
            };
            
            $('#home_summaries_inner').stop(true,true).animate({
                'marginLeft': '+=310'
            }, 500);
        });
        
        var home_summaries_button_next = $('<img />').attr('src', '/images/home-summaries-button-next.png').attr('id', 'home_summaries_button_next').click(function() {
            
            if (parseInt($('#home_summaries_inner').css('marginLeft'),10) <= -620)
            {
                return false;
            };
            
            $('#home_summaries_inner').stop(true,true).animate({
                'marginLeft': '-=310'
            }, 500);
        });
        
        $('#home_summaries').after(home_summaries_button_prev).after(home_summaries_button_next);
    }
    
    //HIGHLIGHT RIGHT HANDSIDE NAV ITEM
    
    var body_id = $('body').attr('id');
    $('.right nav ul li a[href$="'+body_id+'"]').addClass('active');
    
});

function supports_input_placeholder() {
    var i = document.createElement('input');
    return 'placeholder' in i;
};
