$.fn.qtip.styles.mystyle = {
	padding: 3,
	background: '#514639',
	color: 'white',
	fontWeight: 'normal',
	fontSize: '12px',
	textAlign: 'center',
	border: {
		 width: 2,
		 radius: 5,
		 color: '#514639'
	},
	tip: 'bottomMiddle',
	name: 'dark'
}

$(document).ready(function() {
	$('a[rel="lightbox"]').click(function() {
		var id = $(this).attr('href');
		$('#overlay').fadeIn();
		$(id).fadeIn();
		$(id+' input:first').focus();
		return false;
	});
	
	//tips
	$('.qtip[href][title]').qtip({
	content: {
		 text: false // Use each elements title attribute
		},
		position: {
			corner: {
			target: 'topMiddle',
			tooltip: 'bottomMiddle'
			}
		},
		style: 'mystyle'
	});
	
	
	$(' #form_box').hide();
	$('a[rel="formbox"]').click(function() {
		$(' #form_content').empty();
		var id = $(this).attr('href');
		$.ajax({
			url: id,
			cache:false,
			success:function(html){
				$('#form_content').append(html);
				$('#overlay').fadeIn();
				$('#form_box').fadeIn();
				$('#form_content form').attr('action', $('#form_content form').attr('action') + '/ajx/box');
				boxWidth = $('#form_content').width();
				boxHeight = $('#form_content').height();
				$('#form_box').css({ 'margin-left' : -Math.round(boxWidth/2), 'margin-top' : -Math.round(boxHeight/2) });
			},
			error:function(XMLHttpRequest, textStatus, errorThrown){
				alert(textStatus);
			}
		})
		return false;
	});
	
	
	$('#overlay').click(function() { $(' #overlay').fadeOut(); $(' .lightbox').fadeOut(); $(' #form_box').fadeOut(); });
	$('.close').click(function() { $(' #overlay').fadeOut(); $(' .lightbox').fadeOut(); $(' #form_box').fadeOut(); });
	
	$("#quick-search").focus(function(){ if($(this).attr("value") == "Recherchez sur Topino"){ $(this).attr("value", ""); } });
	$("#quick-search").blur(function(){ if($(this).attr("value") == ""){ $(this).attr("value", "Recherchez sur Topino"); } });
	
	$("#login_splash").focus(function(){ if($(this).attr("value") == "Login"){ $(this).attr("value", ""); } });
	$("#login_splash").blur(function(){ if($(this).attr("value") == ""){ $(this).attr("value", "Login"); } });
	$("#password_splash").focus(function(){ if($(this).attr("value") == "Mot de passe"){ $(this).attr("value", ""); } });
	
	$("#zip").focus(function(){ if($(this).attr("value") == 'tapez Le nom d\'un produit, d\'une localité ou un code postal'){ $(this).attr("value", ""); } });
	$("#zip").blur(function(){ if($(this).attr("value") == ""){ $(this).attr("value", 'tapez Le nom d\'un produit, d\'une localité ou un code postal'); } });

	
	$(".product-order select").each(function(){
		$(this).change(function(){
			link = $(this).val();
			if(link != ""){
				window.location.href = link;
			};
		});
	});
	
	$("#select_adress").each(function(){
		$(this).change(function(){
			link = $(this).val();
			if(link != ""){
				window.location.href = link;
			};
		});
	});
	
	var move = false;
	
	$('#faq .closed').hide();
	$('#faq .faq-categories h3').click(function() {
		move = true;
		if ($(this).next().hasClass('closed')) {
			$(this).next().slideDown(500, function() {
				move = false;
				$(this).removeClass('closed');
				$(this).addClass('open');
			});
		}
		else {
			$(this).next().slideUp(500, function() {
				move = true;
				$(this).removeClass('open');
				$(this).addClass('closed');
			});
		}
	});
	
});