$(document).ready(function() {

	if ($('a.lightbox').length != 0) {
		$("a.lightbox").fancybox({
			'padding'			: 0,
			'titleShow'			: true,
			'titlePosition'		: 'outside',
			'cyclic'			: true,
			'overlayColor'		: '#fff',
			'overlayOpacity'	: 0.75,
			'centerOnScroll'	: true
		});
	}

	/* TOOLTIP NAVIGATION EXTRA */
	$("div.navigationExtraElementClass ul li a").not("div.navigationExtraElementClass ul li a.actClass").bind({
		mouseenter: function(){
			// Tooltip Beschriftung
			tempStr = $(this).attr("rel");
			if (tempStr != "") {
				$('div#navigationExtraDescriptionLayer').text(tempStr);
				// Berechnung Position Tooltip
				tempPosition = $(this).position();
				tempPositionParentLayer = $(this).parent().parent().parent().position();
				tempX = tempPositionParentLayer.left + 20 + tempPosition.left + $(this).width() + 10 - ($('div#navigationExtraDescriptionLayer').width() + 10);
				$('div#navigationExtraDescriptionLayer').css({"left": tempX + "px"});
				tempY = $(this).height() + 3 + 1; // + padding + distance
				$('div#navigationExtraDescriptionLayer').css({"top": tempY + "px"});
				// Tooltip einblenden
				$('div#navigationExtraDescriptionLayer').show();
			}
		},
		mouseleave: function(){
			// Tooltip ausblenden
			$('div#navigationExtraDescriptionLayer').hide();
		},
		click: function(){
			// Tooltip ausblenden
			$('div#navigationExtraDescriptionLayer').hide();
		}
	});

	/* CHECK PROJECT-ROLLOVER OK */
	if ($('div.projectsInfoboxClass').length > 0) projectInfoboxOK = true; else projectInfoboxOK = false;

	/* ROLLOVER PROJEKTNAVIGATION TOP */
	$("div#navigationProjectsTopNumbersLayer ul li a").not("div#navigationProjectsTopNumbersLayer ul li a.actClass").bind({
		mouseenter: function(){
			tempID = getProjectID($(this).attr("id"));
			$("div#navigationProjectsLeftLayer ul li a#a" + tempID + "Left").addClass('actClass');
			showProjectInfobox(tempID);
		},
		mouseleave: function(){
			tempID = getProjectID($(this).attr("id"));
			$("div#navigationProjectsLeftLayer ul li a#a" + tempID + "Left").removeClass('actClass');
			hideProjectInfobox(tempID);
		}
	});

	/* ROLLOVER PROJEKTNAVIGATION LEFT */
	$("div#navigationProjectsLeftLayer ul li a").not("div#navigationProjectsLeftLayer ul li a.actClass").bind({
		mouseenter: function(){
			tempID = getProjectID($(this).attr("id"));
			$("div#navigationProjectsTopNumbersLayer ul li a#a" + tempID + "Top").addClass('actClass');
			showProjectInfobox(tempID);
		},
		mouseleave: function(){
			tempID = getProjectID($(this).attr("id"));
			$("div#navigationProjectsTopNumbersLayer ul li a#a" + tempID + "Top").removeClass('actClass');
			hideProjectInfobox(tempID);
		}
	});
	

});

function getProjectID(str) {
	str = str.replace("a","");
	str = str.replace("Top","");
	str = str.replace("Left","");
	return(parseInt(str));
}

function getProjectInfoboxCoordinateX(id) {
	tempPosition = $("div#navigationProjectsTopNumbersLayer ul li a#a" + id + "Top").position();
	return(tempPosition.left);
}

function getProjectInfoboxCoordinateY() {
	tempPosition1 = $("div#navigationProjectsTopWrapper").position();
	tempPosition2 = $("div#navigationProjectsTopNumbersLayer").position();
	tempPositionY = tempPosition1.top + tempPosition2.top + $("div#navigationProjectsTopNumbersLayer").height();
	return(tempPositionY);
}

function getProjectInfoboxPaddingTop() {
	tempPosition1 = $("div#navigationProjectsTopWrapper").position();
	tempPosition2 = $("div#navigationProjectsTopNumbersLayer").position();
	tempPosition3 = $("div#navigationProjectsLeftLayer").position();
	tempPaddingTop = tempPosition3.top - (tempPosition1.top + tempPosition2.top + $("div#navigationProjectsTopNumbersLayer").height());
	if (tempPaddingTop > 0) return(tempPaddingTop); else return(20);
}

function showProjectInfobox(id) {
	if (projectInfoboxOK) {
		$('div#projectsInfobox' + id + 'Layer').show();
		$('div#projectsInfobox' + id + 'Layer').css({"left": getProjectInfoboxCoordinateX(id) + "px","top": getProjectInfoboxCoordinateY() + "px","padding-top": getProjectInfoboxPaddingTop() + "px"});
		//$('div#projectsInfobox' + id + 'Layer').css({"top": getProjectInfoboxCoordinateY() + "px"});
	}
}

function hideProjectInfobox(id) {
	if (projectInfoboxOK) {
		$('div#projectsInfobox' + id + 'Layer').hide();
	}
}

