function isValidEmailAddress(email) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(email);
}
$(function() {
	$('input:text').focus(function(){
		if($(this).val()==$(this)[0].defaultValue){
			$(this).val("");
		}
	});
	$('input:text').blur(function(){
		if($(this).val()==""){
			$(this).val($(this)[0].defaultValue);
		}
	});
	$("textarea").focus(function(){
		if($(this).val()==$(this)[0].defaultValue){
			$(this).val("");
		}
	});
	$('textarea').blur(function(){
		if($(this).val()==""){
			$(this).val($(this)[0].defaultValue);
		}
	});
});
/*--FORM-CONTACT--*/
$(function() {
	$("#c-form").click(function() {
		var c1 = $("input#c1").val();
		var c2 = $("input#c2").val();
		var c3 = $("textarea#c3").val();
		var c4 = $("input#c4").attr('checked');
		var c5 = $("input#c5").val();
		var c5id = $("input#c5").attr("rel");
		
		if (c1 == $("input#c1")[0].defaultValue){
			$("input#c1").addClass("error");
		}
		else{
			$("input#c1").removeClass("error");
			if ((c2 == $("input#c2")[0].defaultValue) || (!isValidEmailAddress(c2))){
				$("input#c2").addClass("error");
			}
			else{
				$("input#c2").removeClass("error");
				if(c5 == $("input#c5")[0].defaultValue){
					$("input#c5").addClass("error");
				}
				else{
					$("input#c5").removeClass("error");
					var dataString = "c5=" + c5 + "&c5id=" + c5id;
					$.ajax({
						type: "POST",
						url: "http://www.luxury-design.com/script/plugin/form-contact/form-check.php",
						data: dataString,
						cache: false,
						success: function(a){
							if(a==0){
								var dataString = "c1="+c1+"&c2="+c2+"&c3="+c3+"&c4="+c4;
								$.ajax({
									type: "POST",
									url: "http://www.luxury-design.com/script/plugin/form-contact/form-send.php",
									data: dataString,
									cache: false,
									success: function(a){
										if(a==0){
											$("#c-form").fadeOut(300, function(){
												$("#answer-01").html("Envoi réussi").fadeIn(300, function(){
													$("#answer-01").delay(1000).fadeOut(300, function(){
														$("input#c1").val($("input#c1")[0].defaultValue).blur();
														$("input#c2").val($("input#c2")[0].defaultValue).blur();
														$("input#c5").val($("input#c5")[0].defaultValue).blur();
														$("textarea#c3").val($("textarea#c3")[0].defaultValue).blur();
														$("#c-form").fadeIn(300);
													});
												});
											});
										}
										else{
											$("#c-form").fadeOut(300, function(){
												$("#answer-01").html("Une erreur s'est produite").fadeIn(300, function(){
													$("#answer-01").delay(1000).fadeOut(300, function(){
														$("input#c5").val($("input#c5")[0].defaultValue).blur();
														$("#c-form").fadeIn(300);
													});
												});
											});
										}
									}
								});
							}
							else{
								$("input#c5").addClass("error");
							}
						}
					});
				}
			}
		}
		return false;
	});  
});
/*--FORM-CONTACT-SHARE--*/
$(function() {
	$("#b-form").click(function() {
		var b1 = $("input#b1").val();
		var b2 = $("input#b2").val();
	
		if ((b1 == $("input#b1")[0].defaultValue) || (!isValidEmailAddress(b1))){
			$("input#b1").addClass("error");
		}
		else{
			$("input#b1").removeClass("error");
			if ((b2 == $("input#b2")[0].defaultValue) || (!isValidEmailAddress(b2))){
				$("input#b2").addClass("error");
			}
			else{
				$("input#b2").removeClass("error");
				var dataString = "b1="+b1+"&b2="+b2;
				$.ajax({
					type: "POST",
					url: "http://www.luxury-design.com/script/plugin/form-contact/form-share.php",
					data: dataString,
					cache: false,
					success: function(a){
						if(a==0){
							$("#b-form").fadeOut(300, function(){
								$("#answer-02").html("Envoi réussi").fadeIn(300, function(){
									$("#answer-02").delay(1000).fadeOut(300, function(){
										$("input#b1").val($("input#b1")[0].defaultValue).blur();
										$("input#b2").val($("input#b2")[0].defaultValue).blur();
										$("#b-form").fadeIn(300);
									});
								});
							});
						}
					}
				});
			}
		}
		return false;
	});  
});
/*--SWAP-THUMBS--*/
jQuery(function($){
	var swapthumbs = $('div').find('div #swap-thumbs');
	swapthumbs.each(function(i){
		
		var title = $(this).find('#swap-title');
		var img_virtual = $(this).find('#img-1');
	
		function showItem(i) {
			img_virtual.fadeOut(100, function(){
				$(this).parent().attr('href',title.parent().eq(i).attr('href'));
				$(this).parent().attr('title',title.parent().eq(i).attr('title'));
				$(this).load(function(){$(this).fadeIn(100);}).attr('src',title.parent().eq(i).attr('rel'));
				if(title.parent().eq(i).attr('rel').indexOf("/luxury-design/medias/images/video/")==0){
					$('#img-2').remove();
					$('<div id="img-2"></div>').insertBefore(img_virtual);
				}
			});
		};
	
		title.each(function(i){
			$(this).mouseenter(function(e){
				e.preventDefault();
				if (img_virtual.attr('src') == title.parent().eq(i).attr('rel')) return;
				showItem(i);
			});
			$(this).click(function(e){
				e.preventDefault();
				var a = title.parent().eq(i);
				if(a.attr('href')){
					if(a.attr('target')=='_blank') {window.open(a.attr('href'));}
					else {location.href = a.attr('href');}
				}
			});
		});
		showItem(0);
	});
});
/*--CUFONT--*/
Cufon.registerFont(window.appFonts['Gotham Light']);
Cufon.registerFont(window.appFonts['Gotham Medium']);
Cufon.registerFont(window.appFonts['Gotham Book']);
Cufon.registerFont(window.appFonts['Roman Type']); // HTF Didot M-42 Medium
Cufon.registerFont(window.appFonts['Roman Type2']); // HTF Didot M-24 Medium
Cufon.registerFont(window.appFonts['Roman Type2Italic']); // HTF Didot M-24 Medium Italic
Cufon.registerFont(window.appFonts['RomanLight']); // HTF Didot L06 Light

Cufon.replace('.menu>ul>li>a, #g-medium',{hover:true,fontFamily:'Gotham Medium'});
Cufon.replace('other, #r-italic',{hover:true, fontFamily:'Roman Type2Italic'});
Cufon.replace('other, #g-book',{hover:true, fontFamily:'Gotham Book'});

/*--MENU-HOVER-INTENT--*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

/*--END OF TYPING--*/
(function(d){function h(a,i){function e(){if(!c){c=true;b.start&&b.start()}}var b=d.extend({start:null,stop:null,delay:400},i);a=d(a);var c=false,f;a.keypress(e);a.keydown(function(g){if(g.keyCode===8||g.keyCode===46)e()});a.keyup(function(){if(c){clearTimeout(f);f=setTimeout(function(){c=false;b.stop&&b.stop()},b.delay)}})}d.fn.typing=function(a){return this.each(function(){h(this,a)})}})(jQuery);

/*--S-MENU--*/
$(function() {
	$('#s-menu ul').height($('.top-wrap-02').height()-30);
	$("ul #s-menu").hoverIntent({over:show, timeout:500, out:hide});
	function show(){
		$(this).find("img").attr("src", $(this).find("li").children(":first-child").attr("rel"));
		$(this).find("ul").fadeIn(300);
	}
	function hide(){
		$(this).find("ul").fadeOut(300);
	}
	$("ul #s-menu li").hover(function(){
		$(this).parent().parent().find("img").attr("src", $(this).children().attr("rel"));
	}, function(){
		$(this).parent().parent().find("img").attr("src", $(this).children(":first-child").attr("rel"));
	});
	//$('img').hide().load(function(){$(this).fadeIn(300)});
});
