// ##########################    MENU TOOLTIP   #############################

$(function () {
    
    
    var delay = (function(){
        var timer = 0;
        return function(callback, ms){
            clearTimeout (timer);
            timer = setTimeout(callback, ms);
        };
    })(); 
    
        $('.menutooltip').each(function () {
            var distance = 20;
            var time = 200;
            var hideDelay = 200;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('a', this);
            var info = $('.tooltip', this).css('opacity', 0);

            var dynamicPosition = document.body.clientWidth / 2 - 118 - (975/2 + 50);

            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    return;
                } else {
                    beingShown = true;

                    info.css({
                        left: document.body.clientWidth / 2 - 118 - (975/2 + 50),
                        display: 'block'
                    }).animate({
                        left: '+=' + distance + 'px',
                        opacity: 1
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        left: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });
  
    });

this.stereo_waisen = function(){	
		xOffset = 20;
		yOffset = 170;
	$("a.vorschau img").hover(function(e){
		this.t = this.src;
		this.title = "";	
		var c = (this.t != "") ? "" + this.t : "";
		$("body").append("<p id='equipment_vorschau'><img src='"+ c +"' width='330' /></p>");								 
		$("#equipment_vorschau")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#equipment_vorschau").remove();
    });	
	$("a.vorschau").mousemove(function(e){
		$("#equipment_vorschau")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px");
	});			
};

$(document).ready(function() {
	stereo_waisen();

    $('#theme').cycle({
	   fx:    'fade',
	   timeout: 12000,
	   speed:  3000,
	   delay: -200,
	   random:  1,
	   next:   '#theme',
	   pause:   1,
	   pager:  '#diashow_pager',
	   pagerAnchorBuilder: function(i,el) {
	       return '<a href="index.php?id=263#" title="springe zu Bild '+i+'"><img src="fileadmin/template/img/clear.gif" border="0" alt="" /></a>';
	   }
	});
	
	$('#equipment_pics').cycle({
	   fx:    'fade',
	   timeout: 8000,
	   speed:  1000,
	   delay: -200,
	   random:  1,
	   next:   '#equipment_pics',
	   pause:   1,
	   pager:  '#diashow_pager',
	   pagerAnchorBuilder: function(i,el) {
	       return '<a href="index.php?id=263#" title="springe zu Bild '+i+'"><img src="fileadmin/template/img/clear.gif" border="0" alt="" /></a>';
	   }
	}); 

    $("div#jqProjekt").hover( function(){
        $("div#jqPTitle h1").addClass("hover");
        $(this).css("cursor","pointer");
        $("div#jqPMenu").show();
        $('div#companySlogan').html("Konstruktive Lösungen");
        $("div#introStartMenu").hide();
        $("div#jqDLeftside").animate({opacity: 0.35});
    },
    function () {
        $("div#jqPTitle h1").removeClass("hover");
        $("div#jqPMenu").hide(); 
        $("div#introStartMenu").show();          
        $("div#jqDLeftside").animate({opacity: 1});
    });
    
    $("div#jqDesign").hover( function(){
       $("div#jqDTitle h1").addClass("hover");
       $(this).css("cursor","pointer");
       $("div#jqDMenu").show();   
        $('div#companySlogan').html("Puren Klang - komfortabel genießen");
       $("div#introStartMenu").hide();
       $("div#jqPLeftside").animate({opacity: 0.35});       
    },
    function () {
        $("div#jqDTitle h1").removeClass("hover");
        $("div#jqDMenu").hide(); 
        $("div#introStartMenu").show();
        $("div#jqPLeftside").animate({opacity: 1});                  
    });    

	$("a.jquery_callback").fancybox({
        'centerOnScroll' : false,
		'zoomSpeedIn'	: 500,
		'overlayShow' : true,
		'overlayOpacity' : .3,	
		'overlayColor' : '#000000',				
		'zoomSpeedOut'	: 300,
		'hideOnContentClick': false,
		'frameWidth': 355,
		'frameHeight': 270
	});
	
    $("a.jquery_tipafriend").fancybox({
        'centerOnScroll' : false,        
		'zoomSpeedIn'	: 500,
		'zoomSpeedOut'	: 300,
		'overlayShow' : true,
		'overlayOpacity' : .3,	
		'overlayColor' : '#000000',			
		'hideOnContentClick': false,
		'frameWidth': 355,
		'frameHeight': 430
	});	
	
    $("a.jquery_music").fancybox({
        'centerOnScroll' : false,
        'scrolling' : false,           
		'zoomSpeedIn'	: 500,
		'zoomSpeedOut'	: 300,
		'overlayShow' : true,
		'overlayOpacity' : .3,	
		'overlayColor' : '#000000',			
		'hideOnContentClick': false,
		'frameWidth': 325,
		'frameHeight': 310
	});			

    $("a.jquery_productrequest").fancybox({
        'centerOnScroll' : false,        
		'zoomSpeedIn'	: 500,
		'zoomSpeedOut'	: 300,
		'overlayShow' : true,
		'overlayOpacity' : .3,	
		'overlayColor' : '#000000',			
		'hideOnContentClick': false,
		'frameWidth': 355,
		'frameHeight': 530
	});

    $(".jqfancybox").fancybox({ 
        "hideOnContentClick": 0, 
        "zoomSpeedIn":500,
        "zoomSpeedOut":500,
        "overlayShow":0
    });
    
   	$("#searchbox").keyup(function(event){
		$.get("fileadmin/javascript/jquery.search/search.php",{query: $("#searchbox").val(), type: "count"}, function(data){
			$("#buttontext").html(data + " Ergebnisse zeigen");
		});
		getResults();
	});
	
	
	$("#submitbutton").click(function(){	
		getResults();
	});
    
   	$("#closeresults").click(function(){
		$("#searchclose").fadeOut(500);	
		$("#resultsContainer").fadeOut(500);
	});

	function getResults()
	{
	
		$.get("fileadmin/javascript/jquery.search/search.php",{query: $("#searchbox").val(), type: "results"}, function(data){
		
			$("#resultsContainer").html(data);
			$("#resultsContainer").fadeIn(500);
			$("#searchclose").fadeIn(500);			
		});
	}
	    
});

