

$(document).ready(function(){

	var mapdiv = document.getElementById('map');
	if(mapdiv != null){
		var map = new GMap2(mapdiv);
	  map.addControl(new GSmallMapControl());
	  var gischow = new GLatLng(53.4387600,12.0116500);
	  map.setCenter(gischow, 7);
	  
	  var marker = new GMarker(gischow);
	  
	  var isOpen = false;
	  GEvent.addListener(marker, "click", function() {
	  	if(isOpen){
	  		marker.closeInfoWindow();
	  		isOpen = false;
	  	} else {
	  		marker.openInfoWindowHtml("<p class=\"paragraph5\"><strong>Jagdschule Rehse</strong><br />Dipl.-Ing. (FH) Gösta Rehse<br /></p><p class=\"subparagraph1\"><strong>Firmensitz/Ausbildungsstätte</strong> <br />Hauptstr. 13<br /> 19386 Gischow<br /></p>");
	  		isOpen = true;
	  	}	  	
	  });
	  GEvent.addListener(marker,"infowindowclose", function(){
	  	isOpen = false;
	  });
	  
	  map.addOverlay(marker);
	}
	  
	  

	
	//image replacement	
	$('.picture_right').each(function(index,el){
		var originalUrl = $(el).attr("src");
		//new image object
		var img = new Image();
		//load image load animation and remove image
		$(el).attr('src','pictures/site/ajax-loader.gif').removeClass('picture_right').addClass('loader');
		//load image
		$(img).load(function(){	    
			$(this).css('display','none');
			$(this).addClass('picture_right');
			$(el).replaceWith(this);
			$(this).show();
		}).attr('src', originalUrl);	
	});

	//fancybox
	$('a.singleImage').fancybox({
		centerOnScroll: true,
		transitionIn: 'elastic',
		transitionOut: 'elastic',
		type: 'image'
	});
	
	//image-gallery
        var images = $('.thumb img').length;
        $image = $('.album li');
        var tnWidth = 0;
        var retrue = false;
        var imageList = new Array();
        var imageAttr = $('.thumb img');
               
        for(x=0;x<images;x++){
          tnWidth = tnWidth + parseInt($(".album li").css("width"));
        }          
        
        if (tnWidth<=700) {
          $("#thumb_navi").css({width: (tnWidth)+(2*40),left: "50%", "margin-left": -((tnWidth)+80)/2});
          $("#thumbs").css({width: tnWidth+1});
        }
        
        $(".album").css({width: tnWidth + 'px'});
        $(".album img").css({display:'inline'});
        
        $("#left").hover(function(e){
            $(".album").stop();
            $(".album").animate({"left":"0px"},5000,"swing");
        },function(){
          $(".album").stop();
        });
        
        $("#right").hover(function(e){
          $(".album").stop();
          var thumbDiv = $("#thumbs").css("width");
          var leftPos = tnWidth - parseInt(thumbDiv);
          if (leftPos >0) {
            $(".album").animate({"left":-leftPos+"px"},5000,"swing");
          }        
        },function(){
          $(".album").stop();
        });
        
               
        $(".thumb img").click(function(){
          $url = $(this).attr("src").split("thumbs/");
          var newUrl = $url[0]+$url[1];
          
          $("#main_image").html("<img />").hide();
          $("#main_image img").attr({src: newUrl, title: $(this).attr("title"), alt: $(this).attr("alt")});
          $("#main_image").fadeIn(1000);
            /*$("#main_image").append(imageList);*/ 
       });
       
       $('#rotation').cycle({ 
            fx: 'fade',
            speed: 2500,
            delay: -2000,
            random: 1 
        });
        
        	$("#refreshimg").click(function(){
        		$.post('pages/captcha/newsession.php');
        		$("#captchaimage").load('pages/captcha/image_req.php');
        		return false;
        	});
        
        jQuery.validator.addMethod("checkComment", function(value, element){
          var regExp = "url=http://|link=http://|http://";
          if (!value.match(regExp)) {
            return true;
          } else {
            return false;
          }
        });
        
        $("#check").validate({
            //set the rules for the field names
            rules: {
              name: {
                required: true,
                minlength: 2
              },
              email: {
                required: true,
                email: true
              },
              comments: {
                required: true,
                checkComment: true,
                minlength: 2
              },
              captcha: {
        				required: true,
        				remote: "pages/captcha/process.php"
        			}
            },
            //set messages to appear inline
            messages: {
            name: "",
            email: "",
            comments: "",
            captcha: ""	
            },
            submitHandler: function(form) {
              form.submit();
       		},        		
       		onkeyup: false
});
        
      
                
});