
/****************************************************************************************************************
	slide  script
****************************************************************************************************************/


function initMenu() {
  $('#login-wrapper').hide();
  $('.connexion_inscription a').click(
    function() {
        $('#login-wrapper').slideToggle('normal');	
      }
    );
  }
/****************************************************************************************************************
	modale script
****************************************************************************************************************/
function basic(){
	$('#basicModal input.basic, .liens_communautes a.basic, a.basic').click(function (e) {
		e.preventDefault();
		$('#compte_container').modal({position: ['5px',], onOpen: modalOpen, onClose: modalClose});
            });
	$('a.video').click(function (e) {
		$('#video_container').modal({position: ['5px',], onOpen: modalOpen, onClose: modalClose});
            });
	$('a.lien_video').click(function (e) {
		$('#video_container').modal({position: ['5px',], onOpen: modalOpen, onClose: modalClose});
            });
        $('a.light_video').click(function (e) {
		$('#video_container').modal({position: ['5px',], onOpen: modalOpen, onClose: modalClose});
            });
        $('a.basic_contacter').click(function (e) {
		$('#ecrire_container').modal({position: ['5px',], onOpen: modalOpen, onClose: modalClose});
            });
	$('a.monpanier').click(function (e) {
		$('#etape_commande').modal({position: ['5px',], onOpen: modalOpen, onClose: modalClose});
		$('#etape_panier').attr("style","display:block");
	});
	$('a.vos_commande').click(function (e) {
		$('#etape_commande').modal({position: ['5px',], onOpen: modalOpen, onClose: modalClose});
		$('#etape_paiement').attr("style","display:block");
	});
	$('a.paiement_cheque').click(function (e) {
	e.preventDefault();
		$('#cheque_container').modal({position: ['5px',], onOpen: modalOpen, onClose: modalClose});
	});
	
	$('a.paiement_bancaire').click(function (e) {
        e.preventDefault();
		$('#coord_bancaire').modal({position: ['5px',], onOpen: modalOpen, onClose: modalClose});
	});
	
}

function amis(){
	$('a.amis').click(function (e) {
		e.preventDefault();
		$('#amis_container').modal({position: ['0px',], onOpen: modalOpen, onClose: modalClose});
	});
	
	
}
/****************************************************************************************************************
	dropdown script
****************************************************************************************************************/


function dropdown(){

    $("ul.dropdown li").hover(function(){
    
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    
    });
    
    $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");

}



/****************************************************************************************************************
	img-replacement  script
****************************************************************************************************************/



function imgRepla(){
/*$("h2").append('<em></em>')*/

	$(".thumbs a").click(function(){
	
		var largePath = $(this).attr("href");
		var largeAlt = $(this).attr("title");
                
                var diapoPath = $(this).attr("alt");
		
		$("#largeImg").attr({ src: largePath, alt: largeAlt });
		$(".lien_diapo").attr({ href:diapoPath , alt: largeAlt });
		$("h2 em").html(" (" + largeAlt + ")"); return false;
	});
}

/*function commentaire() {
			$('input[type="text"]').addClass("idleField");
       		$('input[type="text"]').focus(function() {
       			$(this).removeClass("idleField").addClass("focusField");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
    		$('input[type="text"]').blur(function() {
    			$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});
		}		
/****************************************************************************************************************
	  script commentaire
****************************************************************************************************************/

function commentaire() {
    $('textarea').addClass("idleField");

    $('textarea').focus(function() {
        if ($(this).hasClass('copycode')) return;
        
        $(this).removeClass("idleField").addClass("focusField");
        if (this.value == this.defaultValue) {
            this.value = '';
        }
        if (this.value != this.defaultValue) {
            this.select();
        }
    });

    $('textarea').blur(function() {
        if ($(this).hasClass('copycode')) return;
        
        $(this).removeClass("focusField").addClass("idleField");
        if ($.trim(this.value) == '') {
            this.value = (this.defaultValue ? this.defaultValue : '');
        }
    });
}
/****************************************************************************************************************
	  script rep
****************************************************************************************************************/

function rep(id_com) {
   
		
		$('#reponse_'+id_com+'content').show();
		
					$('#rep_'+id_com).focus();
		}		
/****************************************************************************************************************
	  script carosel
****************************************************************************************************************/
/****************************************************************************************************************
	  script photos fiche produit
****************************************************************************************************************/
function imgReplaHover(){
/*$("h2").append('<em></em>')*/

	$(".thumbsHover a").click(function(){
	
		var largePath = $(this).attr("href");
		var largeAlt = $(this).attr("title");
		var diapo =  $(this).attr("alt");
		$("#largeImgHover").attr({ src: largePath, alt: largeAlt });
		$(".thickbox").attr({ href: diapo, title: largeAlt });
		//$("h2 em").html(" (" + largeAlt + ")");
		return false;
	});
}

/****************************************************************************************************************
	  script smiley
****************************************************************************************************************/

    function AddText(startTag,defaultText,endTag)
{
    with(document.poster)
    {
        if (message.createTextRange)
            {
                var text;
                  message.focus(message.caretPos);
                message.caretPos = document.selection.createRange().duplicate();
                if(message.caretPos.text.length>0)
                    {
                        //gère les espace de fin de sélection. Un double-click sélectionne le mot
                        //+ un espace qu'on ne souhaite pas forcément...
                        var sel = message.caretPos.text;
                        var fin = '';
                        while(sel.substring(sel.length-1, sel.length)==' ')
                            {
                                sel = sel.substring(0, sel.length-1)
                                    fin += ' ';
                            }
                         message.caretPos.text = startTag + sel + endTag + fin;
                    }
                else
                     message.caretPos.text = startTag+defaultText+endTag;
                
            }
        else message.value += startTag+defaultText+endTag;
    } 
 
}
function focus()
{
    document.getElementById('contenu').focus();
}

function insert_text(open, close)
{
   
    msgfield = (document.all) ? document.all.message : document.forms['poster']['message'];
    // IE support
    if (document.selection && document.selection.createRange)
        {
            msgfield.focus();
            sel = document.selection.createRange();
            sel.text = open + sel.text + close;
            msgfield.focus();
        }

    // Moz support
    else if (msgfield.selectionStart || msgfield.selectionStart == '0')
        {
            var startPos = msgfield.selectionStart;
            var endPos = msgfield.selectionEnd;

            msgfield.value = msgfield.value.substring(0, startPos) + open + msgfield.value.substring(startPos, endPos) + close + msgfield.value.substring(endPos, msgfield.value.length);
            msgfield.selectionStart = msgfield.selectionEnd = endPos + open.length + close.length;
            msgfield.focus();
        }

    // Fallback support for other browsers
    else
        {
            msgfield.value += open + close;
            msgfield.focus();
        }

    return;
}	


/****************************************************************************************************************
	nav2 rollover script
****************************************************************************************************************/
function initSlide(){

$("a.tab").hover( function ()
{

// Mettre tous les onglets non actifs
$(".active").removeClass("active");
// Mettre l'onglet cliqué actif

$(this).addClass("active");

// Cacher les boîtes de contenu
$(".content").hide();

var contenu_aff = $(this).attr("title");
$("#" + contenu_aff).fadeIn(110);

}
);
}
function initNav2(){	

	/* init */
	$('#header, #nav2Roll').addClass('JSenabled');
	$('#nav2Roll, #nav2RollContent div').hide();
	
	var isHover = false;
	
	/* rollOver*/
	$('#nav2 li a').hover(function(){
		
		$('#nav2RollContent div').hide();
		
		$('#nav2Roll').show();
		
		$('#'+$(this).parent().attr('id')+'Content, #'+$(this).parent().attr('id')+'Content *').show();

		$('.content').hide();

		$('#nav2 a').removeClass("hover");
		$(this).addClass("hover");
				
		if ($(this).parent().attr('id') == 'jourApresJour') $('#nav2RollContent, #nav2RollBtm').addClass('jaj');
		else $('#nav2RollContent, #nav2RollBtm').removeClass('jaj');
		
		
		
	},function(e){
  		
		// if cursor is above the nav hide the nav2Roll
		if (e.pageY < 10) {
			$('#nav2 a').removeClass("hover");
			$('#nav2Roll').hide();
			
		}
		// else if it is on the nav2Roll
		else{
			$('#nav2Roll').hover(function(){
				// don't do anything !	
			},function(){
				// hide the stuff on roll out
				$('#nav2 a').removeClass("hover");
				$(this).hide();
	
			});
		}
	});
}

/************************
scrollTo
**************************/
function scrollTo(){

$('.faire_commentaire').click(function(){
		$.scrollTo( $('.bottomBlock'), {speed:600} );
	});
	
$('#add_new_field_photo').click(function(){
		$.scrollTo( $('#div_photo'), {speed:600} );
	});	
	

}
function scrollToVideo(){
//console.log('kjhkjkj');
 $('#video_container').serialScroll({
		target:'#div_video_light',
		items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		prev:'a.prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
		next:'a.next',// Selector to the 'next' button (absolute too)
		//axis:'x',// The default is 'y' scroll on both ways
		//navigation:'#navigation li a',
		//stop:true,
		cycle:false,
		duration:400// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		//force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
	});	
	

}


/*************************************/



function toggleVideo(){

	$(".a_aide_video").toggle(function(){
			$.scrollTo( $('#header'), {speed:600} );
		  $(".videoAide").slideDown("slow");
		  }, function () {
		  $(".videoAide").slideUp("slow");
		}); 

}
/*******************************
modal

************************************/


function modalOpen (dialog) {
	dialog.overlay.fadeIn(200, function () {
		dialog.container.fadeIn(200, function () {
			dialog.data.slideDown('slow');
		});
	});
}


function modalOpenVideo (dialog) {
	dialog.overlay.fadeIn(200, function () {
		dialog.container.fadeIn(200, function () {
			dialog.data.animate({ height: "642px"

		});
	});
});
}


/**
 * When the close event is called, this function will be used to 'close'
 * the overlay, container and data portions of the modal dialog.
 *
 * The SimpleModal close function will still perform some actions that
 * don't need to be handled here.
 *
 * onClose callbacks need to handle 'closing' the overlay, container
 * data and iframe.
 */
function modalClose (dialog) {
	dialog.data.slideUp('slow', function () {
		dialog.container.fadeOut(200, function () {
			dialog.overlay.fadeOut(200, function () {
				$.modal.close();
			});
		});
	});
}

function modalCloseVideo (dialog) {
	dialog.overlay.fadeIn(200, function () {
		dialog.container.fadeIn(200, function () {
			dialog.data.animate({ height: "10%"

		});
	});
	});
}




/**********************
**************************/

function tb_initVideo(domChunk2){

	var t = " ";
	var a = "#TB_inline?height=400&amp;width=485&amp;inlineId=video_contain";
	var g = false;
	tb_show(t,a,g);
	this.blur();
	return false;
	
}


/****************************************************************************************************************
	onLoad
****************************************************************************************************************/
$(document).ready(function()
{
	initNav2();
	initSlide();
	//hiddenSelect();
	initMenu();
	basic();
	//initPNG();
	imgRepla();
	commentaire();
	amis();
	imgReplaHover();
	scrollTo();
	toggleVideo();
	// swfObject();
$('.rep_commentaire').hide();
	
});

function is_numeric(num)
{
    var exp = new RegExp("^[0-9-.]*$","g");
    return exp.test(num);
}
