$(document).ready(function() {

	//Cufon replace
	Cufon.replace('h1', {fontFamily: 'gotham'}); 
	Cufon.replace('h2', {fontFamily: 'gotham', hover: true}); 
	Cufon.replace('h3', {fontFamily: 'gotham'});
	Cufon.replace('h2.entry-title-aktuelles', {fontFamily: 'gotham', hover: true});
	Cufon.replace('#answer1 h3', {fontFamily: 'gotham', hover: true});
	Cufon.replace('#answer2 h3', {fontFamily: 'gotham', hover: true}); 
	/*Cufon.replace('h4', {fontFamily: 'gotham'});*/ 
	Cufon.replace('h5', {fontFamily: 'gotham'}); 
	Cufon.replace('h6', {fontFamily: 'gotham'}); 
	Cufon.replace('h7', {fontFamily: 'gotham'}); 
	Cufon.replace('.h1', {fontFamily: 'gotham'}); 
	Cufon.replace('.h2', {fontFamily: 'gotham'}); 
	Cufon.replace('.h3', {fontFamily: 'gotham', hover: true}); 
	Cufon.replace('.h4', {fontFamily: 'gotham'}); 
	Cufon.replace('.h5', {fontFamily: 'gotham'}); 
	Cufon.replace('.h6', {fontFamily: 'gotham'}); 
	Cufon.replace('.h7', {fontFamily: 'gotham'}); 
	Cufon.replace('.captcha-1 input', {fontFamily: 'gotham'}); 
	Cufon.replace('input.wpcf7-submit', {fontFamily: 'gotham'}); 
	Cufon.replace('td.form_head', {fontFamily: 'gotham'});
	Cufon.replace('.town_label', {fontFamily: 'gotham'});
	Cufon.replace('.gallery_link', {fontFamily: 'gotham', hover: true});
	Cufon.replace('#menu-buroprofil a', {fontFamily: 'gotham', hover: true}); 
	Cufon.replace('#menu-buroprofil-en a', {fontFamily: 'gotham', hover: true}); 
	Cufon.replace('.edit-link', {fontFamily: 'gotham', hover: true}); 
	Cufon.replace('.single_back', {fontFamily: 'gotham', hover: true}); 
	Cufon.replace('#loading', {fontFamily: 'gotham'}); 

	//#############################
	Cufon.replace('#question h3', {fontFamily: 'gotham_bold'}); 
	Cufon.replace('.info h4', {fontFamily: 'gotham_bold'}); 
	Cufon.replace('.info a', {fontFamily: 'gotham_bold', hover: true}); 
	Cufon.replace('.startseiten_button', {fontFamily: 'gotham_bold', hover: true}); 
	Cufon.replace('.filter_button', {fontFamily: 'gotham_bold', hover: true}); 
	Cufon.replace('#header ul#navi li', {fontFamily: 'gotham', hover: true});
	Cufon.replace('.sub_cats li', {fontFamily: 'gotham', hover: true});
	
	//Cufon ENDE


	keyBoard.enableKeyboardNav();
	
	$(".vollbild").click(function() {
		$("#header").css("display","none");
		$("#footer").css("display","none");
	});

	Shadowbox.init({
		slideshowDelay: 5,
		displayCounter: false,
		continuous: true,
		viewportPadding: 5,
		animate: false
	});
	$(".checkbox").dgStyle();
	$(".checkbox_contact").dgStyle();
	
	// Searchbox Skripts
	$('#s').click(function(event){
		event.stopPropagation();	//verhindert ausblenden
	});

	$('.searchclick_input').click(function(event){
		event.stopPropagation();	//verhindert ausblenden
	});

	$('#meta_navi').click(function(event){
		event.stopPropagation();	//verhindert ausblenden
	});
	

	var search_fade = false;
	$('.searchclick').click(function() {
		if (search_fade == false)
		{
			$('.searchclick').fadeOut(function() {
				$('.searchclick_input').fadeIn(function() {
					
					$('.s').focus();	//Focus auf Eingabefeld
					if ($(".s").val()=="")
					{
						$(".s").setCursorPosition(0);
					}					
				});
				search_fade = true;
			});
		}
	});


	$('body').click(function() {
		if (search_fade == true)
		{
			$('.searchclick_input').fadeOut(function() {
				$('.searchclick').fadeIn();
				search_fade = false;
			});
		}
	});	

  // #######################################
  // Startseite
  
  $(window).resize(function() {
	  updateImageGallery(true);
  });
  
  $("#answer1 h3").click(function() {
    if($(this).next().is(':visible')) {
    	$(this).next().hide();
    }
    else {
      $(this).next().show();
    }
  });
  $("#answer2 a.closed").click(function() {
    if($(this).next().is(':visible')) {
	  $(this).next().hide();
	  $("#answer2 .h3").removeClass("highlight");
    }
    else {
	$("#answer2 .h3").addClass("highlight");
      $(this).next().show();
    }
  });
  // Open Exhibition Checkboxes
  $("#answer2 a").live('click', function() {
	$amount = $("div.checkbox").length;
	//alert($amount);
	if($(this).parent().css("top")=='0px') {
		$(this).removeClass("closed");
		$(this).parent().addClass("open");
		$top = 32 + Math.round($amount/2)*11;
		$(this).parent().animate({top: '-='+$top}, 500);
    	$(this).next().show();
    	$("#exhibition_checkboxes").show();
    }
	else {
		$(this).parent().removeClass("open");
		$(this).addClass("closed");
    	$(this).parent().animate({top: '+='+$top}, 500);
        $(this).next().show();
    	$("#exhibition_checkboxes").hide();
	}
  });
  // Select Label Color
  $("label").live('click', function() {
	  if($(this).prev().is(':checked')) {
		  $(this).addClass("active");
	  }
	  else {
		  $(this).removeClass("active");
	  }
  });

  
  $("#previous").live('click', function() {
	    var currentStatus = play[i];
		stopSlideGallery();
		$elem = $(this);
		$elem.hide();
		$("#controls").hide();
		$("#controls2").hide();
		$("#play_and_pause").show();
		$("#gallery .options .info").hide();
		$("#show_info").removeClass("active");
        $("#show_info").html(informationenanzeigen);

		//$("#filter").hide();
		$("#show_filter").removeClass("active");
		$("#space_current").hide();
		$("#mask_current").fadeIn(fadeTime, function(){
			$("#mask_current").hide();
			$galleryWidth = $("#gallery").width();
			$gallery = $("#gallery");
		  	$first = $("#gallery > div:first-child");
		  	$current = $("#gallery .current");
		  	$last = $("#gallery > div:last-child");
		  	$left = $current.prev().width()+20;
		  	$gallery.animate({left: '+='+$left}, animateTime, function() {
		  		// Animation complete.
		  		$current.prev().addClass("current");
		  		$current.removeClass("current");
		  		slideAdd -= 1;
			  	updateImageGallery(false);
				$("#mask_current").show();
				$("#mask_current").fadeOut(fadeTime, function(){
					$("#space_current").show();
					$("#mask_current").hide();
					//if(play[i]==false){
						$("#controls").show();
						$("#controls2").show();
					//}
					if(currentStatus==true){
						  play[i] = true;
						t=setTimeout('slideGallery(i)', slideTime);
					}
			    	$("#next").show();
			    	$("#next2").show();
					if($current.prev().hasClass("first")) {
				    	$("#previous").hide();
						$("#previous2").hide();
					}
					else {
						$("#mask_current").show();
						$elem.show();
					}
				});
		  	});
	  	});
		/*
		$content = '';
		  for(j=0; j<play.length; j++){
		      	$content += "play["+j+"]: " + play[j] + " | ";
				$("#menu-item-16").html("<pre>" + $content + "</pre>");
		      }
		      */
	  });
  
  
  var swipeOptions=
			{
				swipe:swipe,
				threshold:10,
				swipeStatus:swipeStatus
				}

  var swipeOptions2=
			{
				swipe:swipe2,
				threshold:10,
				swipeStatus:swipeStatus2
				}
	
	
	$("#play_and_pause").swipe( swipeOptions );

	$("#sb-body-inner").swipe( swipeOptions2 );	
	
	
	function swipe(event, direction)
			{
			
			if (direction=='right'){
					play[i] = false;
					$("#previous").click();
			}
			if (direction=='left') {
					play[i] = false;
					$("#next").click();
				}
			}


	function swipe2(event, direction)
			{
			
			if (direction=='right'){Shadowbox.previous();}
			if (direction=='left') {Shadowbox.next();}
			}

	
  function swipeStatus(event, phase)
			{
				if (phase=="cancel")
				{
					//alert("You didnt swipe far enough ");
				}
			}
			
			
  function swipeStatus2(event, phase)
			{
				if (phase=="cancel")
				{
					//alert("You didnt swipe far enough ");
				}
			}
  var $content = "";
			
$("#next").live('click', function() {
        var currentStatus = play[i];
		stopSlideGallery();
        slideGalleryEnabled = false;
	  	$elem = $(this);
		$elem.hide();
		$("#controls").hide();
		$("#controls2").hide();
		$("#play_and_pause").show();
		$("#gallery .options .info").hide();
		$("#show_info").removeClass("active");
		$("#show_info").html(informationenanzeigen);

		//$("#filter").hide();
		$("#show_filter").removeClass("active");
		$("#space_current").hide();
		$("#mask_current").fadeIn(fadeTime, function(){
			$("#mask_current").hide();
			$galleryWidth = $("#gallery").width();
			$gallery = $("#gallery");
		  	$first = $("#gallery > div:first-child");
		  	$current = $("#gallery .current");
		  	$last = $("#gallery > div:last-child");
		  	$left = $current.width()+20;
		  	$gallery.animate({left: '-='+$left}, animateTime, function() {
		  		// Animation complete.
		  		$current.next().addClass("current");
		  		$current.removeClass("current");
		  		slideAdd += 1;
			  	updateImageGallery(false);
				$("#mask_current").show();
				$("#mask_current").fadeOut(fadeTime, function(){
					$("#space_current").show();
					$("#mask_current").hide();
					//if(play[i]==false){
						$("#controls").show();
						$("#controls2").show();
					//}
					if(currentStatus==true){
						  play[i] = true;
						t=setTimeout('slideGallery(i)', slideTime);
					}
					if(showInfo==true){
						$("#gallery .current .options .info").show();
						$("#show_info").addClass("active");
						$("#show_info").html(informationenausblenden);
					}
			    	$("#previous").show();
			    	$("#previous2").show();
					slideGalleryEnabled = true;
					$("#play_and_pause").show();
					if($current.next().hasClass("last")) {
				    	$("#next").hide();
					    $("#next2").hide();
					}
					else {
					  	$elem.show();
					}
				});
		  	});
		});
		/*
		$content = '';
		  for(j=0; j<play.length; j++){
		      	$content += "play["+j+"]: " + play[j] + " | ";
				$("#menu-item-16").html("<pre>" + $content + "</pre>");
		      }
		      */
	 });


	$("#previous2").live('click', function() {
		$("#previous").click();
	});
	
	$("#next2").live('click', function() {
		$("#next").click();
	});

  /*
  $("#previous").mouseenter(function(){
	  if(play[i] == true) {
		  //$("#play_and_pause").click();
	  };
	  $("#previous img").show();
  });
  $("#previous").mouseleave(function(){
	  $("#previous img").hide();
  });
  
  $("#play_and_pause").mouseenter(function(){
	  $("#play_and_pause img").show();
  });
  $("#play_and_pause").mouseleave(function(){
	  $("#play_and_pause img").hide();
  });  
  
  $("#next").mouseenter(function(){	  
	  if(play[i] == true) {
		  //$("#play_and_pause").click();
	  };
	  $("#next img").show();
  });
  $("#next").mouseleave(function(){
	  $("#next img").hide();
  });
*/

  // Play & Pause
  $("#play_and_pause").click(function() {
	  if($(this).find("img").attr("src") == ajaxUrlPath + "/images/play.png") {
		  $(this).find("img").attr("src", ajaxUrlPath + "/images/pause.png");
		  if((slideGalleryEnabled == true)&&(slideGalleryRunning==false)){
			  play[i] = true;
			  slideGallery(i);
		  }
		  //$("#controls").hide();
		  //$("#controls2").hide();
	  }
	  else {
		  stopSlideGallery();
		  $(this).find("img").attr("src", ajaxUrlPath + "/images/play.png");
		  //$("#controls").show();
		  //$("#controls2").show();
	  }
	  /*
	  $content = "";
	  for(j=0; j<play.length; j++){
      	$content += "play["+j+"]: " + play[j] + " | ";
		$("#menu-item-16").html("<pre>" + $content + "</pre>");
      }
      */
  });
  // ============ 
  
  $("#show_info").click(function() {
	  $("#filter").hide();
	  $("#show_filter").removeClass("active");

		  $(".projektlinktext").html("&gt; " + projektlinktext);
		  Cufon.replace('.projektlinktext', {fontFamily: 'gotham_bold', hover: true});

	  if($("#gallery .current .options .info").is(":hidden")) {
		  showInfo = true;
		  $("#gallery .current .options .info").show();
		  $("#show_info").addClass("active");
		  $("#show_info").html(informationenausblenden);
	  }
	  else {
		  showInfo = false;
		  $("#gallery .current .options .info").hide();
		  $("#show_info").removeClass("active");
		  $("#show_info").html(informationenanzeigen);
	  }
  });
  $("#show_filter").click(function() {
	  if(play[i]==true){
		  $("#play_and_pause").click();
	  }
	  $("#gallery .options .info").hide();
	  $("#show_info").removeClass("active");
	  if($("#filter").is(":hidden")) {
		  $("#show_filter").addClass("active");
		  $("#filter").show();
		  $("#show_info").removeClass("active");
		  $("#show_info").html(informationenanzeigen);
	  }
	  else {
		  $("#show_filter").removeClass("active");
		  $("#filter").hide();
  		  $("#show_info").html(informationenanzeigen);
	  }
  });
  $("#gallery_mode").click(function(){
	  $("#filter").hide();
	  $("#show_filter").removeClass("active");

	  $("#gallery .options .info").hide();
      $("#show_info").removeClass("active");
	  $("#show_info").html(informationenanzeigen);


	  $elem = $(this);
	  if($elem.find("span").html()==galeriemodus) {
		  $("#small_gallery").fadeOut(fadeTime, function(){
			  $("#controls").show();
			  $("#play_and_pause").show();
			  $elem.find("img").attr("src",ajaxUrlPath + "/images/small_gallery.png");
			  $elem.find("span").html(miniaturen);
			  //$("#show_filter").css("left",339);
			  $("#show_filter").show();
			  $("#show_info").show();
			  showBigImage(1);
		  });
	  }
	  else {
		  $("#big_gallery").fadeOut(fadeTime, function(){
			  if(play[i]==true){
				  $("#play_and_pause").click();
			  }
			  $("#play_and_pause").hide();
			  $("#controls").hide();
			  $("#controls2").hide();
			  $elem.find("img").attr("src",ajaxUrlPath + "/images/big_gallery.png");
			  $elem.find("span").html(galeriemodus);
			  $("#options_menu").addClass("small_gallery");
			  $("#filter").addClass("small_gallery");
			  $("#show_info").hide();
			  //$("#show_filter").css("left",176);
			  $("#show_filter").hide();
			  $("#small_gallery").fadeIn();
		  });
	  }
  });
  
  // Thumbnail Bildergalerie
  $("#small_gallery div").mouseenter(function(){
	  $(this).find(".small_mask").hide();
  });
  $("#small_gallery > div").mouseleave(function(){
	  $(".small_mask").show();
  });
  $("#small_gallery div").click(function(){
	  id = $(this).attr("id").split("_")[1];
	  $("#controls").show();
	  $("#play_and_pause").show();
	  $("#show_filter").show();
	  $("#show_info").show();
	  showBigImage(id);
  });
  

});


var keyBoard = {
		//enable KeyboardNav
		enableKeyboardNav: function() {
	  		  $(document).bind("keydown", this.keyboardAction);
		},
	  
		// disable KeyboardNav
		disableKeyboardNav: function() {
			  $(document).unbind("keydown", this.keyboardAction);
		
		},
		// bind Keys to Action
	    keyboardAction:function(e){
			
			//console.debug("keyCode: " + e.which);     // use this, to find the right keys   left = 37 / up= 38 / right= 39  / down=40
			switch(e.which){
				case 37:				// 37 = previous			
					  play[i] = false;
					  if($("#previous").is(":visible")&&!$("#gallery .current").hasClass("first")) {
						  $("#previous").click();
						  $(this).stop(false, false);
					  }
					break;
				case 39:				// 39 = next				
					  play[i] = false;		
					  if($("#next").is(":visible")&&!$("#gallery .current").hasClass("last")) {
						  $("#next").click();
						  $(this).stop(false, false);
					  }
					break;


					
				default:
					//console.debug("key: no match"); 
					break;
			}		
		}
	}


//var fadeTime = 250;
var fadeTime = 650; //450;
//var animateTime = 450;
var animateTime = 750;

//var slideTime = 10000;	//freiland options => from austellung.php

  function showBigImage(id) {
	
	  $("#filter").removeClass("small_gallery");
	  $("#options_menu").removeClass("small_gallery");
	  $("#small_gallery").fadeOut( function(){
		  $("#gallery_mode").find("img").attr("src",ajaxUrlPath + "/images/small_gallery.png");
		  $("#gallery_mode").find("span").html(miniaturen);
		  $position = 0;
		  for(i=0; i < id-1; i++) {
			  $position -= $("#gallery > div").eq(i).find("img").width() + 20;
		  }
		  //alert($position);
		  $("#gallery").css("left", $position);
		  //alert($("#gallery").css("left"));

		  $("#gallery > div:first-child").removeClass("current");
		  $("#gallery .current").removeClass("current");
		  $("#gallery > div").eq(id-1).addClass("current");
		  if($("#gallery .current").hasClass("first")) {
			$("#previous").hide();
			$("#previous2").hide();
		  }
	      else {
			$("#previous").show();
	    	$("#previous2").show();
		  }
		  if($("#gallery .current").hasClass("last")) {
			//alert("Hide Next Button!");
		    $("#next").hide();
		    $("#next2").hide();
		  }
		  else {
			$("#next").show();
	    	$("#next2").show();
		  }
		  $("#mask_current").show();
		  $("#mask_current").fadeOut(fadeTime, function(){
			  $("#space_current").show();
			  $("#mask_current").hide();
		  });
		  updateImageGallery(true);
		  slideAdd = Number(id);
		  $("#show_filter").css("left",241);
		  $("#show_info").show();
		  if(id==1) {
			  $("#gallery").css("left","2560px");
			  $("#big_gallery").show();
			  $("#gallery").animate({left: '-='+2560}, animateTime*2, function(){
				  $("#options_menu").show();
				  if(play[i] == false) {
					  autoStart = true;
					  $("#play_and_pause").click();
				  }
			  });
		  }
		  else {
			  $("#big_gallery").fadeIn( function(){
				  $("#options_menu").show();
				  if(play[i] == false) {
					  autoStart = true;
					  $("#play_and_pause").show();
				  }
				  window.setTimeout("$('#play_and_pause').click()", 2000);
			  });
		  }
	  });
  }

  //=================
  // Bildergalerie
  function initializeImageGallery() {
	  $("#options_menu").hide();
	  $("#big_gallery").hide();
	  $("#small_gallery").hide();
	  $("#loading").show();
	  animateLoadingText();

	  loadImagesOneByOne(0);
	  $first_thumb = $("#small_gallery > div:first-child");
	  $galleryWidth = 0;
	  $("#gallery div img").each( function() {
		  $galleryWidth += Number($(this).attr("width"))+20;
	  });
	  $("#gallery").width($galleryWidth);
	  updateImageGallery(false);
	  // Thumbnail Gallery
	  $("#small_gallery div img").each( function() {
		  $(this).parent().find(".small_mask").height($(this).attr("height"));
		  $(this).parent().find(".small_mask").width($(this).attr("width"));
	  });

  }
  
  function loadImagesOneByOne(index) {
	  $gallery = $("#gallery");
	  //alert(data);
	  if(index < Number(GallerySize)){
			$.get(ajaxUrlPath + "/ajax/img.php?current_id=" + index + "&direction=1&gal="+gal, function(data) {
				$gallery.append(data);
				//alert(data + " nachladen");
				$galleryWidth += $("#gallery div:last-child").width()+20;
				$gallery.width($galleryWidth);
				updateImageGallery(false);
				//alert($("#small_gallery > div").length);
				$("#small_gallery > div").eq(index).css("visibility", "visible");
				index++;
				loadImagesOneByOne(index);
			});
		  }
	  else
	  {
		  Cufon.replace('.options .info h4', {fontFamily: 'gotham_bold'});
		  Cufon.replace('.options .info a', {fontFamily: 'gotham_bold', hover: true});
		  $("#loading").hide();
		  showBigImage(1);
	  }

		  $(".projektlinktext").html("&gt; " + projektlinktext);
		  Cufon.replace('.projektlinktext', {fontFamily: 'gotham_bold', hover: true});



  }
  
  function updateImageGallery(resize) {
	  $gallery = $("#gallery");
	  // Resize
	  $galleryLeft = 0;
	  $galleryWidth = 0;
	  $temp = 0;
	  // ======
	  if (navigator.userAgent.indexOf('IE') != -1) {
		  $window_height = document.documentElement.clientHeight;
	  }
	  else {
		  $window_height = window.innerHeight;
	  }
	  // For Links under Image
	  $window_height = $window_height-27;
	  //alert($window_height);
	  if ((navigator.userAgent.indexOf('IE 7') != -1)||(navigator.userAgent.indexOf('IE 8') != -1)) {
		  $imageHeight = $window_height-144;
	  }
	  else if (navigator.userAgent.indexOf('IE 9') != -1) {
		  $imageHeight = $window_height-163;
	  }
	  else {
		  $imageHeight = $window_height-125;
	  }
	  //alert($imageHeight);
	  $("#gallery > div > img").each( function() {
		  $originalImageHeight = Number($(this).attr("height"));
		  $originalImageWidth = Number($(this).attr("width"));
		  $factor = $imageHeight/$originalImageHeight;
		  $newImageHeight = Math.round($originalImageHeight*$factor);
		  $newImageWidth = Math.round($originalImageWidth*$factor);
		  if($newImageHeight<800) {
			  $(this).css("height",$newImageHeight);
			  $(this).css("width",$newImageWidth);
			  if (navigator.userAgent.indexOf('IE 7') != -1) {
				  $("#masks").css("margin-top",0);
			  }
			  $gallery.css("margin-top",0);
			  if($(this).parent().hasClass("current")) {
				  $("#mask_left").height($newImageHeight);
				  $("#mask_right").height($newImageHeight);
				  $("#space_current").height($newImageHeight);
				  $("#space_current").width($newImageWidth+20);
				  //alert($("#space_current").width());
				  $("#mask_current").height($newImageHeight);
				  $("#mask_current").width($newImageWidth+20);
				  $(this).next(".options").width($newImageWidth);
			  }
			  // Resize
			  if($(this).parent().hasClass("current")) {
				  $galleryLeft = $temp;
			  }
			  $temp -= $newImageWidth+20;
			  $galleryWidth += $newImageWidth+20;
			  // ======
		  }
		  else {
			  $(this).css("height",$originalImageHeight);
			  $(this).css("width",$originalImageWidth);
			  if ((navigator.userAgent.indexOf('IE 7') != -1)||(navigator.userAgent.indexOf('IE 8') != -1)) {
				  $galleryTop = ($window_height-961)/2;
			  }
			  else if (navigator.userAgent.indexOf('IE 9') != -1) {
				  $galleryTop = ($window_height-980)/2;
			  }
			  else {
				  $galleryTop = ($window_height-942)/2;
			  }
			  //alert(navigator.userAgent);
			  if (navigator.userAgent.indexOf('IE 7') != -1) {
				  $("#masks").css("margin-top",$galleryTop);
			  }
			  $gallery.css("margin-top",$galleryTop);
			  if($(this).parent().hasClass("current")) {
				  $("#mask_left").height($originalImageHeight);
				  $("#mask_right").height($originalImageHeight);
				  $("#space_current").height($originalImageHeight);
				  $("#space_current").width($originalImageWidth);
				  $("#mask_current").height($originalImageHeight);
				  $("#mask_current").width($originalImageWidth);
				  $(this).next(".options").width($originalImageWidth);
			  }
			  // Resize
			  if($(this).parent().hasClass("current")) {
				  $galleryLeft = $temp;
			  }
			  $temp -= $originalImageWidth+20;
			  $galleryWidth += $originalImageWidth+20;
			  // ======
		  }
	  });
	  $("#masks").width($("#masks").width()+$("#mask_current").width());
	  $("#masks").width($("#masks").width()+$("#space_current").width());
	  if(resize) {
		  //alert("galWidth: "+$galleryWidth);
		  $gallery.css("left",$galleryLeft);
		  $gallery.css("width",$galleryWidth);
	  }
	  //$("#filter").css("top",Number($("#gallery .current img").height())-133);
	  $("#filter").css("width",Number($("#gallery .current img").width())-26);

	  $("#loading").css("padding-top",Number($("#gallery .first img").height()/2)-10);
	  $("#loading").css("padding-left",(940/2)-30);

	  $imageWidth = Number($("#gallery .current img").width());
	  $rightOffset = 940 - $imageWidth;
	  $paddingLeft = $rightOffset + $imageWidth*0.25 + 40;
	  //=====================================

	  //$("#play_and_pause").css("left",Number($("#gallery .current img").width()*0.25));
	  //$("#play_and_pause").css("padding-top",Number($("#gallery .current img").height()/2)-48);
	  //$("#play_and_pause").css("padding-right",Number($("#gallery .current img").width()*0.25)-48);
	  //$("#play_and_pause").css("padding-bottom",Number($("#gallery .current img").height()/2)-49);
	  //$("#play_and_pause").css("padding-left",Number($("#gallery .current img").width()*0.25)-49);
	  
	  // New Arrow Positioning 2011-08-17
	  if (navigator.userAgent.indexOf('IE') != -1) {
		  $window_width = document.documentElement.clientWidth;
	  }
	  else {
		  $window_width = window.innerWidth;
	  }
	  $imageWidth = Number($("#gallery .current img").width());	  
	  /*
	  if($window_width >= 1280) {
		  $("#previous").css("left",-51);
		  $("#next2").css("left",$imageWidth/2);
		  $rightOffset = 940 - $imageWidth;
		  $paddingLeft = $imageWidth/2 + 20;
	  }
	  else 
	  */
	  if ($window_width >= 1050) {
		  $("#previous2").css("left",-51);
		  $("#next2").css("right",2);
		  $rightOffset = 970 - $imageWidth;
		  $paddingLeft = $rightOffset + $imageWidth*0.25 + 40;
	  }
	  else if ($window_width >= 940) {
		  $("#previous2").css("left",7);
		  $("#next2").css("right",7);	  
		  $imageLeft = $("#gallery .current img").css("left");
		  $rightOffset = 970 - $imageWidth;
		  $paddingLeft = $rightOffset + $imageWidth*0.25 + 40;		  
	  }
	  else if ($window_width < 940) {
		  $("#previous2").css("left",7);
		  $("#next2").css("right",987-$window_width);
		  $rightOffset = $window_width - $imageWidth;
		  $paddingLeft = $rightOffset + $imageWidth*0.25 + 40;
	  }
	  // ================================
	  
	  $("#next2").css("right",-79);
	  $("#previous2").css("padding-top",Number($("#gallery .current img").height()/2)-64);
	  $("#previous2").css("padding-right",Math.round($("#gallery .current img").width()*0.25)+40);
	  $("#previous2").css("padding-bottom",Number($("#gallery .current img").height()/2)-64);
	  $("#next2").css("padding-top",Number($("#gallery .current img").height()/2)-64);
	  $("#next2").css("padding-left",$paddingLeft);
	  $("#next2").css("padding-bottom",Number($("#gallery .current img").height()/2)-64);
  
  }


var intAdd = 1;
function animateLoadingText()
{
 switch(intAdd)
 {
 case 1:
  $("#loading").html(ladetext + ".");
  break;
 case 2:
  $("#loading").html(ladetext + "..");
  break;
 case 3:
  $("#loading").html(ladetext + "...");
  intAdd = 0;
  break;
 }
 Cufon.replace('#loading', {fontFamily: 'gotham'}); 
 intAdd++;
 if($("#loading").is(":visible")) {
	 t=setTimeout('animateLoadingText(intAdd)',250);
 }
}

var slideAdd = 1;
var i = 0;
var play = new Array();
play[i] = false;
var autoStart = false;
var slideGalleryEnabled = true;
var slideGalleryRunning = false;
var showInfo = false;

function slideGallery(id) {
	slideGalleryRunning = true;
	
	if(play[id]==true) {	
		if (slideAdd==$("#gallery > div").size()) {
			//alert("1");
			slideAdd = 1;
			$("#space_current").hide();
			$("#mask_current").fadeIn(fadeTime, function(){
				showBigImage(1);	//REINITIALISIERUNG GALLERY AM ENDE
				$("#play_and_pause").click();
			});
		}
		else if (autoStart==false) {
			$("#next").click();
		}
		autoStart = false;
		t=setTimeout('slideGallery('+id+')', slideTime);
	}
}

function stopSlideGallery() {
  play[i] = false;
  i++;
  clearTimeout(t);
  slideGalleryRunning = false;
}

function removeInput()
{
	if ($(".s").val()=="Input")
	{
		$(".s").val("");
	}
}


new function($) {
  $.fn.setCursorPosition = function(pos) {
    if ($(this).get(0).setSelectionRange) {
      $(this).get(0).setSelectionRange(pos, pos);
    } else if ($(this).get(0).createTextRange) {
      var range = $(this).get(0).createTextRange();
      range.collapse(true);
      range.moveEnd('character', pos);
      range.moveStart('character', pos);
      range.select();
    }
  }
}(jQuery);

