function mycarousel_initCallback(carousel) {
	
	// 1. Punkt highlighten
	jQuery.each($(".news_control a"), function() {
		if($(this).html() == 1) {
			$(this).addClass("active");
		} else {
			$(this).removeClass("active");
		}
	});
	
    jQuery('.news_control a').bind('click', function() {
    	//carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
    	carousel.scroll(jQuery.jcarousel.intval((jQuery(this).text()-1)*3+1));
    	
    	jQuery.each($(".news_control a"), function() {
			$(this).removeClass("active");
		});
		$(this).addClass("active");
		//$(this).click();
    	
        return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
    	carousel.next();
        jQuery.each($(".news_control a"), function() {
    		if($(this).html() == (Math.round(carousel.first / 3) + 1)) {
    			$(this).addClass("active");
    		} else {
    			$(this).removeClass("active");
    		}
    	});

        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        jQuery.each($(".news_control a"), function() {
    		if($(this).html() == (Math.round(carousel.first / 3) + 1)) {
    			$(this).addClass("active");
    		} else {
    			$(this).removeClass("active");
    		}
    	});
        return false;
    });
};

function skim_initCallback(carousel) {
	jQuery('#news_next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#news_back').bind('click', function() {
        carousel.prev();
        return false;
    });
};

function medical_initCallback(carousel) {
    jQuery('#medical_next').bind('click', function() {
    	alert(carousel.button);
        carousel.next();
        return false;
    });

    jQuery('#medical_back').bind('click', function() {
        carousel.prev();
        return false;
    });
};

function nextButtonEvent(carousel, button, enabled) { 
    if (!enabled) { 
    	// Button ausblenden
    	button.style.display = 'none';
    } else {
    	button.style.display = 'block';
    }
};  
function prevButtonEvent(carousel, button, enabled) { 
    if (!enabled) { 
    	// Button ausblenden
    	button.style.display = 'none';
    } else {
    	button.style.display = 'block';
    }    
};


jQuery(document).ready(function() {
	
	// Suchbox
	$(".searchfield").click(function(){
		$(this).val("");
	});
	$(".searchfield").blur(function(){
		var v = $(this).val();
		if(v == "")
		{
			$(this).val("Suchbegriff eingeben");
		}
	});
	
	

	// wenn Javascript aktiv ist, muss die Klasse weg, damit die News Vorschau vernünftig aussieht
	$(".news_no_js").removeClass("news_no_js");
	$(".news_preview_no_js").removeClass("news_no_js");
	$(".controls_no_js").removeClass("controls_no_js");
	
	$(".skim_news_long_no_js").removeClass("skim_news_long_no_js");
	$(".skim_news_no_js").removeClass("skim_news_no_js");
	$(".short_text_no_js").removeClass("short_text_no_js");
	$(".news_detail_controls_no_js").removeClass("news_detail_controls_no_js");
	
	// auch für die Kampagnen-Seite
	$(".campaign_container_no_js").removeClass("campaign_container_no_js");
	
	// Download-Seite
	$(".motive_download_startpage_no_js").removeClass("motive_download_startpage_no_js");
	// Download Motive Seite
	$(".download_motives_submit_no_js").removeClass("download_motives_submit_no_js");
	
	
	
	
	
	
	// Dropdown-Box auf der Download-Motive Seite
	$('.showMotiveDropdown').msDropDown({showIcon:false});
	
	// bei Klick das Hintergrundbild austauschen
	jQuery.each($(".ddTitle"), function() {
		$(this).click(function(){
			
			if($(this).attr("id") != "search_sort_select_title")
			{
				var bg = $(this).css("background-image").split("/");
				if(bg[bg.length - 1] == 'download_hover.jpg")') {
					$(this).css("background-image", "url(/gfx/download.jpg)");
					$(this).children().css("color", "#782259");
				} else {
					// zuerst alle anderen mit dem un-aktiven Hintergrundbild ausstatten
					$(".ddTitle").css("background-image", "url(/gfx/download.jpg)");
					$(".ddTitle").children().css("color", "#782259");
					
					// dann dem aktiven Element das aktive Hintergrundbild setzen
					$(this).css("background-image", "url(/gfx/download_hover.jpg)");
					$(this).children().css("color", "#fff");
				}
			}
			return true;
		});
	});	
	
	
	jQuery.each($(".ddChild a"), function() {
		$(this).click(function(){
			$(".ddTitle").css("background-image", "url(/gfx/download.jpg)");
			$(".ddTitle .textTitle").css("color", "#782259");
			$(this).closest("form").submit();
			return true;
		});
	});
	
		
	
	
	// Dropdown-Box auf der Suchen Seite
	$('#search_sort_select').msDropDown({showIcon:false});
	
	$('#search_sort_select_child a').click(function(){
		$(this).closest("form").submit();
		return true;
	});
	

	// Image Map Mouse Over
	jQuery.each($("area"), function() {
		
		$(this).attr("alt", "");
		
		$(this).mouseover(function() {
			var lan = $(this).attr("id");
			$("#company_map").attr("src","/gfx/karten/" + lan + ".png").fadeIn();
		});
		
		$(this).mouseout(function(){
			$("#company_map").attr("src","/gfx/karte_grau.png").fadeIn();
		});
		
		
		$(this).click(function(){
			window.location.href = $(this).attr('href');
		});
	});
	
	// Kampagnen Seite
	$("#campaignLogos").jCarouselLite({
		btnNext: ".campaign_motive_next",
	    btnPrev: ".campaign_motive_prev",
		visible: 3,
        vertical: true,
        circular: true
    });
	
	jQuery.each($("img.small_motive"), function() {
		
		$(this).click(function(){ 
			var id = $(this).attr("id");
			id = id.substring(1);
			$("#first_motive").attr("src", ($("#small_motive_hidden"+id).attr("src")));
			$("p.motive_name").html($(this).attr("alt"));
		});
	});
	
	
	
	// Medizintechnologien	
	jQuery.each($("div.medical_right"), function() {		
		$(this).mouseover(function(event){ 
			
			if(event.target.nodeName == "SPAN"){			
				$("#mouseover_layer").hide();
				var left = $(this).position().left + $(this).width() + 30 - $("#mouseover_layer").width();
				var top = $(this).position().top - 20;
				$("#mouseover_layer").css("left", left+"px");
				$("#mouseover_layer").css("top", top+"px");
				$("#mouseover_layer").fadeIn(800);
				
				var html = "";
				html = html + "<h2><span>" + $(this).children().attr("alt") + "</span></h2>";
				
				var id = $(this).children().attr("class");
				jQuery.each($("#medical_content" + id), function() {	
					html = html + $(this).html();		
				});
				$("#mouseover_layer").html( html );
				
				/*jQuery.each($("div.medical_hotspot img"), function() {		
					$(this).fadeTo(800, 0.5);
				});
			
				jQuery.each($("div.medical_hotspot"), function() {		
					$(this).fadeTo(800, 0.5);		
				});*/
				
			}			
			return false;
			
		});
		
	});
	
	jQuery.each($("div.medical_left"), function() {		
		$(this).mouseover(function(event){ 
			
			if(event.target.nodeName == "SPAN"){			
				$("#mouseover_layer").hide();
				var left = $(this).position().left - 15;
				var top = $(this).position().top - 15;
				$("#mouseover_layer").css("left", left+"px");
				$("#mouseover_layer").css("top", top+"px");
				$("#mouseover_layer").fadeIn(800);
				
				var html = "";
				html = html + "<h2><span>" + $(this).children().attr("alt") + "</span></h2>";
				
				var id = $(this).children().attr("class");
				jQuery.each($("#medical_content" + id), function() {	
					html = html + $(this).html();		
				});
				$("#mouseover_layer").html( html );
				
				/*jQuery.each($("div.medical_hotspot img"), function() {		
					$(this).fadeTo(800, 0.5);
				});
				jQuery.each($("div.medical_hotspot"), function() {		
					$(this).fadeTo(800, 0.5);		
				});*/
			}
			return false;
		});
	});

	
	$("#mouseover_layer").mouseover(function(){ 
		return false;	
	});
	$("#container").mouseover(function(){ 
		$("#mouseover_layer").hide();
		
		// wieder die farbigen Bilder anzeigen
		/*jQuery.each($("div.medical_hotspot img"), function() {		
			$(this).fadeTo(0,1);
		});
		jQuery.each($("div.medical_hotspot"), function() {		
			$(this).fadeTo(0,1);		
		});*/

	});

	
	
	
	// Medicaltechnology Detail
	$(".medical_div a").attr("target", "_blank");
	$(".medical_detail_long_text a").attr("target", "_blank");
	$(".medical_detail_medium_text a").attr("target", "_blank");
	
	


	
	
	

	// News Seite
	jQuery("#news_preview").jcarousel({
        initCallback: mycarousel_initCallback,
        visible: 3,
        scroll: 3,
        vertical: true,
        animation: 'normal',
        easing: 'swing',
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
	

	
	
	
	
	// Download-Center Seite
	jQuery("#motiveList").jCarouselLite({
        visible: 3,
        scroll: 1,
        btnNext: ".motive_next",
        btnPrev: ".motive_back"
    });

	
	
	// News Detail -> zu grossen Inhalt umblaettern
	jQuery('#skim_news').jCarouselLite({

        visible: 1,
        scroll: 1,
        btnNext: ".news_detail_next",
        btnPrev: ".news_detail_back",
        circular: false
    });
	
	jQuery('#skim_news_long').jCarouselLite({

        visible: 1,
        scroll: 1,
        btnNext: ".news_detail_next",
        btnPrev: ".news_detail_back",
        circular: false
    });
	
	// zu grossen Inhalt umblaettern bei Medizintechnologien Detail
	jQuery('div.skim_medical_pagination').jCarouselLite({
        visible: 1,
        scroll: 1,
        btnNext: "#medical_next",
        btnPrev: "#medical_back",
        circular: false
    });
	

	
	
	$('area').click(function() { 
	    var url = $(this).attr('href'); 
	    var coords = $(this).attr('coords').split(','); 

	    $('#teaser').show();

	    // To prevent default action 
	  return false; 
	});
	
	// Lightbox
	$("a.lightbox").lightbox();
	
	
});

 

