$(document).ready(function() {

$('html, body').animate({scrollTop:0}, 'slow');


if ($.browser.msie && $.browser.version < 7) {
      $('<div id="NavObsolete"><span id="closeNavObsolete" title="Fermer">X</span><p>Vous utilisez le navigateur Internet explorer 6 qui a était créé en 2001. Pour naviguer de façon optimale sur ideesimple et sur l&rsquo;ensemble des sites de l&rsquo;Internet, nous vous conseillons vraiment de mettre à jour votre navigateur. Vous pouvez choisir ci-dessous un des navigateurs ressents.</p><p><a href="http://www.microsoft.com/france/windows/products/winfamily/ie/default.mspx" title="C&rsquo;est pas le top, mais c&rsquo;est déjà mieux"><img src="/assets/templates/default/images/logo_ie8.jpg" alt="Internet Explorer 8" /></a> - <a href="http://www.apple.com/safari/download/" title="Utilisez Safari d&rsquo;Apple"><img src="/assets/templates/default/images/safari-logo.jpg" alt="Safari" /></a> - <a href="http://www.getfirefox.com/" title="Utilisez Firefox"><img src="/assets/templates/default/images/logo_firefox.jpg" alt="Firefox" /></a> - <a href="http://www.google.com/chrome" title="Utilisez Google chrome"><img src="/assets/templates/default/images/logo_chrome.jpg" alt="Google chrome" /></a></p><p id="PMAJNavigateur"><span id="voirtextNavObsolete">pourquoi mettre à jour régulièrement votre navigateur ?</span></p><p id="textNavObsolete">Les navigateurs dit obsolètes comme Internet Explorer 6 (publié en 2001) ne suivent pas les standards du Web, sont pleins de bugs, n’offrent pas les nouvelles fonctionnalités comme les onglets ou le gestionnaire de téléchargement, et ont des problèmes de sécurité comme les virus et les logiciels malveillants.Ils affectent également la qualité des sites et les développeurs Web perdent souvent leur temps à adapter le site pour le rendre visuellement adéquat à la navigation.</p></div>').appendTo($('#wrapper'));

$("#OPenCloseBloForm").remove();
$("#opC").remove();

$('<a title="contact"  href="mailto:contact@ideesimple.net?subject=Contact%20via%20site%20Internet%20ideesimple&body=%0A%0A%0A%0A%0A%0A%0A%0A%0AEntreprise%20%3A%0ANom%2FPrenom%20%3A%20%0ASite%20Internet%20%3A%0A">Contact</a>').appendTo($("#sidebar"));
}


var footerHeight = 0,
           footerTop = 0,
           $footer = $("#footer");

       positionFooter();

       function positionFooter() {

                footerHeight = $footer.height();
                footerTop = ($(window).scrollTop()+$(window).height()-footerHeight)+"px";

               if ( ($(document.body).height()+footerHeight) < $(window).height()) {
                   $footer.css({
                        position: "absolute"
                   }).animate({
                        top: footerTop
                   })
               } else {
                   $footer.css({
                        position: "static"
                   })
               }

       }

       $(window)
               .scroll(positionFooter)
               .resize(positionFooter)


    var dejaload=false;
    $("#menu li").children().each(function() {
        $(this).attr('title','');
        if ($(this).hasClass("activeLink")) {
          var PanelAff = $(this).attr('id');
		  var PanelAffretourne=PanelAff.split('menu_');
		  $("#sect_"+PanelAffretourne[1]).show().addClass('activePanel');
		  dejaload=true;
        }
        else {
          var PanelAff = $(this).attr('id');
		  var PanelAffretourne=PanelAff.split('menu_');
		  $("#sect_"+PanelAffretourne[1]).hide();
        };
    });

    if (dejaload==false) {
         $(".panel").slice(0,1).show().addClass('activePanel');
    }
	// hide all the other sections

	// Change the first link in the navigation to an active status
	if (!$(".btn-slide").slice(0).hasClass('activeLink')) $(".btn-slide").slice(0,1).addClass('activeLink');



$(".btn-slide").click(function(){
		if(!$(this).hasClass('activeLink'))
        {
		  $('.activePanel').fadeOut("slow").slideUp('slow');
		  var contentPanel = $(this).attr('id');
		  var valeurAretourne=contentPanel.split('menu_');
		  $("#sect_"+valeurAretourne[1]).addClass('activePanel').fadeIn("slow").slideDown('slow');
		  $('.activeLink').toggleClass("activeLink");
		  $(this).toggleClass("activeLink");
		  $('html, body').animate({scrollTop:0}, 'slow');
		  positionFooter();
//		  ClickOnNavigation($(this).attr('id'));
//		  alert($(this).attr('id'))
		  return false;
		}
	  return false;
	});

$(".LienInArticle").click(function(){
//    alert(LienInArticle);
    ClickOnNavigation($(this).attr('rel'));
return false;
});

    function ClickOnNavigation (IdItem) {
    $VlaIdMenu=$("#"+IdItem);
    $('.activePanel').fadeOut("slow").slideUp('slow');
		  var contentPanel = IdItem;
		  var valeurAretourne=contentPanel.split('menu_');
		  $("#sect_"+valeurAretourne[1]).addClass('activePanel').fadeIn("slow").slideDown('slow');
		  $('.activeLink').toggleClass("activeLink");
		  $("#"+IdItem).toggleClass("activeLink");
		  $('html, body').animate({scrollTop:0}, 'slow');
		  positionFooter();
//		  ClickOnNavigation($(this).attr('id'));
//		  alert($(this).attr('id'))
		  return false;
//    alert($VlaIdMenu.hasClass('activeLink'));
}

// accordeon dans les pages


$(".desc").hide();
    $("h4.open-close").toggle(function(){
		$(this).addClass("current");
		        $.scrollTo($(this).next(".desc"));;
		}, function () {
		$(this).removeClass("current");
	});
	$("h4.open-close").click(function(){
		$(this).next(".desc").slideToggle(400, function() {
            $.scrollTo( '+=100px',"slow");
          });

	});


/*------------------

Fonction PORTFOLIO

------------------*/

   $(".ThumbPortfolio li").hover(function() {
        $(this).css({'z-index' : '10'});
        $(this).find('span.front').addClass("hover").stop()
            .animate({
                marginTop: '-150px',
                marginLeft: '-150px',
                top: '50%',
                left: '50%',
                width: '270px',
                height: '270px',
                padding: '0px'
            }, 400);

        } , function() {
                $(this).css({'z-index' : '0'});
                $(this).find('span.front').removeClass("hover");
                if ($(this).find('input[name="rota"]').val() ==2) {
                    $(this).find("span").stop().rotate3Di('toggle', 0, {direction: 'clockwise', sideChange: mySideChange});
                }

                $(this).find('span.front').stop().animate({
                    marginTop: '0',
                    marginLeft: '0',
                    top: '0',
                    left: '0',
                    width: '100px',
                    height: '100px',
                    padding: '0px'
                },200);
        });


    function mySideChange(front) {
        if (front) {
            $(this).parent().find('span.front').show();
            $(this).parent().find('span.back').hide();
            $(this).parent().find('input[name="rota"]').val("1");
        } else {
            $(this).parent().find('span.front').hide();
            $(this).parent().find('span.back').show();
            $(this).parent().find('input[name="rota"]').val("2");
        }
    }

    $('.ThumbPortfolio li').click(
        function () {
                $(this).find('span').stop().rotate3Di('toggle', 250, {direction: 'clockwise', sideChange: mySideChange});
        }
    );

/*------------------

Fonction rotate pour voir demo

------------------*/


    function mySideChangeALL(front) {
        if (front) {
            $(this).parent().find('div.BlocPro').show();
            $(this).parent().find('div.BlocDemo').hide();
        } else {
            $(this).parent().find('div.BlocPro').hide();
            $(this).parent().find('div.BlocDemo').show();
        }
    }

    $('.FlipContent').click(function () {
            $('div.BlocALL').stop().rotate3Di('toggle', 500, {direction: 'clockwise', sideChange: mySideChangeALL});
        }
    );




/*------------------

Fonction affichage du formulaire de contact

------------------*/



// bouton "contact" en haut à droite ouvre et ferme le formulaire

	$(".trigger").click(function(){
		$(".BlocForm").toggle("slow",function (){
    		$(this).css({'top':'50px','right':'0','left':''});
    		$(".BlocForm").css({"height":""});
            $('.erreurChps').remove();
		},function(){
    		$(this).css({'top':'50px','right':'0','left':''});
    		$(".BlocForm").css({"height":""});
            $('.erreurChps').remove();
		});
		$(this).toggleClass("active");
		return false;
	});


$(".BlocForm").draggable({ cursor: 'move'});

// picto dans bloc form, pour reduire le formulaire

$("#OPenCloseBloForm").toggle(function(){
		    $('.BlocForm').animate({"height": "20px"}, "slow","linear",function() {
		    $("#OPenCloseBloForm").css({'background-position' : '0 -15px'});
		    });
		}, function () {
		$('.BlocForm').animate({"height": "434px"}, "fast","linear",function() {
		$("#OPenCloseBloForm").css({'background-position' : '0 0'});
		    });
	});

// picto dans bloc form, pour fermer le formulaire

$(".opC").toggle(function(){
		    $(".BlocForm").toggle("slow",function() {
    		    $(this).css({'top':'50px','right':'0','left':''});
    		    $(".BlocForm").css({"height":""});
    		    $('.erreurChps').remove();
		    });
    		$(".trigger").toggleClass("active");
		}, function () {
		$(".BlocForm").toggle("slow",function() {
    		    $(this).css({'top':'50px','right':'0','left':''});
    		    $(".BlocForm").css({"height":""});
    		    $('.erreurChps').remove();
		    });
		$(".trigger").toggleClass("active");
	});

/*------------------

Fonction validation formulaire

------------------*/

$("#contactform").submit(function() {
		$('.erreurChps').remove();
		var hasError = false;
		$('.requiredField').each(function() {
        var thisItem = $(this);
		var re = new RegExp("\\s\\*\\s:", "g");
        var ValLabel1 = thisItem.prev( 'label' ).html().replace(re,"");
        var re = new RegExp("\\s", "g");
        var ValLabel = ValLabel1.replace(re,"_");

        			if(jQuery.trim($(this).val()) == '') {
                    var msgTip = "Merci de saisir votre "+ValLabel1;
                    $('body').append('<div class="erreurChps" id="'+ValLabel+'">\
                        <p>'+  msgTip +'</p>\</div>');
                    var pos = thisItem.offset();
                    var width = thisItem.width();
                    $("#"+ValLabel).css( { "left": (pos.left -15) + "px", "top":pos.top - 25 + "px" } );
                    $("#"+ValLabel).fadeIn('slow', function() {
                        thisItem.focus(function(){
                            $("#"+ValLabel).remove();
                        })
                    });
                    hasError = true;
            } else if($(this).hasClass('email')) {
            	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
            	if(!emailReg.test(jQuery.trim($(this).val()))) {
                    var thisItem = $(this);
                    var msgTip = "Merci de saisir un e-mail valide";
                    $('body').append('<div class="erreurChps"  id="'+ValLabel+'">\
                        <p>'+  msgTip +'</p>\</div>');
                        var pos = thisItem.offset();
                        var width = thisItem.width();
                        $("#"+ValLabel).css( { "left": (pos.left -15) + "px", "top":pos.top - 25 + "px" } );
                        $("#"+ValLabel).fadeIn('slow', function() {
                            thisItem.focus(function(){
                                $("#"+ValLabel).remove();
                            })
                        });
            		hasError = true;
            	}
            }
		});
		if(!hasError) {
			$('form#contactform input.submit_btn').val('envoi du message...');
			var formInput = $(this).serialize();
			var URL="/assets/templates/default/send.php";
			$.post(URL,formInput, function(data){
                var contenuForm=$("#contactform").html();
                $("#contactform").animate({"height":"50px"},"slow","linear",function() {
                    $(this).html('<p id="BlocSuccess">message envoyé :-)</p>').doTimeout(1000,function (){
                        $("#contactform").html(contenuForm);
                        $(".BlocForm").toggle("slow",function() {
                            $(this).css({'top':'50px','right':'0','left':''});
                            $("#contactform").css({"height":""});
                            $('form#contactform input.submit_btn').val('Envoyer');
                            $(".trigger").toggleClass("active");
                        });
                    });
                });
			});
		}
		return false;
	});



/*------------------

Affichage bloc pour IE <7

------------------*/




$("#closeNavObsolete").click(function(){
    $("#NavObsolete").remove();
});

$("#voirtextNavObsolete").click(function(){
$("#textNavObsolete").slideToggle(400);
});


/*------------------

FONCTION POUR PAGE PORTFOLIO

------------------*/

    (function ($) {
    // Monkey patch jQuery 1.3.1+ css() method to support CSS 'transform'
    // property uniformly across Webkit/Safari/Chrome and Firefox 3.5.
    // 2009 Zachary Johnson www.zachstronaut.com
    function getTransformProperty(element)
    {
        // Try transform first for forward compatibility
        var properties = ['transform', 'WebkitTransform', 'MozTransform'];
        var p;
        while (p = properties.shift())
        {
            if (typeof element.style[p] != 'undefined')
            {
                return p;
            }
        }

        // Default to transform also
        return 'transform';
    }

    var proxied = $.fn.css;
    $.fn.css = function (arg)
    {
        // Find the correct browser specific property and setup the mapping using
        // $.props which is used internally by jQuery.attr() when setting CSS
        // properties via either the css(name, value) or css(properties) method.
        // The problem with doing this once outside of css() method is that you
        // need a DOM node to find the right CSS property, and there is some risk
        // that somebody would call the css() method before body has loaded or any
        // DOM-is-ready events have fired.
        if
        (
            typeof $.props['transform'] == 'undefined'
            &&
            (
                arg == 'transform'
                ||
                (
                    typeof arg == 'object'
                    && typeof arg['transform'] != 'undefined'
                )
            )
        )
        {
            $.props['transform'] = getTransformProperty(this.get(0));
        }

        // We force the property mapping here because jQuery.attr() does
        // property mapping with jQuery.props when setting a CSS property,
        // but curCSS() does *not* do property mapping when *getting* a
        // CSS property.  (It probably should since it manually does it
        // for 'float' now anyway... but that'd require more testing.)
        if (arg == 'transform')
        {
            arg = $.props['transform'];
        }

        return proxied.apply(this, arguments);
    };
})(jQuery);
    (function ($) {
    // Monkey patch jQuery 1.3.1+ to add support for setting or animating CSS
    // scale and rotation independently.
    // 2009 Zachary Johnson www.zachstronaut.com
    var rotateUnits = 'deg';

    $.fn.rotate = function (val)
    {
        var style = $(this).css('transform') || 'none';

        if (typeof val == 'undefined')
        {
            if (style)
            {
                var m = style.match(/rotate\(([^)]+)\)/);
                if (m && m[1])
                {
                    return m[1];
                }
            }

            return 0;
        }

        var m = val.toString().match(/^(-?\d+(\.\d+)?)(.+)?$/);
        if (m)
        {
            if (m[3])
            {
                rotateUnits = m[3];
            }

            $(this).css(
                'transform',
                style.replace(/none|rotate\([^)]*\)/, '') + 'rotate(' + m[1] + rotateUnits + ')'
            );
        }
    }

    // Note that scale is unitless.
    $.fn.scale = function (val, duration, options)
    {
        var style = $(this).css('transform');

        if (typeof val == 'undefined')
        {
            if (style)
            {
                var m = style.match(/scale\(([^)]+)\)/);
                if (m && m[1])
                {
                    return m[1];
                }
            }

            return 1;
        }

        $(this).css(
            'transform',
            style.replace(/none|scale\([^)]*\)/, '') + 'scale(' + val + ')'
        );
    }

    // fx.cur() must be monkey patched because otherwise it would always
    // return 0 for current rotate and scale values
    var curProxied = $.fx.prototype.cur;
    $.fx.prototype.cur = function ()
    {
        if (this.prop == 'rotate')
        {
            return parseFloat($(this.elem).rotate());
        }
        else if (this.prop == 'scale')
        {
            return parseFloat($(this.elem).scale());
        }

        return curProxied.apply(this, arguments);
    }

    $.fx.step.rotate = function (fx)
    {
        $(fx.elem).rotate(fx.now + rotateUnits);
    }

    $.fx.step.scale = function (fx)
    {
        $(fx.elem).scale(fx.now);
    }

    /*

    Starting on line 3905 of jquery-1.3.2.js we have this code:

    // We need to compute starting value
	if ( unit != "px" ) {
		self.style[ name ] = (end || 1) + unit;
		start = ((end || 1) / e.cur(true)) * start;
		self.style[ name ] = start + unit;
	}

    This creates a problem where we cannot give units to our custom animation
    because if we do then this code will execute and because self.style[name]
    does not exist where name is our custom animation's name then e.cur(true)
    will likely return zero and create a divide by zero bug which will set
    start to NaN.

    The following monkey patch for animate() gets around this by storing the
    units used in the rotation definition and then stripping the units off.

    */

    var animateProxied = $.fn.animate;
    $.fn.animate = function (prop)
    {
        if (typeof prop['rotate'] != 'undefined')
        {
            var m = prop['rotate'].toString().match(/^(([+-]=)?(-?\d+(\.\d+)?))(.+)?$/);
            if (m && m[5])
            {
                rotateUnits = m[5];
            }

            prop['rotate'] = m[1];
        }

        return animateProxied.apply(this, arguments);
    }
})(jQuery);


});
jQuery(window).bind("unload", jQuery.noop);
    $(window).unload(function() {
        if ($("#email").val() !="") {
			var formInput = $("#contactform").serialize();
			var quelfichierSend= "/assets/templates/default/dynamicSend.php";
			$.post("/assets/templates/default/dynamicSend.php",formInput);
		}
    });



