//________global functions________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

var initial_marginTop = 0;
var current_picture_src = "";

$(document).ready(function(){

	//init_tooltips();

	init_textbox_focus2();

	init_textbox_focusable2();

	init_css32();

	$("img" , '#header_menu').each(function() {
		if ( $(this).attr("src").indexOf( "_selected" , 0) == -1) {
		$(this).hover(
			function() {
				current_picture_src = $(this).attr("src").replace(".png", "_selected.png");
				$(this).attr({ src: current_picture_src });
			},
			function() {
				current_picture_src = $(this).attr("src").replace("_selected.png", ".png");
				$(this).attr({ src: current_picture_src});
			});
		}
	});

	$('.paddleToFade').each(function() {
		$(this).hover(
			function() {
				$(this).append("<div class='overlay'></div>");
				$(".overlay", this).stop().css("opacity", 0.3).fadeIn("slow");
				var link = $(this).find('a').attr('href');
                	$(".overlay", this).click(function() {
                		window.location.href = link;
                	});
			},
			function() {
				$(".overlay", this).remove();
			}
		);
	});

	/*$('.jrumble').jrumble({
		opacity:0.1,
		speed:50,
		x:2,
		y:2,
		rotation:5
	});
	$('.jrumble').hover(
		function() {
			$(this).trigger('startRumble');
		},
		function(){
			$(this).trigger('stopRumble');
		});
	*/

	if ($('#google_map_container').length > 0)	set_google_map("syst'aime D", "<b>syst'aime D</b><br />171 avenue Charles de Gaulle Bat C, 92200 Neuilly sur seine", "171 avenue Charles de Gaulle Bat C, 92200 Neuilly sur seine", undefined, undefined, "13", "google_map_container", "15", "");

	if ($('#references').length > 0) {
		$('span.button').each(function () {
			$(this).click(function () {
				page_number = $(this).attr('id').replace('button', '');
				$('.references').hide();
				$('#references'+page_number).css("display", "inline-block");
				$('.button').removeClass('selected');
				$(this).addClass('selected');
				resize_min_page();
			});
		});
	}

	resize_min_page();

	reposition_footer();

});

$(window).resize(function() {
	reposition_footer();	//replace le footer en fonction de la taille de la fenetre
});

function init_textbox_focusable2(v_textbox_class) {

	if (typeof(v_textbox_class)=="undefined") v_textbox_class = "focusable";

	$("input[type=text]."+v_textbox_class).focus(function() {
		if ($(this).attr("title").length>0)
			if ($(this).val() == $(this).attr("title"))
				$(this).val("");
	});
	$("input[type=text]."+v_textbox_class).blur(function() {
		if ($(this).attr("title").length>0)
			if ($(this).val() == "")
				$(this).val($(this).attr("title"));
	});
}

function init_textbox_focus2(v_textbox_class) {

	if (typeof(v_textbox_class)=="undefined") v_textbox_class = "input-txt,input-txtl";

	var array_elements = v_textbox_class.split(",");

	for(var i=0; i<=array_elements.length-1; i++) {

		v_textbox_class_ok = array_elements[i];

		$("input[type=text]."+v_textbox_class_ok+", input[type=password]."+v_textbox_class_ok+", textarea."+v_textbox_class_ok).focus(function() {
			$(this).addClass(v_textbox_class_ok+"-focused");
		});
		$("input[type=text]."+v_textbox_class_ok+", input[type=password]."+v_textbox_class_ok+", textarea."+v_textbox_class_ok).blur(function() {
			$(this).removeClass(v_textbox_class_ok+"-focused");
		});
	}
}

function init_css32(v_elements) {

	if (typeof(v_elements)=="undefined") v_elements = ".css3, .btn, .shadowed, .rounded, .input-btn, .input-txt, .input-txtl";

	if (window.PIE) {
		$(v_elements).each(function() {
			PIE.attach(this);
		});
	}
}

function GetDomOffset( Obj, Prop ) {
	var iVal = 0;
	while (Obj && Obj.tagName != 'BODY') {
		eval('iVal += Obj.' + Prop + ';');
		Obj = Obj.offsetParent;
	}
	return iVal;
}

//adapte le footer en fonction de la taille de la fenetre
function reposition_footer() {

	var footerObject = document.getElementById('footer');
	var footerTop = GetDomOffset( footerObject, 'offsetTop' );
	var windowHeight = $(window).height();
	var footerHeight = $('#footer').height();

	var marginTop = windowHeight - ( footerTop + footerHeight );
	if (marginTop > 0 ) $('#footer').css('margin-top', marginTop+'px');
	else $('#footer').css('margin-top', initial_marginTop+'px');


}

function resize_min_page() {
	var diff = $("#content_right").height() + 15 - $("#page").height();
	var new_height = $("#content_right").height() + 15;
	if ( diff > 0 ) $("#page").css("min-height", new_height + "px");
}

