$(document).ready(function(){					   
						   
    /*********************** MENU */
    $("#menu .nactive span").fadeTo("fast", 0, function(){
        $(this).css("display","block");
    });

    $("#menu .nactive a").hover(function(){
        $(this).find("span").fadeTo(500, 1);
    }, function(){
        $(this).find("span").fadeTo(500, 0);
    });

    /*********************** SLIDEPROMO */
    /*var nbPromo = $("#allpromo .c-iphone li").length;
    var nbApp = $("#allpromo .c-app li").length;
    var nbForfaits = $("#allpromo .c-forfaits li").length;
    var i = 0;
    var e = 0;

    $("#allpromo .c-iphone li").slice(1, nbPromo).fadeTo(0,0).css("display","block");
    $("#allpromo .c-iphone li:first").css("z-index","10");
    $("#allpromo .c-app li").slice(1, nbApp).fadeTo(0,0).css("display","block");
    $("#allpromo .c-app li:first").css("z-index","10");
    $("#allpromo .c-forfaits li").slice(1, nbForfaits).fadeTo(0,0).css("display","block");
    $("#allpromo .c-forfaits li:first").css("z-index","10");

    function fadePromo() {
	$("#allpromo .c-iphone li:eq(" + i + ")").fadeTo(700, 0, function (){
            $(this).css({"display":"none","z-index":"1"});
            i++;
            if(i == nbPromo){
                i = 0;
                $("#allpromo .c-iphone li").css("display","block");
            }
            $("#allpromo .c-iphone li:eq(" + i + ")").fadeTo(700,1).css("z-index","10");
        });
    }
    function fadeApp() {
	$("#allpromo .c-app li:eq(" + i + ")").fadeTo(700, 0, function (){
            $(this).css({"display":"none","z-index":"1"});
            i++;
            if(i == nbApp){
                i = 0;
                $("#allpromo .c-app li").css("display","block");
            }
            $("#allpromo .c-app li:eq(" + i + ")").fadeTo(700,1).css("z-index","10");
        });
    }
		
		function fadeForfaits() {
			$("#allpromo .c-forfaits li:eq(" + e + ")").fadeTo(700, 0, function (){
					$(this).css({"display":"none","z-index":"1"});
					e++;
					if(e == nbForfaits){
							e = 0;
							$("#allpromo .c-forfaits li").css("display","block");
					}
					$("#allpromo .c-forfaits li:eq(" + e + ")").fadeTo(700,1).css("z-index","10");
			});
    }

    if(nbPromo > 1){
	var timer = setInterval(fadePromo, 8000);
    }
    if(nbApp > 1){
			//var timer = setInterval(fadeApp, 8000);
    }
		
		if(nbForfaits > 1){
			var timer2 = setInterval(fadeForfaits, 8000);
    }*/

    /*********************** CHOICE IPHONE */
	$("#fonctionnalites-iphone3gs").hide();
    $("#choice-iphone #vis-iphone3gs img").fadeTo('fast',0.6);
    var versIphone = "vis-iphone4";

    $("#choice-iphone #vis-iphone4, #choice-iphone #vis-iphone3gs").click(function(){
        $("#choice-iphone li").removeClass("active");
        $(this).addClass("active");

        versIphone = $(this).attr("id");
        if(versIphone == "vis-iphone4"){
            $("#choice-iphone #vis-arrow div").css("background-position","center top");
            $("#choice-iphone #vis-iphone4 img").animate({height:'298px', width:'142px', opacity:1, marginTop:0}, 500);
            $("#choice-iphone #vis-iphone3gs img").animate({height:'298px', width:'183px', opacity:0.6}, 500, function(){
                var targetOffset = $("#tab-iphone").offset().top;
                $("html, body").animate({scrollTop: targetOffset}, 1000);
                $("#fonctionnalites .bk-iphone4").css("display","block").fadeTo(800, 1);
            });
        } else {
            $("#choice-iphone #vis-arrow div").css("background-position","center bottom");
            $("#choice-iphone #vis-iphone3gs img").animate({height:'298px', width:'183px', opacity:1, marginTop:0}, 500);
            $("#choice-iphone #vis-iphone4 img").animate({height:'298px', width:'142px', opacity:0.6}, 500, function(){
                var targetOffset = $("#tab-iphone").offset().top;
                $("html, body").animate({scrollTop: targetOffset}, 1000);
                $("#fonctionnalites .bk-iphone4").fadeTo(800, 0, function(){
                    $(this).css("display","none");
                });
            });
        }

        if(tabContent == "caracteristiques"){
            showCaract();
        }
        if(tabContent == "fonctionnalites"){
            showFonctionnalites();
        }
        if(tabContent == "accessoires"){
            showAccessoires();
        }
        return false;
    });

    /*********************** TABNAV */
    /* HOVER */
    $(".tab-nav .nactive span").fadeTo("fast", 0, function(){
        $(this).css("display","block");
    });
    $(".tab-nav .active span").fadeTo("fast", 1, function(){
        $(this).css("display","block");
    });

    var tabActive = 0;
    $(".tab-nav a").hover(function(){
	tabActive = 0;
	if($(this).find("span").css("opacity") == 0){
	    $(this).find("span").fadeTo(500, 1);
	    tabActive = 1;
	}
    }, function(){
	if(tabActive == 1){
	    $(this).find("span").fadeTo(500, 0);
	}
    });

    var tabId;
    var tabContent = "fonctionnalites";

    /* CLICK */
    $(".tab-nav li").click(function(){
		$(".tab-nav li").removeClass("active nactive");
		$(".tab-nav span").css("opacity","0");
		$(this).find("span").css("opacity","1");
		tabActive = 0;
	
		tabId = $(this).attr("id");
		tabContent = tabId.substr(4, (tabId.length - 1));
		$("#content .tab-content").hide();
		$("#" + tabContent).show();

		if(tabContent == "caracteristiques"){
			showCaract();
		}
		if(tabContent == "fonctionnalites"){
			showFonctionnalites();
		}
		if(tabContent == "accessoires"){
			showAccessoires();
		}
		return false;
    });

	/*$("#visuel-forfaits .promomoins26ans").click(function(){
		$('#content .tab-content').hide();
		$('#tarifs').show();
		$('.tab-nav li').removeClass('active');
		$('.tab-nav span').css('opacity','0');
		$('.tab-nav #tab-tarifs span').css('opacity','1');
		//location.href='#bk-edspecialeorigami';
		//return false;
	});*/
	
	$("#push0").click(function(){
		$("#tab-forfait h4 a:first").click();
	});

	$("#push1").click(function(){
		$("#tab-origami h4 a:first").click();
	});

    function showCaract(){
        $("#caracteristiques-iphone4, #caracteristiques-iphone3gs").hide();
        var iphoneId = $("#choice-iphone li.active").attr("id");
        var iphoneVers = iphoneId.substr(4, (iphoneId.length - 1));
        $("#caracteristiques-" + iphoneVers).show();
    }
    function showFonctionnalites(){
        $("#fonctionnalites-iphone4, #fonctionnalites-iphone3gs").hide();
        var iphoneId = $("#choice-iphone li.active").attr("id");
        var iphoneVers = iphoneId.substr(4, (iphoneId.length - 1));
        $("#fonctionnalites-" + iphoneVers).show();
    }
    function showAccessoires(){
        $("#accessoires-iphone4, #accessoires-iphone3gs").hide();
        var iphoneId = $("#choice-iphone li.active").attr("id");
        var iphoneVers = iphoneId.substr(4, (iphoneId.length - 1));
        $("#accessoires-" + iphoneVers).show();
    }
    /* TABNAV END */

    /*********************** ANCRE */
    
    $(".ancre").click(function(){
        var vAncre = $(this).attr("href");
		var vOffset = $(vAncre).offset();
		$("html, body").animate({scrollTop: vOffset.top}, 1000);
        return false;
    });

    /*********************** POPIN */
    $("#mask").fadeTo(0,0.8);

    $("a[name=modal]").click(function(e) {
	e.preventDefault();
        var id = $(this).attr("href");

        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        $("#mask").css({'width':maskWidth,'height':maskHeight});

	$("#mask").fadeIn(2000);

	var offset = $(this).offset();
	var winH = offset.top - 500;
	if(winH < 0){
	    winH = 200;
	}

        var winW = $(window).width();

	$(id).css("top",  winH);
        $(id).css("left", winW/2-$(id).width()/2);

        $(id).fadeIn(2000);
    });

    $(".window .popin-close").click(function (e) {
        e.preventDefault();

	$(".window").fadeOut(800);
	$("#mask").fadeOut(800);
    });

    $("#mask").click(function () {
	$(".window").fadeOut(800);
	$("#mask").fadeOut(800);
    });

    /*********************** FORFAITS */
    /* LIEN VISUEL */
    $("#visuel-forfaits .find-forfait a").click(function(){
	$(".tab-nav li").removeClass("active nactive");
	$(".tab-nav span").css("opacity","0");
	$("#tab-forigami span").css("opacity","1");
	$(".tab-content").hide();
	$("#forigami").show();
    });

    /* CHOICE FORFAITS */
    var clkOrigami = 0;
    var origamiVers;
    var origamiClkVers;
    var posOrigami;
    var posClkOrigami;
    var vPeriod;
    var listPos = ["28px", "246px", "461px", "654px"];

    var vStep2Hour = 0;
    var vStep2Period = 0;
    var vStep2Plus = 0;

    var vNbHour;
    var clkHourPlus = 0;
    var vStep3Plus = 0;
    var vStep3Default = 0;
    var clkPlus = null;

    /* CLICK */
    /*$("#choice-origami a").click(function(){		
	    // init
	    $("#bk-step2, #bk-step3, #bk-step4, .choice-plus, .choice-period").hide();
	    $(".choice-hour li, .choice-hour a, .choice-period a, .options-plus a, .options-default a").removeClass("active check");
	    resetAfterStep2();
	    vStep2Hour = vStep2Period = vStep2Plus = clkHourPlus = vStep3Plus = vStep3Default = 0;
	    fctOrigami($(this), 1);
	    $.ajax({
		       type: "GET",
		       url: "get-content.php",
		       data: "action=get_step2&origami="+origamiVers,
		       success: function(msg){
				    $(".choice-hour ul").html(msg);
		       }
		     });
	    $.ajax({
		       type: "GET",
		       url: "get-content.php",
		       data: "action=get_mentions&origami="+origamiVers,
		       success: function(msg){
				    $("#mentions").html(msg);
		       }
		     });
	    
	    $("#bk-step2").show();
	    $("#choice-origami a").removeClass("active");
	    $(this).addClass("active");
	    posClkOrigami = $(this).parent().prevAll("li").length;
	    clkOrigami = 1;
	    var vOffset = $("#bk-step2").offset();
	    $("html, body").animate({scrollTop: vOffset.top}, 1000);
	    if(origamiVers == "jet"){
		$("#bk-step2 .bk-step-content").attr("id","jet-step2");
	    } else {
		$("#bk-step2 .bk-step-content").attr("id","");
	    }
	    return false;
    });*/
    /* HOVER */
    $("#choice-origami a").click(function(e){
		$("#choice-origami a").removeClass('active');
		$(this).addClass('active');
		fctPosOrigami($(this));
		fctOrigami($(this), 0);
		
		$.ajax({
		    type: "GET",
		    url: "get-content.php",
		    data: "action=get_mentions&origami="+origamiVers,
		    success: function(msg){
			$("#mentions").html(msg);
		    }
		});
		
		e.preventDefault();
		/*}, function(){
		if(clkOrigami == 0){
			$("#choice-origami-highlight, .infos-origami").hide();
		} else {
			$(".infos-origami").hide();
			$("#choice-origami-highlight").css("background-position",listPos[posClkOrigami] + " top");
			$("#infos-" + origamiClkVers).show();
		}*/
    });
    /* FCT */
    function fctOrigami(vThis, a){
		var origamiId = vThis.parent().attr("id");
        origamiVers = origamiId.substr(4, (origamiId.length - 1));
		/*if(a == 1){
	    	origamiClkVers = origamiVers;
			if(origamiClkVers == "jet"){
				$(".title-step2").hide();
				$(".title-step2jet").show();			
			}else{
				$(".title-step2").show();
				$(".title-step2jet").hide();
			}		
	}*/

	$(".infos-origami").hide();
	$("#choice-origami-highlight, #infos-" + origamiVers).show();
    }
    function fctPosOrigami(vThis){
	posOrigami = vThis.parent().prevAll("li").length;
	$("#choice-origami-highlight").css("background-position",listPos[posOrigami] + " top");
    }

    /* STEP2 */
    /* HOUR */
    /*$(".choice-hour li").live('click',function(){
			
		$(".choice-period").show();
		resetAfterStep2();
		vNbHour = $(this).prevAll().length;
    	vNbHour2 = $(this).attr("rel");
		$(".choice-hour li, .choice-hour a").removeClass("check active");
		$(this).addClass("check");
		$(this).find("a").addClass("active");
		vStep2Hour = 1;
		fctShowStep3();
		return false;
    });*/
    /* HOUR PLUS HOVER/CLICK */
    /*$(".choice-plus .bk-click").live('click', function() {
    	resetAfterStep2();
		clkHourPlus = 1;
		clkPlus = $(this).prevAll().length;
		$(this).addClass("plus-active");
		$(this).addClass("active");
		vStep2Plus = 1;
		fctShowStep3();
    });
    $(".choice-plus .bk-click").live('mouseout', function() {
		if(clkHourPlus == 0){
		    $(this).removeClass("plus-active");
		}
    });
    $(".choice-plus .bk-click").live('mouseover', function() {
		if(clkHourPlus == 0){
		    $(this).addClass("plus-active");
		}
    });*/
    /* PERIOD */
    /*$(".choice-period a").click(function(){
    	resetAfterStep2();
		$(".choice-period a").removeClass("active");
		$(this).addClass("active");
		vStep2Period = 1;
		vPeriod = $(this).attr("rel");
		fctShowStep3();
		return false;
    });*/

    /* FCT */
    /*function resetAfterStep2 () {
    	clkHourPlus = 0;
    	$(".choice-plus .bk-click").removeClass("plus-active");
    	$(".choice-plus li").removeClass("active");
    	vStep2Plus = vStep3Plus = vStep3Default = 0;
    	clkPlus = null;
    	posAvtg = null;
    	posOpt = null;
    }
    function getPlus () {
	    $.ajax({
	 	   type: "GET",
	 	   url: "get-content.php",
	 	   data: "action=get_step2_plus&origami="+origamiClkVers+"&hour="+vNbHour+'&engage='+vPeriod,
	 	   success: function(msg){
	 			$(".choice-plus ul").html(msg);
	 	   }
	 	});
    }

    function getStep3 () {
	    $.ajax({
	 	   type: "GET",
	 	   url: "get-content.php",
	 	   data: "action=get_step3&origami="+origamiClkVers,
	 	   success: function(msg){
			$("#bk-options").html(msg);
			// SELECTION DU SANS OPTION
			if((origamiVers == "star") || (origamiVers == "first") || (origamiVers == "jet")){
			    $(".noption a").click();
			    $(".navantage a").click();				
			}			
	 	   }
	 	});
    }

    function getStep4 () {
	    $.ajax({
	 	   type: "GET",
	 	   url: "get-content.php",
	 	   data: "action=get_step4&origami="+origamiClkVers+"&hour="+vNbHour+"&hour2="+vNbHour2+"&plus="+clkPlus+"&avtg="+posAvtg+"&opt="+posOpt+"&period="+vPeriod,
	 	   success: function(msg){
	 			$("#bk-step4").html(msg);
	 	   }
	 	});
    }

    function showStep4(){
    	getStep4 ();
		$("#bk-step4").show();
		var vOffset = $("#bk-step3").offset();
		$("html, body").animate({scrollTop: vOffset.top}, 1000);
    }

    function fctShowStep3(){
		if((origamiClkVers == "star")){		
		    if((vStep2Hour == 1) && (vStep2Period == 1) && (vStep2Plus == 1)){
		    	getStep3();
				$("#bk-step3").show();
				showStep4();
		    } else if ((vStep2Hour == 1) && (vStep2Period == 1)) {
		    	getPlus ();
				$("#bk-step3").hide();
				$("#bk-step4").hide();
			    $(".choice-plus").show();
		    }
		} else {
		    if((vStep2Hour == 1) && (vStep2Period == 1)){
		    	getStep3();
		    	getPlus ();
			    $(".choice-plus").show();
				$("#bk-step3").show();
				$("#bk-step4").hide();
		    }
		}
    }

    var posAvtg = null;
    var posOpt = null;*/

    /* STEP3 */
    /*$("#bk-options a").live('click',function(){
    	if ($(this).parent().parent().attr("class") == 'options-plus' || $(this).parent().parent().attr("class") == 'options-plus options-border') {
    		posAvtg = $(this).parent().prevAll("li").length;
    	}
    	if ($(this).parent().parent().attr("class") == 'options-default') {
    		posOpt = $(this).parent().prevAll("li").length;
    	}
		if($(this).parents(".options-plus").length == 1){
		    vStep3Plus = 1;
		}
		if($(this).parents(".options-default").length == 1){
		    vStep3Default = 1;
		}
		$(this).parents("ul").find("a").removeClass("active");
		$(this).addClass("active");
		switch (origamiClkVers) {
			 case 'first':
				 if(vStep3Default == 1){ showStep4(); }
			 break;			 
			 default:
				 if((vStep3Plus == 1) && (vStep3Default == 1)){showStep4(); }
			 break;
		}
		return false;
    });*/

    /* CUFON */
    Cufon.replace('.font-light', { fontFamily: 'HNeueLTStdLt' });
    Cufon.replace('.font-roman', { fontFamily: 'HNeueLTStdRoman' });
});

function imprimer(){
	options = "width=900,height=200" ;
	window.open( "imprimer.html", "imprimer", options ) ;
}
