jQuery.noConflict();
jQuery(document).ready(function () {

    // Write your own code here.


    jQuery("#nav").superfish(
    {
        hoverClass: 'sfhover',
        delay: 800,
        animation: { opacity: 'show', height: 'show' },
        speed: 'fast',
        dropShadows: false,
        autoArrows: true
    });

    jQuery("#accordion-categories-firstopen").accordion({
        autoHeight: false
    });

    /*jQuery('h2').wrapInner('<span />');*/

    // focus next input field on enter
    jQuery("input").enterToTab();


    jQuery(".TextBoxFieldJS[value!='']").DefaultValue();

    // logon-box trim username and password
    jQuery("#plc_lt_zoneRight_plcRight_plcRight_lt_zoneRight_logonform_Login1_LoginButton").click(function () {

        var strPassword = jQuery("#plc_lt_zoneRight_plcRight_plcRight_lt_zoneRight_logonform_Login1_Password").val();
        strPassword = jQuery.trim(strPassword);

        jQuery("#plc_lt_zoneRight_plcRight_plcRight_lt_zoneRight_logonform_Login1_Password").val(strPassword);

        var strUSername = jQuery("#plc_lt_zoneRight_plcRight_plcRight_lt_zoneRight_logonform_Login1_UserName").val();
        strUSername = jQuery.trim(strUSername);

        jQuery("#plc_lt_zoneRight_plcRight_plcRight_lt_zoneRight_logonform_Login1_UserName").val(strUSername);
    });

    // Image Gallery with Fancybox
    jQuery(".fancybox a[rel=gallery]").fancybox({
        'overlayOpacity': 0.9,
        'overlayColor': '#000',
        'type': 'image',
        'padding': 2,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'easingIn': 'easeOutBack',
        'easingOut': 'easeInBack'
    });

    // Video with Fancybox
    jQuery(".fancyboxvideo").fancybox({
        'overlayOpacity': 0.9,
        'transitionIn': 'elastic',
		'scrolling': 'no',
		'padding': 5,
		'width': 410,
		'height': 400,
        'transitionOut': 'elastic',
        'easingIn': 'easeOutBack',
        'easingOut': 'easeInBack',
        'type': 'iframe'
    });
	
	jQuery(".playbutton").fancybox({
        'overlayOpacity': 0.9,
        'transitionIn': 'elastic',
		'scrolling': 'no',
		'padding': 5,
		'width': 410,
		'height': 400,
        'transitionOut': 'elastic',
        'easingIn': 'easeOutBack',
        'easingOut': 'easeInBack',
        'type': 'iframe'
    });

    jQuery(".processpictures a[rel=gallery]").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': true,
        'type': 'image'
    });

    jQuery(".fancyBoxConsultation[rel=lightbox]").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
		'scrolling': 'no',
        'overlayShow': true,
        'height': 450,
        'type': 'iframe',
        'showNavArrows': false
    });

    jQuery(".fancyBoxQuickCheck[rel=lightbox]").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': true,
        'height': 300,
        'width': 350,
        'type': 'iframe',
        'showNavArrows': false
    });

    jQuery("#fancyBoxRegistration[rel=lightbox]").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
		'scrolling': 'no',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': true,
        'height': 650,
        'type': 'iframe'
    });
	
	// Handle with play button
	
	jQuery(".fancyboxvideo").hover(function () {
        var el = jQuery(this);
        linkUrl = el.attr("href");
		
        // playbutton
        playButton = jQuery(".playbutton:first");
        playButton.attr("href", linkUrl);
		playButton.css("display", "block");
        playButton.fadeIn();

    });

    jQuery(".playbutton").mouseleave(function () {

        // playbutton
        playButton = jQuery(".playbutton:first");
        playButton.fadeOut();

    });

    // Handle with Company created

    if (jQuery("#plc_lt_zoneRight_plcRight_plcRight_lt_zoneRight_DEVIEditContribution_editForm_formElem_form_FirmaGegruendet_1").is(":checked") == true) {
        jQuery("#company").slideUp();
        jQuery("#nocompany").slideDown();
    }

    if (jQuery("#plc_lt_zoneRight_plcRight_plcRight_lt_zoneRight_DEVIEditContribution_editForm_formElem_form_FirmaGegruendet_0").is(":checked") == true) {
        jQuery("#company").slideDown();
        jQuery("#nocompany").slideUp();
    }

    jQuery("#plc_lt_zoneRight_plcRight_plcRight_lt_zoneRight_DEVIEditContribution_editForm_formElem_form_FirmaGegruendet_1").click(function () {
        jQuery("#company").slideUp();
        jQuery("#nocompany").slideDown();
    });

    jQuery("#plc_lt_zoneRight_plcRight_plcRight_lt_zoneRight_DEVIEditContribution_editForm_formElem_form_FirmaGegruendet_0").click(function () {
        jQuery("#company").slideDown();
        jQuery("#nocompany").slideUp();
    });

    // Autoformat Error Messages
    jQuery(".EditingFormErrorLabel").each(function () {
        var e = jQuery(this);
        elementsToFormat = e.parent().add(e.parent().prev()).add(e.parent().prev("label"));
        elementsToFormat.css({ "border-bottom": "solid 1px #c00000", "color": "#c00000" });
        e.hide();
        jQuery("html").scrollTop(0);
    });


    jQuery(".listbox-colored:odd").css("background", "#FFED00");

    jQuery(".additional_fields").each(function () {

        var This = jQuery(this);
        var charCounter = jQuery(".charCounter", this);

        if (charCounter.length != 0) {
            var MaxAllowedChars = charCounter.text();
            TextAreaToCheck = This.next().find("textarea:first");
            var OldValue = "";

            // set init value (used id edit form)
            this.CurrentCharsCount = TextAreaToCheck.val().length;
            charCounter.text(MaxAllowedChars - this.CurrentCharsCount);

            TextAreaToCheck.keyup(function () {
                reference = jQuery(this);
                CurrentCharsCount = jQuery(this).val().length;

                OldValue = reference.val();

                //console.log("max allowed: " + MaxAllowedChars.toString());
                //console.log("current: " + CurrentCharsCount.toString());

                if (CurrentCharsCount > MaxAllowedChars) {
                    reference.val(OldValue.substring(0, MaxAllowedChars));
                    This.addClass("warningstate");
                    return false;
                }
                else {
                    This.removeClass("warningstate");
                }

                charCounter.text(MaxAllowedChars - CurrentCharsCount);

            });
        }

    });

});

// Enconding for secure emailaddresses
function JSrot13(text) { 
var text = text.replace(/%/, "@");
var rot13text_rotated = ""; 
/* the function will return this string */;
for (i = 1; i < (text.length + 1); i++) { 
k = text.charCodeAt(i - 1); 
if (k >= 97 && k <= 109){ k = k + 13; }
else if (k >= 110 && k <= 122) { k = k - 13; }
else if (k >= 65 && k <= 77) { k = k + 13; }
else if (k >= 78 && k <= 90) { k = k - 13; }
rot13text_rotated = rot13text_rotated + String.fromCharCode(k);
}
return rot13text_rotated;
} 

function Securemail(maillink) { 
	var maillink_output; maillink_output = JSrot13(maillink); location.href = 'mailto:' + maillink_output; 
}
function displaymailaddress(linktext) {
 var linktext_output; linktext_output = JSrot13(linktext);
 linktext_output = linktext_output.replace(/@/, "<span style='display:none'> *secure E-Mailaddress* <\/span>@"); document.write(linktext_output);
}
//Formular Enter-Key abfangen
(function (jQuery) {

    jQuery.fn.enterToTab = function () {
        return this.each(function () {
            jQuery(this).bind('keypress', function (event) {
                if (event.keyCode == '13') {
                    event.preventDefault();
                    var list = jQuery(":focusable");
                    list.eq(list.index(this) + 1).focus().select();
                }
            });
        });
    }

    jQuery.extend(jQuery.expr[':'], {
        focusable: function (element) {
            var nodeName = element.nodeName.toLowerCase(),
                tabIndex = jQuery.attr(element, 'tabindex');
            return (/input|select|textarea|button|object/.test(nodeName)
                     ? !element.disabled
                    : 'a' == nodeName || 'area' == nodeName
                    ? element.href || !isNaN(tabIndex)
                    : !isNaN(tabIndex))
            // the element and all of its ancestors must be visible
            // the browser may report that the area is hidden
                    && !jQuery(element)['area' == nodeName ? 'parents' : 'closest'](':hidden').length;
        }
    });

})(jQuery);

jQuery.fn.DefaultValue = function(text){
    return this.each(function(){
	
		this.isTextValue = false;
		this.newText = text;
		
		var defaultValue = this.value;

		if ( this.newText == "" || this.newText == null || typeof(this.newText) == "undefined")
		{
			this.isTextValue = false;
		}
		else
		{
			this.isTextValue = true;
			this.value = this.newText;			
		}
		//Make sure we're dealing with text-based form fields
		if(this.type != 'text' && this.type != 'password' && this.type != 'textarea')
			return;	
		//Store field reference
		var fld_current=this;	
		//Set value initially if none are specified
        if(this.value=='') {
			this.value=this.newText;
		}		
		//Remove values on focus
		jQuery(this).focus(function() {
			if(this.isTextValue)
			{
				//this.value= defaultValue;
			}
			else {
				if ( this.value == defaultValue)
				this.value = "";
			}

		});

		//Place values back on blur
		jQuery(this).blur(function() {
			if(this.value == '')
			{
				if (this.isTextValue == true)
					this.value = this.newText;
				else
					this.value=defaultValue;
			}
				
		});
		

    });

};


