(function($){	
	
 function pageload(hash) {

  if (!hash || hash == "/" || hash == "/twindex.php") {
   hash = "/news";
  }

  var vars = hash.split("/");
  var _href = vars[1];

  if (_href.substr(0,4) == "page") { // old page link fix
   var vars = ("/news/"+_href).split("/");
   var _href = vars[1];
  }
 if (Number(_href)) {
  var vars = ("/news/"+_href).split("/");
  var _href = vars[1];
 }

  if (vars[2]) {

   // second variable
   var _check = vars[2].substr(0,4);

   if (_check == "page") {
    // page
    var _page = vars[2].substr(4,9);		
    var _url = "files/ajax/"+_href+".php?page="+_page;
    var navigate_url = "files/ajax/navigate.php?page="+_page;
   } else {
    // id
    var _url = "files/ajax/"+_href+".php?id="+vars[2];		
    var navigate_url = "files/ajax/navigate.php?id="+vars[2];
   }

   if (vars[3]) {
    var _check = vars[3].substr(0,4);
    if (_check == "page") {
     // page
     var _page = vars[3].substr(4,9);		
     var _url = _url+"&page="+_page;
     var navigate_url = navigate_url+"&page="+_page;
    } else {
     var _url = _url+"&id="+vars[3];
     var navigate_url = navigate_url+"&id="+_vars[3];
    }		
   }

  } else {
   // just the page
   var _url = "files/ajax/"+_href+".php";	
   var navigate_url = "files/ajax/navigate.php";	
  }	
  // set loading
  $(".content").css("display","none");
  $(".content").html("<div class=\"loading\"><p>loading...</p></div>");
  $('.content').attr("id","content_loading");
  $(".content").css("display","block");
  setShadows();

  // set title

  // ajax request
  $.ajax({
   url: _url,
   cache: false,
   success: function(html){
    // set content
    $(".content").css("display","none");	
    $(".content").html(html);
    $('.content').attr("id","content_"+_href);  
    $(".content").css("display","block");
    setShadows();
		
    // for new ajax & mp3 links:
    $("a[class='mp3']").unbind("click");	
    $("a[class='mp3']").click(function(){
     var file = this.rel;
     var title = this.title;
     loadList(file,title);
     return false;
    });
    $("a[class='ajax']").unbind("click");
    $("a[class='ajax']").click(function(){
     var hash = this.rel;
     hash = hash.replace(/^.*#/, '');
     $.historyLoad(hash);
     return false;
    });

   }
  });

  // set navigation
  // through ajax request...

  $.ajax({
   url: navigate_url,
   cache: false,
   success: function(html){
    // set content
    $("#navigate").css("display","none");	
    $("#navigate").html(html);
    $("#navigate").css("display","block");

    // for new ajax
    $("a[class='ajax']").unbind("click");
    $("a[class='ajax']").click(function(){
     var hash = this.rel;
     hash = hash.replace(/^.*#/, '');
     $.historyLoad(hash);
     return false;
    });

   }
  });

 }
	
$(document).ready(function() { 

  // init player
  createPlayer();

  $("a[class='mp3']").click(function(){
   var file = this.rel;
   var title = this.title;
   //alert(file+" "+title);
   loadList(file,title);
   return false;
  });

  /* in case there is a form */
  $('#mailinglist').ajaxForm({ 
   url: 'files/php/mailinglist.php',
   target: '#response', 
   success: function() { 
    $('#mailinglist').resetForm();                           
   } 
  });

  // clear input on focus
  $('.input').focus(function() {
   if($(this).val()==$(this).attr('title')){
    $(this).val('');
   }
  });
  $('.input').blur(function() {
   if($(this).val()=='') {
    $(this).val($(this).attr('title'));
   }
  });
  //
	
  // Initialize history plugin.
    // The callback is called at once by present location.hash. 
    $.historyInit(pageload, "jquery_history.html");
    // set onlick event for buttons
    $("a[class='ajax']").click(function(){
     // 
     var hash = this.rel;
     hash = hash.replace(/^.*#/, '');
     // moves to a new page. 
     // pageload is called at once. 
     // hash don't contain "#", "?"
     $.historyLoad(hash);
     return false;
    });

    // default beginpage or google link
    var _hash = window.location.toString().split(".net");
    _hash = _hash[1].replace(/^.*#/, '');
    pageload(_hash);

});

})(jQuery);

function setShadows() {
  var set = $("#body > .middle").height();
  $("#body > .left, #body > .right").css("height",set+"px");	
}


function obfuscate(coded,title) {
 cipher = "aZbYcXdWeVfUgThSiRjQkPlOmNnMoLpKqJrIsHtGuFvEwDxCyBzA1234567890"
 shift=coded.length
 link=""
 for (i=0; i<coded.length; i++){
  if (cipher.indexOf(coded.charAt(i))==-1){
   ltr=coded.charAt(i)
   link+=(ltr)
  } else {     
   ltr = (cipher.indexOf(coded.charAt(i))-shift+cipher.length) % cipher.length
   link+=(cipher.charAt(ltr))
  }				
 }
 document.write("<a href='mailto:"+link+"'>"+title+"</a>");
}
