

	jQuery().ready(function() {

		/* ecoveloppe animation on homepage */
		jQuery("#ecoveloppes").hide().delay(1500).fadeIn(500).delay(10000).animate({ 'width': "220px"}, "slow").animate({ 'height': "41px"}, "slow").mouseover(function() {jQuery(this).stop(true, true).animate({ 'height': "142px"}, "slow").animate({ 'width': "530px"}, "slow")}).mouseleave(function() {jQuery(this).delay(1000).stop(true, true).animate({ 'width': "220px"}, "slow").animate({ 'height': "41px"}, "slow")});
		/* Open ecovelopes in new scrollable window */
		jQuery("#ecoveloppes a").click(function(e) {
			e.preventDefault();
			window.open(jQuery(this).attr('href'),'_blank','width=1240,height=750,resizable=0,menubar=0,toolbar=0,scrollbars=1,status=0');
			return false;
		});

		
		/* Open envelopes in new window */
		jQuery("li#menu-item-31 li a, li#menu-item-100 li a").attr('target', '_blank');
		jQuery("li#menu-item-31 li a, li#menu-item-100 li a").addClass('ext');
		jQuery("a.ext").live('click',function(e) {
			e.preventDefault();
			//window.open(jQuery(this).attr('href'),jQuery(this).html(),'width=1200,height=750,resizable=0,menubar=0,toolbar=0,scrollbars=0,status=0');
			window.open(jQuery(this).attr('href'),'_blank','width=1200,height=750,resizable=0,menubar=0,toolbar=0,scrollbars=0,status=0');
			return false;
		});
		
		
		
		
		/* Animation on external sites links */
		jQuery('#access li.menu-item-type-custom li a').each(function() {
		
			var link = this;
			var width = jQuery(this).css('width');
			var height = jQuery(this).css('height');
			jQuery(this).css({ 'height': "0", 'width': "0" });
			
			jQuery(this).parents('.menu > li.menu-item-type-custom').children('a').mouseenter(function() {
				jQuery(link).css({ 'height': "0", 'width': "0" });
				jQuery(link).animate({ 'height': height, 'width': width }, "slow");
			});
			jQuery(this).parents('.menu > li.menu-item-type-custom').mouseleave(function() {
			});	
		});
		
		jQuery('.menu li.menu-item-type-custom').children('a').attr('target', '_blank');
		
		follow_links();
			
		jQuery('li#menu-item-31, li#menu-item-100, #access li.menu-item-type-custom').each(function() {
		
			jQuery(this).mouseenter(function() { 
				jQuery('#content').fadeTo(0,0.25);
				jQuery('#content').css({'text-shadow': '0px 0px 4px #862525'});

			});
			jQuery(this).mouseleave(function() { 
				jQuery('#content').fadeTo(0,1);
				jQuery('#content').css({'text-shadow': '0px 0px 0px #862525'});
			});
	
		});
		
		jQuery("li#menu-item-31 li, li#menu-item-100 li").each(function() {
		
			jQuery(this).mouseenter(function() {
				jQuery(this).append('<a href="' + jQuery(this).children('a').attr('href') + '" class="ext expand"></a>');
				jQuery(this).children('a.expand').animate({ 'height': "139px", 'width': "380px" }, "slow");
			});
			
			jQuery(this).mouseleave(function() {
				jQuery(this).children('a.expand').remove();
			});

		});

		/*  Background scroll */
		jQuery("li.menu-item-type-post_type a, li.menu-item-type-taxonomy a, li.menu-item-home a, a.catch, .navigation a, li.menu-item-truc a").not('.ext').live('click',function(e) {

			e.preventDefault();
			jQuery("#content").html('');
			jQuery("#subnav").remove('');
			jQuery("#content").addClass('loading');
			if (jQuery("#main").css('background-image').match('fond_global.png')) {
				if (jQuery(this).parent('li').attr('id')=='menu-item-294' || jQuery(this).parent('li').attr('id')=='menu-item-73') jQuery("#main").animate({ backgroundPosition: '0px -790px'}, "slow");
				if (jQuery(this).parent('li').attr('id')=='menu-item-8' || jQuery(this).parent('li').attr('id')=='menu-item-74') jQuery("#main").animate({ backgroundPosition: '0px -1388px'}, "slow");
				if (jQuery(this).parent('li').attr('id')=='menu-item-293' || jQuery(this).parent('li').attr('id')=='menu-item-291'
					|| jQuery(this).parent('li').attr('id')=='menu-item-223' || jQuery(this).parent('li').attr('id')=='menu-item-257') jQuery("#main").animate({ backgroundPosition: '0px -624px'}, "slow");
				if (jQuery(this).parent('li').attr('id')=='menu-item-19' || jQuery(this).parent('li').attr('id')=='menu-item-37' 
					|| jQuery(this).parent('li').attr('id')=='menu-item-105' || jQuery(this).parent('li').attr('id')=='menu-item-106'
					|| jQuery(this).parent('li').attr('id')=='menu-item-10' || jQuery(this).parent('li').attr('id')=='menu-item-263'
					|| jQuery(this).parent('li').attr('id')=='menu-item-23' || jQuery(this).parent('li').attr('id')=='menu-item-104'
					|| jQuery(this).parent('li').attr('id')=='menu-item-224' || jQuery(this).parent('li').attr('id')=='menu-item-258') jQuery("#main").animate({ backgroundPosition: '0px 0px '}, "slow");
			}
			jQuery("li").removeClass('current-menu-item current_page_item');
			jQuery(this).parent('li').addClass('current-menu-item current_page_item');
			jQuery("#main-wrapper").load(jQuery(this).attr('href') + " #main",function() {follow_links();addSubnav();});
			if (typeof(window.history.pushState) == 'function') {
				window.history.pushState(null, jQuery(this).html(), jQuery(this).attr('href'));
			}
		});
		
		
		if(arbres>0) {
		
			setInterval( function() {
				var counterString = (arbres++).toString();
				var chunks = [];
				for( var i = 0; i < counterString.length; i++ ) {
					chunks.push( "<img src='http://www.pocheco.com/2010/wp-content/themes/pocheco/images/flip/18/flip_0" + counterString[i] + ".png' />" );
				}
				jQuery('#number').html( chunks.join('') );
			}
			, 180000 );

			var counterString = (arbres++).toString();
			var chunks = [];
			for( var i = 0; i < counterString.length; i++ ) {
				chunks.push( "<img src='http://www.pocheco.com/2010/wp-content/themes/pocheco/images/flip/18/flip_0" + counterString[i] + ".png' />" );
			}
			jQuery('#number').html( chunks.join('') );
		}

	});


	
	function follow_links() {
	
		jQuery("ul#subnav li.current_page_item").css('width',  function() {
			var position = jQuery(this).position();
			var reference = jQuery('#content').css('marginLeft').replace("px", "");
			//alert(reference);
			return (reference-position.left-20);
		});
	}
	
	function addSubnav() {
	
		jQuery("#subnav li a").die();
		jQuery("#subnav li a").click(function(e) {
			e.preventDefault();
			jQuery("#content").html('');
			jQuery("#content").addClass('loading');
			jQuery("#main-wrapper").load(jQuery(this).attr('href') + " #main",function() {follow_links();addSubnav();});
			if (typeof(window.history.pushState) == 'function') {
				window.history.pushState(null, jQuery(this).html(), jQuery(this).attr('href'));
			}
		});
	}
	


/**
 * @author Alexander Farkas
 * v. 1.21
 */


(function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
	
	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');
			
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			
			fx.start = [start[0],start[2]];
			
			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);
