//*jQuery InnerFade*

(function(a){a.fn.innerfade=function(b){return this.each(function(){a.innerfade(this,b)})};a.innerfade=function(b,c){var e={animationtype:"fade",speed:"normal",type:"sequence",timeout:2000,containerheight:"auto",runningclass:"innerfade",children:null};if(c){a.extend(e,c)}if(e.children===null){var g=a(b).children()}else{var g=a(b).children(e.children)}if(g.length>1){a(b).css("position","relative").css("height",e.containerheight).addClass(e.runningclass);for(var d=0;d<g.length;d++){a(g[d]).css("z-index",String(g.length-d)).css("position","absolute").hide()}if(e.type=="sequence"){setTimeout(function(){a.innerfade.next(g,e,1,0)},e.timeout);a(g[0]).show()}else{if(e.type=="random"){var f=Math.floor(Math.random()*(g.length));setTimeout(function(){do{h=Math.floor(Math.random()*(g.length))}while(f==h);a.innerfade.next(g,e,h,f)},e.timeout);a(g[f]).show()}else{if(e.type=="random_start"){e.type="sequence";var h=Math.floor(Math.random()*(g.length));setTimeout(function(){a.innerfade.next(g,e,(h+1)%g.length,h)},e.timeout);a(g[h]).show()}else{alert("Innerfade-Type must either be 'sequence', 'random' or 'random_start'")}}}}};a.innerfade.next=function(d,b,e,c){if(b.animationtype=="slide"){a(d[c]).slideUp(b.speed);a(d[e]).slideDown(b.speed)}else{if(b.animationtype=="fade"){a(d[c]).fadeOut(b.speed);a(d[e]).fadeIn(b.speed,function(){removeFilter(a(this)[0])})}else{alert("Innerfade-animationtype must either be 'slide' or 'fade'")}}if(b.type=="sequence"){if((e+1)<d.length){e=e+1;c=e-1}else{e=0;c=d.length-1}}else{if(b.type=="random"){c=e;while(e==c){e=Math.floor(Math.random()*d.length)}}else{alert("Innerfade-Type must either be 'sequence', 'random' or 'random_start'")}}setTimeout((function(){a.innerfade.next(d,b,e,c)}),b.timeout)}})(jQuery);function removeFilter(a){if(a.style.removeAttribute){a.style.removeAttribute("filter")}};


jQuery.noConflict();
jQuery(document).ready(function () {


	jQuery('#referenzfade').innerfade({
			speed: 'slow',
			timeout: 3000,
			type: 'random_start',
			containerheight: '50px'
		});


	// Write your own code here.

	// focus next input field on enter
	jQuery("input").enterToTab();
	
	jQuery(".TextBoxField").DefaultValue("test");
	
	// Image Gallery with Fancybox
	
	jQuery(".fancybox").fancybox({
				'overlayOpacity' : 0.5,
				'overlayColor' : '#000',
				'type' : 'image',
				'padding' : 2,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'easingIn'      : 'easeOutBack',
				'easingOut'     : 'easeInBack'
	});		
	
	// 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);
    });
	
});

// 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(){

		//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=text;
		} else {
			//Other value exists - ignore
			return;
		}

		

		//Remove values on focus

		$j(this).focus(function() {
			if(this.value==text || this.value=='')
				this.value='';
		});

		//Place values back on blur
		$j(this).blur(function() {
			if(this.value==text || this.value=='')
				this.value=text;
		});

		

		//Capture parent form submissio
		//Remove field values that are still default

		$j(this).parents("form").each(function() {
			//Bind parent form submit
			$j(this).submit(function() {
				if(fld_current.value==text) {
					fld_current.value='';
				}
			});
		});

    });

};
