/**
 * Retourne le base url de la fenêtre courante, eg. : http://www.mon-domaine.fr/
 */
window.location.baseUrl = function()
{
	var uri = window.location.protocol + '//' + window.location.hostname;
	if(window.location.port)
	        uri = uri + ':' + window.location.port;
	uri = uri + '/';

	return uri;
}

$(document).ready(function() {


	// liens d'evitement
	$("div.skip_link a").focus(function(){
		$(this).parents("div.skip_link").addClass('on');
	});
	$("div.skip_link a").blur(function(){

		$(this).parents("div.skip_link").removeClass('on');
	});

	// Handlers sur les liens
	jQuery('a').each(function() {
		var _this = jQuery(this);

		//ouverture dans une nouvelle fenêtre des liens new_window
		if (_this.is('.new_window'))
		{
			_this.click(function(e){
			        var link_url = this.href;
		
				//le lien est déjà une URL absolue
				if(link_url.indexOf('http://') == 0 || link_url.indexOf('https://') == 0)
		                {
		                        window.open(this.href, '_blank');
		                }
		                //reconstruction de l'URL absolue
		                else
		                {
					if(link_url.indexOf('/') == 0)
					        link_url = link_url.substr(1, link_url.length);
		
		                        window.open(window.location.baseUrl() + link_url, '_blank');
		                }
		
				e.preventDefault();
			});
		}
		// Liens de redimensionnement de text
		else if (_this.is('.bigger_txt'))
		{
			if ($.cookie('S') >= 2)
			{
				_this.parent().css('display', 'none');
			}
			_this.click(function(e) {
				if ((size = $.cookie('S')) !== null)
					size++;
				else
					size = 1;

				$.cookie('S', size, {path: '/'});

				$('head link[@href*=font_size_]').remove();
				$('head').append('<link rel="stylesheet" type="text/css" href="/fileadmin/templates/gaya/Photoquai/css/font_size_'+size+'.css" media="screen" />');

				if (size >= 2)
					_this.parent().css('display', 'none');
				else
					$('a.lower_txt').parent().css('display', 'inline');

				e.preventDefault();
			});
		}
		// Liens de redimensionnement de text
		else if (_this.is('.lower_txt'))
		{
			if ($.cookie('S') < 1)
			{
				_this.parent().css('display', 'none');
			}
			_this.click(function(e) {
				if ((size = $.cookie('S')) !== null)
					size--;
				else
					size = 0;

				$.cookie('S', size, {path: '/'});

				$('head link[@href*=font_size_]').remove();
				$('head').append('<link rel="stylesheet" type="text/css" href="/fileadmin/templates/gaya/Photoquai/css/font_size_'+size+'.css" media="screen" />');

				if (size <= 0)
					_this.parent().css('display', 'none');
				else
					$('a.bigger_txt').parent().css('display', 'inline');

				e.preventDefault();
			});
		}
	});
});
