/*
 *  @file         global.js
 *  @description  Comportements globaux
 *  @author       Rafaël (ixmedia.com)
 */
$(function() {

	$('a').keyup(function(e) {
		if (e.which === 9) $(this).addClass('focus');
	});
	$('a').blur(function() {
		$(this).removeClass('focus');
	});
	
	$('a[title] img').removeAttr('title');
	
	$('a img').each(function() {
		$(this).parent().addClass('image-link');
	});
	
	// To detect native support for the HTML5 placeholder attribute
	var fakeInput = document.createElement('input'),
		placeHolderSupport = ('placeholder' in fakeInput);
	// Applies placeholder attribute behavior in web browsers that don't support it
	if (!placeHolderSupport) {
		$('[placeholder]').each(function() {
			$this = $(this);
			
			var originalText = $this.attr('placeholder');
			
			$this.val(originalText);
			$this.addClass('placeholder');
			
			$this.bind('focus', function () {
				$(this).removeClass('placeholder');
				if ($(this).val() === originalText) $(this).val('');
			});
			
			$this.bind('blur', function () {
				if ($(this).val().length === 0) {
					$(this).val(originalText);
					$(this).addClass('placeholder');
				}
			});
			
			// Empties the placeholder text at form submit if it hasn't changed
			$this.parents('form').bind('submit', function () {
				if ($(this).val() === originalText) $(this).val('');
			});
			
			// Clear at window reload to avoid it stored in autocomplete
			$(window).bind('unload', function () {
				if ($(this).val() === originalText) $(this).val('');
			});
		});
	}
});

