/**
 * jQuery Cookie plugin - https://github.com/carhartl/jquery-cookie
 *
 * Copyright (c) 2010 Klaus Hartl, @carhartl
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
(function($) {
    $.cookie = function(key, value, options) {

        // key and at least value given, set cookie...
        if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value === null || value === undefined)) {
            options = $.extend({}, options);

            if (value === null || value === undefined) {
                options.expires = -1;
            }

            if (typeof options.expires === 'number') {
                var days = options.expires, t = options.expires = new Date();
                t.setDate(t.getDate() + days);
            }

            value = String(value);

            return (document.cookie = [
                encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
                options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
                options.path    ? '; path=' + options.path : '',
                options.domain  ? '; domain=' + options.domain : '',
                options.secure  ? '; secure' : ''
            ].join(''));
        }

        // key and possibly options given, get cookie...
        options = value || {};
        var decode = options.raw ? function(s) { return s; } : decodeURIComponent;

        var pairs = document.cookie.split('; ');
        for (var i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) {
            if (decode(pair[0]) === key) return decode(pair[1] || ''); // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, thus pair[1] may be undefined
        }
        return null;
    };
})(jQuery);


$(document).ready(function () {

//$("tr#row_1,tr#row_2,tr#row_3").css("display","none");

//$("#input_1").DefaultValue("Telefon");
//$("#input_2").DefaultValue("E-Mail");
//$("#input_3").DefaultValue("Mitteilung");

 		$(".picture_gallery a").fancybox({
				'titleShow'     : true,
		'titlePosition'	:	'over',
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack'


			});

	$("#zertifikat").hover(
	  function () {
	  $("#zert_info").stop();
	   $("#zert_info").animate({ 
			opacity: 1
			}, 500 );
	  },
	  function () {
	  $("#zert_info").stop();
	  $("#zert_info").animate({ 
			opacity: 0
			}, 500 );
	  }
	);	
	
	$("li.menu1").click(function(){
		document.location.href = $(this).find("a:first").attr("href"); 
	});

	$("li.menu1.notselected").animate({ 
	opacity: 0.3
	}, 1000 );
	
	$("li.menu1.notselected").hover(
	  function () {
	   $(this).addClass("selected");
   	   $(this).stop();
	   $(this).animate({ 
			opacity: 1
			}, 200 );
	  },
	  function () {
	  $(this).removeClass("selected");
 	  $(this).stop();
	  $(this).animate({ 
			opacity: 0.3
			}, 800 );
	  }
	);

	$("#glossar_links").css("width",$(window).width()+ "px");		
	
	if ($.cookie("showlehrling") == null) {//Lehrlinge gesucht
		$("#show_lehrling_info").fancybox({
				'titleShow'     : true,
		'titlePosition'	:	'over',
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'width' : 300,
		'height' : 320,
		'autoDimensions' : false,
		'scrolling':'no'


			}).trigger("click");
		$.cookie("showlehrling","angezeigt"); 
	} 
	
	
});

$(window).resize(function() {
  $("#glossar_links").css("width",$(window).width()+ "px");
});



//Secure Mail
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);}




function showPic( imgName, imgCaption, imgWidth, imgHeight, textColor, bgColor ) {
	if(imgWidth<=100)imgWidth=100
	if(imgHeight<=100)imgHeight=100
	winHeight=imgHeight+20;
	w = window.open('','Demo','toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,copyhistory=no,width='+imgWidth+',height='+winHeight);
	w.document.write( "<html><head><title>"+imgCaption+"</title>" );
	w.document.write( "<STYLE TYPE='text/css'>" );
	w.document.write( "A {font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: "+textColor+"; text-decoration : none;}" );
	w.document.write( "A:Visited {font-family: Arial, Helvetica, sans-serif;font-size: 11px; font-weight: bold; color: "+textColor+"; }" );
	w.document.write( "A:Active { font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: "+textColor+"; }" );
	w.document.write( "A:Hover { font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: "+textColor+"; }" );
	w.document.write( "IMG {border-color : "+textColor+";}" );
	w.document.write( "BODY { font-family: Arial, Helvetica, sans-serif; font-size : 11px; font-weight: normal; color : "+textColor+"; background-color : "+bgColor+"; }" );
	w.document.write( "</STYLE>" );
	w.document.write( "<script language='JavaScript'>\n");
	w.document.write( "IE5=NN4=NN6=false\n");
	w.document.write( "if(document.all)IE5=true;\n");
	w.document.write( "else if(document.getElementById)NN6=true\n");
	w.document.write( "else if(document.layers)NN4=true\n");
	w.document.write( "function autoSize() {\n");
	w.document.write( "	if(IE5) self.resizeTo(document.images[0].width+10,document.images[0].height+31+20)\n");
	w.document.write( "	else if(NN6) self.sizeToContent()\n");
	w.document.write( "	else top.window.resizeTo(document.images[0].width,document.images[0].height+20)\n");
	w.document.write( "	self.focus()\n");
	w.document.write( "}\n</scr");
	w.document.write( "ipt>\n");
	w.document.write( "</head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onLoad=" );
	w.document.write( "'javascript:autoSize();'>" );
	w.document.write( "<table cellpadding=0 cellspacing=0 border=0><tr><td colspan=3><img src='"+imgName+"' border=0 alt='"+imgCaption+"'></td></tr>" );
	w.document.write( "<tr><td align='left'>  <a href='javascript:window.print()'>Ausdrucken</a></td>" );
	w.document.write( "<td align='center'> </td>" );
	w.document.write( "<td align='right'><a href='javascript:top.window.close();'>Schliessen</a>  </td></tr>" );
	w.document.write( "</table></body></html>" );
	w.document.close();
}

function showPicFix(imgName, imgWidth, imgHeight) {
	if(imgWidth<=100) {imgWidth=100}
	if(imgHeight<=100) {imgHeight=100}
	var winHeight=imgHeight+20;
	w = window.open(imgName,'Referenz','toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,copyhistory=no,width='+imgWidth+',height='+winHeight);
	w.document.close();
}

//default value Plugin;


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
		$(this).focus(function() {
			if(this.value==text || this.value=='')
				this.value='';
		});
		
		//Place values back on blur
		$(this).blur(function() {
			if(this.value==text || this.value=='')
				this.value=text;
		});
		
		//Capture parent form submission
		//Remove field values that are still default
		$(this).parents("form").each(function() {
			//Bind parent form submit
			$(this).submit(function() {
				if(fld_current.value==text) {
					fld_current.value='';
				}
			});
		});
    });
};



