/**
 * Some onload stuff
 */

	
	/* media center */
	Cufon.replace('div.resources .resource .description div.h1,div.resources .resource .description div.content', { fontFamily: 'miso',fontSize:'20px'});
	Cufon.replace('.newsoverview .head span', { fontFamily: 'miso',fontSize:'18px'});
	Cufon.replace('#holder div.resources .row.paging .show', { fontFamily: 'miso', fontSize:'20px' });
	Cufon.replace('.pagination span, .col.txt, a.linkDownload', { fontFamily: 'miso', fontSize:'20px' });
	Cufon.replace('.col.txt, .col.last', { fontFamily: 'miso', fontSize:'14px' });
	


jQuery(document).ready(function() {

	// all links with rel='external' to blank target
	jQuery("a[rel='external']").attr("target", "_blank");
	
	// filter checkbox
	jQuery('input[type="checkbox"]').ezMark();

	// anti skype
	window.setTimeout(function() {
			jQuery('.skype_pnh_container').html('');
			jQuery('.skype_pnh_print_container').removeClass('skype_pnh_print_container');
	}, 800);
	
	// convert all media links
	if(jQuery("a.media").size()) {
		jQuery("a.media").media();
	}
	
	// styling dropdown with an image
	jQuery("form#language select").msDropDown().bind("change", function() { window.location = jQuery(this).val(); });
	
	// Contactform validation
	jQuery("form#contactform").validate({
		rules: {
			gender: { required: true },
			surname: { required: true },
			name: { required: true },
			company: { required: true },
			email: { required: true, email: true },
			phone: { required: true },
			country: { required: true }
		},
		messages: {	
			gender: " ",
			surname: " ",
			name: " ",
			company: " ",
			email: " ",
			phone: " ",
			country: " "
		},
		unhighlight: validateUnhighlight,
		errorPlacement: validateErrorPlacement
	});
	
	jQuery("form#contactformulier").validate({
		rules: {
			gender: { required: true },
			surname: { required: true },
			name: { required: true },
			company: { required: true },
			email: { required: true, email: true },
			phone: { required: true },
			country: { required: true },
			city: { required: true },
		  address: { required: true },
		  zipcode: { required: true }
		},
		messages: {	
			gender: " ",
			surname: " ",
			name: " ",
			company: " ",
			email: " ",
			phone: " ",
			country: " ",
			city: " ",
			address: " ",
			zipcode: " "
		},
		unhighlight: validateUnhighlight,
		errorPlacement: validateErrorPlacement
	});

		jQuery('#gps .map').mobilymap({
			position: 'center',
			popupClass: 'bubble',
			markerClass: 'point',
			popup: true,
			cookies: false,
			caption: false,
			setCenter: true,
			navigation: true,
			navSpeed: 1000,
			navBtnClass: 'navBtn',
			outsideButtons: '.map_buttons a',
			onMarkerClick: function(){},
			onPopupClose: function(){},
			onMapLoad: function(){}
		});


	// product details; tabs
	if(jQuery("#tabs").size()) {
		jQuery('#tabs').tabs();
	}
	
	
	if(jQuery(".contact_container").size()) {
	 
		jQuery(".connectUs").click(function () {
			if(jQuery(this).hasClass("active")){
				jQuery(this).removeClass("active");
				jQuery(this).next().removeClass("show");
			}else{
				jQuery(this).addClass("active");
				jQuery(this).next().addClass("show");
			}
		});
		jQuery(".social_icons").click(function () {
			jQuery(".connectUs").removeClass("active");
			jQuery(this).removeClass("show");
		
		});
	}
	
	// product details; actions below the product image
	if(jQuery("#product-actions").size()) {
		
		jQuery("#product-actions a.images").bind("click", function() {
			jQuery("#tabs").tabs('select', 3);
			return false;
		});
		
		jQuery("#product-actions a.video").bind("click", function() {
			jQuery("#tabs").tabs('select', 4);
			return false;
		});
	}

	jQuery('#coda-slider-1').codaSlider({
		autoHeight: false,
		dynamicTabs: false,
		dynamicArrows: false,
		autoSlide: true,
		autoSlideInterval: 4000,
		autoSlideStopWhenClicked: false		
	});
	
	// find all a's with a mailto link. Add a tracker to them
	/* 
	jQuery("a[href^=mailto:]").each(function() {
		jQuery(this).click(function() {
			if(typeof(_gaq) != 'undefined') {
				_gaq.push(['_trackPageview', '/' + jQuery(this).attr("href")]);
			}
		});
	});
	*/
	
	flashMovie = null;
	flashMovie = jQuery('#banner1'); flashMovie.flash({ swf: 'assets/swf/vehicle-and-driver-identification.swf', width: 960, height: 330, play: true });
	flashMovie = jQuery('#banner2'); flashMovie.flash({ swf: 'assets/swf/handsfree-access.swf', width: 960, height: 330, play: true });
	flashMovie = jQuery('#banner3'); flashMovie.flash({ swf: 'assets/swf/vehicle-detection.swf', width: 960, height: 330, play: true });
	flashMovie = jQuery('#banner4'); flashMovie.flash({ swf: 'assets/swf/vehicle-management.swf', width: 960, height: 330, play: true });

});

/*   */



jQuery(window).load(function() {
	equalHeight(jQuery(".eqhead"));
	equalHeight(jQuery(".eqtekst"));
	equalHeight(jQuery(".expand"));
	equalHeight(jQuery(".product-group a.product"));
});

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = jQuery(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	
	group.height(tallest);
} 


/**
 * Validate methods to place the errors in the TD behind the TD of the input field
 */
function validateUnhighlight(element, errorClass, validClass) {

		jQuery(element).removeClass(errorClass).addClass(validClass);
		jQuery(element).parent().next().addClass(validClass);
}

function validateErrorPlacement(error, element) {

 	// group checks
	if(element.hasClass("radio")) {
		element.parent("td").next("td").html('');
		
	}
	
	error.appendTo( element.parent("td").next("td") );
}

//flash banner vars
function play() {
	flashMovie.flash(
		function() {
			this.Play();
		}
	);
}

function pause() {
	flashMovie.flash(
		function() {
			this.StopPlay();
		}
	);
}

function firstFrame() {
	flashMovie.flash(
		function() {
			this.GotoFrame(0);
		}
	);
}

function lastFrame() {
	flashMovie.flash(
		function() {
			this.GotoFrame(9);
		}
	);
}

function prevFrame() {
	flashMovie.flash(
		function() {
			var currentFrame = this.TGetProperty('/', 4),
				previousFrame = parseInt(currentFrame) - 2;

			if (previousFrame < 0) {
				previousFrame = 9;
			}

			this.GotoFrame(previousFrame);
		}
	);
}

function nextFrame() {
	flashMovie.flash(
		function() {
			var currentFrame = this.TGetProperty('/', 4),
				nextFrame = parseInt(currentFrame);

			if (nextFrame >= 10) {
				nextFrame = 0;
			}

			this.GotoFrame(nextFrame);
		}
	);
}

function sendToFlash() {
	flashMovie.flash(
		function() {
			this.SetVariable('/:message', document.getElementById('data').value);
		}
	);
}

function getFromFlash() {
	flashMovie.flash(
		function() {
			document.getElementById('data').value = this.GetVariable('/:message');
		}
	);
}

	//submit
	if(jQuery("input.username").size()) {
		jQuery("input.username").watermark("Username");
	}
	if(jQuery("input.password").size()) {
		jQuery("input.password").watermark("Password");
	}
