/* Author:

*/

var myElements = [".home",".about",".portfolio",".download",".contact"];
var newTarget = ".home";
var offset = 125;

$(document).ready(function() { 
  resizeTarget(newTarget);
  $("#content").load('home.html');
});

$(".home").click(function() {
	resizeTarget(".home");
	$("#content").hide();
	$("#content").load('home.html #content');
	$("#content").show(500);
});
$(".about").click(function() {
	resizeTarget(".about");
	$("#content").hide();
	$("#content").load('about.html #content');
	$("#content").show(500);
});
$(".portfolio").click(function() {
	resizeTarget(".portfolio");
	$("#content").load('portfolio.html #content');
	$("#content").show(500);
});
$(".download").click(function() {
	resizeTarget(".download");
	$("#content").hide();
	$("#content").load('download.html #content');
	$("#content").show(500);
});
$(".contact").click(function() {
	resizeTarget(".contact");
	$("#content").hide();
	$("#content").load('contact.html #content');
	$("#content").show(500);
});

function resizeTarget(target) {
	
	newTarget = target;
				
	var w = $(document).width();
	var h = $(document).height();
	var n = 1;
	
	for (i=0;i < myElements.length; i++) {		
		if(myElements[i] != target) {
			$(myElements[i]).animate({ height: 24 }, 500 );
			
		} else {
			$(myElements[i]).animate({ height: h - offset }, 500 );
			n = n + i;
		}	
	}
	
	$("#content").height(h-150);
	$("#content").css({
        top: n*25,
        left: 0
    })
}
// RESIZE
(function($,sr){
// debouncing function from John Hann
  // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
  var debounce = function (func, threshold, execAsap) {
      var timeout;
 
      return function debounced () {
          var obj = this, args = arguments;
          function delayed () {
              if (!execAsap)
                  func.apply(obj, args);
              timeout = null; 
          };
 
          if (timeout)
              clearTimeout(timeout);
          else if (execAsap)
              func.apply(obj, args);
 
          timeout = setTimeout(delayed, threshold || 100); 
      };
  }
	// smartresize 
	jQuery.fn[sr] = function(fn){  return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };
 
})(jQuery,'smartresize');
 
 
// usage:
$(window).smartresize(function(){  
  // code that takes it easy...
  //location.reload(); 
});
