// UNIVERSAL JS
$(function() {
	document.documentElement.className = document.documentElement.className.split(' noJS')[0];

	$('hgroup').click(function() {
		window.location = 'http://www.nohodental.com/';
	});

    try {
		psJS[document.documentElement.id]();
	} catch(e) {}
});

// PAGE-SPECIFIC JS
var psJS = {
    'gallery': function() {
		var cssAnim =
			document.documentElement.style.webkitTransition !== undefined
			|| document.documentElement.style.MozTransition !== undefined
			|| document.documentElement.style.OTransition !== undefined
			|| document.documentElement.style.msTransition !== undefined
			|| document.documentElement.style.transition !== undefined;
		
		if(cssAnim) {
			$('#gallery-pane').addClass('css-anim');
		}

		var $galImgs = $('#gallery-pane > img'),
			$galThumbs = $('#gallery-nav > span > img');
    	$galThumbs.live('mouseover', function() {
			var $newImage = $galImgs.eq($galThumbs.index(this));
			if(!$newImage.hasClass('active')) {
				if(!cssAnim) {
					$galImgs.filter('.active').animate({
						"left": "-"+$(this).width()+"px",
						"opacity": 0
					}).removeClass('active');
					$newImage.css({
						"left": "100%",
						"top": ($newImage.parent().height() - $newImage.height())/2 + "px"
					}).animate({
						"left": ($newImage.parent().width() - $newImage.width())/2 + "px",
						"opacity": "1"
					}).addClass('active');
				} else {
					$galImgs.filter('.active').css({
						"-webkit-transform": "translate3d(-"+$(this).width()+"px, 0, 0)",
						"-moz-transform": "translate(-"+$(this).width()+"px, 0)",
						"-o-transform": "translate(-"+$(this).width()+"px, 0)",
						"transform": "translate(-"+$(this).width()+"px, 0)",
						"opacity": 0
					}).removeClass('active');
					$newImage.css({
						"-webkit-transition-duration": "0",
						"-webkit-transform": "translate3d(100%, 0, 0)",
						"-moz-transition-duration": "0",
						"-moz-transform": "translate(100%, 0)",
						"-o-transition-duration": "0",
						"-o-transform": "translate(100%, 0)",
						"transition-duration": "0",
						"transform": "translate(100%, 0)",
						"top": ($newImage.parent().height() - $newImage.height())/2 + "px"
					})
					$newImage.css({
						"-webkit-transition-duration": "0.3s",
						"-webkit-transform": "translate3d("+($newImage.parent().width() - $newImage.width())/2+"px, 0, 0)",
						"-moz-transition-duration": "0.3s",
						"-moz-transform": "translate("+($newImage.parent().width() - $newImage.width())/2+"px, 0)",
						"-o-transition-duration": "0.3s",
						"-o-transform": "translate("+($newImage.parent().width() - $newImage.width())/2+"px, 0)",
						"transition-duration": "0.3s",
						"transform": "translate("+($newImage.parent().width() - $newImage.width())/2+"px, 0)",
						"opacity": "1"
					}).addClass('active');
				}
			}
		});
		$(window).load(function() {
			$galThumbs.eq(Math.floor(Math.random()*$galThumbs.length)).trigger('mouseover');
		});
    }
}

// NAMESPACES/GLOBALS FOLLOW BELOW
