/**********************************************
** Copyright - Virtual Life GmbH
**********************************************/

/**********************************************
** Start jQuery in "no conflict" mode
**********************************************/
var j = jQuery.noConflict();

/**********************************************
** jQuery
**********************************************/
j(document).ready(function() {
	//j('#footer').hide();
});

// Mega-Dropdown
(function(j){j.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=j.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){j(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;j(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{j(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
//On Hover Over
function megaHoverOver(){
    j(this).find(".sub").stop().fadeTo('slow', 1).show(); //Find sub and fade it in
    //j(this).find(".sub").stop().slideDown('slow').show();
    (function(j) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            j(this).find("ul").each(function() { //for each ul...
                rowWidth += j(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    if ( j(this).find(".row").length > 0 ) { //If row exists...

        var biggestRow = 0;	

        j(this).find(".row").each(function() {	//for each row...
            j(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

        j(this).find(".sub").css({'width' :biggestRow}); //Set width
        j(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin

    } else { //If row does not exist...

        j(this).calcSubWidth();  //Call function to calculate width of all ul's
        j(this).find(".sub").css({'width' : rowWidth}); //Set Width

    }
}
//On Hover Out
function megaHoverOut(){
  //j(this).find(".sub").stop().slideUp('slow').hide();
  j(this).find(".sub").stop().fadeTo('slow', 0, function() { //Fade to 0 opactiy

      j(this).hide();  //after fading, hide it
  });
}
//Set custom configurations
var config = {
     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
     interval: 100, // number = milliseconds for onMouseOver polling interval
     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 200, // number = milliseconds delay before onMouseOut
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};

j(document).ready(function() {
	j("ul#topnav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
	j("ul#topnav li").hoverIntent(config); //Trigger Hover intent with custom configurations
	
});

// Bilder-Slider
j(document).ready(function(){
	//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
	//Vertical Sliding
	j('.boxgrid.slidedown').hover(function(){
		j(".cover", this).stop().animate({top:'-260px'},{queue:false,duration:300});
	}, function() {
		j(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
	});
	//Horizontal Sliding
	j('.boxgrid.slideright').hover(function(){
		j(".cover", this).stop().animate({left:'325px'},{queue:false,duration:300});
	}, function() {
		j(".cover", this).stop().animate({left:'0px'},{queue:false,duration:300});
	});
	//Diagnal Sliding
	j('.boxgrid.thecombo').hover(function(){
		j(".cover", this).stop().animate({top:'260px', left:'325px'},{queue:false,duration:300});
	}, function() {
		j(".cover", this).stop().animate({top:'0px', left:'0px'},{queue:false,duration:300});
	});
	//Partial Sliding (Only show some of background)
	j('.boxgrid.peek').hover(function(){
		j(".cover", this).stop().animate({top:'90px'},{queue:false,duration:160});
	}, function() {
		j(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
	});
	//Full Caption Sliding (Hidden to Visible)
	j('.boxgrid.captionfull').hover(function(){
		j(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
	}, function() {
		j(".cover", this).stop().animate({top:'250px'},{queue:false,duration:160});
	});
	//Caption Sliding (Partially Hidden to Visible)
	j('.boxgrid.caption').hover(function(){
		j(".cover", this).stop().animate({top:'160px'},{queue:false,duration:160});
	}, function() {
		j(".cover", this).stop().animate({top:'220px'},{queue:false,duration:160});
	});
});


/**********************************************
** Mootools
**********************************************/
window.addEvent('domready', function() {
    //$("footer").style.display = 'none';
});
