/**********************************************************************************
* WLW - JavaScript
* 
* erstellt von: ermi02 26.11.2008  >> von Andre im Feb. 09 auf AJAX abgeaendert!
*
*********************************************************************************/

/*
 * Zu- und wegschalten der Lightbox (z.B. bei Impressum und Kontakt)
 *
 * zurueck-Button im Kontaktformular
 */
function contactBackButton() {
	try {
		if (navigator.appName == "Microsoft Internet Explorer") {
			parent.document.lightboxkontaktinhalt.location.href = "kontakt.html";
		} else {
			self.location.href = "kontakt.html";
		}
	} catch (e) {
		//alert(e.message);	
	}
}

(function($) {
    $.fn.lb_ids = [];

    $.fn.lightbox = function(options) {
    	$.each(options.container, function(index, obj){add(obj);});
    	$.each(options.links, function(index, obj){addlink(obj);});
    	$("#lightboxschliessenlink").bind("click", deactivate);
    	//$(this).bind("activate", function(event, id){activate(id);});
    	$(this).bind("activate", function(event, obj){activate(obj);});
    	$(this).bind("setLightboxHeight", function(event, id){setLightboxHeight(id)});
    	
    	// Links der Imagemap, die die Umfrage aufruft
    	if ($("#umfrage").length > 0){
        	$("#umfrageGo").bind("click", deactivate);
        	$("#umfrageNo").bind("click", deactivate);
        	$("#umfrageZu").bind("click", deactivate);
    	}

    	// Fuer den IE6 muss die Grosse des Hintergrunds angepasst werden
    	function setBackgroundHeight(obj) {
    		if(obj != undefined) {
    			var browserVersion = navigator.appVersion.substr((navigator.appVersion.indexOf("MSIE") + 5),1);
    			if ((browserVersion != "7") && (browserVersion != "8")) {
    				if (screen.availHeight < document.body.clientHeight) {
    					$("#lightboxbackground").css("height", document.body.clientHeight + 'px');
    				}
    			}
    		}
    	}
    	
    	// Bei 1024*768px soll Lightbox passen, wenn kleiner ist sie scrollbar
    	function setLightboxHeight (id) {
    		//alert(id + " "+ options.the_referrer);
    		var maxHeightCont = 530; // Standardhoehe der Container
    		var theHeight = getsize("height");
    		var theDiffHeight = theHeight - minHeight; // minHeight aus getsize.js
    		var maxHeight = 664; // max. zur Verfuegung stehende Hoehe
    		var fullHeight = 530; // Hoehe fuer Lightboxen 
    		var contentHeight = 530; // Hoehe des iframes/contents innerhalb der Lightboxen
    		if(id == "lightboxnutzungsbedingungen" || id =="lightboxdatenschutz") {
    			contentHeight = 469;
    		}
    		if(id == "lightboximpressum" || id == "lightboxcrowdsourcing") {
    			maxHeightCont = 410;
    		}
    		if(id == "EmailOK" || id == "EmailSendError") {
    			maxHeightCont = 50;
    		}
    		if(theHeight <= maxHeight) {
    			if(fullHeight + theDiffHeight < maxHeightCont) {
	    			$("#" + id + "").css("height", fullHeight + theDiffHeight + 'px');
					$("#" + id + "inhalt").css("height", contentHeight + theDiffHeight + 'px');
    			} else { // damit eine Maximalhoehe des Inhalts moeglich ist
	    			$("#" + id + "").css("height", maxHeightCont + 'px');
	    			// Workaround, suboptimal
	        		if(id == "lightboxnutzungsbedingungen" || id =="lightboxdatenschutz") {
	        			maxHeightCont = 469;
	        		}
					$("#" + id + "inhalt").css("height", maxHeightCont + 'px');
    			}
	    		if(id == "EmailFormopen" || id == "EmailOK" || id == "EmailSendError") {
					$("#" + id + "inhalt").css("overflow", 'auto');
					$("#" + id + "inhalt").css("overflow-x", 'hidden'); // fuer IE
	    		}
    		} else {
    			if(fullHeight < maxHeightCont) {
	    			$("#" + id + "").css("height", fullHeight + 'px');
					$("#" + id + "inhalt").css("height", contentHeight + 'px');
    			} else { // damit eine Maximalhoehe des Inhalts moeglich ist
	    			$("#" + id + "").css("height", maxHeightCont + 'px');
	    			// Workaround, suboptimal
	        		if(id == "lightboxnutzungsbedingungen" || id =="lightboxdatenschutz") {
	        			maxHeightCont = 469;
	        		}
					$("#" + id + "inhalt").css("height", maxHeightCont + 'px');
    			}
    		}
    	}
    	
    	
    	function add(obj) {
            if(obj != undefined) {
                $(this).lb_ids.push(obj.id);
                var con = $("#" + obj.id);
                con.bind("lb_activate", function(){obj.onactivate();});
            } else {
            	$(this).lb_ids.push(obj);
            }
        };
    	function addlink(obj) {
    		if (obj != undefined) {
    			var con = $("#" + obj.linkid);
				con.bind("click", function() {activate(obj);});
				con.attr("href", "#");
    		}
    	}
        function activate(obj) {
        	var theID;
        	if(obj.id == undefined) {
        		theID = obj;
        	} else if($.isFunction(obj.id)) {
            		theID = obj.id();
        	} else {
        		theID = obj.id;
        	}
//            setBackgroundHeight($(this));
            $("#lightboxschliessenlink").show();
            setBackgroundHeight(obj);
            setLightboxHeight(obj.id);
            $("#lightboxbackground").show();
            $("#lightboxschliessen").show();
            
            // Fuer einen Zurueck-Button
            if(obj.backfunction == "nbyes") { // Nutzungsbedingungen
            	$("#zurueck").show();
            } else {
            	if(obj.backfunction == "dsyes") { // Datenschutzerklaerung
            		$("#dszurueck").show();
            	} else { // Aufruf aus dem Fuss
	            	$("#zurueck").hide();
	            	$("#dszurueck").hide();
            	}
            }

            $.each($(this).lb_ids, function(index, testid) {
            	//alert(testid + " id= " + theID);
                if (testid == theID) {
                    var target = $("#" + theID);
                    target.show();
                    target.trigger("lb_activate");
                } else {
                    $("#" + testid).hide();
                }
            });
        }
        function deactivate() {
            $(this).hide();
            $.each($(this).lb_ids, function(index, id) {
              //alert("test " + id);
              $("#" + id).hide();
            });
            $("#lightboxschliessen").hide();
            $("#lightboxbackground").hide();
        	$(".lightboxbackground").css("opacity", "0.55");
        }
    };
})(jQuery);

// zur Ueberpruefung der Hoehe
function checkResize() {
    if(document.getElementById("EmailFormopen") && document.getElementById("EmailFormopen").style.display == "block") {
        $("#lightbox").trigger("setLightboxHeight", "EmailFormopen");
      }
    if(document.getElementById("EmailOK") && document.getElementById("EmailOK").style.display == "block") {
        $("#lightbox").trigger("setLightboxHeight", "EmailOK");
      }
    if(document.getElementById("EmailSendError") && document.getElementById("EmailSendError").style.display == "block") {
        $("#lightbox").trigger("setLightboxHeight", "EmailSendError");
      }
    if(document.getElementById("lightboxnutzungsbedingungen") && document.getElementById("lightboxnutzungsbedingungen").style.display == "block") {
        $("#lightbox").trigger("setLightboxHeight", "lightboxnutzungsbedingungen");
      }
    if(document.getElementById("lightboxdatenschutz") && document.getElementById("lightboxdatenschutz").style.display == "block") {
        $("#lightbox").trigger("setLightboxHeight", "lightboxdatenschutz");
      }
    if(document.getElementById("lightboximpressum") && document.getElementById("lightboximpressum").style.display == "block") {
        $("#lightbox").trigger("setLightboxHeight", "lightboximpressum");
      }
    if(document.getElementById("lightboxhilfe") && document.getElementById("lightboxhilfe").style.display == "block") {
        $("#lightbox").trigger("setLightboxHeight", "lightboxhilfe");
      }
    if(document.getElementById("lightboxkontakt") && document.getElementById("lightboxkontakt").style.display == "block") {
        $("#lightbox").trigger("setLightboxHeight", "lightboxkontakt");
      }
    if(document.getElementById("lightboxfeedback") && document.getElementById("lightboxfeedback").style.display == "block") {
        $("#lightbox").trigger("setLightboxHeight", "lightboxfeedback");
      }
}



function lightboxLoadSlider(design) {
	$(function() {
		$( "#slider1" ).slider({
			value:0,
			min: 0,
			max: 5,
			step: 1,
			// "Segmentbalken" beim Verschieben mit der Maus setzen
			slide: function( event, ui ) {
				$(".ui-slider").css("backgroundImage", "url(/image/" + design + "/xx/" + ui.value + ".png)");
			},
			// "Segmentbalken" beim Setzen der Werte anpassen
			change: function( event, ui ) {
				$(".ui-slider").css("backgroundImage", "url(/image/" + design + "/xx/" + ui.value + ".png)");
			}
		});
	});
}

