(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:3,interval:3,timeout:200};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
//enable console
$.enableConsole = false;
$.fn.console = $.console = function(method){
	if (window.console && console[method] && $.enableConsole)
		console[method].apply(this, [].splice.call(arguments,1))
	return this;
}
$.enableConsole = true;
// donothing
function donothing() {

}

function init_nav (){
	$('.mainnav li.nav_left').find('ul.subnav').each( function(){
		var w = $(this).prev('a').width();
		$(this).hide();
		$(this).css({'left':-(600-w)}).show();
	});	
}

var rotator = function() {}
	rotator.prototype = {
	initialize: function(controls, viewport) {
		this.controls = controls || "div.rotator .controls";
		this.prev = $(this.controls).children("a.btn_left");
		this.next = $(this.controls).children("a.btn_right");
		this.viewport = viewport || "div.rotator";
		this.items = $(this.viewport).children("ul").children("li");
		this.interval = 4000;
		this.index = 0;
		var Scope = this;
		this.timer = setInterval(function() { Scope.nextImage(); }, this.interval);
		this.jsActive(this.controls, this.items);
		this.eventHandlers(this.prev, this.next);
	},
    
    jsActive: function(controls, items) {
        $(controls).show();
        $(items).not(":first").hide();
    },
    
    fadeIn: function(index) {
        this.items.eq(index).fadeIn();
    },
    
    hide: function(index) {
        this.items.eq(index).hide();
    },    
    
    nextImage: function() {
        this.hide(this.index);
        this.index++;
        if(this.index >= this.items.length) {
            this.index = 0;
        }
        this.fadeIn(this.index);
    },
    
    prevImage: function() {
        this.hide(this.index);
        this.index--;
        if(this.index <= -1) {
            this.index = this.items.length - 1;
        }
        this.fadeIn(this.index);
    },
    
    eventHandlers: function(prev, next) {
        var Scope = this;
        $(prev).bind("click",function() {
            Scope.prevImage();
            clearInterval(Scope.timer);
            return false;
        });
        $(next).bind("click",function() {
            Scope.nextImage();
            clearInterval(Scope.timer);
            return false;
        });
    }
};

function init_gallery() {
	var e=$('.gallery table');	
	var img = e.find('img.big');
	e.find('.sw').each( function(){
		var btn=$(this);
		btn.find('a').attr('href','javascript:donothing();');
		btn.click( function(){
			img.animate({opacity:0},400,function(){				
				img.attr({src:btn.find('img').attr('src')});
				img.animate({opacity:1},400);
			});
		})
		btn.hoverIntent(
				function(){
					img.animate({opacity:0},200,
					function(){				
						img.attr({src:btn.find('img').attr('src')});
						img.animate({opacity:1},200);
					})
				;},
				function(){
					
			});
	})
}

function init_gallery_box (){
	$("div.galerie a").fancybox(); 	
	//$("div.galerie a").attr('href','javascript:donothing();');
}


// -------------------------------------------------------//
// decrypt link functions by georg.hemprich@hafenkrone.de //
//--------------------------------------------------------//

// decrypt help function										
function decryptCharcode(n,start,end,offset) {
	n = n + offset;
	if (offset > 0 && n > end)	{
		n = start + (n - end - 1);
	} else if (offset < 0 && n < start)	{
		n = end - (start - n - 1);
	}
	return String.fromCharCode(n);
}
// decrypt string
function decryptString(enc,offset) {
	var dec = "";
	var len = enc.length;
	for(var i=0; i < len; i++)	{
		var n = enc.charCodeAt(i);
		if (n >= 0x2B && n <= 0x39)	{
			dec += decryptCharcode(n,0x2B,0x3A,offset);	// 0-9 . , - + / :
		} else if (n >= 0x40 && n <= 0x5A)	{
			dec += decryptCharcode(n,0x40,0x5A,offset);	// A-Z @
		} else if (n >= 0x61 && n <= 0x7A)	{
			dec += decryptCharcode(n,0x61,0x7A,offset);	// a-z
		} else {
			dec += enc.charAt(i);
		}
	}
	return dec;
}
// decrypt spam-protected links
function linkTo_UnCrypt(s)	{
	location.href = decryptString(s,-1);
}
