/*-------------------------------------------------------------------------------------
	*
	*	@copyright:_________2008, Tjaereborg
	*	@link:______________http://www.tjaereborg.de
	*	@author:____________Jung v. Matt/Neckar
	*	@function:__________subnavigation flyout
	*
	*	@version:___________1.0
	* 	@revision:__________$Revision: 13 $
	* 	@lastmodified:______$Date: 2008-09-29 15:28:38 +0200 (Mo, 29 Sep 2008) $
	*
-------------------------------------------------------------------------------------*/
/*------------------------------------------------
	*	Adding class to html-tag to hide sections 
		on page load without flickering
--------------------------------------------------*/
document.documentElement.className += " jsLoad";
/*------------------------------------------------
	*	loading jQuery plugins
--------------------------------------------------*/
/**
 * @author Alexander Farkas
 * v. 1.02
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);

/*------------------------------------------------
	*	Browser sniffing
--------------------------------------------------*/
// Internet Explorer sniffing
var gpIESniff = $.browser.msie;
var gpIEVersionSniff = $.browser.version;
// IE6
if(gpIESniff && gpIEVersionSniff < 7)var gpIE6Sniff = true;

/*------------------------------------------------
	*	Fire all Functions which need to be 
		executed or initialized if DOM is loaded
--------------------------------------------------*/
jQuery(function($) {
	
	// Main navigationflyout
	customEffects.snFlyOut();
	
	// CSS effects
	customEffects.cssEffects();
	
});

/*------------------------------------------------
	*	custom page effects
--------------------------------------------------*/
var customEffects = {

	// Sub navigation flyout
	snFlyOut:function () {

		var delayOnLv0, delayOffLv0;
		// First of all, disable the fallback css menu behaviour
		var snFB = $("#snFb");
		if (snFB){
			snFB.attr("rel", "alternate stylesheet");
			snFB.attr("disabled", "disabled");
		}
		$("#subNav li.level0").bind("mouseenter focus", function(){
			var el = $(this);
			if(el.attr('class') != 'level0 last') {
				el.find("a:first").css({background: "url(/css/images/subnav_hover.gif) repeat-x", color: "#00905A"});
				if (el.children('div').width() < 154)
					el.children('div').css({ width: "154px" })
				el.find("a:first").stop().animate({opacity: "1.0"}, {duration:100,complete:function() {
					el.find(".snFlyOut:hidden").slideDown("fast");
				}})
				$("#subNav li.level0:not(.isActual)").find(".snFlyOut:visible").slideUp("fast");
			}
		})

		// Hover out, blur subnav
		.bind("mouseleave focus", function(){
			var el = $(this);
			if(el.attr('class') != 'level0 last') {
				if(el.find(".snFlyOut").length > 0){
					if(el.children('a').attr('class') != 'select')
						el.find("a:first").css({background: "url(/css/images/subnav.gif) repeat-x", color: "#FFF"});
					el.parent('ul').children('.last').css({ borderRight: "none" });
					el.find(".snFlyOut").slideUp("low",function () {
						el.find("a:first").stop().animate({opacity: "1.0"}, {duration:100});
					});
				} else {
					el.find("a:first").stop().animate({opacity: "1.0"}, {duration:100});
				}
			}
		});
	},

	// Tooltip mouseover function
	toolTip:function (ttItems) {
		ttItems.tooltip({ 
			track: true, 
			delay: 200, 
			showURL: false, 
			showBody: " - ", 
			fade: 250 
		});
	},

	// CSS effects
	cssEffects:function () {
		if (gpIE6Sniff){
			$("tr").bind("mouseenter focus", function(){
				$(this).addClass("ieHover");
			})
			// Hover out, blur mainnav
			.bind("mouseleave", function(){
				$(this).removeClass("ieHover");
			})
		}
	}

}