isIE = $.browser.msie && !$.support.opacity;
isIE6 = isIE && $.browser.version < 7;
var android = (navigator.platform.indexOf("android")>=0);

function RePosition(){
    if (android ||  navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod'){
        $("#Stickybar").css("position", "static");
        $("#Stickybar .content .drawer")
		.css("position", "absolute")     
		.css("bottom", "auto")
        .css("margin-top", "-221px")
		.css("margin-left", "50px");
   }
}

function moveSB(){
	RePosition();
	$('#Stickybar').appendTo('body').show();
	$("#Stickybar .drawerTrigger").click(function(){
		$("#Stickybar .drawer").slideToggle('fast');
	});
	$("#Stickybar .minimise").click(function(){
		$("#Stickybar .drawer").slideUp('fast');
	});
	
	/*if($('#memo_home_haut').length != 0){
		$("#Stickybar .drawer").slideDown('fast');
	} else {*/
		$("#Stickybar .drawer").hide();
	//}
}

function resizeVeil(){
	$('#overlayMentionsLegalesVeil').css({'height': $(document).height(),'width': $(window).width()});
}

function moveML(){
	var o = $('#overlayMentionsLegales, #overlayMentionsLegalesVeil');
	var v = $('#overlayMentionsLegalesVeil');
	var m = $('#overlayMentionsLegales');
	o.appendTo('body');
	$('.overlayMentionsLegalesOpen').live('click', function(e){
		if(isIE){
			v.stop().fadeTo('fast',0.5);	//#overlayMentionsLegalesVeil
			m.stop().fadeIn('fast');		//#overlayMentionsLegales
		} else {
			o.stop().fadeIn('fast');//both
		}
		resizeVeil();
		e.preventDefault();
	})	
	$('.overlayMentionsLegalesClose').live('click', function(e){
		o.stop().fadeOut('fast');
		resizeVeil();
		e.preventDefault();
	})	
	resizeVeil();
	$(window).resize(function(){
			resizeVeil();
	});
		
}

function autoClose(){	
	if($('#memo_home_haut').length != 0){
		$("#Stickybar .drawer").slideUp('fast');
	}
}

function verifEmailFormat(tested){
	var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
	return(reg.test(tested));
}

$(function (){	
	setTimeout('moveSB()', 800);
	setTimeout('moveML()', 1000);
	setTimeout('autoClose()', 5000);	
	
	$('.hint').each(function() {
		$(this)
		.data('default', $(this).val())
		.addClass('inactive')
		.focus(function(e) {
			$(this).removeClass('inactive');
			if ($(this).val() == $(this).data('default') || '') {
				$(this).val('');
			}
		})
		.blur(function(e) {
			var default_val = $(this).data('default');
			if ($(this).val() == '') {
				$(this).addClass('inactive');
				$(this).val($(this).data('default'));
			}
		});
	});		
	
	$('#Stickybar #sendEmail').click(function(){
		var saisie = $('#Stickybar #email_user').val();
			if(verifEmailFormat(saisie)){
				$('#Stickybar #formInscriptionNewsletter').fadeOut(300,function(e){				
					$('#Stickybar .Confirmation').fadeIn(300);
				});				
			$('body').append('<img src="http://www.daxon.fr/Services/Action.aspx?email=' + saisie+ '&partenaire=newssticky&s=tag&a=inscriptionnewsletter" id="TagNewsletter" />');
			} else {
				alert('Merci de saisir une adresse email valide');
			}
	});	
	
	
	$('#FooterNewsSendEmail').click(function(){
		var saisie = $('#FooterNewsEmail').val();
			if(verifEmailFormat(saisie)){
				$('#FooterNewsInscription').slideUp(200,function(e){				
					$('#FooterNewsConfirmation').slideDown(200);
				});
			$('body').append('<img src="http://www.daxon.fr/Services/Action.aspx?email=' + saisie+ '&partenaire=newsfooter&s=tag&a=inscriptionnewsletter" id="TagNewsletter" />');
			}else{
				alert('Merci de saisir une adresse email valide');
			}
	});	
	
});
