/**
 * @author dale
 */

$(document).ready(function() {
	
	var colors = Array (
		'#009FBB', // bleu
		'#C5015B', // rose
		'#C8D200', // vert
		'#FBBB11', // jaune
		'#EE7F01' // orange
		//'#94ADB9' // gris
	);
	
	// BLOG changement de couleur toutes les x secondes
	var x = 2000; // secondes x 1000
	var changeColor = function() {
		var rand = Math.floor((10 - 5) * Math.random());
		$("body.blog").animate({backgroundColor: colors[rand]}, 3000);
		$("body.blog h2.different_color").animate({backgroundColor: colors[rand]}, 3000);
		$("body.blog p.postinfo a, div.posttext a, div.navigation a").animate({color: colors[rand]}, 3000);
	}
	//var refreshing  = setInterval(changeColor, x);




	
	$("div#menu ul li a")
	.mouseover(function() {var rand = Math.floor((10 - 5) * Math.random()); $(this).animate({backgroundColor: colors[rand], backgroundPosition: "7px 50%", paddingLeft: "25px"}, "fast")})
	.mouseout(function() {$(this).animate({backgroundColor: "#009FBB", backgroundPosition: "-15px 50%", paddingLeft: "5px"}, "fast")});


	$(".thumb").click(function() {
		$(".post").fadeOut("fast").delay(250);
		$.post(
			"/wp-content/themes/propulse/site-portfolio-ajax.php",
			{id: this.id},
			function(data){
				$("#posts").html(data);
			}
		);
		$("#post_"+this.id).fadeIn("fast");
	});


	$("div#bouton_ag")
	.mouseover(function(){$("div#bouton_ag").animate({ top: "-20px", opacity: "1", "filter": ""}, 200)})
	.mouseout(function(){$("div#bouton_ag").animate({ top: "20px", opacity: "0.4", "filter": ""}, 200)})
	;
	// le filter est pour pallier au pb de transparence perdue sous IE
	
	
	$("input#with_cv").change(function(){
		if($("input#with_cv").is(":checked")){
			$("td#le_cv_1").html("CV *");
			$("td#le_cv_2").html('<input type="file" name="cv" id="cv">');
			$("td#le_societe_1").html("")
			$("td#le_societe_2").html("")
			$("td#le_submit").html('<input type="submit" value="Envoyer" onclick="return(valid_form_with_cv());">');
		}
		if(!$("input#with_cv").is(":checked")){
			$("td#le_cv_1").html("");
			$("td#le_cv_2").html("");
			$("td#le_societe_1").html("Société")
			$("td#le_societe_2").html('<input type="text" name="societe" id="societe">')
			$("td#le_submit").html('<input type="submit" value="Envoyer" onclick="return(valid_form_no_cv());">');
		}
	});
	
	//$.imJQMosaic({ image:'/wp-content/uploads/2010/02/Burling-5.jpg', target: 'sample_1', frameWidth: '760', frameHeight:'350', numberOfTilesX: '20', numberOfTilesY: '9', tileBorder: '0', tileBorderColor: '#fff', tileBorderRadius: '3', effectIntensity: '0.4', effectColor: '#fff' }); 

	$("a.carre_accueil").css({backgroundPosition: "0px 150px"});
	$("a.carre_accueil").mouseover(function(){$(this).animate({backgroundPosition: "0px 0px"}).css({color: "#fff"})})
	$("a.carre_accueil").mouseout(function(){$(this).animate({backgroundPosition: "0px 150px"}).css({color: "#aaa"})});
	
	
	$("div.carre_accueil").click(function() {
		$("#dialog").load("news.php").dialog({
			modal: true,
			overlay: true,
			shadow: true,
			width: 630,
			height: 600,
			resizable: false,
			close: function() {$("#dialog").dialog('destroy');},
			title: "Blah"
		});
	});

	$(".defil").cycle({ 
	    fx:      "scrollDown", 
	    speed:    300, 
	    timeout:  4000 
	});
	
	$(".slideshow").cycle({ 
	    fx:      "fade", 
	    speed:    300, 
	    timeout:  4000 
	});

	$("#temoignages").cycle({ 
	    fx:      "fade", 
	    speed:    300, 
	    timeout:  0,
		pager:	 '#nav'
	});
	
});





/**
 * jQuery Background Position
 * @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);

