$('html').addClass('js');

HS = {
    initSearchBox: function() {
		// Add placeholder text if browser does not support HTML5 forms
		$('ul li#search #s').placeholder();
    },

    initPinboardSlides: function() {

		// Requires Cycle plugin (load in pinboard.php)
        $('#header .banner-slides').show();
		$('.banner-slides div.slide').css('width','100%');

		$('#header .banner-slides').cycle({ 
			timeout: 5000,
			slideResize: 0,
		    pause: 1
		});
    },
    isWindowSizeSmall: false,

    initAttribution: function() {
        $('#header .attribution').hide();

        $('#header .cc').mouseenter(function() {
            $('#header .attribution').fadeIn('slow');
        });
        $('#header .attribution').mouseleave(function() {
            $(this).fadeOut();
        });
    },

    initOurPeople: function() {
        $('ul.our-people li.headshifter:nth-child(3n)').addClass('nth-child');

		var isiPad = navigator.userAgent.match(/iPad/i) != null;
		var isiPhone = navigator.userAgent.match(/iPhone/i) != null;

		if (isiPad == false) {
			if (isiPhone == false) {
				$('ul.our-people li.headshifter').mouseenter(function() {
		            $(this).find('.name').stop(true, true).hide();
		            $(this).find('.interests').stop(true, true).fadeIn(500);
		        },
		        function() {
		            $(this).find('.name').stop(true, true).show();
		            $(this).find('.interests').stop(true, true).fadeOut(500);
		        }).mouseleave(function() {
		            $(this).find('.name').stop(true, true).show();
		            $(this).find('.interests').stop(true, true).fadeOut(500);
		        },
		        function() {
		            $(this).find('.name').stop(true, true).hide();
		            $(this).find('.interests').stop(true, true).fadeIn(500);

		        });
			}
		}
    },

    initListColumns: function() {
        // Category/Tag/Archive grid columns. Requires jquery.easyListSplitter.js
		if ($(window).width() > 615) {
        	var colNum = 3;
		} else {
        	var colNum = 2;			
		}

        $('.list-columns').easyListSplitter({
            colNumber: colNum
        });
        $('.wp-tag-cloud').easyListSplitter({
            colNumber: colNum
        });
    },

    initCodeExpand: function() {
        $('.post .wp_syntax').mouseenter(function() {
            if ($(window).width() > 1025) {
                $(this).stop(true, true).animate({
                    width: '685',
                    marginLeft: '-220px'
                },
                400);
            }
        });
        $('.post .wp_syntax').mouseleave(function() {
            if ($(window).width() > 1025) {
                $(this).stop(true, true).animate({
                    width: '465',
                    marginLeft: '0'
                },
                400);
            }
        });
    },

	initSlideshow: function() {
		if ($('#slideshow-thumbnails')) {

			$('#slideshow-thumbnails a img').live('click',function() {

				$('#slideshow-thumbnails a').removeClass("active");
				$(this).parent().addClass("active");

				var originalSrc = $(this).attr("src");
				var newSrc = originalSrc.split('-225x165')[0];
				var newExt = originalSrc.split('-225x165')[1];

				var fullSrc = newSrc + newExt;

				$("#slideshow-images img").fadeOut(function(){
					$(this).attr("src",fullSrc);
					$(this).fadeIn();
				});

				return false;
			})
		}
	}
};

$(document).ready(function() {
	HS.initSearchBox();
	HS.initAttribution();
	HS.initOurPeople();
	
	if ($(window).width() > 360) {
		HS.initListColumns();
	}
})

jQuery(function($) {
	//	Patch for Mobile Safari's orientation change bug
	//	Based on http://www.blog.highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/
    if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
		$('meta[name="viewport"]').attr('content','width=device-width, minimum-scale=1.0, maximum-scale=1.0');
		document.body.addEventListener("gesturestart",function() {
			$('meta[name="viewport"]').attr('content','width=device-width, minimum-scale=0.25, maximum-scale=1.6');
		}, false);
	}
});
