
$(document).ready(function () {

    // Keep nav current
    $("#menu li a, #links a").live('click', function () {
        $("#menu li a").removeClass("active", 1000);
        $(this).addClass("active", 1000);
    });

    // Ajax logic
    $(function () {
        AjaxContent.init({
            containerDiv: "#main",
            contentDiv: "#main"
        }).ajaxify_links("#menu a, footer #links a");
    });

    // Pick a random background
    $.backstretch("img/random/rotator.php", {
        speed: 500
    });

    // Shadowbox setup
    Shadowbox.init();
    $(".gallery li a, a[rel^='shadowbox']").live('click', function (event) {
        Shadowbox.open(this);
        return false;
    });
	
// Support for non-placeholder support browsers
$('input, textarea').livequery(function(){
  $(this).placeholder();
});

    // Smmooth Scrolling
    $('a[href*=#]').live('click', function () {
        if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({
                    scrollTop: targetOffset
                }, 600);
                return false;
            }
        }
    });

// End of DOM READY

});


// Nav Ajax
var AjaxContent = function(){
    var container_div = ''; 
	var content_div = ''; 
	return {
		getContent : function(url){
			$(container_div).animate({opacity:0}, //Turn the opacity to 0
					function(){ // the callback, loads the content with ajax
						$(container_div).load(url+" "+content_div, //only loads the selected portion
						function(){						   
						   $(container_div).animate({opacity:1}); //and finally bring back the opacity back to 1
					}
				);        
			});
		},
		ajaxify_links: function(elements){
  				$(elements).live('click', function() {
				AjaxContent.getContent(this.href);
				return false; //prevents the link from being followed
			});
		},
		init: function(params){ //sets the initial parameters
			container_div = params.containerDiv; 
			content_div = params.contentDiv;
			return this; //returns the object in order to make it chainable
		}
	}
}();
// # Nav Ajax



// Scroll to menu
function goToByScroll(id) {
    $('html,body').animate({
        scrollTop: $("#" + id).offset().top
    }, 600);
    return false
}


// Hide iPhone URL bar
addEventListener("load", function () {
    setTimeout(hideURLbar, 0);
}, false);

function hideURLbar() {
    window.scrollTo(0, 0);
}



