(function(){

        var html5elmeents = "address|article|aside|audio|canvas|command|datalist|details|dialog|figure|figcaption|footer|header|hgroup|keygen|mark|meter|menu|nav|progress|ruby|section|time|video".split('|');

  
          for(var i = 0; i < html5elmeents.length; i++){

  				document.createElement(html5elmeents[i]);

  			}

  		}

  )();

$(document).ready(function() {	

	jQuery.fx.speeds._default = 1000;

	function displayNewsArrows() {
		if(jQuery("#top-news .moveable").position().top < 0)
			jQuery("#top-news .up").show();
		else
			jQuery("#top-news .up").hide();

		if(-jQuery("#top-news .moveable").position().top < jQuery("#top-news .moveable").height())
			jQuery("#top-news .down").show();
		else
			jQuery("#top-news .down").hide();
	}

	displayNewsArrows();

	jQuery("#top-news .up").click(function() {

		jQuery("#top-news .moveable").animate({
			top : '+=50'
		}, function() {
			displayNewsArrows();
		});
	});

	jQuery("#top-news .down").click(function() {

		jQuery("#top-news .moveable").animate({
			top : '-=61'
		}, function() {
			displayNewsArrows();
		});
	});
	
	/**************
	 * Partenaires *
	 **************/

	jQuery(".partenaire").each(function() {

		var description = jQuery(this).children(".description");
		var title = jQuery(this).children("h3").html();
		description.attr("title", title);

		jQuery(this).click(function() {

			description.dialog("open");
			return false;
		});

		description.dialog({
			autoOpen : false,
			show : "explode",
			hide : "explode",
			width : 500,
			modal : true,
			buttons : {
				"Fermer" : function() {
					jQuery(this).dialog("close");
				}
			}
		});
	});
	
	/******************
	 * Offres d'emploi *
	 ******************/

	jQuery(".offre-emploi").each(function() {

		var description = jQuery(this).children(".description");
		var title = jQuery(this).children("h3").html();
		var uid = (document.location.href.split("#"))[1];
		var cssid = "c" + description.attr("id");

		description.attr("title", title);

		jQuery(this).click(function() {

			description.dialog("open");
			return false;
		});

		description.dialog({
			autoOpen : uid == cssid,
			show : "explode",
			hide : "explode",
			width : 500,
			modal : true,
			buttons : {
				"Postuler" : function() {
					document.location.href = "mailto:job@amexio.fr?subject=Candidature au poste de : " + title;
				},
				"Fermer" : function() {
					jQuery(this).dialog("close");
				}
			}
		});
	});
	
	/***************
	 * Témoignages *
	 **************/

	jQuery(".temoignage").each(function() {

		var description = jQuery(this).children(".description");

		jQuery(this).children(".lire").click(function() {

			description.dialog("open");
			return false;
		});

		description.dialog({
			autoOpen : false,
			show : "explode",
			hide : "explode",
			width : 500,
			modal : true,
			buttons : {
				"Fermer" : function() {
					jQuery(this).dialog("close");
				}
			}
		});
	});
	
	/**********
	 * Offres *
	 *********/

	jQuery("#schema-offres .offre").each(function() {

		var description = jQuery(this).children(".description");

		jQuery(this).click(function() {
			description.dialog("open");
			return false;
		});

		description.dialog({
			autoOpen : false,
			show : "explode",
			hide : "explode",
			width : 500,
			modal : true,
			buttons : {
				"Fermer" : function() {
					jQuery(this).dialog("close");
				}
			}
		});
	});
	
	/**************
	 * Références *
	 *************/

	jQuery(".reference").each(function() {

		var description = jQuery(this).children(".description");

		if (description.html() != "") {
			jQuery(this).click(function() {
				description.dialog("open");
				return false;
			});
			
			$(this).css("cursor","pointer");		
		}

		description.dialog({
			autoOpen : false,
			show : "explode",
			hide : "explode",
			width : 500,
			modal : true,
			buttons : {
				"Fermer" : function() {
					jQuery(this).dialog("close");
				}
			}
		});
	});
});

