var position = 0;
	
/*	function scrollingDetector(){
		alert("You've scrolled to " + $(window).scrollTop() + " pixels.");
	}
*/

	function checktout(checkb,id,idtxt){
		$(id).find(':checkbox').attr('checked', $(checkb).checked);
		if($(checkb).checked==true) $(idtxt).text('Tout décocher');  else $(idtxt).text('Tout cocher');	
	}

	function count_checkbox(){
		var clength = $("#compar input:checked").length;
		
		if(clength<2)
			alert('- Merci de sélectionner au moins 2 offres à comparer !');
		else if(clength>4)
			alert("Vous pouvez comparer 4 offres au maximum !");
		else
			$("#compar").submit();	
	}

	function goto(uri,message){
		if(message=="") window.location.href=uri;
		else if(confirm(message)){
			window.location.href=uri;
		}
	}

	function affich_dom(){
		$(".disabled").slideToggle();	
	}
	
	function effet_hl(){
		setTimeout(function(){
			$("#effect").removeAttr('style').fadeOut();
		}, 1000);
	};	

	
	function confirmcgv(){
		if($("#confirm_cgv").length!=0) {
			if(document.getElementById('confirm_cgv').checked===false){
				if(confirm('Vous n\'avez pas coché les CGV.\nCliquez sur OK pour les accepter et poursuivre votre commande.')) { document.getElementById('confirm_cgv').checked=true; return true }
				var options = {};
				$("#confirm_cgv_box").effect("highlight",options,2000,effet_hl);
				return false;
			}
		}
	}
	
	function loading_box(id){
		$.fn.colorbox({inline:true, href:"#loading_box", open:true, width:'300px', height:'200px'});	
		$("#loading_box").show();
		$(id).show();
	}


$(function() {
	
	
		$(".cibles_img img").hover(function(){
			$(".cibles_bloc").hide();
			$("#"+$(this).attr("rel")).fadeIn();
		});
	
	
		function top_relative(state) {
			if(state==true) {
				$("#entete").hide();
				$("#contenu").addClass('postop');
			$("#entete").addClass('postop').fadeIn("slow");	

			}else {
				$("#contenu").removeClass('postop');	
				$("#entete").removeClass('postop');
			}
		}
	
	
		function pos_rel(){
		 if ($("#entete").hasClass('postop')) return true;
		 else return false;
		}


		$('.acc_slider').each(function(){
			$(this).nivoSlider({
				effect:'random', //Specify sets like: 'fold,fade,sliceDown'
				slices:15,
				animSpeed:500, //Slide transition speed
				pauseTime:5000,
				startSlide:0, //Set starting Slide (0 index)
				controlNav:false, //1,2,3...
			  controlNavThumbsFromRel:false, //Use image rel for thumbs
				manualAdvance:false, //Force manual transitions
				captionOpacity:0.8, //Universal caption opacity
		/*		info:{'pca','toto','titi','tata'},*/
				beforeChange: function(){},
				afterChange: function(){},
				slideshowEnd: function(){} //Triggers after all slides have been shown
			});
		});

		 $(window).scroll(function() {
			var scrollinfo = $(window).scrollTop();
//			if(scrollinfo > 10 && !pos_rel() ) top_relative(true);
//			if(scrollinfo < 10 && pos_rel() ) top_relative(false);
		});

		$(".theme_bloc").mouseover(function(){
			$(this).find(".pictos").show();	
		});
		$(".theme_bloc").mouseout(function(){
			$(this).find(".pictos").hide();	
		});


		// gestion des liens sur boites div
		$(".goto_lnk").click(function(){ 
			if($(this).attr("rel")!="") window.location.href=$(this).attr("rel"); 
		});
		
		// gestion des slides sur ancres
/*		$('a[href*=#]')
		.not('a[href=#]')
		.bind('click', function() {
		  if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
			  var targetOffset = $target.offset().top;
			  $('html,body').animate({scrollTop: targetOffset}, "normal");
	
			  return false;
			}
		  }});
*/



		   
		   		// PASSER EN FONCTION
		$('#checkall').click(function () {
			$(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);
			if(this.checked==true) $("#lab_checkall").text('Tout décocher');  else $("#lab_checkall").text('Tout cocher');
		});
		$('#checkall_hist').click(function () {
			$(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);
			if(this.checked==true) $("#lab_checkall_hist").text('Tout décocher');  else $("#lab_checkall_hist").text('Tout cocher');
		});
		$('.checkall_ext').click(function () {
			//checktout("#checkall_ext","#formbox","#lab_checkall_ext");
			$(this).parents('div:eq(0)').find(':checkbox').attr('checked', this.checked);
			if(this.checked==true) $("#lab_checkall_ext").text('Tout décocher');  else $("#lab_checkall_ext").text('Tout cocher');
		});

		   
		   
	/// formulaire jnice
		jQuery.each(jQuery.browser, function(i, val) {
   			if(i!="Internet Explorer" && jQuery.browser.version.substr(0,1)!="6") {
				$('form.jNice').jNice();
				return false;
			}
 		}); 


	//// TABS ////
		$(".tabis").tabs();
		var $tabs = $("#tabs").tabs();
				
		
/*		$(".startconf").click(function(){
			var selected = 0;
			var idsel = Number($(this).attr('id')); 
			if(idsel>0)	selected = idsel;							 // ALLER A ... ID DU LIEN
			else		selected = $tabs.tabs('option', 'selected'); // TAB SUIVANT
			var sel = selected+1;
			$tabs.tabs('select',sel); 
			return false;
		});
*/
		$tabs.tabs('select',0);
		$("#tabs").css("visibility","visible");		

	//// VERTICAL TABS /////
		$(".verttabs").each(function(){
			$(this).tabs({ event: 'click' }).addClass('ui-tabs-vertical ui-helper-clearfix');
		});
		$(".bandeau_promo").tabs("rotate", 5000, true);


	/// LIEN LOGO
	$("#accroche_host").click(function(){window.location.href = "/";});
		   
	//// BANDEAU ADMINISTRATION TOP
	$("#open").click(function(){
		$("div#panel").slideDown("slow");	
		$("#bouton").hide();
		$("#accroche_host").css("visibility","hidden");

	});	
	$(".topadmin").click(function(){
		$("div#panel").slideDown("slow");	
		$("#bouton").hide();
		$("#toggle a").toggle();
	});	
	$(".topwebmail").click(function(){
		$("div#panel").slideDown("slow");	
		$("#bouton").hide();
		$("#toggle a").toggle();
	});	
	$("#close").click(function(){
		$("div#panel").slideUp("slow",function(){
			$("#bouton").show();
			$("#accroche_host").css("visibility","visible");			
		});	
	});		
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});		
			   
	//// MENU HORIZONTAL ////
		$('#bloc_menu3').menu({
			content: $('#bloc_menu3').next().html(),
			flyOut: true		
		});
		$('#bloc_menu4').menu({
			content: $('#bloc_menu4').next().html(),
			flyOut: true
		});
		$('#bloc_menu4x').menu({
			content: $('#bloc_menu4x').next().html(),
			flyOut: true
		});
		$('#bloc_menu5').menu({
			content: $('#bloc_menu5').next().html(),
			flyOut: true,
			directionV: 'down',
			detectV: false 
		});
		$('#bloc_menu6').menu({
			content: $('#bloc_menu6').next().html(),
			flyOut: true
		});
		$('#bloc_menu7').menu({
			content: $('#bloc_menu7').next().html(),
			flyOut: true
		});
		$('#bloc_menu7x').menu({
			content: $('#bloc_menu7x').next().html(),
			flyOut: true
		});
		$('#bloc_menu10').menu({
			content: $('#bloc_menu10').next().html(),
			flyOut: true
		});

	//// LISTE D'OFFRE | COMPAR /////	
		$("li.texte ul").toggle("slow");
		$("#compar_offre").click(function(){
			$("li.texte ul").toggle("slow");
		});
		
		
	//// TOOLTIP /////
		$('a.tooltip[href][title]').qtip({
			content: {
				text: false // Use each elements title attribute
			},
			style: { 
			 width: 290,
			  padding: 5,
			  background: '#ffffff',
			  color: '#000000',
			  textAlign: 'left' ,
			  border: {
				 width: 1,
				 radius: 1,
				 color: '#333333'
			  },
			 tip: 'topMiddle'
		   },
			position: {
			  // target: 'topRight',
			   adjust: { screen: true }
			}
		});
	function callback(){
			setTimeout(function(){
				$("#effect").removeAttr('style').fadeOut();
			}, 1000);
		};	
		
	///// HIGHTLIGHT /////
	if($("#effect").length) {
		var options = {};
		$("#effect").effect("highlight",options,2000,callback);
	}
	
		
	
	//// OVERLAY ////
		if($(".iframe").length!=0)
			$(".iframe").colorbox({width:"90%", height:"90%", iframe:true}); 
		if($(".iframe_title").length!=0)
			$(".iframe_title").colorbox({width:"80%", height:"80%", iframe:true, title:'<a href="/inc/client/form_coupon.php" title="Acc&egrave;s au formulaire"><img style="cursor:pointer" onclick="javascript:window.location.href=\'/inc/client/form_coupon.php\';" src="/assets/images/images/bt_inscription.jpg" alt="inscription2 en ligne"/>'}); 
		if($(".iframe_small").length!=0)
			$(".iframe_small").colorbox({width:"600px", height:"90%", iframe:true}); 
		
		
	//// IMPRESSION CONFIGURATEUR ////
		var content = '<img src="/image/logo.jpg" /><br />10 rue Louis de Broglie <br>  CS 52383 <br> 44323 NANTES cedex 3<br />';
		content += 'Tel service commercial : 0826 80 46 78 (0,15€/min)<br />';
		content += 'Tel service technique : 0892 88 46 78 (0,34€/min)<br />';
		content += 'Email service commercial : contact@host.fr<br />';
		content += 'Email service technique : tech@host.fr<br />';
		content += 'Fax : +33 (0)2 40 50 20 45<br />';

		
//		var uri = jQuery.url.attr("source");
		var uri = '';
		if($(".legal").length!=0){
			var print_css = '<link rel="stylesheet" type="text/css" media="print" href="/css/print_offre.css" /><link rel="stylesheet" type="text/css" media="screen" href="/css/screen_offre.css" />';
			$(".top_offre").prepend(print_css);
			$(".top_offre").prepend(content);
			$("#prx-000").append(" € ht");
			$.fn.colorbox({inline:true, href:".top_offre", open:true, width:750, height:'90%'});
			$().bind('cbox_complete', function(){
				$('.top_offre').printElement();
			});
			$().bind('cbox_closed', function(){
					$(".top_offre").hide();
					$("#waitingbox").show();
					window.location.href=uri;
			});
		}
		//// ENVOI PAR MAIL CONFIGURATEUR ////
		if($("#mailbox").length!=0){
			$.fn.colorbox({inline:true, href:"#mailbox", open:true, width:750});
			$().bind('cbox_closed', function(){
					$("#mailbox").hide();
					$("#waitingbox").show();
					//var uri = jQuery.url.attr("path");
					var uri = '';
					window.location.href=uri;
			});
		}
		//// IMPRESSION PANIER ////
		var cbox = false;
		if($(".print_kart").length!=0) {
			var print_css2 = '<link rel="stylesheet" type="text/css" media="print" href="/css/print_panier.css" /><link rel="stylesheet" type="text/css" media="screen" href="/css/screen_panier.css" />';
			$(".print_kart").each(function(){
				$(this).click(function(){
					if(confirm("Souhaitez vous imprimer ce panier ?")){
						cbox = true;
						$("#content_css").prepend(print_css2);
						$("#content_kart").show();
						$(".legal2").show();
						$("img.display_screen").hide();
						var boxprint = '#contenu_kart';
//						alert(boxprint);
						$.fn.colorbox({inline:true, href:boxprint, open:true, width:750, height:'90%'});
						$().bind('cbox_complete', function(){
							var nbech = $("#echeancier2").length;
							if(nbech==0) {
								var echeancier = $(".echeancier h4").text();							   
								$("#contenu_kart").append('<div id="echeancier2">'+echeancier+'</div>');	
								if(cbox===true) $('#contenu_kart').printElement();
								cbox=false;
							}
						});
						$().bind('cbox_closed', function(){
							$("#echeancier2").remove();	
							$("#content_kart").hide();						   
							$(".legal2").hide();
							$("img.display_screen").show();
							$("#content_css").html('');
						});
					}
				});
										   });
		}

		///// AFFICHAGE LOGIN BOX ////
		$("#bt_connect").click(function(){
		//	alert('connection box');
			$("#tabs").css("visibility","visible");
			$.fn.colorbox({inline:true, href:"#tabs", open:true, width:750, height:'90%'});
			$().bind('cbox_closed', function(){
				$("#tabs").css("visibility","hidden");
			});
    	});

			
	//// GALLERY  ////
		if($("a[rel='lightbox']").length!=0)
		   $("a[rel='lightbox']").colorbox();
	
	

	//// COOKIES ///////
		var options = { path: '/', expires: 10 };
		
		$('#bt_detail').click(function() {
			$.cookie('liste', 'detail', options);
			return false;
		});
		$('#bt_vignette').click(function() {
			$.cookie('liste', 'vignette', options);
			return false;
		});

	///// FORM COUPON //////
		$(".btcoupon").click(function(){
			coupon($(this).val(),'coupon');
		});
		$(".btexist").click(function(){
			coupon($(this).val(),'exist');
		});
		function coupon(type,bloc){
			//alert(type+bloc);
			$(".bloc_"+bloc).each(function(){
				$(this).slideUp();							 
			});
			$("#bloc_"+type).slideDown();
			
		}
		
	$("#paiement_secu").show();
	
	////// MINI PANIER /////
		$(".toppanier").click(function(){
			window.location.href="/panier.html";							  
		});
		$(".toppanier_vide").click(function(){
		//	alert('Votre panier est actuellement vide');
			window.location.href="/panier.html";							  
		});


	////// DOMAINES ///// 
		$("#affich_dom img").click(function(){
			content = $(this).attr('src');
			if(content=='/image/masquer.png') 	$(this).attr('src','/image/afficher.png');
			else 								$(this).attr('src','/image/masquer.png');
		});
		
		$("#nomdom_top").click(function(){
			if($(this).val() == 'Saisissez votre domaine...') $(this).val('');							
		});
		$("#nomdom_top").blur(function(){
			if($(this).val()=='') 	$(this).val('Saisissez votre domaine...');
		});
		

		$(".checkdom").click(function(){
			var dom = $(this).val();		
			var idoffre = document.getElementById("dom["+dom+"][idoffre]").value;
			var idoffreprix = document.getElementById("dom["+dom+"][idoffreprix]").value;
			var credits = document.getElementById("dom["+dom+"][credits]").value;
			var loyer = document.getElementById("dom["+dom+"][loyer]").value;
			var duree = document.getElementById("dom["+dom+"][duree]").value;
			
			if(this.checked==true) {
				var check = 1;
			}else{
				var check = 0;
			}
				$.post("/histo_dom.html", 
					{dom: dom,idoffre: idoffre,idoffreprix: duree,credits: credits,loyer: loyer,duree: duree,check: check},
					function(data){
						//alert("Retour ajax "+data);
					}
				);

		});
		
		
			
		$("#boxcom").click(function(){
			var hbox = $(".boxcom").height();
			var options = { path: '/', expires: 10 };
			if(hbox<100) {
				var height=130;
				$.cookie('boxcom', 'open', options);
			}else{
				var height=30; 
				$.cookie('boxcom', 'close', options);
			}
			$(".boxcom").animate({
			height:height
			}, 300, "linear" );
		});
		
		$(".openboxcom").click(function(){
		 $(".boxcom").animate({
			height:130
			}, 300, "linear" );
		});
		
		// WAITITNG
		if($(".bt_addkart").length>0){
			$(".bt_addkart").click(function(){
				loading_box("#add_kart");			
			});
		}
		
		// liste catégorie détaillée ou non
		
		if($("#list_cat li.nosubcat").length>0){
			$("#list_cat_hide_detail").show();
		}
		
		$("#list_cat_hide_detail").click(function(){
			$(this).hide();
			$("#list_cat_show_detail").show();		
			$("#col_gauche ul#list_cat li span").hide();
			$("#col_gauche ul#list_cat li.nosubcat").css("height","auto"); 
		});
		$("#list_cat_show_detail").click(function(){
			$(this).hide();
			$("#list_cat_hide_detail").show();	
			$("#col_gauche ul#list_cat li span").show();
			$("#col_gauche ul#list_cat li.nosubcat").css("height","300px"); 
		});
		
		

});

