//contentbig

/*
 * JQUERY est neccessaire pour executer tous les scripts suivant.
 * 
 *De test d'existant sont réaliser pour éviter les appel anonymes a des éléments du DOM
 */

/*
 * CUFON - neccessite les fichiers :
 * 
 * cufon.js
 * Myriad_Pro_Regular_400.font.js
 * Myriad_Pro_Semi_Bold_600.font.js
 */

Cufon.set('fontFamily', 'Myriad Pro Regular').replace('.font_myriad');
Cufon.set('fontFamily', 'Myriad Pro Semi Bold').replace('.font_myriad_bold');

Cufon.replace('#contentbig strong', {
	fontFamily: 'Myriad Pro Regular',
	textShadow: '#c3c3c3 0px 1px'
});

if($("#contentbig_devis_header") != undefined) {
	Cufon.replace('#contentbig_devis_header', {
		fontFamily: 'Myriad Pro Regular',
		textShadow: '#99143c 0px 1px'
	});
}

if($("#contentbig_devis_telephone") != undefined) {
	Cufon.replace('#contentbig_devis_telephone', {
		fontFamily: 'Myriad Pro Semi Bold',
		color: '-linear-gradient(#4c4c4c, #9d9d9d)'
	});
}

if($(".btn_slide .text_dark") != undefined) {
	Cufon.replace('.btn_slide .text_dark', {
		fontFamily: 'Myriad Pro Regular',
		color: '-linear-gradient(#6c6c6c, #a5a5a5)'
	});
}

if($(".btn_slide .text_light") != undefined) {
	Cufon.replace('.btn_slide .text_light', {
		fontFamily: 'Myriad Pro Regular',
		textShadow: '#5c5c5c 0px -1px',
		color: '-linear-gradient(#FFFFFF, #FFFFFF)'
	});
}

if($("#sitepart") != undefined) {
	Cufon.replace('#sitepart', {
		color: '#9f9f9f'
	});
}

if($("#content_normal .title") != undefined) {
	Cufon.replace('#content_normal .title', {
		textShadow: '#CCCCCC 0px 1px',
		fontFamily: 'Myriad Pro Semi Bold',
		color: '-linear-gradient(#5d5d5d, #000000)',
		hover: {
			color: '-linear-gradient(#FFFFFF, #f7f7f7)'
		}
	});
}

if($("#content_inter .main_title") != undefined) {
	Cufon.replace('#content_inter .main_title', {
		textShadow: '#c3c3c3 0px 1px',
		fontFamily: 'Myriad Pro Semi Bold',
		color: '-linear-gradient(#c7528f, #f7316e, #f95353)'
	});
}

if($(".blue_title") != undefined) {
	Cufon.replace('.blue_title', {
		fontFamily: 'Myriad Pro Semi Bold',
		color: '-linear-gradient(#3e99ec, #2f5bb1)'
	});
}

if($(".btn_blue") != undefined) {
	Cufon.replace('.btn_blue', {
		textShadow: '#2d6aa0 0px 1px',
		color: '-linear-gradient(#FFFFFF, #f9eff1)'
	});
}

if($(".btn_blue_cta") != undefined) {
	Cufon.replace('.btn_blue_cta', {
		textShadow: '#2d6aa0 0px 1px',
		color: '-linear-gradient(#FFFFFF, #f9eff1)'
	});
}

if($(".btn_green") != undefined) {
	Cufon.replace('.btn_green', {
		textShadow: '#2d6aa0 0px -1px',
		color: '-linear-gradient(#FFFFFF, #f9eff1)'
	});
}

if($(".btn_green_cta") != undefined) {
	Cufon.replace('.btn_green_cta', {
		textShadow: '#2d6aa0 0px -1px',
		color: '-linear-gradient(#FFFFFF, #f9eff1)'
	});
}

if($(".btn_pink") != undefined) {
	Cufon.replace('.btn_pink', {
		textShadow: '#5b1935 0px -1px',
		color: '-linear-gradient(#FFFFFF, #f9eff1)'
	});
}

if($(".btn_pink_cta") != undefined) {
	Cufon.replace('.btn_pink_cta', {
		textShadow: '#5b1935 0px -1px',
		color: '-linear-gradient(#FFFFFF, #f9eff1)'
	});
}

if($(".btn_pink_small") != undefined) {
	Cufon.replace('.btn_pink_small', {
		textShadow: '#5b1935 0px -1px',
		color: '-linear-gradient(#FFFFFF, #f9eff1)'
	});
}

if($(".btn_pink_small_cta") != undefined) {
	Cufon.replace('.btn_pink_small_cta', {
		textShadow: '#5b1935 0px -1px',
		color: '-linear-gradient(#FFFFFF, #f9eff1)'
	});
}

if($(".mailto_cta") != undefined) {
	Cufon.replace('.mailto_cta', {
		fontFamily: 'Myriad Pro Regular',
		color: '-linear-gradient(#545454, #a8a8a8)'
	});
}

if($(".mailto_normal") != undefined) {
	Cufon.replace('.mailto_normal', {
		fontFamily: 'Myriad Pro Regular',
		color: '-linear-gradient(#545454, #a8a8a8)'
	});
}

if($(".devis_header") != undefined) {
	Cufon.replace('.devis_header', {
		textShadow: '#0e3963 0px 1px'
	});
}

if($(".devis_telephone") != undefined) {
	Cufon.replace('.devis_telephone', {
		color: '-linear-gradient(#4c4c4c, #7f7f7f)'
	});
}

Cufon.replace('.footer_part strong', {
	fontFamily: 'Myriad Pro Regular',
	color: '-linear-gradient(#4c4c4c, #9d9d9d)'
});

Cufon.replace('#partenaires strong', {
	fontFamily: 'Myriad Pro Regular',
	color: '-linear-gradient(#4c4c4c, #9d9d9d)'
});

if($(".header_inter .title_one_line") != undefined) {
	Cufon.replace('.header_inter .title_one_line', {
		fontFamily: 'Myriad Pro Regular',
		color: '-linear-gradient(#6e6e6e, #171717)',
		textShadow: '#FFFFFF 0px 1px'
	});
}

if($(".header_inter .title_two_line") != undefined) {
	Cufon.replace('.header_inter .title_two_line', {
		fontFamily: 'Myriad Pro Regular',
		color: '-linear-gradient(#6e6e6e, #171717)',
		textShadow: '#FFFFFF 0px 1px'
	});
}

if($(".sub_title") != undefined) {
	Cufon.replace('.sub_title', {
		fontFamily: 'Myriad Pro Semi Bold',
			color: '-linear-gradient(#000000, #5d5d5d)',
		textShadow: '#c3c3c3 0px 1px'
	});
}

if($(".under_sub_title") != undefined) {
	Cufon.replace('.under_sub_title', {
		fontFamily: 'Myriad Pro Semi Bold',
		color: '-linear-gradient(#434242, #888888)',
		textShadow: '#c3c3c3 0px 1px'
	});
}

if($(".mini_devis .devis_header") != undefined) {
	Cufon.replace('.mini_devis .devis_header', {
		fontFamily: 'Myriad Pro Regular',
		color: '-linear-gradient(#FFFFFF, #f9eff1)',
		textShadow: '#99143c 0px 1px'
	});
}

if($(".tableheader") != undefined) {
	Cufon.replace('.tableheader', {
		fontFamily: 'Myriad Pro Semi Bold',
		color: '-linear-gradient(#5d5d5d, #000000)',
		textShadow: '#c3c3c3'
	});
}

if($("#service_box_1 .content_service_box strong") != undefined) {
	Cufon.replace('#service_box_1 .content_service_box strong', {
		fontFamily: 'Myriad Pro Regular',
		color: '-linear-gradient(#e2061e, #fb2d2e)',
		textShadow: '#c3c3c3'
	});
}

if($("#service_box_2 .content_service_box strong") != undefined) {
	Cufon.replace('#service_box_2 .content_service_box strong', {
		fontFamily: 'Myriad Pro Regular',
		color: '-linear-gradient(#f94c71, #f93d63)',
		textShadow: '#c3c3c3'
	});
}

if($("#service_box_3 .content_service_box strong") != undefined) {
	Cufon.replace('#service_box_3 .content_service_box strong', {
		fontFamily: 'Myriad Pro Regular',
		color: '-linear-gradient(#0c8a33, #13b144)',
		textShadow: '#c3c3c3'
	});
}

if($("#service_box_4 .content_service_box strong") != undefined) {
	Cufon.replace('#service_box_4 .content_service_box strong', {
		fontFamily: 'Myriad Pro Regular',
		color: '-linear-gradient(#079f7d, #088064)',
		textShadow: '#c3c3c3'
	});
}

/* CUFON TEMPLATE ADWORDS */

if($("a.mini_devis_bleu") != undefined) {
	Cufon.replace('a.mini_devis_bleu"', {
		fontFamily: 'Myriad Pro Semi Bold',
		color: '-linear-gradient(#FFFFFF, #f9eff1)',
		textShadow: '#0e3963 0px 1px'
	});
}

if ($(".right_list strong") != undefined) {
	Cufon.replace('.right_list strong', {
		fontFamily: 'Myriad Pro Semi Bold',
		color: '-linear-gradient(#4c4c4c, #9d9d9d)'
	});
}

if ($(".ul.agences span") != undefined) {
	Cufon.replace('ul.agences span', {
		fontFamily: 'Myriad Pro Semi Bold',
		color: '-linear-gradient(#656565, #000)'
	});
}

$(document).ready(function(){

	/*
	 * CTA pour les effet fadeIn / fadeOut sur les boutons
	 */
	$("#text-head").fadeTo(0, 0.5);
	$('#logo_name').mouseenter(
			function(){
				$(this).stop().animate({'opacity': 0}, 450);
				$("#text-head").stop().fadeTo(650, 1);
			}).mouseleave(
			function(){
				$(this).stop().animate({'opacity': 1}, 450);
				$("#text-head").stop().fadeTo(650, 0.5);
			});
	
	$('#home').mouseenter(
			function(){
				$(this).stop().animate({'opacity': 0}, 450);
			}).mouseleave(
			function(){
				$(this).stop().animate({'opacity': 1}, 450);
			});
	
	$('#btn_slide_mini_all').mouseenter(
			function(){
				$(this).stop().animate({'opacity': 0}, 450);
			}).mouseleave(
			function(){
				$(this).stop().animate({'opacity': 1}, 450);
			});
	
	$('.btn_slide_mini_size').mouseenter(
			function(){
				$(this).stop().animate({'opacity': 0}, 450);
			}).mouseleave(
			function(){
				$(this).stop().animate({'opacity': 1}, 450);
			});
	
	$('.btn_green').mouseenter(
			function(){
				$(this).stop().animate({'opacity': 0}, 450);
			}).mouseleave(
			function(){
				$(this).stop().animate({'opacity': 1}, 450);
			});
	
	$('.btn_pink_small').mouseenter(
			function(){
				$(this).stop().animate({'opacity': 0}, 450);
			}).mouseleave(
			function(){
				$(this).stop().animate({'opacity': 1}, 450);
			});
	
	$('.btn_pink').mouseenter(
			function(){
				$(this).stop().animate({'opacity': 0}, 450);
			}).mouseleave(
			function(){
				$(this).stop().animate({'opacity': 1}, 450);
			});
	
	$('.btn_blue').mouseenter(
			function(){
				$(this).stop().animate({'opacity': 0}, 450);
			}).mouseleave(
			function(){
				$(this).stop().animate({'opacity': 1}, 450);
			});
	
	$('.mailto_normal').mouseenter(
			function(){
				$(this).stop().animate({'opacity': 0}, 450);
			}).mouseleave(
			function(){
				$(this).stop().animate({'opacity': 1}, 450);
			});
	
	/************************************************************************ SLIDESHOW INTER PAGE */
	if($("#slideshow_btn_content") != undefined) {
		/* TIMER CORNER */
		var timer_sec_inter = 4000;
		var timer_inter;
		var cur_slideshow_col_btn = $('.slideshow_btn_img_cta').last();
		
		function clock_inter() {
			if(cur_slideshow_col_btn.parent(".slideshow_btn").next(".slideshow_btn").children(".slideshow_btn_img_cta").html() == null) {
				cur_slideshow_col_btn = $('.slideshow_btn_img_cta').first();
			}else {
				cur_slideshow_col_btn = cur_slideshow_col_btn.parent(".slideshow_btn").next(".slideshow_btn").children(".slideshow_btn_img_cta");
			}
			cur_slideshow_col_btn.click()
			timer_inter = setTimeout(clock_inter, timer_sec_inter);
		}
		clock_inter();
		
		var slideshow_btn_content_width = 0;
		$(".slideshow_btn").each(function(index) {
			slideshow_btn_content_width += $(this).width();
			slideshow_btn_content_width += $(this).css("margin-left").replace("px", "") * 1;
			slideshow_btn_content_width += $(this).css("margin-right").replace("px", "") * 1;
		});
		$("#slideshow_btn_content").width(slideshow_btn_content_width);
		
		$('.slideshow_btn_img_cta').mouseenter(
				function(){
					$(this).stop().animate({'opacity': 0}, 450);
					clearTimeout(timer_inter);
				}).mouseleave(
				function(){
					// POUR REACTIVER LE TIMER APRES MOUSE LEAVE
					//timer_inter = setTimeout(clock_inter, timer_sec_inter);
					$(this).stop().animate({'opacity': 1}, 450);
				});
		
		//slideshow_col
		var bool_slideshow_col = true;
		var cur_slideshow_col_img = $('.slideshow_col img').first();
		$('.slideshow_col img').fadeTo(0, 0);
		cur_slideshow_col_img.fadeTo(0, 1);
		$('.slideshow_btn_img_cta').click(function() {
			if(bool_slideshow_col) {
				cur_slideshow_col_btn = $(this);
				var pos = $('.slideshow_btn_img_cta').index($(this));
				if(pos !== $('.slideshow_col img').index(cur_slideshow_col_img)) {
					$('.slideshow_btn_img_cta').show();
					$(this).hide();
					bool_slideshow_col = false;
					var new_img = $(".slideshow_col img").eq(pos);
					//new_img.fadeTo(0, 0);
					cur_slideshow_col_img.fadeTo(500, 0, function() {
						cur_slideshow_col_img.hide();
						//new_img.show();
						new_img.fadeTo(500, 1);
						cur_slideshow_col_img = new_img;
						bool_slideshow_col = true;
					});
				}
			}
		});
	}
	
	/************************************************************************ MINI SLIDESHOW */
	if($("#btn_slide_mini_slide img") != undefined) {
		$("#btn_slide_mini_slide img").fadeTo(0, 0.6);
		$("#btn_slide_mini_slide img").mouseover(function() {
			$(this).stop().fadeTo(450, 1);
		});
		$("#btn_slide_mini_slide img").mouseout(function() {
			$(this).stop().fadeTo(450, 0.5);
		});
		var bool = true;
		$("#btn_slide_mini_left").click(function() {
			if(bool) {
				bool = false;
				var obj = $("#btn_slide_mini_slide").children("img").first();
				var margin = obj.width();
				margin = "-" + margin + "px";
				obj.animate({marginLeft: margin}, 300, function() {
					$("#btn_slide_mini_slide").append(obj);
					obj.css("margin-left", "0px");
					bool = true;
				});
			}
		});
		$("#btn_slide_mini_right").click(function() {
			if(bool) {
				bool = false;
				var obj = $("#btn_slide_mini_slide").children("img").last();
				var margin = obj.width();
				margin = "-" + margin + "px";
				obj.css("margin-left", margin);
				$("#btn_slide_mini_slide").prepend(obj);
				obj.animate({marginLeft: 0}, 300, function() {
					bool = true;
				});
			}
		});
	}
	
	/*
	 * BIG SLIDESHOW : neccessite les fichiers :
	 * 
	 * easing.js
	 */
	if($("#big_slide_img") != undefined) {
	
		$("#colour_banner_background_red").width($("#colour_banner").width());
		$("#colour_banner_background_green_light").width($("#colour_banner").width());
		$("#colour_banner_background_red").width($("#colour_banner").width());
		$("#colour_banner_background_green_light").width($("#colour_banner").width());
		$("#colour_banner_background_pink").width($("#colour_banner").width());
		
		/* TIMER CORNER */
		var timer_sec = 4000;
		var timer;
		var current_btn_slide = $(".btn_slide:last");
		function clock() {
			if(current_btn_slide.parent(".content_slide").next(".content_slide").children(".btn_slide").html() == null) {
				current_btn_slide = $(".btn_slide").eq(0);
			}else {
				current_btn_slide = current_btn_slide.parent(".content_slide").next(".content_slide").children(".btn_slide");
			}
			slideshow(current_btn_slide);
			timer = setTimeout(clock, timer_sec);
		}
		clock();
		
		var bool_slide = true;
		var color_red = "#eb1422";
		var color_pink = "#f32651";
		var color_green_light = "#03a034";
		var color_green_dark = "#00906f";
		var pool_stack_next = "";
	
		$(".big_slide_img").hide();
		$(".big_slide_img").eq(0).show();
		$(".btn_slide").mouseenter(function() {
			slideshow($(this));
			clearTimeout(timer);
		});
		$(".btn_slide").mouseleave(function() {
			timer = setTimeout(clock, 1000);
		});
	}
	
	function slideshow(obj) {
		current_btn_slide = obj;
		$(".btn_slide .text_dark").show();
		$(".btn_slide .text_light").hide();
		$(".btn_slide").next("p").css("color", "#878484");
		$(".btn_slide").removeClass("btn_slide_green_dark").removeClass("btn_slide_red").removeClass("btn_slide_pink").removeClass("btn_slide_green_light");

		obj.children(".text_light").show();
		obj.children(".text_dark").hide();

		if(obj.attr("data-class") != undefined) {
			var classname = obj.attr("data-class");	
			obj.addClass(classname);
			
			var position = $(".btn_slide").index(obj);
			var background_image = null;
			if(classname.indexOf("btn_slide_red") != -1) {
				background_image = $("#colour_banner_background_red");
				obj.next("p").css("color", color_red);
			}else if(classname.indexOf("btn_slide_green_light") != -1) {
				background_image = $("#colour_banner_background_green_light");
				obj.next("p").css("color", color_green_light);
			}else if(classname.indexOf("btn_slide_green_dark") != -1) {
				background_image = $("#colour_banner_background_green_dark");
				obj.next("p").css("color", color_green_dark);
			}else if(classname.indexOf("btn_slide_pink") != -1) {
				background_image = $("#colour_banner_background_pink");
				obj.next("p").css("color", color_pink);
			}
			$(".big_slide_img").each(function(index) {
				if(index != position) {
					if($.browser.msie) {
						$(this).stop().hide();
					}else {
						$(this).stop().fadeTo(1000, 0);
					}
				}
			  });
			if($.browser.msie) {
				$(".big_slide_img").eq(position).stop().show();
			}else {
				$(".big_slide_img").eq(position).stop().fadeTo(400, 1);
			}
			pool_stack_next = background_image;
			move(background_image);
		}
	}
	
	function move(obj) {
		if(bool_slide && obj != null) {
			bool_slide = false;
			var newwidth = $("#colour_banner").width();
			$("#colour_banner_background_red").width(newwidth);
			$("#colour_banner_background_green_light").width(newwidth);
			$("#colour_banner_background_green_dark").width(newwidth);
			$("#colour_banner_background_pink").width(newwidth);
			$("#colour_banner_content").prepend(obj);
			obj.animate({width: "0px"}, 0);
			obj.animate({width: newwidth},
					{queue:false,
						duration: 1500,
						easing: 'easeInOutExpo',
						complete: 
						function() {
							bool_slide = true;
							if(pool_stack_next != obj) {
								move(pool_stack_next);
							}
						}
				});
		}
	}
});

/************************************************************************ GOOGLE MAP */
function showmap(list) {
	for(var i in list) {
	$("#gmap_contener").gmap3(
	    {
	        action: 'addMarker',
	        address: list[i],
	        map:{
	            center: true,
	            zoom: 4
	        },
	        marker:{
	            options:{
	                draggable: false,
	                icon: "/extension/wemagine/design/wemagine/images/icon/gmap.png"
	            }
	        }
	    });
	}
}
