
// ---------------------------------------------------------------------------------------
// Overlay SUB
// ---------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------
function startOverlayToolSub(){
	var overlaySubActive = 'inactive';
	
	function overlayToolSubAjaxRequest(keyword, subkeyword){
		$('#overlayToolSubContent').append('<img id="overlaySubLoaderGif" src="images/overlayLoader.gif">');
		$("#overlayToolSubContainer").fadeIn("normal", function (){
			//alert(subkeyword);
			overlaySubActive = 'active';
			$.ajax({
				type: "POST",
				url: "sub_keyword.php",
				data: "keyword=" + keyword + "&subkeyword=" + subkeyword,
				dataType: "html",
				success: function(html)
				{
					$('#overlaySubLoaderGif').fadeOut('normal', function() {
						$('#overlaySubLoaderGif').remove();
						$('#overlayToolSubContent').append(html);
						$(".dynamicOverlaySubJava").fadeIn("fast");
						//$('#overlayToolSubContainer').click(function () {
						//	removeOverlayToolSub();
						//});
					});
				}
			});
		});
	}
	
	// Link ersetzen
	
	$('a.overlayToolSubLink').removeAttr('href'); 
	$('a.overlayToolSubLink').click(function () {
		if (overlaySubActive == 'inactive')
	    {
			var textLinkSubParentName = $(this).attr('parentname');
			var textLinkSubName = $(this).attr('name');
			
			overlayToolSubAjaxRequest(textLinkSubParentName, textLinkSubName);
	    }
	});

}

function removeOverlayToolSub(){
		$("#overlayToolSubContainer").fadeOut("normal", function() {
			$('.dynamicOverlaySubJava').remove();
		});
		startOverlayToolSub();
	}

// ---------------------------------------------------------------------------------------
// Overlay
// ---------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------

function startNivoSliderIfLoaded(){
	$('#slider').nivoSlider({
        effect: 'fade',
        animSpeed: 500, //Slide transition speed
        pauseTime: 10000,
        startSlide: 0, //Set starting Slide (0 index)
        directionNav: false, //Next & Prev
        directionNavHide: false, //Only show on hover
        controlNav: false, //1,2,3...
        controlNavThumbs: false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel: false, //Use image rel for thumbs
        keyboardNav: false, //Use left & right arrows
        pauseOnHover: false, //Stop animation while hovering
        manualAdvance: false, //Force manual transitions
        captionOpacity: 0.8, //Universal caption opacity
	});
}

overlayActive = 'inactive';

function overlayToolAjaxRequest(keyword){
	$('#overlayToolContent').append('<img id="overlayLoaderGif" src="images/overlayLoader.gif">');
	$("#overlayToolContainer").fadeIn("normal", function (){
		$("#impfooter").fadeOut("normal");
		overlayActive = 'active';
		$.ajax({
			type: "POST",
			url: "keyword.php",
			data: "keyword=" + keyword,
			dataType: "html",
			success: function(msg)
			{
				//$('#overlayToolStatic').append('<div id="overlayToolContainer"><div id="overlayToolContent"></div></div>');
				$('#overlayLoaderGif').fadeOut('normal', function() {
					$('#overlayLoaderGif').remove();
					$('#overlayToolContent').append(msg);
					//$("#test").css({'display' : 'inline' , 'height' : '600px'});
					//setTransparency('test', 1.0);
					$(".dynamicOverlayJava").fadeIn("fast", function(){
						if($('img#Bild1').length > 0){
							bild1loaded = 'false';
						}
						else{
							bild1loaded = 'true';
						}
						if($('img#Bild2').length > 0){
							bild2loaded = 'false';
						}
						else{
							bild2loaded = 'true';
						}
						if($('img#Bild3').length > 0){
							bild3loaded = 'false';
						}
						else{
							bild3loaded = 'true';
						}
						$("#Bild1").load(function(){
							//alert('loaded 1');
							bild1loaded = 'true';
							if(bild2loaded == 'true' & bild3loaded == 'true')
							{
								startNivoSliderIfLoaded();
								//alert('1');
							}
						});
						$("#Bild2").load(function(){
							bild2loaded = 'true';
							//alert('loaded 2');
							if(bild1loaded == 'true' & bild3loaded == 'true')
							{
								startNivoSliderIfLoaded();
								//alert('2');
							}
						});
						$("#Bild3").load(function(){
							bild3loaded = 'true';
							//alert('loaded 3');
							if(bild1loaded == 'true' & bild2loaded == 'true')
							{
								startNivoSliderIfLoaded();
								//alert('3');
							}
						});
					});
					startOverlayToolSub();
				});
			}
		});
	});
}

function removeOverlayTool(){
	$("#overlayToolContainer").fadeOut("normal", function() {
		$("#impfooter").fadeIn("normal");
		$('.dynamicOverlayJava').remove();
	});
	overlayActive = 'inactive';
}

// ----------------------
// ----------------------
// ----------------------

// Link ersetzen

$('a.overlayToolLink').removeAttr('href'); 
$('a.overlayToolLink').click(function () {
	if(loginWindow == 'on'){
		$('#loginWindowBlind').slideUp('normal');
		$('#loginWindow').slideUp('normal', function() {
			loginWindow = 'off';
		});
	}
	if (overlayActive == 'inactive')
    {
		var textLinkName = $(this).attr('name');
		overlayToolAjaxRequest(textLinkName);
    }
});

// ----------------------
// ----------------------
// ----------------------
