$(document).ready(function(){ 
        $.fn.superfish.defaults = {
			hoverClass:    'sfHover',          // the class applied to hovered list items
			pathClass:     'current', // the class you have applied to list items that lead to the current page
			pathLevels:    0,                  // the number of levels of submenus that remain open or are restored using pathClass
			delay:         800,                // the delay in milliseconds that the mouse can remain outside a submenu without it closing
			animation:     {opacity:'show'},   // an object equivalent to first parameter of jQuery’s .animate() method
			speed:         'normal',           // speed of the animation. Equivalent to second parameter of jQuery’s .animate() method
			autoArrows:    false,               // if true, arrow mark-up generated automatically = cleaner source code at expense of initialisation performance
			dropShadows:   true,               // completely disable drop shadows by setting this to false
			disableHI:     false,              // set to true to disable hoverIntent detection
			onInit:        function(){},       // callback function fires once Superfish is initialised – 'this' is the containing ul
			onBeforeShow:  function(){},       // callback function fires just before reveal animation begins – 'this' is the ul about to open
			onShow:        function(){},       // callback function fires once reveal animation completed – 'this' is the opened ul
			onHide:        function(){}        // callback function fires after a sub-menu has closed – 'this' is the ul that just closed
		};
		
		$("ul.sf-main").supersubs({ 
            minWidth:    12,   // minimum width of sub-menus in em units 
            maxWidth:    27,   // maximum width of sub-menus in em units 
            extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish();  // call supersubs first, then superfish, so that subs are 
                         // not display:none when measuring. Call before initialising 
                         // containing tabs for same reason.
		
		// initialize scrollable
		$(".scrollable").scrollable(); 
		
		// Tooltips
		$(".visualtooltip").tooltip({onShow: function() {
					
					// Bescheuerte Funktion, um die Tooltips irgendwie im Slider zu positionieren, ohne dass sie abgeschnitten werden
					
					var myoffset = this.getTrigger().parent().parent().attr("mypos") * 762;					
					var triggerleft = this.getTrigger().parent().css('left');
					var triggertop = this.getTrigger().parent().css('top');
					var divheight = $(".scrollable").css('height');
					var divwidth = $(".scrollable").css('width');
					
					var mypx = triggertop.indexOf('px');
					triggertop = triggertop.substring(0, mypx);
					
					mypx = divheight.indexOf('px');
					divheight = divheight.substring(0, mypx);
					
					mypx = divwidth.indexOf('px');
					divwidth = divwidth.substring(0, mypx);
					
					mypx = triggerleft.indexOf('px');
					triggerleft = triggerleft.substring(0, mypx);
					triggerleft = triggerleft * 1;
					triggertop = triggertop * 1;
					
					this.getTip().css('position','absolute');
					this.getTip().css('z-index','1000');
					
					if(triggertop < (divheight / 2))
					{
						// this.getTip().css('top',triggertop+"px");
						
						this.getTip().animate({
								top: triggertop
							  }, 400, function() {
								//
							  });
							  
					}
					else
					{
						
						triggertop -= 200;
						// this.getTip().css('top',triggertop+"px");
						this.getTip().animate({
								top: triggertop
							  }, 400, function() {
								//
							  }); 
					}
					
					
					if(triggerleft < (divwidth / 2))
					{
						triggerleft +=  myoffset;
						//this.getTip().css('left',triggerleft+"px");
						this.getTip().animate({
								left: triggerleft
							  }, 200, function() {
								//
							  });
					}
					else
					{
						triggerleft -= 200;
						triggerleft +=  myoffset;
						
						//this.getTip().css('left',triggerleft+"px");
						this.getTip().animate({
								left: triggerleft
							  }, 200, function() {
								//
							  });
					}
					
       				return true;

					
					
				}});
		
		// LeadForms laden
		$('#leadMachine div h1').html('<img src="/themes/vitalis/shared/res/wait.gif">');
		//$('#leadMachine').load('/kontakt/form1/');
		
		$.get("/leadmachine/form1/", function (data) { 
			$("#leadMachine").empty().append(data);
		});
		
		
		
		/*
		$.get("/leadmachine/form1/", function (data) { 
			data = '"' + data + '"';    
			$("#leadMachine").html(data);
			var newHTML = $('#leadMachine').html();
			$('#leadMachine').html(newHTML.substr(1,newHTML.length-2));
		}); 
		*/
		
		$(".leadform1").live('click', function(event) {
			$('#leadMachine div h1').html('<img src="/themes/vitalis/shared/res/wait.gif">');
			$('#leadMachine div form').html(' ');
			$.get("/leadmachine/form1/", function (data) { 
				$("#leadMachine").empty().append(data);
				$("#leadform1").attr('class','activeTab');$("#leadform2").attr('class','inactiveTab');$("#leadform3").attr('class','inactiveTab');
			});
			// $('#leadMachine').load('/kontakt/form1/',function(){$("#leadform1").attr('class','activeTab');$("#leadform2").attr('class','inactiveTab');$("#leadform3").attr('class','inactiveTab');});
			event.preventDefault(); return false;
		});
		$(".leadform2").live('click', function(event) {
			$('#leadMachine div h1').html('<img src="/themes/vitalis/shared/res/wait.gif">');
			$('#leadMachine div form').html(' ');
			$.get("/leadmachine/form2/", function (data) { 
				$("#leadMachine").empty().append(data);
				$("#leadform1").attr('class','inactiveTab');$("#leadform2").attr('class','activeTab');$("#leadform3").attr('class','inactiveTab');
			});
			//$('#leadMachine').load('/kontakt/form2/',function(){$("#leadform1").attr('class','inactiveTab');$("#leadform2").attr('class','activeTab');$("#leadform3").attr('class','inactiveTab');});
			event.preventDefault(); return false;
		});
		$(".leadform3").live('click', function(event) {
			$('#leadMachine div h1').html('<img src="/themes/vitalis/shared/res/wait.gif">');
			$('#leadMachine div form').html(' ');
			$.get("/leadmachine/form3/", function (data) { 
				$("#leadMachine").empty().append(data);
				$("#leadform1").attr('class','inactiveTab');$("#leadform2").attr('class','inactiveTab');$("#leadform3").attr('class','activeTab');
			});
			//$('#leadMachine').load('/kontakt/form3/',function(){$("#leadform1").attr('class','inactiveTab');$("#leadform2").attr('class','inactiveTab');$("#leadform3").attr('class','activeTab');});
			event.preventDefault(); return false;
		});
		
		$("a.iframe").fancybox({
		'width': 800,
		'height': 600
		
		});

//alert($('#visualnext').css('left'));

}); 
