(function($){
 var _Ajax = {
  withMethod:function(method, data, callback, dataType){
   if(jQuery.isFunction(data)){
    type = callback;
    callback = data;
    data = {};
   }
   return jQuery.ajax({
    type:method,
    url:"/includes/apps/ajax_func.php"+sidaddq,
    data:data,
    success:callback,
    dataType: dataType,
    async: false
   });
  }
 };
 jQuery.extend({
  head: function(data, callback){
   return _Ajax.withMethod("POST", data, callback);
  }
 });
})(jQuery);

(function($, jQuery) {

 var _LinkHandler = function( target, options ) {
  this.target = target;
  this.options = options;
  if(this.target.attr("href").substring(0,1) != "#" && !this.target.hasClass("nologin")){
   this.checkHeader();
  }else
  return true;
 }
 $.extend(_LinkHandler.prototype, {
  checkHeader:function(){
   var headData = new Object();
   headData.action = "getHead";
   headData.url = this.target.attr("href");
   headData.location = window.location.href;
   headData.protokoll = window.location.protocol;
   headData.host = window.location.host;
   if(this.target.attr("rel")=="prettyPhoto"){
	   return true;
   }
   
   var newWindow = {};
   var lochref = decodeURIComponent(this.target.attr("href"));
   switch($.head(headData).responseText){
    case "200":
    case "302":	
	 if(this.target.attr("target")){
 	  newWindow = window.open(lochref, this.target.attr("target"));
 	  newWindow.focus();		 
	 }else
	 window.location.href = lochref;
	 
     break;
    case "401":
     this.makeLogin(this.target);
     break;
     case "404":
      window.location.href = "/error/404.htm";
     break;

    default:
     this.makeLogin(this.target);
   }
   return true;
  },
  makeLogin:function(target){

   $.extend($.prettyPhoto,{
    openAjaxLogin:function(typ,loginUrl,desc){
     this.open(loginUrl+typ,"",desc);
    }
   });
   var litd_prettyPhoto = function(target, options){
    this.options = options;
    this.target = target;
    this.loginURL = "/open/login.html?ajax_data="+this.options;
    $.prettyPhoto.openAjaxLogin("#ajax?default_height=338",this.loginURL);
   }
   new litd_prettyPhoto($(this),this.target.attr("href"));
   return true;
  }
 });
 jQuery.fn.litdLinkHandler = function( options ) {
  options = $.extend( {}, jQuery.fn.litdLinkHandler.defaults, options );
	$(this).bind('click',function(){
	if(!$(this).hasClass("nologin")){
	   new _LinkHandler($(this),options);
	   return false;
	}else
		return true;
  });
 };
})(jQuery, jQuery);

$(document).ready(function(){						   	 	
 $("a").litdLinkHandler();
});
