//________global functions________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
$(document).ready(function(){ 
 	
 	// #### enable superfish navigation menu
	$("#navigation_menu").superfish({		
		delay:			'100',
		animation:   		{ opacity	:'show', height:'none' },
		speed:       		'fast',
		dropShadows: 		true,
		autoArrows:  		true
	});		
	$('#navigation_menu').superfish().find("ul").bgIframe({opacity:false}); // add this bit for bgIframe support only

	// #### set tooltips
	$('label').each(function() {	
		if ($(this).attr("class").length<=0)	
			if ($(this).attr("title").length>0) 
				$(this).addClass("label_help");
	});
	
	$('a[title]').tooltip({ 'fade':250, 'showURL':false }); 	
	$('label[title]').tooltip({ 'fade':250, 'showURL':false }); 	
	
	// #### set prettycheckboxes
	$('input[type=checkbox], input[type=radio]').each(function() {
		if ($(this).attr("class").indexOf("none")<0)
			$(this).prettyCheckboxes()
	});
		
	// #### set textbox focus style
	$('input[type=text].textbox, textarea.textbox').focus(function() {
		$(this).addClass("textbox_focus");
	});
	// #### set textbox blur style
	$('input[type=text].textbox, textarea.textbox').blur(function() {
		$(this).removeClass("textbox_focus");
	});	
	
	// #### pictures lazyload fadein effects
	/*$("img").each(function() {
		if ($(this).attr("class").indexOf("none")<0)
			$(this).lazyload({ 
				effect      : "fadeIn" 	
			});
	});*/
	
	if ($("#slider")) {
		initialize_slider();
	}
}); 


function mailpage() {
	
	var v_string;
	
	v_string = "mailto:?subject=" +document.title;
	v_string += "&body= Je recommande cette page : " +document.title +" consultable a l'adresse suivante : " +document.location.href;
	
	//win = window.open(v_string,'emailWindow');
	//if (win && win.open &&!win.closed) win.close(); 	
	//alert(v_string);
	
	location.href = v_string;
}


var index_slider = 0;
var max_index_slider = 0;
var slider_timer = null;

function initialize_slider() {
	
	max_index_slider = $(".slider_picture").length-1;
	slider_timer = setTimeout("tick_slider()",5000);
	
	if ($("#slider_arrow_left")) {
		$("#slider_arrow_left").click(function() {
			clearTimeout(slider_timer);
			next_slider();
		});
	}
	if ($("#slider_arrow_right")) {
		$("#slider_arrow_right").click(function() {
			clearTimeout(slider_timer);
			previous_slider();
		});
	}
}
function tick_slider() {		
	next_slider();
	slider_timer = setTimeout("tick_slider()",5000);
}
function previous_slider() {
	index_slider++;
	if (index_slider>max_index_slider) index_slider = 0;	
	display_slider();	
}

function next_slider() {
	index_slider--;
	if (index_slider<0) index_slider = max_index_slider;
	display_slider();	
}
function display_slider() {
	
	$(".slider_picture").each(function() {		
		if ($(this).attr("id") == "slider_picture_"+index_slider) {
			$(this).fadeIn("fast");
		} else {
			$(this).fadeOut("fast");
		}
	});	
}


function load_creation_title(v_title) {
	set_control_html("creation_title",v_title);
}

function load_creation_description(v_description) {

	set_control_html("creation_description",v_description);
}

function mailpage() {
	
	var v_string;
	
	v_string = "mailto:?subject=" +document.title;
	v_string += "&body= Je recommande cette page : " +document.title +" consultable a l'adresse suivante : " +document.location.href;
	
	//win = window.open(v_string,'emailWindow');
	//if (win && win.open &&!win.closed) win.close(); 	
	//alert(v_string);
	
	location.href = v_string;
}
function search_text_evt(evt, v_default_string) {
	if (evt.keyCode == 13) search_text(v_default_string);
}

function search_text(v_default_string) {
	
	v_search_value = get_control_value("t_search_text");
	if (v_search_value.length<=0) {
		alert("Merci de saisir des mots clef de recherche");
		return false;
	}
	if (v_search_value.toLowerCase() == v_default_string.toLowerCase()) {
		alert("Merci de saisir des mots clef de recherche");
		return false;
	}
	
	document.location.href = "search.html?s=" +escape(v_search_value);
}

// set the product main picture according to the clicked thumb picture
function set_creation_main_picture(v_idcreation, v_idpicture, v_picture_filename, v_lighbox_picture_filename) {

	try {
		
		if (!doc_id("creation_main_picture_"+v_idcreation)) return false;
		
		set_control_display("creation_main_picture_"+v_idcreation, "none")
		set_control_display("img_loading_" +v_idcreation)
		
		var myImage = new Image();	
			
		myImage.onload = function() { 
			doc_id("creation_main_link_" +v_idcreation).href = v_lighbox_picture_filename;
			doc_id("creation_main_picture_" +v_idcreation).src = v_picture_filename;
			set_control_display("creation_main_picture_" +v_idcreation); 
			set_control_display("img_loading_"+v_idcreation, "none")
		}
		
		myImage.src = v_picture_filename;
		
	}catch(err) {
		
		set_control_display("product_main_picture_"+v_idcreation); 
		set_control_display("img_loading_"+v_idcreation, "none")
	}
}

function show_menu(v_idmenu) {
		
	v_array = getElementsByTagName2("ul", "submenu_cell");
	for (i=0; i<=v_array.length-1; i++) {
		v_array[i].style.display = "none";
	}
	
	if (doc_id("submenu_cell_" +v_idmenu)) doc_id("submenu_cell_" +v_idmenu).style.display = "";
	
}

function hide_menu(v_idmenu) {
	
	if (doc_id("submenu_cell_" +v_idmenu)) doc_id("submenu_cell_" +v_idmenu).style.display = "none";	
}


function send_form_contact() {
	
	if (check_form_contact()) {
		if (doc_id("flag_send_contact")) doc_id("flag_send_contact").value = "1";
		if (doc_id("form_contact")) doc_id("form_contact").submit();
	}
}

function check_form_contact() {
	return true;
}

function goto_pagination(v_page) {
	
	if (doc_id("t_offset")) doc_id("t_offset").value = parseInt(v_page) - 1;
	if (doc_id("form_pagination")) doc_id("form_pagination").submit();
}


function send_form_inscription() {
	
	if (check_form_inscription()) {
		if (doc_id("flag_send_inscription")) doc_id("flag_send_inscription").value = "1";
		if (doc_id("form_inscription")) doc_id("form_inscription").submit();
	}
}

function check_form_inscription() {
	return true;
}

