/* Author: 
	Matt Ladner and Friends
*/

$(document).ready(function() {

    var PageLoader = {
            ieCheck: function() {
                var body = $('body:first'),
                        ie = "ie";
                body.each(function () {
                    var node = $(this),
                            majorVersion = 0;
                    if ($.browser.msie) {
                        majorVersion = parseInt($.browser.version, 10);
                        node.addClass(ie);
                        if ("number" === typeof majorVersion && !isNaN(majorVersion)) {
                            node.addClass([ie, majorVersion].join('-'));
                        }
                    }
                });
            },
            clientPage: function() {
                var body = $('body:first');

                if (body.hasClass('clients')) {

                    // This is the clients page, so add a class that can be used
                    // to brutally style this page
                    if ($.browser.msie) {
                        // See how wide the content area is. If it's smaller than a set amount, then
                        // suggest that the clients be shown in 1 or 2 columns instead of 3.
                        var setAmounts = {
                            twoColumns: 900,
                            oneColumn: 700
                            },
                            node = $('#main-content div:first');

                            node.each(function() {
                                var width = $(this).width();
                                if (width <= setAmounts.oneColumn) {
                                    body[0].className = [body[0].className, "client-display-single-column"].join(' ');
                                } else if (width <= setAmounts.twoColumns) {
                                    body[0].className = [body[0].className, "client-display-double-column"].join(' ');
                                }
                            });

                    }
                }
            },
            skillsPage: function() {
                var window = $(window),
                    body = $('body:first');


                if (body.hasClass('single-skills')) {

                    $('#main-content h2:first').each(function() {
                        var header = $(this),
                            span = header.children('span:first'),
                            methodNames = ['addClass', 'removeClass'],
                            className = 'hide-background-image';

                        header.resize(function() {
                            var index = 0,
                                headerWidth = header.width(),
                                spanWidth = span.innerWidth();

                            if (headerWidth > spanWidth) {
                                index = 1;
                            }
                            header[methodNames[index]](className);
                        });
                    });
                }
            }
        };

    var pageLoadFunctions = [
        'ieCheck',
        'clientPage',
        'skillsPage'
    ];

    $.each(pageLoadFunctions, function(i, functionName) {
        var f = PageLoader[functionName];
        if ("function" === typeof f) {
            f();
        }
    });

	$.localScroll();

	$('.to-top').click(function() {
		$('html, body').animate({ scrollTop: 0 }, 'slow');
	});
	
	
	resizeBubbles();
	$(window).resize(function() {
		resizeBubbles();
	});

});
$("h2.in").each(function() {
        var wordArray = $(this).text().split(" ");
        wordArray[wordArray.length-2] += "&nbsp;" + wordArray[wordArray.length-1];
        wordArray.pop();
        $(this).html(wordArray.join(" "));
});


function resizeBubbles() {
	var bubbleWidth = $('.skill-bubble').css('width');
	$('.skill-bubble').css('height', bubbleWidth);
	$('.skill-bubble span').css({'width': bubbleWidth, 'height': bubbleWidth});

}
