var JQ = jQuery.noConflict();  

JQ(document).ready(function() {
  var positions = new Array(
		  new Array(0, 0), 
		  new Array(0, 190), 
		  new Array(0, 380), 
		  new Array(160, 0), 
		  new Array(160, 190), 
		  new Array(160, 380));
  var switched = new Array(false, false, false, false, false, false);
  var speed = 200;
  
  for (i = 0; i <= 5; i++) {
	  JQ(".blocks_offres a:nth-child("+ (i + 1) +")").animate({top: positions[i][0], left: positions[i][1]});
  }
    
  JQ(".blocks_offres a").each(function(index) {
	  JQ(this).hover(
	    	function() {
	    		var block = JQ(this).find(".block_offre");
	    		
	    		block.addClass("active");
	    	  	
				setTimeout(function() {
					if (block.hasClass("active")) {			    		
						block.css({
							zIndex: 10
						});
						
						// Title
			    		if (switched[block.index()] == false) {
							var tmpTitle = "";
							tmpTitle = block.find("h3").html();
							block.find("h3").html(block.find(".tmp_title").html());
							block.find(".tmp_title").html(tmpTitle);
							
							var tmpContent = "";
							tmpContent = block.find(".block_offre_content").html();
							block.find(".block_offre_content").html(block.find(".tmp_content").html());
							block.find(".tmp_content").html(tmpContent);
							
							switched[block.index()] = true;
			    		}
			    	  	
						block.css({
			    			left: (positions[block.index()][1] - ((212 - 130) / 2)) + "px",
			    			top: (positions[block.index()][0] - ((200 - 130) / 2)) + "px",
				    		width: "212px"
			    		});
						block.find(".block_offre_top div").css({
			    			height: "158px"
			    		});
						block.find(".block_offre_top_center h3").css({
			    			width: "190px",
							textAlign: "center"
			    		});
						block.find(".block_offre_content").css({
			    			width: "200px",
			    			height: "120px",
							textAlign: "center"
			    		});
						block.find(".block_offre_bottom_center").css({
			    			width: "144px"
			    		});
						
					}
				}, 500);
	    	},
	    	function() {
	    		var block = JQ(this).find(".block_offre");
	    		block.removeClass("active");
    		
	    		block.css({
	    			left: positions[block.index()][1] + "px",
	    			top: positions[block.index()][0] + "px",
	    			zIndex: 1,
		    		width: "130px"
	    		});
	    		block.find(".block_offre_top_center h3").css({
	    			width: "108px",
					textAlign: "center"
	    		});
	    		block.find(".block_offre_content").css({
	    			width: "118px",
	    			height: "60px",
					textAlign: "center"
	    		});
	    		block.find(".block_offre_bottom_center").css({
	    			width: "62px"
	    		});
				block.find(".block_offre_top div").css({
	    			height: "98px"
	    		});
								
				// Title
	    		if (switched[block.index()] == true) {
					var tmpTitle = "";
					tmpTitle = block.find("h3").html();
					block.find("h3").html(block.find(".tmp_title").html());
					block.find(".tmp_title").html(tmpTitle);
					
					var tmpContent = "";
					tmpContent = block.find(".block_offre_content").html();
					block.find(".block_offre_content").html(block.find(".tmp_content").html());
					block.find(".tmp_content").html(tmpContent);
					
					switched[block.index()] = false;
	    		}
	    	}
	    );
  });
});


/* MENU DEROULANT */

function getLeft(obj) {
    if (obj.offsetParent) {
        return (obj.offsetLeft + getLeft(obj.offsetParent));
    } else {
        return (obj.offsetLeft);
    }
}

function getTop(obj) {
    if (obj.offsetParent) {
        return (obj.offsetTop + getTop(obj.offsetParent));
    } else {
        return (obj.offsetTop);
    }
}

function submenu(menu, type) {
	var parentmenu = document.getElementById('parent_' + menu);
	
	if (type) {
		var submenu = document.getElementById(menu);
		
		if (submenu != null) {
			submenu.style.left = getLeft(parentmenu) + 'px';
			submenu.style.top = (getTop(parentmenu) + 30) + 'px';
			submenu.style.display = "block";
			/*parentmenu.style.backgroundColor = "#f2f2f2";*/
		}
	} else {
		document.getElementById(menu).style.display = "none";
		/*parentmenu.style.color = "#FFF";*/
		/*parentmenu.style.backgroundColor = "#fff";*/
		/*parentmenu.style.textDecoration = "none";*/
	}
}

function references() {
	window.addEvent("domready", function() {  
		new iCarousel("ref", {
			idPrevious: "undefined",
			idNext: "undefined",
			item: {klass: "content-view-listitemref"},  
			animation: {  
				type: "fade",
				transition: Fx.Transitions.linear,
				rotate: {
					type: "auto",
					interval: 4500
				}  
			}  
    		});  
	});
}

function showRightArticles(node, link) {
	$('popup_background_'+node).style.display = 'block';
	$('popup_background_'+node).style.width = document.body.offsetWidth  + 'px';
	//$('popup_background_'+node).style.height = document.body.offsetHeight+200  + 'px';	
	$('popup_background_'+node).style.height = JQ(window).height() + 'px';
	$(node).className = 'parent_show';
}

function hideRightArticles(node) {
	$(node).className = 'parent_hide';
	$('popup_background_'+node).style.display = 'none';
}

