//create function, it expects 2 values.
function insertAfter(newElement,targetElement) {
	//target is what you want it to go after. Look for this elements parent.
	var parent = targetElement.parentNode;
	
	//if the parents lastchild is the targetElement...
	if(parent.lastchild == targetElement) {
		//add the newElement after the target element.
		parent.appendChild(newElement);
		} else {
		// else the target has siblings, insert the new element between the target and it's next sibling.
		parent.insertBefore(newElement, targetElement.nextSibling);
		}
}

J(document).ready(function(){
	//Liste des produits
	//over
	J(".shop_list_entry").hover(
		function() {
			J(this).css("background-image", "url('templates/creageneve/images/bg_square.gif')");
		},
		function() {
			J(this).css("background-image", "none");
			J(this).css("background-color", "#fff");
			
			J(this).children(".left").children(".date").css("color", "#D9294F");
			J(this).children(".left").children(".subdate").css("color", "#D9294F");
			J(this).children(".left").children("p").children("a").css("background-color", "#7F7F7F");
			J(this).children(".right").children("h3").children("a").css("color", "#010101");
			J(this).children(".right").children("h3").children("span").css("color", "#777777");
			J(this).children(".right").children(".description").css("color", "#7E7E7E");
			J(this).children(".right").children("p").children("a").css("color", "#DA294F");			
		}
	);
	//focus
	J(".shop_list_entry").click(function(){
		//background
		J(this).css("background-image", "none");
		J(this).css("background-color", "#da294f");
		
		//changement de couleurs
		J(this).children(".left").children(".date").css("color", "#fff");
		J(this).children(".left").children(".subdate").css("color", "#fff");		
		J(this).children(".left").children("p").children("a").css("background-color", "#6d1427");
		J(this).children(".right").children("h3").children("a").css("color", "#fff");
		J(this).children(".right").children("h3").children("span").css("color", "#000");
		J(this).children(".right").children(".description").css("color", "#fff");
		J(this).children(".right").children("p").children("a").css("color", "#000");
	});
	
	//Liste des produits d'un intervenant
	//over
	J(".intervenant_courses").hover(
		function() {
			J(this).css("background-image", "url('templates/creageneve/images/bg_square.gif')");
		},
		function() {
			J(this).css("background-image", "none");
			J(this).css("background-color", "#fff");
			
			J(this).children(".left").children(".date").css("color", "#D9294F");
			J(this).children(".left").children("p").children("a").css("background-color", "#7F7F7F");
			J(this).children(".right").children("h3").children("a").css("color", "#010101");
			J(this).children(".right").children("h3").children("span").css("color", "#777777");
			J(this).children(".right").children(".description").css("color", "#7E7E7E");
			J(this).children(".right").children("p").children("a").css("color", "#DA294F");			
		}
	);
	//focus
	J(".intervenant_courses").click(function(){
		//background
		J(this).css("background-image", "none");
		J(this).css("background-color", "#da294f");
		
		//changement de couleurs
		J(this).children(".left").children(".date").css("color", "#fff");
		J(this).children(".left").children("p").children("a").css("background-color", "#6d1427");
		J(this).children(".right").children("h3").children("a").css("color", "#fff");
		J(this).children(".right").children("h3").children("span").css("color", "#000");
		J(this).children(".right").children(".description").css("color", "#fff");
		J(this).children(".right").children("p").children("a").css("color", "#000");
	});
	
	//Liste des intervenants
	//over
	J(".intervenant").hover(
		function() {
			J(this).css("background-image", "url('templates/creageneve/images/bg_square.gif')");
			// J(this).children(".intervenantContent").children(".intervenantName").css("color", "#999");
			// J(this).children(".intervenantContent").children(".intervenantDescription").css("color", "#fff");
		},
		function() {
			J(this).css("background-color", "#fff");
			J(this).css('background-image', 'none');
			J(this).children(".intervenantContent").children(".intervenantName").css("color", "#666");
			J(this).children(".intervenantContent").children(".intervenantDescription").css("color", "#999");
		}
	);
	
	
	J('[rel=facebook]').attr('href', 'http://www.facebook.com/sharer.php?u=' + document.location.href + '&t=' + document.title);
	J('[rel=twitter]').attr('href', 'http://twitter.com/home?status=' + document.location.href);
	J('[rel=linkedin]').attr('href', 'http://www.linkedin.com/shareArticle?mini=true&url=' + document.location.href + '&title=' + document.title);
	
	
	/**
	 * Modification d'un div de classe video en player video
	 *
	 * @author Micha‘l Ambass <michael.ambass@wng.ch>
	 * @date 09.07.2010
	 **/
	 
	 var playerCount = 0;
	 
	 
	 J('a.video').each(function(){
	 	videoURL = J(this).attr('href');
	 	
	 
	 	/* var player = '<script type="text/javascript">var so = new SWFObject("http://extranet.wng.ch/creageneve/player.swf","mpl","555","300","9"); so.addParam("allowfullscreen","true"); so.addParam("allowscriptaccess","always"); so.addParam("wmode","opaque"); so.addVariable("file", '+videoURL+'); so.write("video_' + playerCount + '"); <div id="video_' + playerCount + '">Contenu alternatif</object>'; */
	 	
	 	var player = '<div id="video_' + playerCount +'"></div>';
		J(player).insertAfter(J(this));
		
		
			 	
	 	// J(this).wrap('<div id="video_' + playerCount +'"></div>');
		// J(this).css('display', 'none');
/*


<object type="application/x-shockwave-flash" data="fichierflash.swf" width="604" height="20">
<param name="movie" value="fichierflash.swf" />
<param name="wmode" value="transparent" />
<p>Image ou texte alternatif</p>
</object>
*/
		var so = new SWFObject('http://extranet.wng.ch/creageneve/player.swf','mpl','555','300','9');
		so.addParam('allowfullscreen','true');
		so.addParam('allowscriptaccess','always');
		so.addParam('wmode','opaque');
		so.addVariable('file', videoURL);
		so.write('video_' + playerCount);
		playerCount = playerCount + 1;
	 });
	 
});
