/***
 * Humanique site specific javascript functions and classes
 */

$(document).ready(function() {

	// open all links marked rel="external" in a new window
	$("a[rel=_blank]").attr('target', '_blank');
	
	// opens selected url in option value when selection is changed
	$("select#select_risk_home").change(function() {
		var url = $("option:selected", this).val();
		$("div.risk-info-txt p").css("display", "none");
		
		
		if (url=='') {
			$("div.risk-info-txt p.risk-info-default").css("display", "block");
			$("p.risk-info-more-link").css("display", "none");
		}
		
		if(url !='') {
			temp = url.split("/");
			temp.reverse();
			var div_class = temp[0];
			
			$("div.risk-info-txt p.risk-info-"+div_class).css("display", "block");
			$("p.risk-info-more-link").css("display", "block");
			
			//window.location = url;
			return false;
		}
		return false;
	});
	
	// opens selected url in option value when link is clicked
	$("a#select_form_button_home").click(function() {
		var url = $("option:selected", $("select#select_risk_home")).val();
		if(url !='') {
			window.location = url;
			return false;
		}
	});	
	
	// opens selected url in option value when link is clicked
	$("a#select_form_button").click(function() {
		var url = $("option:selected", $("select#select_risk_static")).val();
		if(url !='') {
			window.location = url;
			return false;
		}
	});
	
	// all external urls are registred to google analytics
	$("a[rel=_blank]").click(function() {
			var url = $("a[rel=_blank]").attr("href");
			_gaq.push(['_trackPageview', url]);
	});

	// all factsheet downloads are registred to google analytics
	$(".inner-page a#factsheet_button").click(function() {
			var url = $("a#factsheet_button").attr("href");
			_gaq.push(['_trackPageview', url]);
	});
	
	$(".inner-page-2 a#factsheet_button").click(function() {
		var url = $("a#factsheet_button").attr("href");
		_gaq.push(['_trackPageview', url]);
	});
	
	// all click events on homepage_map_widget are registered to google analytics, through event
	$("input#maps_submit_address_home").click(function() {
		if($('#maps_input_address_home').val() != 'Zoek op gebied of op postcode (b.v. 1234 AB)') {
			_gaq.push(['_trackEvent', 'homepage_map_widget', 'click', 'zoek adres of postcode']);
			// _gaq.push(['_trackEvent', 'category', 'action', 'opt_label', opt_value]);
		}
	});

	// all enter events on homepage_map_widget are registered to google analytics, through event
	$("input#maps_input_address_home").keydown(function(e) {
		if(e.keyCode == 13) {
    	  if($('#maps_input_address_home').val() != 'Zoek op gebied of op postcode (b.v. 1234 AB)') {
    		  _gaq.push(['_trackEvent', 'homepage_map_widget', 'enter', 'zoek adres of postcode']);
    	  }
    	}
    });
	
	// all click events on homepage_map_widget are registered to google analytics, through event
	$("input#maps_submit_address_sidebar").click(function() {
		input_val = $('#maps_input_addres_sidebar').val();
		if(input_val != 'Zoek gebied of postcode') {
			_gaq.push(['_trackEvent', 'sidebar_map_widget', 'click', 'zoek adres of postcode']);
		}
	});

	// all enter events on sidebar_map_widget are registered to google analytics, through event
	$("input#maps_input_addres_sidebar").keydown(function(e) {
		if(e.keyCode == 13) {
			input_val = $('#maps_input_addres_sidebar').val();
			if(input_val != 'Zoek gebied of postcode') {
				_gaq.push(['_trackEvent', 'sidebar_map_widget', 'enter', 'zoek adres of postcode']);
				$('#maps_input_addres_sidebar').focus();
			}
    	}
    });
	
});	
