var R_DIR = "steinmueller";
var lastaction;
var refreshing = 4*1000; // 60 * 1000 = 1 Minute (1000 = millisekunden, 60 = sekunden)
var refreshId=0;
	
$(document).ready(function() {
	lastaction = new Date().getTime();
	if ($('.galleryimages')) {
		$('.galleryimages a:last').addClass("last");
	} 

   $('a.showBoxy').each(function() {
       var title = $(this).attr("title");
       $(this).boxy({
            title:"Info",
            closable:true,
            fixed:false,
            modal:true
        });
   });


   datepicker_init();

   
   $('form.enquireform > input.submit').click(function(e) {
      e.stopPropagation();
      if (_formValidation($(this).parent())==true) { return false; }
      $(this).parent().submit();
   });
   
   var imgnav = new image_navigation();
   imgnav.init();
});
function datepicker_init() {
   // datepickers in contact-form:
   $('input.datepicker').each(function() {
       $(this).datepicker({showButtonPanel: false, dateFormat: "yy-mm-dd"});
   });
}

function _formValidation(form) {
    var ret = false;
    $(".required",$(form)).each(function() {
        if ($(this).val()=="") {
            $(this).css("background","#eee").css("border","2px solid #f00");
           ret = true;
        }
    });
    return ret;
}
var image_navigation = function() {
   var me = this;
   this.init = function() {   		
   		$('.galleryimages a:first').addClass("active");
   		$('.galleryimages a').click(function() {
   			setRefreshTimeout();
   			if (!$(this).hasClass("active")) {
   				//$('div.loader').show();
   				
   				$('.galleryimages a').removeClass("active");
   				$(this).addClass('active');
   				
   				var src_new = $(this).attr("href");
                changePicture(src_new);
   			}
   			return false;
   		});
   		setRefreshTimeout();
   }
}
function changePicture(src_new) {
	$('#the_big_image').fadeOut(2000,function() {
        var img_new = new Image();
        $(img_new)
        .hide()
        .load(function() {
          	$('#the_big_image').attr("src",src_new);
          	$('#the_big_image').fadeIn(2000,function() {
          		$('#the_big_image2').attr("src",src_new);
          	});
        })
        .attr("src",src_new);
    });
}
function nextImage() {
	var actImage = $('.galleryimages a.active');
	$(actImage).removeClass("active");
	if ($(actImage).hasClass("last")) {
		$('.galleryimages a:first').click();
	} else {
		$(actImage).next().click();
	}
	setRefreshTimeout();
}

function setRefreshTimeout(first) {
	if (refreshId!=0) {
		clearTimeout(refreshId);
	}
	if (first=="1") {
		refreshId = setTimeout("nextImage()",0);
	} else {
		refreshId = setTimeout("nextImage()",refreshing);
	}
}
