$(function() {

	$('#datepicker').datepicker();
	
	$('#header #logo a, #header-page #logo a').removeAttr('style');

});


			
$(function() {

	$('#menu ul li a').each(function() {
	
		var $this = $(this);
		var words = $this.text().split(' ');
		var type_words = 0;
		
		if ($this.text().length <= 14) {
			type_words = 1;
			
			if ($this.text().length != 13) {
				if (words.length == 2 && $this.text().length > 11) {
					$(words).each(function() {
						if ($(this).length <= 6) {
							type_words = 0;
						}
					});
				}
			}
			
			// console.debug('type_words : ' + $this.text() + ' / ' + type_words);
		}
		
		if (words.length > 1) {
			$(words).each(function() {
				if ($(this).length >= 15) {
					type_words = 2;
				}
			});
		}
		
		if (words.length >= 3 && $.trim($this.text()).length >= 25) {
			var safe_type = true;
			
			if (words.length == 3) {
				$(words).each(function() {
					if ($(this).length < 5) {
						safe_type = false;
					}
				});
			}
		
			if (safe_type) {
				type_words = 3;
			}
		}
		
		if (words.length >= 5) {
			type_words = 4;
		}
		
		switch (type_words) {
		
			case 1 :
			
				$this.addClass('center');
			
			break;
			
			case 2 :
				
				if ($.browser.msie && $.browser.version == '6.0') {
				} else {
					$this.css({
						width: $this.width() + 25
					});
				}
			
			break;
			
			case 3 :
			
				$this.css({
					lineHeight: '13px'
				});
			
			break;
			
			case 4 :
			
				$this.css({
					lineHeight: '13px',
					width: $this.width() + 40
				});
			
			break;
		
		}
		
		if ($.browser.msie && $.browser.version == '6.0') {
			if (words.length == 1) {
				$this.css('width', '1%');
			}
		}
	
	});

	$('#footer-page a, #footer a').each(function() {
		if ($(this).attr('onfocus') == undefined) {
			$(this).css('font-weight', 'normal');
		}
	});
	
	$('#lien_pays a').click(function() {
		if ($('#bloc_pays').is(':hidden')) {
			$('#bloc_pays').slideDown('slow');
		} else {
			$('#bloc_pays').slideUp('slow');
		}
	});
	
	$('.nav1').mouseleave(function() {
		$('#bloc_pays').slideUp('slow');
	});
	
	$('#header-texte p:eq(1)').css({
		marginLeft: 80, 
		marginTop: 10,
		textTransform: 'lowercase',
		fontSize: '13px',
		letterSpacing: '2px'
	});
	$('#header-texte p:eq(2)').css({
		marginLeft: 160,
		fontSize: '13px',
		letterSpacing: '2px'
	});
	
	$('.csc-default img').each(function() {
		if ($(this).height() > 90 && $(this).width() > 90) {
			$(this).css('padding', '3px');
			
			if ($(this).css('float') == 'left') {
				$(this).css('margin-left', 0);
			}
			
			if ($(this).css('float') == 'right') {
				$(this).css('margin-right', 0);
			}
		}
	});
	
	// if ($('#bloc_impression').length != 0) {
		// var html_bloc_impression = $('#bloc_impression p').html().split('&nbsp;');
		
		// if (html_bloc_impression[0] != undefined && html_bloc_impression[1] != undefined) {
			// $('#bloc_impression p').html(html_bloc_impression[0] + html_bloc_impression[1]);
		// }
	// }
	
	if ($('.tx-srfeuserregister-pi1').length != 0) {
		$('.tx-srfeuserregister-pi1 label').each(function() {
			var text_label = $(this).html().split('<br>');
			
			if (text_label[0] != undefined && text_label[1] != undefined) {
				$(this).html(text_label[0] + text_label[1]);
			}

			text_label = $(this).html().split('<BR>');
			
			if (text_label[0] != undefined && text_label[1] != undefined) {
				$(this).html(text_label[0] + text_label[1]);
			}
		});
	}
	
	if ($('.navigation ul.subMenu a').length != 0) {
		$('.navigation ul.subMenu a').each(function() {
			var words = $(this).text().split(' ');
			var word_length_safe = '';
		
			for (var i = 0; i < words.length; i++)  {
				if (word_length_safe == '') {
					if (words[i].length >= 8) {
						word_length_safe = false;
					} else {
						word_length_safe = true;
					}
				}
			}
			
			if (($(this).text().length >= 25 && !word_length_safe) || ($(this).text().length >= 25 && words.length >= 3)) {
				$(this).css({
					lineHeight: '15px',
					paddingTop: '3px',
					paddingBottom: '3px'
				});
			}
		});
	}
	
	if ($('.tx-srfeuserregister-pi1').length != 0) {
		if ($.browser.msie && $.browser.version == '7.0') {
			$('.tx-srfeuserregister-pi1 dl table').css('margin-left', '-110px');
			$('.tx-srfeuserregister-pi1 dl table input').css('margin-left', '-10px');
			
			if ($('.tx-srfeuserregister-pi1 dl input[type=submit]').length != 0) {
				var position_submit = $('.tx-srfeuserregister-pi1 dl input[type=submit]').position();
				
				if (position_submit.left >= 500) {
					$('.tx-srfeuserregister-pi1 dl input[type=submit]').css('margin-left', '-80px');
				}
			}
		}
	}
	
	if ($('#page').height() < 400) {
		$('#page').height(400);
	}
	
});

$(document).ready(function(){
	tooltip();
});
            
            
function jumpMenu(id) {
	var target =document.getElementById(id).options[document.getElementById(id).selectedIndex].value
	document.location.href=target;
}

function tx_stlgncases_pi1_showAnswers(radio,div,answers) {

	if(document.getElementById(div)) {
		document.getElementById(div).style.display = "block";
	}

	arrayAnswers = answers.split(',');
	for(var i in arrayAnswers) {
		document.getElementById('tx_stlgncases_pi1-answers['+arrayAnswers[i]+']').className = "tx_stlgncases_pi1-answers_ok"
	}
}

// d�roulant filiales - Menu transversaux
sfHover = function() {
	var sfEls = document.getElementById("transversauxFiliales");
	
	if (sfEls != null) {
		sfEls = sfEls.getElementsByTagName("LI");
	
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function tx_stlgncongres_pi1_toggleNews(id) {
	div = document.getElementById(id);
	if(div.style.display == "block") {
		div.style.display = "none";
	}else{
		div.style.display = "block";
	}
}

function collapseContent(id) {
	div = document.getElementById(id);
	if(div.style.display == "block") {
		div.style.display = "none";
	}else{
		div.style.display = "block";
	}
}

function setActiveStyleSheet(title){  // select the stylesheet
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
}

function openPrintVersion() {
   //laPage = window.top.location;
   //laFenetre = window.open(laPage, "_blank", "");
   //laFenetre.setActiveStyleSheet('Print preview');
   //laFenetre.print();
   setActiveStyleSheet('Print preview');
   window.print();
   setTimeout("setActiveStyleSheet('Screen');", 5000); 
}

setActiveStyleSheet("Screen");

(function() {

	$.fn.parseXML = function(url, lang) {
	
		this.each(function() {
		
			var $this = $(this);
			
			$this.html('<div></div>');
			
			$.ajax({
				url: url,
				dataType: 'xml',
				cache: false,
				success: function(data) {
					data = $(data).find('hugin_quote');
					
					var date = data.find('expire date').text();
					var time = data.find('expire time').text();
					
					var currency = data.find('quotes currency').text();
					var last_price = data.find('quotes current_day last_price').text();
					
					var percent = data.find('changes current_day percent').text();
					
					var html = 	'<h5>' + lang + '</h5>' +
								'<p>' + date + ' ' + time + ' | ' + last_price + ' ' + currency + ' ' + percent + ' %</p>';
					
					$this.find('div').remove();
					$this.html(html);
				}
			});
		
		});
	
	}

})(jQuery);


(function($) {

	$.fn.maxHeightFlex = function() {
		var $this = $(this);
		var max = current_height = 0;
	
		return $this.each(function() {
			var elements = $(this).find('dl');
			
			elements.each(function(){
				current_height = $(this).height();
				
				if (max < current_height) {
					max = current_height;
				}
			});
		
			elements.height(max);
		});
	}

})(jQuery);

function closePopupVideo() {
	$('#overlay').fadeTo(0, 'fast', function() {
		$('#overlay').remove();
	});
	
	$('#lightbox').fadeTo(0, 'fast', function() {
		$('#lightbox').remove();
	});
}


(function($) {
	$.fn.lightboxVideo = function(settings) {
		var options =  {
			video_url: '',
			video_width: '600px',
			video_height: '400px',
			video_autostart: 'true'
		}; 
		$.extend(options, settings);
		
		var $this = $(this);
		
		$this.css('cursor', 'pointer');
		
		$this.click(function(e) {
			e.preventDefault();
			
			var video = $this.attr('rel');
			
			var overlay = $('<div></div>').attr('id', 'overlay').css({
				background: '#000',
				position: 'absolute',
				opacity: 0,
				zIndex: 9999
			});
			
			var player_video = $('<div style="position: relative; z-index: 99999; text-align:center;background-color:black;padding:3px;opacity: 0.5"><a href="javascript:void(0)" onclick="closePopupVideo();" style="color:white;font-weight:bolder;opacity:1;">Close</a></div><div><object height="' + options.video_height + '" width="' + options.video_width + '" type="application/x-shockwave-flash" data="' + options.video_url + 'player.swf?file=' + video + '&autostart=' + options.video_autostart + '"><param name="movie" value="' + options.video_url + 'player.swf?file=' + video + '&autostart=' + options.video_autostart + '" /><param value="true" name="allowfullscreen"><param value="always" name="allowscriptaccess"><param value="high" name="quality"><param value="false" name="cachebusting"></object></div>');
			
			var lightbox = $('<div></div>').attr('id', 'lightbox').css({
				background: 'transparent',
				position: 'absolute',
				height: options.video_height,
				width: options.video_width,
				top: 0,
				opacity: 0,
				left: 0,
				zIndex: 9999
			}).append(player_video);
			
			$('body').append(overlay).append(lightbox);
			
			lightbox.fadeTo('fast', 1);
			overlay.fadeTo('fast', .8);
			
			overlay.click(function() {
				overlay.fadeTo(0, 'fast', function() {
					overlay.remove();
				});
				
				lightbox.fadeTo(0, 'fast', function() {
					lightbox.remove();
				});
			});
			
			resizeOverlay();
			centerLightbox();
			
			$(window).resize(resizeOverlay).resize(centerLightbox).scroll(centerLightbox);
			
		});
		
		function resizeOverlay() {
			var window_width = $(window).width();
			var document_height = $(document).height();
			
			$('#overlay').width(window_width).height(document_height).css({
				top: 0,
				left: 0	
			});
		}
		
		function centerLightbox() {
			var window_width = $(window).width();
			var document_height = $(document).height()
			
			var lightbox_width = $('#lightbox').width();
			var lightbox_height = $('#lightbox').height();
			
			$('#lightbox').css({
				left: (window_width - lightbox_width) / 2 + 'px',
				top: (document_height - lightbox_height) / 2 + 'px'
			});
		}
	}
	
})(jQuery);

$(function() {

	/*$('.flex_3cols').HeightFlex();
	
	$('img.ligthbox_video').lightboxVideo({
		video_url: 'fileadmin/templates/video/'
	});
	
	$('img.lightbox_video').lightboxVideo({
		video_url: 'fileadmin/templates/video/'
	});*/

});

//lightbox Classic

(function($) {
	
	$.lightbox = function(html) {
		var overlay = $('<div></div>').attr('id', 'overlay').css({
			background: '#000',
			position: 'absolute',
			opacity: 0,
			zIndex: 9999,
			left:0,
			top:0
		});
		
		var lightbox = $('<div></div>').attr('id', 'lightbox').css({
			position: 'absolute',
			top: 0,
			opacity: 0,
			left: 0,
			zIndex: 9999,
			color: '#000000'
		}).append(html);
		
		$('body').append(overlay).append(lightbox);
		
		lightbox.fadeTo('fast', 1);
		overlay.fadeTo('fast', .8);
		
		overlay.click(close);
		lightbox.find('a.close').click(close);
		
		resizeOverlay();
		centerLightbox();
		
		$(window).resize(resizeOverlay).resize(centerLightbox).scroll(centerLightbox);
		
		function close() {
			overlay.fadeTo(0, 'fast', function() {
				overlay.remove();
			});
			
			lightbox.fadeTo(0, 'fast', function() {
				lightbox.remove();
			});
		}
		
		function resizeOverlay() {
			var window_width = $(window).width();
			var document_height = $(document).height();
			
			$('#overlay').width(window_width).height(document_height);
		}
		
		function centerLightbox() {
			var window_width = $(window).width();
			var document_height = $(window).height();
			
			var lightbox_width = $('#lightbox').width();
			var lightbox_height = $('#lightbox').height();
			
			$('#lightbox').css({
				left: (window_width - lightbox_width) / 2 + 'px',
				top: (document_height - lightbox_height) / 2 + 'px'
			});
		}
	}
	
})(jQuery);


