/* Copyright (c) 2009 Jurriaan Topper (iksi.tv) */

(function($) {

 function pageload(hash) {

  if (!hash) {
	hash = "/home";
  }
  var vars = hash.split("/");
  var _href = vars[1];
  if (vars[2]) {
	 var _check = vars[2].substr(0,4);
	 if (_check == "page") {
		// page
		var _page = vars[2].substr(4,9);		
		var _url = "files/load/"+_href+".php?page="+_page;
	 } else {
		// id
		var _page = vars[3].substr(4,9);
		var _url = "files/load/"+_href+".php?serie="+vars[2]+"&page="+_page		
	 }

    $.ajax({
     url: _url,
     cache: false,
     success: function(html){
	  $("#"+_href+" > .holder > .body > .content").html(html);
	  setBlocks(_href);
     }
    });
  }

  // scroll to the right position on the page
  //if (!vars[3]) {
   // not while browsing photos
   //$.scrollTo("1200",600);
   $.scrollTo($('#'+_href),600);
  //}
  // $("#content").css("display","none");
  //   $.ajax({
  //    url: "files/pages/"+_href+".php",
  //    cache: false,
  //    success: function(html){
  //     $("#content").html(html);
  //     $("#content").css("display","block");                   			  
  //    }
  //   });  				    
  // document.title = " _ " + hash;
	$('#'+_href).parent().parent().parent().attr("id","body_"+_href);
	
	// $('a.back').unbind('click');	
	// $("a.back").click(function(event){
	//  	event.preventDefault();		
	// 	alert("back!");
	// });
	
 }	
	
 $(document).ready(function() {
  
  setBlocks();


  // Initialize history plugin.
  $.history.init(pageload);

  $("a").live("click",function(){
   var hash = $(this).attr("rel");
   if (hash) {
   	$.history.load(hash);
   	return false;
   }
  });
   
 });

})(jQuery);

function setBlocks(input) {
 if (!input) {
  // set all
  var divs = ["news","events","about","music","photos","videos","contact","discography"];
 } else {
  // set specific
  var divs = [input];
 }
 for (var i=0; i < divs.length; i++) {
  var div = divs[i];
  var set = $("#"+div+" > .holder > .body > .content").height()+20;
  $("#"+div+" .body .left").css("height",set+"px");
  $("#"+div+" .body .right").css("height",set+"px");
 };
}