/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.

 *  depends on: preload.css.js, jquery.easing.js
 * 
 *   
 *   
 *    
 *     
 *      
 *       
 *        
 *
 */


/*
 * Core Plugins for lumenphoto.de - http://lumenphoto.de
 *
 * Open source under the BSD License.
 * Copyright © 2010 Thomas Appel
 * All rights reserved.
*/

// rapid degug call //

//function debug(statement){
    
  //  window.console && console.log(statement);

  //  return this;

//};



// shutter effect on Frirends an making of

// binds an mouseover / mouseout handler on the wrapper div of all grid images

//(function($){
//
//    $.fn.shutter = function(options) {
//
//        var defaults = {
//        // default options
//
//        },
//        // extend options
//        opts = $.extend({},defaults, options),
//
//        shutter = $(document.createElement("div")).css({opacity:0.5}).addClass('shutter')[0],
//
//        images = this.find('img').after(shutter),
//
//        shutterDiv = images.next('div');
//
//        debug(shutter)
        
        
        // shutter

//function animation(obj,amount,time){
//
//    $(obj).not(':animated').stop().animate({width:amount},time);
//
//    return this;
//
//};
//
//        // add the shutter to all images
//
//        this
//
//            .bind('mouseover.shutter',function(e){
//
//                var a = $(e.target).filter(shutterDiv)[0];
//
//                    a && new animation(a,0,250);
//
//            })
//
//            .bind('mouseout',function(e){
//
//                var b = $(e.target)[0];
//
//
//                    b && $(b.nextElementSibling).animate({width:100+'%'},250);
//
//
//            });
//
//
//
//        return this;
//
//
//
////code here
//
//    };
//})(jQuery);




(function($){

    $.fn.shutter = function(){

    var shutter = '<div class="shutter"/>';

    return this.each(function(){

        var gridImg = $(this).find('img');

        gridImg.after(shutter);

        var shutterDIV = $(this).find('.shutter');

        shutterDIV.css({opacity:0.5});

        gridImg.css({opacity:0.5});

       // $(this).bind('mouseenter',funca).bind('mouseout',funcb);

$(this).hover(funca,funcb);

function funca(){

        $(this).find('.shutter').stop().animate({width:0},250);

        gridImg.fadeTo(250,1);
    };

function funcb(){
        
        //$(this).unbind('mouseout');

        $(this).find('.shutter').stop().animate({width:100 + "%"},250);

        gridImg.fadeTo(250,0.5);
    };

});

};

})(jQuery);


// images scale


(function($){

 $.fn.imgScale = function(options){

        var defaults = {

            grid : 1,

            offset: 0,

            margin: 4

        },

            settings = $.extend({},defaults,options);

            return this.each(function(){

         //   if (settings.grid <= 1) {settings.margin = 0};

            settings.grid <= 1 ? settings.margin = 0 : settings.wraper = $(this).find(' li > div');

                var $this = $(this),
                
                    thisHeight = Math.round($this.innerHeight()/settings.grid - (settings.offset/settings.grid) - settings.margin),

                    thisImg    = $this.find('img'),

                    ratio,imWidth,imHeight;

        $.each(thisImg,function(){

// if there's a height/width attribute take these values, else parse image heights/widths

                    var thisImgHeight   = $(this).attr('height') !== 0 ? $(this).attr('height') : $(this).innerHeight(),

                        thisImgWidth    =  $(this).attr('width') !== 0 ? $(this).attr('width') : $(this).innerWidth(),

                        ratio           = thisImgWidth/thisImgHeight,

                        newWidth        = Math.round(ratio*thisHeight);

                      $(this).attr({height:thisHeight,width:newWidth});

                      settings.grid > 1 && settings.wraper.css({width:(newWidth*settings.grid)+(settings.margin*settings.grid)});

                    });

            });

    };


})(jQuery);


(function($){

    $.fn.menuFade = function (){

        return this.removeClass('menu').find('a').append('<span class="hover" />').each(function(){

        var $span = $('> span.hover', this).css({opacity:'0'});

        $(this).hover(function(){

        $span.stop().fadeTo(750,1.0);

	}, function(){

            $span.stop().fadeTo(750,0.0);

            });

        });
    };
})(jQuery);


// preload main images

(function($){


$.fn.preloader = function(options,callback){

    var defaults = {

        imgArr : '',

        progressBar:'',

        progressBarWrap : $(),

        progressCounter:'#prc',

        callback : function(){}

    };

    
    
        var settings = $.extend({},defaults, options),

        callback = settings.callback;

        var loadBarWrap = $(settings.progressBarWrap),

        loadBar = $(settings.progressBar),

        counter = $(settings.progressCounter),

        arr = settings.imgArr,

        

        trigger = true,
        
        
        lbw;

        arrLength = arr.length, i = 0;

//  alert('preloader')




if (arr.length <= 0){

    altCallback();

};

if ($.isEmptyObject({})){

        loadBarWrap = loadBar.parents().filter('a')

};

loadBar.addClass('loading');



var icacheLen = $('.imgCache').length;



for (var h = 0;h<arr.length;++h){
		
	checkCache(arr[h], h);
		
	};



function checkCache(img,n){

for (var i = 0;i<icacheLen;++i){
	
		$($('.imgCache')[i]).find('img')[0].src === img.src ? trigger = false : null;
	
	};

    return trigger;

    };


function progress(){

	var cache = '<span class="cache imgCache">',

    	cacheStr ='',

	    prog = 0;

    

$.each(arr,function(i,e){
	


// loading images

	var n  = i,

    	img = new Image(e.height,e.width),

//	    src = $(arr[i]).attr('src'),

	    src = arr[i].src,

    	speed = Math.floor(loadBarWrap.innerWidth()/arr.length)+30;

	    $(img).load(function(element){

		$(this).hide().css({'display':'block'});

// init image cache…

    cacheStr += '<img class="cache" src="'+ src +'"/>';

// progressbar stuff

var run = loadBarWrap.innerWidth()/arrLength;

    loadBar.animate({width: run * ++prog}, speed,function(){

        counter.text(Math.round((100/loadBarWrap.innerWidth())*loadBar.innerWidth()));

// all images loaded

if (loadBar.innerWidth() >= loadBarWrap.innerWidth()){

    

    loadBar.removeClass('loading').addClass('loaded');

// fire callback & append cache



    cache += cacheStr + '</span>';

    $(cache).appendTo('body');

    $(callback);

};
    });

        })
        /*
              .error(function(){

                 alert('ERROR 8: image could NOT be loaded (PEPBCAC EXCEPTION ERROR)');

              })*/

              .attr({'src':src});
        
        });
    };



trigger && $(settings.progressBar)[0] ? setTimeout(progress, 10) : altCallback();

!$(settings.progressBar)[0] ? emptyCallback():null;

//        if (!$(settings.progressBar)[0]){
//
//            emptyCallback();
//
//        };


function altCallback(){

            counter.empty();

        loadBar.animate({width:100+'%'},620,'easeInOutExpo',function(){

            $(this).removeClass('loading').addClass('loaded');

        $(callback);
        });

};

function emptyCallback(){



        settings.callback.call(this);


};


return this;
};

})(jQuery);

/* carousel scroller
------------------------------------------------------------------------------------
------------------------------------------------------------------------------------*/
/*
**
*
* Since jQuery.carScroller is an implementation of the jQuery smScroll Plugin (to be released in 2010)
* the documentation can be foud there.
*
*
*/

(function($){

    function scroller(opts){

        var container = opts.self,

            ul = container.find('ul:first'),

            self = this,

            eventData,

            ch,

            my,targetY,tempY,

            tc,

            v=0,

            speed = 0,

            scOffset,

            toTop, toBottom,

            scrollTimer,            
            
            stop = false,
            
            initStop = opts.scrollSpeed,
            
            initStart = 0,

			a, // hover image

			tempspeed,
            
			timerSpeed = opts.timerRate,
			
			cOffsetTop;
            
            


        this.scroll = function(){
        	
        	

        var dir;
        
        /*

         if (my < tempY)
    
            { dir = 'up'  
            
            container.removeClass('still');
            
            }

       else if  (my > tempY)

            { dir = 'down'  
            
            container.removeClass('still');
            //container.removeClass('still').removeClass('up').addClass('down');
            
            }

       else if (my === tempY)

            { dir = 'still'  
            
            //container.removeClass('up').removeClass('down').addClass('still');
        
			container.addClass('still');
            
            };
        

            */

            targetY = my - container.offset().top;

            ch = container.height(),

            tc = Math.floor(ch/2);

            toTop = targetY < tc;

            toBottom = targetY > tc;

            // defining scroll zones

           /*

           var zone = {

                up1: targetY < tc/3,                    // upper third
                up2: targetY < tc/2 && targetY > tc/3,  // upper half
                up3: targetY > tc/2 && targetY < tc,    // upper zone

                down1:targetY > tc && targetY < tc+tc/2,
                down2:targetY > tc+tc/2 && targetY < ch-tc/3 ,
                down3:targetY > ch-tc/3 && targetY <= ch


            };

            */
            
    	        scOffset = Math.abs((ul.offset().top) - cOffsetTop);



			speed = (targetY-tc)/tc;
                
                stop && (initStop += -1);
                
                !stop && (initStop = Math.min(16,++initStart));                  

                v = scOffset+(initStop*speed) >> 0.1;
                

				if (v >= ul.height()-ch){

                	v = ul.height()-ch;

                };

                if (v <=0){

                	v = 0;

                };
  


        container.scrollTop(v);

        tempspeed = speed; // getting up/down direction

        scrollTimer = setTimeout(function(){

                self.scroll();
                tempY = my;


            },timerSpeed);

        }

        

        container.bind('mousemove.carScroller',this,function(e){
        	
        	        if (container.is(':animated')){
        	
        	return false;
        	
        	}
        	
		else {
            my = e.pageY;
		}
            
        })

            .bind('mouseenter.carScroller',this,function(e){
            	
            	stop = false;
            	initStop = opts.scrollSpeed;
            	initStart = 0;
            	
            	cOffsetTop = container.offset().top;
                
                my = e.pageY;

                eventData = e.data;

                eventData.scroll();

                return;

            })

            .bind('mouseleave.carScroller',this,function(e){
            	
            	stop = true;

                setTimeout(function(){

                    clearTimeout(scrollTimer);

                },500);
                
//            if ($.browser.msie) {
//            	
//            	   	return false;
//            	
//            	};

            });

        if (opts.hoverItems){ // my be we should attach this directly to the image itself
				container.bind('mouseover.carScroller',this,function(e){
                a = $([e.target,e.target.parentNode]).filter('img')[0];
                if (a)
                    $(a).fadeTo(350,1)
            })
            .bind('mouseout.carScroller',this,function(e){            
                if (a)
                    $(a).not('.current').stop(true,false).fadeTo(350,0.5);

            });

            function filter (){                
                return this.nodeName.toLowerCase() === 'img' && !!$(this).parents('li:not(.active)')[0];
            };
		}
/*
        opts.images.hover(function(){

            $(this).fadeTo(250,1)

        },function(){


            $(this).not('.current').fadeTo(250,0.5)

        });

*/



        return this;
    };

    $.fn.carScroller = function(options) {

        var defaults = {

	        self :  this,
	        
	        scrollSpeed : 12

        },

        opts = $.extend({},defaults, options);

        opts.namespace = 'carScroller';

        opts.images = this.find('img');
        
        $.browser.msie && (function(){
        	
        	        	opts.hoverItems=false;
			        	opts.self.scrollTop(0);        	
        	
        	})();


        opts.self.data('scroller',new scroller(opts));
        


    return this;


    };
})(jQuery);



/* FlipBook
------------------------------------------------------------------------------------
------------------------------------------------------------------------------------*/

(function($){

    function kill (obj){


        obj.unbind('mousemove.flipBook');

        obj.unbind('mouseenter.flipBook');

        //$('*').unbind();

    };


    function loadImges(opts,callback){

        var m=0 ,arr =opts.images, ch = [], icache ='<span class="cache" id="flipBookCache_'+opts.currentID+'">';

    // init loading class

        opts.canv.addClass('loading')

        for  (var i = 0;i<arr.length;++i){

            new loadSingleImage(i);

        };

        function loadSingleImage(index){

                 var img = new Image();

                    img.src = arr[index];

                    $(img).load(function(){

                        ch[index] = this;

                        var h = this.naturalHeight ?  this.naturalHeight : this.height,

                            w = this.naturalWidtht ?  this.naturalWidth : this.width;

                            this.setAttribute('height',h);

                            this.setAttribute('width', w);

                        icache += '<img src="'+arr[m]+'" />';

                        ++m;

                    // remove loading class

                        m === arr.length && (function(){


                        opts.canv.removeClass('loading')

                        icache += '</span>';

                       !$('body').find('#flipBookCache_'+opts.currentID)[0] && $('body').append(icache);

                        callback.call(this,$(ch));

                    })();

                });

        };

    };


    function createObj (_node, _id,_class,_attr){

        var obj = document.createElement(_node),

            i = 0;

            _id && (obj.id = _id);

            _class && (obj.className = _class);

            _attr && $(obj).css(_attr);

            return $(obj); // return jQuery Object

    };

    function animation (obj,i,o,dur,easing,callback){

        obj instanceof jQuery === false && (obj = $(obj));

        var w = i? 100+'%':0,

            opc = i? 1:0,

            parent = $(obj[0].parentNode);

            parent.css('position') === 'static' && parent.css({'position':'relative'});


            this.slip = function(){

            obj.animate({width:w,opacity:opc},dur,easing,function(){

                callback.call(this,obj);

            });


            }


            i && this.slip();

            o && obj.find('*').fadeOut() && setTimeout(this.slip,500);



    };



    function main (opts){

    var x,

        self = this,

        m,

        s,

        mx, eventData, initTimer;




        var zOnE = 100/opts.images.length,

            zon0 = 0,

            idx = 0,

            tmp = 0;

        this.animFlib = function(a,b){

    var zi = opts.zIndex;

        if (a>b) {


            $(opts.imglist[a]).fadeIn(250);

            //a <=2 && $(opts.imglist[(a-2)]).css({'display':'none'});

        }


        if (a<b) {

            $(opts.imglist[a]).css({'display':'block'});
            $(opts.imglist[(a+1)]).fadeOut(250);
        }

        };



        this.doCkeck = function(){ // checking the mouseposition an trigger flip function

            var mW = opts.self.outerWidth(), z,

                offset = opts.self.offset().left,

                x = Math.round(100-(((mW-((mx - offset))))/(mW/100))); // 0 - 100

// defining trigger Zones

               if (x >= zon0 ){

                    zon0 += zOnE;

                    idx  +=1;


               };

               if (x <= zon0 ){

                    zon0 -= zOnE;

                    idx  -=1;

               };

               if (tmp !== idx){

                   self.animFlib(idx,tmp)

               };

               tmp = idx; // catch value for referenz


       initTimer = setTimeout(function(){


           self.doCkeck();


       },20)

        };

        this.createFlip = function(images){

            var l = images.length,initImgs,cz=opts.clickedIndex,zi=opts.zIndex;

            opts.imglist = images;

            for (var i = 0;i<images.length;++i){

                $(images[i]).css({zIndex:(zi+i)});
            };

            opts.canv.append(images);


                // fadeIn first image
                $(images).css({'display':'none'});

                if (opts.clickedIndex < 0){

                    initImgs = $($(images[(cz-1)]),$(images[cz]));

                }
                else {

                    initImgs = $(images[cz]);
                }

                initImgs.fadeIn(250,function(){

                    self.initMM();

                });

        };

        opts.canv = new createObj('div','flipBookC_'+opts.currentID,'flipBook',{

           height:100+'%',display:'block',opacity:0,position:'absolute',top:0,marginLeft:'auto'

           }).appendTo(opts.self);

            animation(opts.canv,true,false,opts.slideInDuration,opts.slideInEasing,function(){

            opts.zIndex = parseInt(opts.canv.css('zIndex'));

            $(document).data('lock.flipBook',true);



            loadImges(opts,function(cached){

                    self.createFlip(cached);

                });

           })


this.initMM = function(){
        opts.canv

/*

 firefox doesn't trigger the mouseenter/mouseover event here, if the canvas slides beneath the cursor

 so we have to trigger the timer by the first mousemove event and unbind it afterwards

*/

        .bind('mousemove.ckeck',this,function(e){

          mx = e.pageX;



        if(eventData) {

            opts.canv.unbind('mousemove.ckeck');

        }  else {

            eventData = e.data;

            eventData.doCkeck();

        };

        return;

        })

/*

 this triggers just the current mouse position

*/
        .bind('mousemove.flipBook',this,function(e){

          mx = e.pageX;




        })

/*

 start the timerloop

*/

        .bind('mouseenter.flipBook',this,function(e){

            //var mytimer = setInterval()
            mx = e.pageX;

            eventData = e.data;

            eventData.doCkeck();

            return;

        })
/*

stop timer

*/

        .bind('mouseleave.flipBook',this,function(){


            // clear timer

            setTimeout(function(){

                    clearTimeout( initTimer );

               },0);


        })

/*

stop timer and remove data

*/
        .bind('click.flipBook',this,function(e){




            kill(opts.self);

            animation(opts.canv,false,true,opts.slipInDuration,opts.slipInEasing,function(){


               setTimeout(function(){

                    clearTimeout( initTimer );

               },0);

                opts.canv.empty().remove();

                // remove lock
                $(document).removeData('lock.flipBook');

                eventData = null;

                

            })

        });


};


    };


    $.fn.flipBook = function(options) {

        var defaults = {
        // default options
            slideInEasing : 'swing',

            slideInDuration : 250
        },
        // extend options
        opts = $.extend({},defaults, options),

        self = this;



    this.bind('click.flipBook',function(e){

       e.preventDefault();

       var a = $([e.target,e.target.parentNode]).filter('a')[0];

       !!a && (function(images){

       opts.self = $(a).parents().filter(self);

       opts.currentID  = $(opts.self[0].parentNode).prevAll().length;
    // make array
       opts.images = opts.self.find('a').get().join(',').split(',');
       // trigger some stuff
       opts.clickedIndex = $.map(opts.images,function(n,i){

            if (n === a.href){

                return i;
            };

        })[0];


        opts.self.data('flipBook',new main(opts));

       })();

    });

    return this;

    };
})(jQuery);



/* typo3 mail encryption
------------------------------------------------------------------------------------
------------------------------------------------------------------------------------*/

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)
}
function decryptString(enc, offset) {
  var dec = "";
  var len = enc.length;
  for(var i = 0;i < len;i++) {
    var n = enc.charCodeAt(i);
    if(n >= 43 && n <= 58) {
      dec += decryptCharcode(n, 43, 58, offset)
    }else {
      if(n >= 64 && n <= 90) {
        dec += decryptCharcode(n, 64, 90, offset)
      }else {
        if(n >= 97 && n <= 122) {
          dec += decryptCharcode(n, 97, 122, offset)
        }else {
          dec += enc.charAt(i)
        }
      }
    }
  }
  return dec
}
function linkTo_UnCryptMailto(s) {
  location.href = decryptString(s, -1)
};

basic();
function basic(){

    $('meta[content*=TYPO3]').remove();

}




