var $j = jQuery.noConflict();

jQuery(document).ready(function() {
	
	jQuery('img[rel=headerlayer]').click(function(e){
		headerLayer();        
	}); 
	
	jQuery('a[rel=lageplanlayer]').click(function(e){
		lageplanLayer();        
	}); 	
	
  jQuery("a[rel=fancybox]").fancybox({
    'hideOnContentClick': true,
    'hideOnOverlayClick': false,
    //'showCloseButton': true,
    'overlayShow':true,
    'overlayOpacity': 0.5,
	'overlayColor'		:	'#FFF',  
    'centerOnScroll': false,
    'callbackOnStart': function(){
    } 
  });
  
  jQuery("#navigationShortcuts li.navLevel1").hover(
	      function () {  
		    if(jQuery(this).attr('class') == 'navLevel1'){
			  jQuery('a:first',this).css('color','#e2001a');	
		    }
		    else{
		      jQuery('a:first',this).css('color','#3e3d40');	
		    }	
	        jQuery('ul:first',this).css('display', 'block'); 
	      }, 
	      function () {
		    if(jQuery(this).attr('class') == 'navLevel1'){
			  jQuery('a:first',this).css('color','');	
			}	    	  
	        jQuery('ul:first',this).css('display', 'none'); 
	      }
	    );  
  
  jQuery("#navigationMain li.navLevel1").hover(
	      function () {  
	    	jQuery('a:first',this).css('color','#e2001a');
	    	jQuery('ul:first',this).css('display', 'block'); 
	      }, 
	      function () {
		    if(jQuery(this).attr('class') == 'navLevel1'){
			  jQuery('a:first',this).css('color','');
			  jQuery('ul:first',this).css('display', 'none'); 
			}	    	  
	      }
	    );   
  
});

function headerLayer(){
	
	if(jQuery('#headerlayer').css('display') == 'block'){
		jQuery('#headerblocker').css({
			  'display':'none'
		});
		jQuery('#headerlayer').fadeOut("slow");
	}
	else{
		jQuery('#headerblocker').css({
			  'display':'block',
			  'opacity': '0.6',
			  'filter': 'alpha(opacity="60")',
			  '-moz-opacity': '0.6',
			  '-khtml-opacity': '0.6'
		});
		jQuery('#headerlayer').fadeIn("slow");
	}
}

function lageplanLayer(){

	if(jQuery('#lageplanlayer').css('display') == 'block'){
		jQuery('#lageplanblocker').css({
			  'display':'none'
		});
		jQuery('#lageplanlayer').fadeOut("slow");
	}
	else{
		jQuery('#lageplanblocker').css({
			  'display':'block',
			  'opacity': '0.6',
			  'filter': 'alpha(opacity="60")',
			  '-moz-opacity': '0.6',
			  '-khtml-opacity': '0.6'
		});
		jQuery('#lageplanlayer').fadeIn("slow");
	}
}

jQuery.fn.center = function(params) {

	var options = {
		vertical: false,
		horizontal: true
	}
	
	op = jQuery.extend(options, params);

	return this.each(function(){
	
		//initializing variables
		var $self = jQuery(this);
		//get the dimensions using dimensions plugin
		var width = $self.width();
		var height = $self.height();
		
		//get the paddings
		var paddingTop = parseInt($self.css("padding-top"));
		var paddingBottom = parseInt($self.css("padding-bottom"));
		//get the borders
		var borderTop = parseInt($self.css("border-top-width"));
		var borderBottom = parseInt($self.css("border-bottom-width"));
		if(isNaN(borderBottom)) borderBottom = 0;
		//get the media of padding and borders
		var mediaBorder = (borderTop+borderBottom)/2;
		if(isNaN(mediaBorder)) mediaBorder = 0;
		var mediaPadding = (paddingTop+paddingBottom)/2;
		//get the type of positioning
		var positionType = $self.parent().css("position");
		// get the half minus of width and height
		var halfWidth = (width/2)*(-1);
		var halfHeight = ((height/2)*(-1))-mediaPadding-mediaBorder;
		// initializing the css properties
		var cssProp = {
			position: 'absolute'
		};

		if(op.vertical) {
			$self.css('height', height);
			$self.css('top', ((jQuery(window).height()/2)-50)+'px');
			if(isNaN(halfHeight) == false){
			  $self.css('margin-top',halfHeight+'px');
			}
		}
		if(op.horizontal) {
			$self.css('width', width);
			$self.css('left', '50%');
			if(isNaN(halfWidth) == false){
			  $self.css('margin-left',halfWidth+'px');
			}
			
		}
		//check the current position
		if(positionType == 'static') {
			$self.parent().css("position","relative");
		}
		//aplying the css
		$self.css(cssProp);
	});
};
