$(document).ready(function() {

	// form validation
	$.validator.addMethod("notdefault", function(value, element) { if(value==element.defaultValue) { return false; } else { return true; } }, "");
	$.validator.messages.required = "";
	$.validator.messages.email = "";
	$("#formSearch").validate();
	$("#formNewsletter").validate();
	
	$("#formContact").bind("submit", function() {
		if($("input[name='about[]']").is(':checked')) {
			$("#error_about").css("display","none");
			return true;
		}else{
			$("#error_about").css("display","block");
			return false;
		}
	});
	$("input[name='about[]']").bind("click", function() {
		if($("input[name='about[]']").is(':checked')) {
			$("#error_about").css("display","none");
		}
	});
	$("#formContact").validate();

	$('#q').formatInput();
	$('#newsletter_email').formatInput();
		
	if (document.getElementById("scrollerWrapper")) {
		width = parseInt($("#scroller1").css("width"));
		pos1 = $("#scroller1").position().left;
		pos2 = $("#scroller2").position().left;
		scrollInt=setInterval("doScroll()",60)
	}
	
	$("#scrollingHotSpotLeft").mouseover(function() {
		scrollingSpeed = 9;
	});
	
	$("#scrollingHotSpotLeft").mouseout(function() {
		scrollingSpeed = 3;
	});
	
	$("#scrollingHotSpotRight").mouseover(function() {
		scrollingSpeed = -9;
	});
	
	$("#scrollingHotSpotRight").mouseout(function() {
		scrollingSpeed = -3;
	});

	$("div#makeMeScrollable div.item").bind("click", function() {
		scrollingSpeed = 0;
		var id = this.id.replace("item1_","");
		id = id.replace("item2_","");
		$(".popups div").css("display","none");
		$("#popup"+id).css("display","block");
		scrollPopup = true;
		return false;
	});
	
	$("div#makeMeScrollable div.item").mouseover(function() {
		scrollingSpeed = 0;
	});
	$("div#makeMeScrollable div.item").mouseout(function() {
		if(!scrollPopup) {
			scrollingSpeed = -3;
		}	
	});
	
	$("a.browse").bind("click", function() {
		$(".popups div").css("display","none");
		scrollPopup = false;
		scrollingSpeed = -3;
		return false;
	});
	$("a.close").bind("click", function() {
		$(".popups div").css("display","none");
		scrollPopup = false;
		scrollingSpeed = -3;
		return false;
	});
	
	//hover li toplevels, only needed for IE6
	$("#toplevels li").hover(function() {
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
	
	$("a.linkGoogleMap").fancybox({ 'frameWidth': 705, 'frameHeight': 605, 'overlayOpacity': 0.7, 'overlayColor': '#000', 'hideOnContentClick': false });
	
	if($("a#linkPrivacyPolicy").length) {
		if($("a#linkPrivacyPolicy").attr("href").indexOf("popup=Y") < 0) {
			$("a#linkPrivacyPolicy").attr("href",$("a#linkPrivacyPolicy").attr("href")+"?popup=Y");
			$("a#linkPrivacyPolicy").fancybox({ 'frameWidth': 705, 'frameHeight': 605, 'overlayOpacity': 0.7, 'overlayColor': '#000', 'hideOnContentClick': false });
		}
	}

});

var scrollingSpeed = -3;
var scrollPopup = false;
var pos1, pos2, width;
function doScroll() {
	pos1 = pos1 + scrollingSpeed;
	pos2 = pos2 + scrollingSpeed;
	$("#scroller1").css( { "left": pos1 + "px" } );
	$("#scroller2").css( { "left": pos2 + "px" } );
	
	if (pos1 < (width * -1)) {
		pos1 = pos2 + width;
		$("#scroller1").css( { "left": pos1 + "px" } );
	}
	if (pos2 < (width * -1)) {
		pos2 = pos1 + width;
		$("#scroller2").css( { "left": pos2 + "px" } );
	}
	if (pos1 > width) {
		pos1 = pos2 - width;
		$("#scroller1").css( { "left": pos1 + "px" } );
	}
	if (pos2 > width) {
		pos2 = pos1 - width;
		$("#scroller2").css( { "left": pos2 + "px" } );
	}
}

$.fn.formatInput = function() {
 return this.focus(function() {
  if( this.value == this.defaultValue ) {
   this.value = "";
  }
 }).blur(function() {
  if( !this.value.length ) {
   this.value = this.defaultValue;
  }
 });
};
