/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(cssname){
  
    //loads popup only if it is disabled
	if(popupStatus==0){
		$(".overlaybox_background").css({
			"opacity": "0.7"
		});
		$(".overlaybox_background").fadeIn("slow");
		$(cssname).fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(cssname){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$(".overlaybox_background").fadeOut("slow");
		$(cssname).fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(cssname){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(cssname).height();
	var popupWidth = $(cssname).width();
	//centering
	$(cssname).css({
		"position": "fixed",
		"bottom": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$(".overlaybox_background").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

    // eyecatcher platzhalter entfernen wenn grußkarten label gedrückt
    $("ul.greetinglist li label").click(function(){
        $("#grusskarteneyecatcherbox").hide();
        $(this).addClass("weisserhintergrund");
    });

    // eyecatcher platzhalter anzeigen wenn "keine grußkarte" gedrückt
    $("#nocard, #nocardlabel").bind("click", function(event){
        $("#cardFields").hide();
        $("#grusskarteneyecatcherbox").show();
    });
    
    // blendet eyecatcher aus, wenn per ZURÜCK knopf auf die bundle seite zugegriffen wird
    if ($('#nocard:checked').val() != 'true') {
        $("#grusskarteneyecatcherbox").hide();
    }

    // zeigt eyecatcher an, wenn erstmals webseite geladen wird
    if ($('#nocard:checked').val() == '1') {
        $("#grusskarteneyecatcherbox").show();
    }

    // bundle platzhalter ausblenden bei klick auf bundle item
    $("#slipknotlist").bind("click", function(event){
          $("#schleifeneyecatcherbox").hide();
    });
    
    // bundle platzhalter einblenden bei klick auf "keine schleife"
    $("#slipknot").bind("click", function(event){
          $("#schleifeneyecatcherbox").show();
          $("#slipknotFields").hide();
    });
    
    // der "zurück" knopf
    $('a.back').click(function(){
        parent.history.back();
        return false;
    });
    
    
    
    $('.orderformcontainer').mouseover(function(){
        $("#schleifeneyecatcherbox").hide();
    });
    
    $("#schleifeneyecatcherbox").show();
    /* $("#schleifeneyecatcherbox").delay(6500).hide(700); */
    $('#schleifeneyecatcherbox').mouseover(function(){
        $("#schleifeneyecatcherbox").hide();
    });

    // klick auf klasse öffnet overlay fenster; id bestimmt inhalt
	$(".overlaylink").bind("click", function(event){
		// overlay name aus tag übernehmen
        var cssidname = '#' + $(this).attr("overlay") + "_box";
        // zentrierung vom overlay
		centerPopup(cssidname);
		// overlay laden
		loadPopup(cssidname);
	});
	// klick auf X oder button oder background schließt das overlay fenster
    $(".overlaybox_close, .overlaybox_button, .overlaybox_background").click(function(){
		disablePopup(".overlayBox");
	});
    // das drücken von ESCAPE beendet das overlay
    $(document).keyup(function(e){
        if(e.keyCode==27 && $(".overlayBox").is(':visible')){
            disablePopup(".overlayBox");
        }
    });

    // user hat auf den link "agb gelesen" geklickt; schaltet dazugehörige checkbox an
    $("#agbgelesen").bind("click", function(event){
        // check AGB checkbox when clicking on the link
        $('#conditions').attr("checked", true);
    });
});
