$(document).ready(function() {
	
	$("a[href$='.pdf']").click(function(){
        var url = $(this).attr("href");
        _gaq.push(['_trackEvent', 'Downloads', 'PDF', url]);
    });
	
	$("#click_europe").click(function () { 
	  var taal = $("#taal").val();
      hideall();
      $("#display_europe").show();
      $("#networkcontinent").val("5");
      var dataString = "networkcontinent=5,taal=" + taal;
			$.ajax({ 
				type: "GET",
				url: "/inc/ajax.dhtml",
				data: dataString,
				async: false,
				success: function(html) {
					$("#networkcountry").html(html)
				}
			});
			$('#networkcountryselect').show();
    });
    
    $("#click_america").click(function () { 
      var taal = $("#taal").val();
      hideall();
      $("#display_america").show();
      $("#networkcontinent").val("2");
      var dataString = "networkcontinent=2,taal=" + taal;
			$.ajax({ 
				type: "GET",
				url: "/inc/ajax.dhtml",
				data: dataString,
				async: false,
				success: function(html) {
					$("#networkcountry").html(html)
				}
			});
			$('#networkcountryselect').show();
    });
    
    $("#click_asia").click(function () { 
      var taal = $("#taal").val();
      hideall();
      $("#display_asia").show();
      $("#networkcontinent").val("3");
      var dataString = "networkcontinent=3,taal=" + taal;
			$.ajax({ 
				type: "GET",
				url: "/inc/ajax.dhtml",
				data: dataString,
				async: false,
				success: function(html) {
					$("#networkcountry").html(html)
				}
			});
			$('#networkcountryselect').show();
    });
    
    $("#click_australia").click(function () { 
      var taal = $("#taal").val();
      hideall();
      $("#display_australia").show();
      $("#networkcontinent").val("4");
      var dataString = "networkcontinent=4,taal=" + taal;
			$.ajax({ 
				type: "GET",
				url: "/inc/ajax.dhtml",
				data: dataString,
				async: false,
				success: function(html) {
					$("#networkcountry").html(html)
				}
			});
			$('#networkcountryselect').show();
    });
    
    $("#click_africa").click(function () { 
      var taal = $("#taal").val();
      hideall();
      $("#display_africa").show();
      $("#networkcontinent").val("1");
      var dataString = "networkcontinent=1,taal=" + taal;
			$.ajax({ 
				type: "GET",
				url: "/inc/ajax.dhtml",
				data: dataString,
				async: false,
				success: function(html) {
					$("#networkcountry").html(html)
				}
			});
			$('#networkcountryselect').show();
    });
    
	  $("#networkcontinent").change( function () { 
			var taal = $("#taal").val();
			var dataString = "networkcontinent=" + this.value + ",taal=" + taal;
			var continent = this.value;
			$.ajax({ 
				type: "GET",
				url: "/inc/ajax.dhtml",
				data: dataString,
				async: false,
				success: function(html) {
					$("#networkcountry").html(html)
				}
			});
			$('#networkcountryselect').show();
			if(continent == "1")
			{
				hideall();
      			$("#display_africa").show();
      		}
			else if (continent == "2")
			{
				hideall();
				$("#display_america").show();
			}
			else if (continent == "3")
			{
				hideall();
				$("#display_asia").show();     			
			}
			else if (continent == "4")
			{
				hideall();
      			$("#display_australia").show();
			}
			else if (continent == "5")
			{
				hideall();
				$("#display_europe").show();
			}
			
		});


	// 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();
	$("#formContact").validate();
	$("#formExtranet").validate();
	
	$('#q').formatInput();
	$('#extranet_login').formatInput();
	$('#extranet_password').formatInput();
	
	// scroller
	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;
	});
	
	// references
	$('#s_land').bind("change", function() {
		$('#formFilters').submit();
	});
	$('#s_solution').bind("change", function() {
		$('#formFilters').submit();
	});
	$('#s_product').bind("change", function() {
		$('#formFilters').submit();
	});

	// hover li toplevels, only needed for IE6
	var test_ie = $.support.opacity; // opacity doesn't work on all IE
	if(!test_ie) {
		$("#toplevels li").hover(function() {
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});
	}

	$("a.zoom").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300 });
	$("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 });
		}
	}
});

function hideall() {
	$("#display_europe").hide();
	$("#display_australia").hide();
	$("#display_asia").hide();
	$("#display_america").hide();
	$("#display_africa").hide();
	$("#display_all").hide();
}

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;
  }
 });
};
