$(document).ready(function() {

	$(".navigation_1_li").mouseover(function()
	{
		$(this).find(".navigation_2_base").show();
		/*$(this).find(".navigation_1_a").removeClass("navigation_1_a_nothover").addClass("navigation_1_a_hover");*/
		if($(this).attr('data-color')!=undefined)
		{
			var color = $(this).attr('data-color');
			$(this).find(".navigation_1_a").css({"color":"#fff", "background-color":color});
			$(this).find(".navigation_2_base").css("background-color", color);	
		}
		else
		{
			$(this).find(".navigation_1_a").css({"color":"#fff","background-color":"#ee7f00"});
		}
		
	});

	$(".navigation_1_li").mouseout(function()
	{
		$(this).find(".navigation_2_base").hide();
		/*$(this).find(".navigation_1_a").removeClass("navigation_1_a_hover").addClass("navigation_1_a_nothover")*/;
		if($(this).attr('data-color')!=undefined)
		{
			//var color = $(this).attr('data-color');
			$(this).find(".navigation_1_a").css({"color":"#000","background-color":"#ee7f00"});
			$(this).find(".navigation_2_base").css("background-color", "#ee7f00");	
		}
		else
		{
			$(this).find(".navigation_1_a").css({"color":"#000","background-color":"#fff"});
		}
	});
	
	$(".tableau_article").click(function()
	{
		document.location.href=$(this).find("a.tableau_article_nom").attr('href');
	});
	

	//$('<div class="tete_box" id="tmp_panier">test</div>');
	
	/*Ajout des box dans le bandeau*/
	
	if(GLOBAL['session_client_id']=='')
	{ //libelle a afficher dans le bouton "mon compte"
		libelle_mon_compte = 'Mon compte';
	}
	else
	{
		libelle_mon_compte = GLOBAL['session_client_nom'];
	}
	
	$('#centre_tete').append( 
			//mon panier
			$('<div class="tete_box" id="tete_panier_div"/>').css({'right':'0px', 'top':'74px', 'width': '244px', 'cursor':'pointer', 'z-index':'500'}).append(
					$('<img alt="panier" title="panier" src="'+GLOBAL['url_template']+'css/icone_panier.png"/>').css({'position':'absolute', 'left':'0px', 'top':'-4px'})
			).append(
					$('<input id="nb_articles" value="Mon panier          '+nb_art+' article(s)" readonly />').css({'position':'absolute', 'left':'28px', 'top':'2px', 'width': '212px', 'cursor':'pointer'})
			).click(function() 
					{
				location.href=GLOBAL['url_site']+'index.php?page=panier';
			})
	)/*.append(		
			//me connecte
			$('<div class="tete_box" id="tete_connecter_div"/>').css({'left':'845px', 'top':'12px', 'width': '105px', 'cursor':'pointer', 'background-color':'#ff0'}).append(
					$('<img src="'+GLOBAL['url_template']+'css/icone_connecter.png"/>').css({'position':'absolute', 'left':'48px', 'top':'10px', 'background-color':'#fff'})
			).append(
					$('<a/>').css({'left':'-48px', 'top':'10px'}).append('Me connecter')
			).click(function() 
					{
				splash('../mon_compte/connexion.php', 'Me connecter');
			})
	)*/.append(
			//mon compte
			$('<div class="tete_box" id="tete_compte_div"/>').css({'right':'0px', 'top':'0px', 'width': '154px', 'cursor':'pointer', 'z-index':'800'}).append(
					$('<img alt="compte" title="compte" src="'+GLOBAL['url_template']+'css/icone_compte.png"/>').css({'position':'absolute', 'right':'5px', 'top':'0px', 'z-index':'900'})
			).append(
					$('<a/>').css({'left':'4px', 'top':'7px', 'z-index':'900'}).append(libelle_mon_compte)
			)
	).append(
			//Nous contacter
			$('<div class="tete_box" id="tete_contacter_div"/>').css({'right':'0px', 'top':'34px', 'width': '154px', 'cursor':'pointer', 'z-index':'500'}).append(
					$('<img alt="contact" title="contact" src="'+GLOBAL['url_template']+'css/icone_contacter.png"/>').css({'position':'absolute', 'right':'5px', 'top':'0px'})
			).append(
					$('<a/>').css({'left':'4px', 'top':'7px'}).append('Nous contacter')
			).click(function() 
			{
				window.location.href=GLOBAL['url_site']+'formulaire_contact.html';
			})
	).append(
			//Recherche
			$('<div class="tete_box" id="tete_recherche_div"/>').css({'left':'388px', 'top':'74px', 'width': '284px', 'z-index':'500'}).append(
					$('<img alt="recherche" title="recherche" src="'+GLOBAL['url_template']+'css/icone_recherche.png"/>').css({'position':'absolute', 'left':'0px', 'top':'-4px'})
			).append(
					$('<input type="text" id="tete_recherche_input" placeholder="Rechercher un article ?" value="Rechercher un article ?" maxlength="34"/>').css({'position':'absolute', 'width': '252px', 'left':'29px', 'padding-left':'-105px', 'top':'2px', 'cursor':'pointer'}).keydown(function(event) {
						if (event.keyCode == '13') 
						{
							window.location.href=GLOBAL['url_site']+"index.php?recherche="+$(this).val();
						}
					}).click(function(){$(this).val('');})
			).append(
					$('<img alt="recherche" title="recherche" id="tete_recherche_bouton" src="'+GLOBAL['url_template']+'css/icone_recherche_bouton.png"/>').css({'position':'absolute', 'left':'262px', 'top':'6px', 'cursor':'pointer'}).click(function() 
						{
							window.location.href=GLOBAL['url_site']+"index.php?recherche="+$('#tete_recherche_input').val();
						})
			)
	);
	
	/*Si on est connecte, il faut ajouter le petit menu deroulant de gestion du compte*/
	if(GLOBAL['session_client_id']=='')
	{ //on est pas connecte: on ne peut que cliquer pour afficher le popup de connexion
		$('#tete_compte_div').click(function() 
		{
			splash(GLOBAL['url_template']+'mon_compte/connexion.php?page=connexion', '');
		});
	}
	else
	{ //on est connecte: on affiche le menu de gestin du compte
		$('#tete_compte_div').append(				
				$('<div id="menu_compte"><ul></ul></div>')
			);
		
		$('#menu_compte>ul')
			.append(				
				$('<li>Modifier compte</li>').click(function() 
				{
					window.location.href=GLOBAL['url_site']+'index.php?page=mes_coordonnees';
				}))
			.append(
				$('<li>Mon panier</li>').click(function() 
				{
					location.href=GLOBAL['url_site']+'index.php?page=panier';
				}))
			.append(
				$('<li>Mes commandes</li>').click(function() 
				{
					window.location.href=GLOBAL['url_site']+'index.php?page=mon_compte';
				}))
			.append(
				$('<li>Payer une commande</li>').click(function() 
				{
					window.location.href=GLOBAL['url_site']+'index.php?page=reglement_commande';
				}))	
			.append(
				$('<li>Déconnexion</li>').click(function() 
				{
					window.location.href=GLOBAL['url_template']+'mon_compte/disconnect.php';
				})
			);
		
		
		$("#tete_compte_div").mouseover(function()
		{
			$("#menu_compte").show();
		});

		$("#tete_compte_div").mouseout(function()
		{
			$("#menu_compte").hide();
		});
	}
	
	$( "#filtre_prix_slider" ).slider({
		range: true,
		min: 0,
		max: 500,
		values: [ 75, 300 ],
		slide: function( event, ui ) {
			$( "#filtre_prix" ).val(  ui.values[ 0 ]+ "\u20ac - " + ui.values[ 1 ] + "\u20ac");
		}
	});
	$( "#filtre_prix" ).val($( "#filtre_prix_slider" ).slider( "values", 0 ) + "\u20ac -" + $( "#filtre_prix_slider" ).slider( "values", 1 )+"\u20ac" );
	
	var tab_tailles = new Array();
	tab_tailles[0] = 'XS';
	tab_tailles[1] = 'S';
	tab_tailles[2] = 'M';
	tab_tailles[3] = 'L';
	tab_tailles[4] = 'XL';
	tab_tailles[5] = 'XXL';
	$( "#filtre_taille_slider" ).slider({
		range: true,
		min: 0,
		max: 5,
		values: [ 1, 4 ],
		slide: function( event, ui ) {
			$( "#filtre_taille" ).val(  tab_tailles[ui.values[ 0 ]]+ " - " + tab_tailles[ui.values[ 1 ]]);
		}
	});
	$( "#filtre_taille" ).val(tab_tailles[$( "#filtre_taille_slider" ).slider( "values", 0 )] + " - " + tab_tailles[$( "#filtre_taille_slider" ).slider( "values", 1 )] );

	/*Ajout informations dans le pied de page*/
	/*
	$(".foot_info_colonne:nth-child(1)")
	.append('<a>Condition générales de vente</a>'
		+'<a>Mentions légales</a>'
		+'<a>Référencement</a>'
		+'<a>Partenaires</a>'
		+'<img src="'+GLOBAL['url_site']+'template/1/css/foot_contact_telephone.jpg" style="margin-top:25px"/>')
	.after('<div class="foot_info_colonne">'
		+'<img src="'+GLOBAL['url_site']+'template/1/css/foot_point_informations.jpg"/>'
		+'<a>Comment commander ?</a>'
		+'<a>Vous aider à commander</a>'
		+'<img src="'+GLOBAL['url_site']+'template/1/css/foot_paiement_securise.jpg" style="margin-top:25px"/>'
		+'<a>Comment payer ?</a>'
		+'<img src="'+GLOBAL['url_site']+'template/1/css/foot_logo_credit_mutuel.gif" style="margin-top:5px"/>'
		+'<img src="'+GLOBAL['url_site']+'template/1/css/foot_logo_kwixo.jpg" style="margin-top:2px"/>'
		+'</div>'
		+'<div class="foot_info_colonne">'
		+'<img src="'+GLOBAL['url_site']+'template/1/css/foot_engagement_satisfaction.jpg"/>'
		+'<a>Vos garanties ?</a>'
		+'<img src="'+GLOBAL['url_site']+'template/1/css/foot_livraison_gratuite.jpg" style="margin-top:40px"/>'
		+'<img src="'+GLOBAL['url_site']+'template/1/css/foot_logo_so_colissimo.gif" style="margin-top:10px"/>'
		+'<img src="'+GLOBAL['url_site']+'template/1/css/foot_logo_tnt.jpg" style="margin-top:10px"/>'
		+'</div>');
	$(".foot_info_colonne:nth-child(4)")
	.prepend('<img src="'+GLOBAL['url_site']+'template/1/css/foot_bon_a_savoir.jpg"/>')
	$(".foot_info_colonne:nth-child(4)")
	.after('<script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=discountmariage"></script>'
		+'<div class="foot_info_colonne">'
		+'<img src="'+GLOBAL['url_site']+'template/1/css/foot_reseaux_sociaux.jpg"/>'
		+'<a class="addthis_button_compact" href="http://www.addthis.com/bookmark.php?v=250&amp;username=discountmariage"><img src="'+GLOBAL['url_site']+'template/1/css/foot_addthis.jpg" style="margin-top:30px"/></a>'
		+'<iframe src="http://www.facebook.com/plugins/like.php?href'+GLOBAL['url_site']+'&amp;send=false&amp;layout=button_count&amp;width=450&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=verdana&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:75px; height:35px;text-align: right; padding-top: 20px;" allowTransparency="true"></iframe>'
		+'<div align="right" style="padding-top: 10px;padding-right: 65px;"><g:plusone size="small" href="'+GLOBAL['url_site']+'" count=false></g:plusone></div>'
		+'</div>'
		)
	;
	$("#foot_mention_legale").html("* Coût de l'appel 0,34&euro;/min - ** A parir de 150&euro; d'achat sur le site. France métropolitaine uniquement.");
	
	
	$('#foot_lien_ref li:not(:nth-child(1))').before('<span>-</span>');
	  */
	
	if (navigator.appName=="Microsoft Internet Explorer")
	{	
		/*
		$(".contenu_principal").css({'width':'759px'});
		
		$("#centre_contenu").wrapInner('<div style="border:20px solid #F0A" />').wrapInner('<div style="border:20px solid #000" />');
*/

		if($("#menu").length > 0)
		{
			$("#centre_contenu").wrapInner('<tr />').wrapInner('<tbody />').wrapInner('<table width="100%" />');
			$("#menu").wrap('<td valign="top" />');
			$(".contenu_principal").wrap('<td valign="top" />');
		}

		$("#menu_compte>ul>li").mouseover(function()
		{
			$(this).css({"background":"#DBD9DA","font-weight":"bold"});
		}).mouseout(function()
		{
			$(this).css({"background":"#fff","font-weight":"normal"});
		});
		
		$("button").mouseover(function()
		{
			$(this).css({"color":"#fff","cursor":"pointer"}).find('span').css({"color":"#fff","cursor":"pointer"});
		}).mouseout(function()
		{
			$(this).css({"color":"#000"}).find('span').css({"color":"#000"});
		});
		
		$("#foot_groupe_colonnes li").css({"float":"left"});
		

		$(".tableau_article").mouseover(function()
		{
			$(this).addClass("tableau_article_hover");
		});
		
		$(".tableau_article").mouseout(function()
		{
			$(this).removeClass("tableau_article_hover").addClass("tableau_article");
		});
		
	}

	
});

function splash(url, name, post_data) //post_data est facultatif
{
	if($("#spalsh").length==0)
	{		
		$('#centre_tete').append(
				$('<div id="spalsh" title="'+name+'"/>').append(
						$('<img alt="Chargement" title="Chargement" id="loader" src="'+GLOBAL['url_template']+'css/loader.gif"/>').css({'position':'absolute', 'left':'310px', 'top':'150px'})
				)
		);
	}
	else
	{
		$("#spalsh").empty();
	}

	$("#spalsh").dialog({
		title: name,
		width: 640,
		modal: true,
		draggable: true,
		minHeight: 450,
		open: function(){
			$("#spalsh").find(".ui-widget-header").css({"background-color":"#0ff", "border-bottom":"1px solid #ff0"});
			if(typeof post_data == "undefined")
			{
				$("#spalsh").load(url);
			}
			else
			{
				$("#spalsh").load(url, post_data);
			}
		},
		close: function(){
			$('select').show();
		}
	});
}
