
(function($) {
$.fn.reverseOrder = function() {
	return this.each(function() {
		$(this).prependTo( $(this).parent() );
	});
};
})(jQuery);
        function resizeMain(){
            $('#kreise').css({background:"transparent url('/img/kreise_bg.png') no-repeat top center"});
            $('#holder').css({height:'auto'});
            if($('#holder').height()<$('body').height()){
                $('#holder').css({height:$('body').height()});
            }
        }
        $(document).ready(resizeMain);
        $(window).resize(resizeMain);
        $(document).ready(function(){
            $('#startpage td').each(function(i,e){
                $(e).mouseover(function(){
                	$('#bigpic').css({backgroundPosition:'0px '+-(i+1)*333+'px'});
			$(this).css({backgroundPosition:'0 -101px'});
            	});
                $(e).mouseout(function(){
                	$('#bigpic').css({backgroundPosition:'0px 0px'});
			$(this).css({backgroundPosition:'0 0'});
            	});
		$(e).click(function(){
			location.href = $(this).find('a').attr('href');
		});
        });
        $(document).ready(function(){
			$("a.imgpopup").prettyPhoto({theme: 'light_square'});
        });
        $(document).ready(function(){
        	var posis = new Array(287,149,59,0,-50);
        	var ratios = new Array(1,.9,.7,.5,.4);
        	var tops = new Array(0,20,34,50,56);
        	var indxs = new Array(7,6,5,4,3,2,1);
        	var dir = 1;
        	var w = 360;
        	var h = 460;
        	var going = false;
        	$('.imgdreid>img').load(function(){
        			$(this).parent().css({width:'',height:''});
					$(this).animate({opacity:1},{queue:false,duration:1000});
				});
        	$('.dreid .thumbs a').click(function(){
        		$(this).blur();
        		var oi = $(this).parents('.imgdreid>img:first')
        		$(oi).parent().css({width:$(oi).width(),height:$(oi).height()});
        		$(oi).css({opacity:0},{queue:false,duration:1});
        		$(oi).attr({src:$(this).attr('href')});
        		//$(oi).hide();
        		return false;	
        	});
        	$('.next').fadeIn();
        	$('.prev').fadeIn();
        	
        	//build up 3d
        	function doThe3D(dura){
        		going=true;
        		$('.thumbs').hide();
	        	$('.dreid>.stage>div>img').each(function(i,e){
	        		i<4?j=i:j=4;
	        		if(i<4){
	        			$(e).parent().fadeIn({queue:false,duration:dura});
	        		}else{
	        			$(e).parent().hide();
	        		}
					$(e).animate({width:w*ratios[j],height:h*ratios[j]},dura);
					$(e).parent().animate({left:posis[j],top:tops[j]},{duration:dura,complete:function(){
						going = false;
						var t = $(e).parent().parent().parent().find('.thumbs:first');
						if($(t).children('a').length>1)
							$(t).fadeIn({duration:dura,queue:false});
					}});
					$(e).parent().css({zIndex:indxs[j]});
				});
        	}
        	doThe3D(0);
        	$('.next').click(function(){
        		if(!going){
	        		$(this).parent().find('.stage>div:first').fadeOut(function(){
						$(this).children('img').css({width:w*ratios[3],height:h*ratios[3]});
						$(this).css({left:posis[3],top:tops[3]});
						$(this).css({zIndex:indxs[3]});
	        			$(this).parent().append($(this));
	        			doThe3D(1000);
	        		});
        		}
        	})
        	$('.prev').click(function(){
        		if(!going){
	        		$(this).parent().find('.stage>div:nth-child(4)').fadeOut(function(){
						$(this).children('img').css({width:w*ratios[0],height:h*ratios[0]});
						$(this).css({left:posis[0],top:tops[0]});
						$(this).css({zIndex:indxs[0]});
	        			$(this).parent().prepend($(this));
	        			doThe3D(1000);
	        		});
        		}
        	})
        });
    });
