
function schreiben(name,value,expires)
{
 var date = new Date();
 date = new Date(date.getTime() +expires);
 document.cookie = name+'='+value+'; expires='+date.toGMTString()+'; path=/';
}

function lesen(n)
{
 cookie = document.cookie;
 res = '';
 while(cookie != '')
 {
  while(cookie.substr(0,1) == ' '){cookie = cookie.substr(1,cookie.length);}
  cookiename = cookie.substring(0,cookie.indexOf('='));
  if(cookie.indexOf(';') != -1)
  {cookiewert = cookie.substring(cookie.indexOf('=')+1,cookie.indexOf(';'));}
  else{cookiewert = cookie.substr(cookie.indexOf('=')+1,cookie.length);}
  if(n == cookiename){res = cookiewert;}
  i = cookie.indexOf(';')+1;
  if(i == 0){i = cookie.length}
  cookie = cookie.substring(i,cookie.length);
 }
return(res)
}

function loeschen(name)
{
 document.cookie = name+'=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/';
}

function seite_nach_links(){
schreiben("pos","links", 1000*60*60*24*30);
var div = jQuery("#page");
var offset = div.offset();
div.css("marginLeft",offset.left);
div.animate({marginLeft: "15px"}, "slow");
jQuery('#seite_nach_links_link').remove();
jQuery("body").append("<a id='seite_in_die_mitte_link' href='javascript:seite_in_die_mitte()'>Seite in die Mitte schieben</a>");
}

function seite_in_die_mitte(){
loeschen("pos");
var div = jQuery("#page");
var abstand = (jQuery(window).width()- div.width())/2;
if (abstand >= 0){
div.animate({marginLeft: abstand}, "slow", function() {
   div.css("marginLeft","auto");
   });
}
else
{
div.css("marginLeft","auto");
}
jQuery('#seite_in_die_mitte_link').remove();
jQuery("body").append("<a id='seite_nach_links_link' href='javascript:seite_nach_links()'>Seite an den linken Rand schieben</a>");
}

jQuery(document).ready(function() {

// Navigation ausblenden
	jQuery("#navi ul li ul li").hide();
	jQuery(".current_page_item").children("ul").children("li").slideDown("slow");
	jQuery(".current_page_ancestor").children("ul").children("li").slideDown("slow");

if (lesen("pos") == "links")
{
jQuery("#page").css("marginLeft","15px");
jQuery("body").append("<a id='seite_in_die_mitte_link' href='javascript:seite_in_die_mitte()'>Seite in die Mitte schieben</a>");
}
else
{
jQuery("body").append("<a id='seite_nach_links_link' href='javascript:seite_nach_links()'>Seite an den linken Rand schieben</a>");
}

// Slideshow auf der Titelseite
  	jQuery('#slideshow1').cycle({
		fx: 'fade'
	});

	//Bilder aus Slideshow klickbar machen (id = Verlinkte Seite) (direkte Links (<a> gehen mit cycle nicht im IE) 
	jQuery('#slideshow1 img').click(function(){
	location = "http://www.mon-tec.eu/wordpress/" + $(this).attr("id");
});

//Referenzen
jQuery(".kategorie_unten").hide();
jQuery("#kategorie_unten_ueberschrift").click(function(){
jQuery(".pfeil").remove();
jQuery("#kategorie_oben_ueberschrift h2").prepend('<img class="pfeil" src="http://www.mon-tec.eu/wordpress/wp-content/themes/mon-tec/images/pfeil_ver.png" />');
jQuery("#kategorie_unten_ueberschrift h2").prepend('<img class="pfeil" src="http://www.mon-tec.eu/wordpress/wp-content/themes/mon-tec/images/pfeil_hor.png" />');
jQuery(".kategorie_unten").slideDown();
jQuery(".kategorie_oben").slideUp();
});
jQuery("#kategorie_oben_ueberschrift").click(function(){
jQuery(".pfeil").remove();
jQuery("#kategorie_unten_ueberschrift h2").prepend('<img class="pfeil" src="http://www.mon-tec.eu/wordpress/wp-content/themes/mon-tec/images/pfeil_ver.png" />');
jQuery("#kategorie_oben_ueberschrift h2").prepend('<img class="pfeil" src="http://www.mon-tec.eu/wordpress/wp-content/themes/mon-tec/images/pfeil_hor.png" />');
jQuery(".kategorie_oben").slideDown();
jQuery(".kategorie_unten").slideUp();
});

//YouTube in Fancybox anzeigen
jQuery(".youtube").fancybox({
	 'frameWidth': 640,
	 'frameHeight': 505
});

//  Fancybox
    jQuery.fn.getTitle = function() {
      var arr = jQuery("a.fancybox");
      jQuery.each(arr, function() {
        var title = jQuery(this).children("img").attr("title");
        jQuery(this).attr('title',title);
      })
    }
    var thumbnails = 'a:has(img)[href$=".bmp"],a:has(img)[href$=".gif"],a:has(img)[href$=".jpg"],a:has(img)[href$=".jpeg"],a:has(img)[href$=".png"],a:has(img)[href$=".BMP"],a:has(img)[href$=".GIF"],a:has(img)[href$=".JPG"],a:has(img)[href$=".JPEG"],a:has(img)[href$=".PNG"]';
    jQuery(thumbnails).addClass("fancybox").attr("rel","fancybox").getTitle();
    jQuery("a.fancybox").fancybox({
    'imageScale': true,
    'padding': 10,
    'zoomOpacity': true,
    'zoomSpeedIn': 500,
    'zoomSpeedOut': 500,
    'overlayShow': true,
    'overlayOpacity': 0.3,
    'hideOnContentClick': false,
    'centerOnScroll': true
    });
	
//Kontaktformular (Telefonnr)	
	if ((jQuery("#rueckruf span input").attr("checked") == 0) || (jQuery("#rueckruf span input").attr("checked") == null))
	{
	jQuery("#telefon").hide();
	}
	jQuery("#rueckruf span input").click(function(){
	jQuery("#telefon").slideToggle("slow");
	});
//Icons vor Links anzeigen
	// $("a[href$='.pdf']").addClass("pdf");
	// $("a[href$='.zip'], a[href$='.rar']").addClass("zip"); 
 	//$('a').filter(function() {
//	  return this.hostname && this.hostname !== location.hostname;
	//  }).addClass("external");
		
	Hyphenator.run();

//Ende load on ready
});
