var cTimer = false;
    function spriteOpen(elm,p,step,h,steps) {
        if(step==-1) {
            $('.second',p).hide();
            $('.first',p).fadeOut('fast',function(){
                 $('.sprite',p).show();
                 step =parseInt(step)+1;
                 spriteOpen(elm,p,step,h,steps);
            });
        }else if(step<steps) {            
            if(step==(steps-3)) {
                $(p).addClass('open');
                $('.second',p).fadeIn('slow');
            }
            var cpos = parseInt(h)*step;
            cpos = cpos*-1;
            $(elm).css({'top':cpos+'px'});
            step =parseInt(step)+1;
            cTimer = setTimeout(function() {spriteOpen(elm,p,step,h,steps);},26);
        } else {
            clearTimeout(cTimer);
            $('.sprite',p).hide();
            $('.second',p).show();            
        }
    }

    function spriteClose(elm,p,step,h,steps) {
         if(step==-1) {
            $('.first',p).hide();
            $('.second',p).fadeOut('fast',function(){
                 $('.sprite',p).show();
                 step =parseInt(step)+1;
                 spriteClose(elm,p,step,h,steps);
            });
        }else if(step<steps) {
            if(step==(steps-3)) {
                $(p).removeClass('open');
                $('.first',p).fadeIn('slow');
            }
            var t = parseInt(elm.style.top);
            cpos = t+h;
            $(elm).css({'top':cpos+'px'});
            step =parseInt(step)+1;
            cTimer = setTimeout(function() {spriteClose(elm,p,step,h,steps);},26);
        } else {
            clearTimeout(cTimer);
            $('.sprite',p).hide();
            $('.first',p).show();            
        }
    }


$().ready(function() {
     $('.info-box').each(function() {
        $('div.first, div.second',this).append('<div class="clickE"></div>');        
        $(this).append('<div class="sprite"><img src="/css/img/sprite.png"/></div>');
     });
     $('div.first .clickE').click(function(){
        var elm = $('.sprite img',this.parentNode.parentNode)[0];
        spriteOpen(elm,this.parentNode.parentNode,-1,220,24);
     });
      $('div.second .clickE').click(function(){
        var elm = $('.sprite img',this.parentNode.parentNode)[0];
        spriteClose(elm,this.parentNode.parentNode,-1,220,24);
     });
     $('div.second').removeClass('hidden');
     $('#Teaser').click(function(){
            $('div',this).each(function(){
                var _e = this;
                if(this.className.indexOf('hidden')!=-1) {
                   $(this).fadeIn('slow',function(){$(_e).removeClass('hidden');});
                } else {
                    $(this).fadeOut('slow',function(){$(_e).addClass('hidden');});
                }
            });
            $('#Stage div').each(function(){
                var _e = this;
                if(this.className.indexOf('hidden')!=-1) {
                   $(this).fadeIn('slow',function(){$(_e).removeClass('hidden');});
                } else {
                    $(this).fadeOut('slow',function(){$(_e).addClass('hidden');});
                }
            });
     });
     if($(".first .carousel").size()>=1) {
     	$(".first .carousel").jcarousel({'itemVisible': 1,'itemScroll': 1});
     }
     /* new: initialize with fix width and height*/
     if($(".second .carousel").size()>=1) {
     	$(".second .carousel").jcarousel({'itemVisible': 1,'itemScroll': 1,'itemWidth':212,'itemHeight':110});
     }
     
     
     
});