/**
 * @author Norman Malessa
 * Javascript Functions for www.n-system.de
 */

jQuery.noConflict();



/*
 * Lightbox fuer OpenPic oeffnen
 */
function showOpenPicLightbox(pic) {
	var targetPic	= pic.replace("_preview","");
	var closeButton	= '<p align="center"><a href="' + targetPic + '" target="_blank" title="Dieses Bild herunterladen">Download</a> | <a onclick="closeLightbox()" href="#" title="Zur&uuml;ck zur &Uuml;bersicht">Zur&uuml;ck</a></p>';
	jQuery("#lightbox-panel").html('<img src="' + pic + '" style="width:600px; height:400px" />' + closeButton);
	jQuery("#lightbox").css("height", jQuery('body').height() + "px");
	jQuery("#lightbox, #lightbox-panel").fadeIn(300);
}



/*
 * Lightbox schliessen 
 */
function closeLightbox() {
	jQuery("#lightbox, #lightbox-panel").fadeOut(300);
}



/*
 * Seiten Start 
 */
jQuery(document).ready(function() {
	
	// Banderole soll Logo nicht ueberdecken
	var posLeft = parseInt(jQuery("#logo").offset().left);
	if (posLeft < 120) {
		jQuery("#banderole").css({'display':'none'});
	}
	
	
	// Adjust Content Height
	elements_height = eval( jQuery("#bottommodules").outerHeight(true) + jQuery("#footer").outerHeight(true) + jQuery("#pathway").outerHeight(true) + jQuery("#mainmenu").outerHeight(true) + jQuery("#header").outerHeight(true) + jQuery("#toplink").outerHeight(true) + 20 );
	jQuery("#maincontent").css( {'min-height' : document.documentElement.clientHeight - elements_height} );
	
	
	// Lightbox Close Funktion
	jQuery("#lightbox").click(function() {
		closeLightbox();
	});
	
	
	// OpenPics Thumbnails
	jQuery(".openpics_thumbnail").wrap(function() {
		var targetPic = jQuery(this).attr('src').replace("_thumb","_preview");
		return '<div class="openpic_div"><a onclick="showOpenPicLightbox(\'' + targetPic + '\')" href="#"></a></div>';
	});
	
	
	// Tabs
	jQuery(".tab_content").hide();
	jQuery("ul.tabs li:first").addClass("active").show();
	jQuery(".tab_content:first").show();
	
	jQuery("ul.tabs li").click(function() {
		jQuery("ul.tabs li").removeClass("active");
		jQuery(this).addClass("active");
		jQuery(".tab_content").hide();
		var activeTab = jQuery(this).find("a").attr("href");
		jQuery(activeTab).fadeIn();
		return false;
	});

	
});
