/**
 * offer-card.js
 *
 * Fiches détaillées des offres d'emploi et de stage
 * @author collomb
 * @version 1.0
 */

/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */
(function(d){function e(c){var a;if(c&&c.constructor==Array&&c.length==3)return c;if(a=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(c))return[parseInt(a[1]),parseInt(a[2]),parseInt(a[3])];if(a=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(c))return[parseFloat(a[1])*2.55,parseFloat(a[2])*2.55,parseFloat(a[3])*2.55];if(a=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(c))return[parseInt(a[1],16),parseInt(a[2], 16),parseInt(a[3],16)];if(a=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(c))return[parseInt(a[1]+a[1],16),parseInt(a[2]+a[2],16),parseInt(a[3]+a[3],16)];return f[d.trim(c).toLowerCase()]}function g(c,a){var b;do{b=d.curCSS(c,a);if(b!=""&&b!="transparent"||d.nodeName(c,"body"))break;a="backgroundColor"}while(c=c.parentNode);return e(b)}d.each(["backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","color","outlineColor"],function(c,a){d.fx.step[a]=function(b){if(b.state== 0){b.start=g(b.elem,a);b.end=e(b.end)}b.elem.style[a]="rgb("+[Math.max(Math.min(parseInt(b.pos*(b.end[0]-b.start[0])+b.start[0]),255),0),Math.max(Math.min(parseInt(b.pos*(b.end[1]-b.start[1])+b.start[1]),255),0),Math.max(Math.min(parseInt(b.pos*(b.end[2]-b.start[2])+b.start[2]),255),0)].join(",")+")"}});var f={white:[255,255,255]}})(jQuery);

$(document).ready(onOCDocumentReady);

/**
 * Execution auto au chargement de la page
 */
function onOCDocumentReady() {
	$("#aOfferContact").click(onContactLinkClick);
	$("#jAddToSelection").click(onSelectClick);
}

/**
 * Demande à l'utilisateur de saisir une annotation
 */
function onSelectClick(event) {
	var $this = $(this);
	jPrompt('Annotation :', '', 'Ajouter une offre à ma sélection', function(annotation) {
		if (annotation !== null) {
			document.location.href = $this.attr('href') + '&annotation=' + encodeURIComponent(annotation);
		}
	});
	event.preventDefault();
	return false;
}

/**
 * Lors du click sur le bouton "postuler à cette annonce"
 */
function onContactLinkClick(event) {
	event.preventDefault();
	$("#pOfferContact").hide();
	$("#divOfferContact").fadeIn('fast', function(){$("#divOfferContact").show().animate({backgroundColor: "#ffffff" }, 'slow');});
	$.getJSON($(this).attr("href"));
	return false;
}
