$(document).ready(function() {

    $.fn.wait = function(time, type) {
        time = time || 2500;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };
    
    // DYNAMIC DIV POSITIONING
    
    if ($.browser.msie && jQuery.browser.version <= 6.0) {
        
    } else {
        var bodyWidth = $(window).width();
        var bodyHeight = $(window).height(); 
        var DivLeftMargin = (bodyWidth-1007)/2;
        $('#wrapper').css({"width":bodyHeight-100+"px"});
        if(DivLeftMargin < 205) {
            if(bodyWidth < 1217) {
                $('#leftmain').hide();
                $('#rightmain').css({"margin-left":DivLeftMargin+"px"});                  
            } else {
                $('#leftmain').wait().fadeTo(2000, 1);
                $('#rightmain').css({"margin-left":"204px"});                              
              }
          } else {
                $('#leftmain').wait().fadeTo(2000, 1);
                $('#rightmain').css({"margin-left":DivLeftMargin+"px"});              
            }  
    	
        $(window).resize(function() {
          var bodyWidth = $(window).width();
          var bodyHeight = $(window).height(); 
          var DivLeftMargin = (bodyWidth-1007)/2; 
          $('#wrapper').css({"width":bodyHeight-100+"px"});                              
          if(DivLeftMargin < 205) {
            if(bodyWidth < 1217) {
                $('#leftmain').hide();
                $('#rightmain').css({"margin-left":DivLeftMargin+"px"});
            } else {
                $('#leftmain').wait().fadeTo(2000, 1);
                $('#rightmain').css({"margin-left":"204px"});    
              }
          } else {
                $('#leftmain').wait().fadeTo(2000, 1);
                $('#rightmain').css({"margin-left":DivLeftMargin+"px"});              
            }     
        });
    }
    
    // MAIN_MENU
    
    $('ul#mainmenu li').hover(
    function() {
        var menuitemID = $(this).attr('id');
        if(menuitemID != '') {
            $('li#'+menuitemID+' ul').show();        
            $('li#'+menuitemID+' a').addClass('active');        
            $('li#'+menuitemID+' li a').removeClass('active');
        }
    },
    function () {
        var menuitemID = $(this).attr('id');
        if(menuitemID != '') {
            $('li#'+menuitemID+' ul').hide();
            $('li#'+menuitemID+' a').removeClass('active');
        }
    });

    // NEWSTICKER

    $('div#ticker div').marquee('pointer').mouseover(function () {
          $(this).trigger('stop');
    }).mouseout(function () {
          $(this).trigger('start');
    }).mousemove(function (event) {
       if ($(this).data('drag') == true) {
           this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
       }
    }).mousedown(function (event) {
        $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
    }).mouseup(function () {
        $(this).data('drag', false);
    });

    // IMAGE_MENU
    
    function onAfter(curr, next, opts) {
        var index = opts.currSlide;
        $('#prev')[index == 0 ? 'hide' : 'show']();
        $('#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
    }
    
    $('#imgmenu').cycle({
		fx:         'scrollHorz',
		timeout:    9000,
        speed:      900,		
		delay:      100,
		pause:      1,
        next:       '#imgmenuslider',
        after:      onAfter
    });

    
    $('div.imenuitem').hover( function(){
        var containerID = $(this).attr('id'); 
        var menutxt = '';
        switch(containerID)
           {
                case 'imStandup': menutxt = 'Stand Up Zauberei findet frontal vor dem Publikum statt und spricht alle gleichzeitig an.';
                break;
                case 'imMental': menutxt= 'Markus Benders mystische Mental-Show befasst sich mit Gedankenlesen und Gedankenkontrolle. Ein Erlebnis der unglaublichen Art.';
                break;
                case 'imCloseup': menutxt= 'Close Up Zauberei findet direkt an den Tischen der Gäste statt und ist individuell auf kleine Gruppen von Zuschauern zugeschnitten.';
                break;
                case 'imMagicDinner': menutxt = 'Beim Magischen Dinner werden zauberhafte Momente durch kulinarische Genüsse ergänzt.';
                break;
                case 'imBar': menutxt= 'Barzauberei ist schnell, direkt, unglaublich und trifft mitten ins Schwarze.';
                break;
                case 'imRestaurant': menutxt= 'Restaurantzauberei versüßt Ihren Gästen den Aufenthalt und animiert sie dazu immer wieder zu kommen.';
                break;                     
                default: menutxt = '';
           }
        $('div.hoverimg', this).fadeIn(500);
        $('div#menu2content').html(menutxt).fadeIn(500); 
    },
    function () {
        var containerID = $(this).attr('id');
        $('div.hoverimg', this).fadeOut(500);        
    });     

    // IMAGE GALLERY

    $("div.colspan div.galleryelement").hover(function() {
    	$(this).find('img').css({'z-index' : '800'}).addClass("hover").stop()
    		.animate({
    			marginTop: '-110px', 
    			marginLeft: '-75px', 
    			width: '250px'
    		}, 400);
    	
    	} , function() {
    	$(this).find('img').css({'z-index' : '0'}).removeClass("hover").stop()
    		.animate({
    			marginTop: '0', 
    			marginLeft: '0',
    			width: '100px'
    		}, 400);
    });
 
});
