var APP_ROOT;
var THEME_ROOT = 'themes/Multiflex-web/';
var Site = {
		
	/*
	 * Site.__init
	 */
	__init: function(isStatic) {
		
		// Pfad nach laden der Seite setzen
		APP_ROOT = (typeof WebSite == "object" || isStatic ? '' : '../');
		
		this.draw_Navigation();
    this.Submenu();
    this.Center();
    this.rClickStop();
    this.load_PNG();
    
    fSizeStd = 1;
		font_unity = 'em';
		init_fSize();
		
		$('a.incFontSize').click(function(e) {
			e.preventDefault();
			incFontSize(fSizeStd);
		});
		$('a.decFontSize').click(function(e) {
			e.preventDefault();
		 decFontSize(fSizeStd);
		});
	},
	
	rClickStop: function() {
		
		if(typeof(WebSite) == 'undefined') {
		function click (e) {
  		if (!e)
  	  	e = window.event;
	  	
	  	if ((e.type && e.type == "contextmenu") || (e.button && e.button == 2) || (e.which && e.which == 3)) {
 	   		return false;
  		}
		}
	
		if (document.layers)
  		document.captureEvents(Event.MOUSEDOWN);
	
		document.onmousedown = click;
		document.oncontextmenu = click;
		}
	},
	
	/*
	 * Site.draw_Navigation
	 */
	draw_Navigation: function() {
		
		var debug = 0;
				
		function drawIt(x,y) {
		  var ctx = document.getElementById("canvasObj").getContext('2d');
		 
			ctx.clearRect(0,0,875,80); 
			
			ctx.beginPath();
			ctx.moveTo(0,10);    
			ctx.lineTo(0,80);
			ctx.lineTo(875,80);
			ctx.lineTo(875,10);
			ctx.lineTo(x+150,10);
			ctx.bezierCurveTo(x,y,x,y,x-150,10);
			ctx.lineTo(x-150,10);
			ctx.fillStyle = "rgba(158,14,33,0.6)";
			ctx.fill(); 
			ctx.closePath();
			
			ctx.clearRect(117,0,9,80);
			ctx.clearRect(243,0,9,80);
			ctx.clearRect(369,0,9,80);
			ctx.clearRect(495,0,9,80);
			ctx.clearRect(621,0,9,80);
			ctx.clearRect(747,0,9,80); 
		}
		
		function debug_(debug, str) {
			if(debug == 1) {
				$('body').append('<div style="position:absolute;background:white;top:50px;left:50px;" id="debug"></div>');
				$('div#debug').html(str);
			}
		}
		
		function animate(x,y) {
			animateTO = setTimeout(function() {
				if(y>10) {
					y--;
				}
					
				drawIt(x-40,y);				
				animate(x,y);
			}, 0);
		}
		
		window.onload = function() {
				drawIt(0,10);
			 $('#Navigation_Main').mousemove(function(e) {
   
	     var position = $(this).position();
	     var offset = $(this).offset();
	     var x = e.pageX - (offset.left);
	     var y = e.pageY - (offset.top);
	     
	     debug_(0, 'x:'+x+'y:'+y);
	     
	     if(y > 10 && x>40 && x<915 && y<50) {
	     	drawIt(x-40,y);
	     	//clearTimeout(animateTO);
	     } else {
	     	//animate(x-40,y);
	     }
     });
 		}
	},
	
	/*
	 * Site.Submenu
	 */
	Submenu: function() {
		function slide_up() { $('ul#Navigation_Sub', this).slideDown(); }
		function slide_down() { $('ul#Navigation_Sub', this).slideUp(); }
		
		var config = {    
     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     interval: 200, // number = milliseconds for onMouseOver polling interval    
     over: slide_up, // function = onMouseOver callback (REQUIRED)    
     timeout: 500, // number = milliseconds delay before onMouseOut    
     out: slide_down // function = onMouseOut callback (REQUIRED)    
		};

		$('div#Navigation_Main ul li').hoverIntent(config);
		
		// Arrows
		if($('body.Service').length == 0) {
			$('ul#Navigation_Sub li').has('ul').css('background', 'url('+APP_ROOT+THEME_ROOT+'images/pfeil_inaktiv.jpg) no-repeat 143px 8px');
			$('ul#Navigation_Sub li.active').has('ul').css('background', 'url('+APP_ROOT+THEME_ROOT+'images/pfeil_aktiv.jpg) no-repeat 143px 8px');
			$('ul#Navigation_Sub li').hover(function() {
				$(this).has('ul').css('background', 'url('+APP_ROOT+THEME_ROOT+'images/pfeil_aktiv.jpg) no-repeat 143px 8px');
			}, function() {
				$(this).has('ul').css('background', 'url('+APP_ROOT+THEME_ROOT+'images/pfeil_inaktiv.jpg) no-repeat 143px 8px');
				$('ul#Navigation_Sub li.active').has('ul').css('background', 'url('+APP_ROOT+THEME_ROOT+'images/pfeil_aktiv.jpg) no-repeat 143px 8px');
			});
		}
	},
	
	/*
	 * Site.Center
	 */
	Center: function() {
		function centerIt () {
		
			if($(window).height() < $('div#Wrap').height())
				$('div#Wrap').css("top", "0px");
			else
				$('div#Wrap').css("top", ( $(window).height() - $('div#Wrap').height() ) / 2+$(window).scrollTop() + "px");
			$('div#Wrap').css("left", ( $(window).width() - $('div#Wrap').width() ) / 2+$(window).scrollLeft() + "px");
		}
		
		centerIt();
		$(window).resize(function () {
			centerIt();
		});		
	},
	
	/*
		 * Site.load_PNG
		 */
		load_PNG: function() {
			if(!this.IE || this.IEVersion != 6)
				return;
			var images = document.getElementsByTagName('img');
			
			for (var c = 0; c < images.length; c++) {
				
				if (!images[c].src.match(/\.png/))
					continue;
				
	  		images[c].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + images[c].src + "')";
	      images[c].src = APP_ROOT + 'skins/brandbox_default/icons/others/spacer.gif';
				
			}
		}
	
}

