dojo.require("dojo.behavior");



/* Zapping */
var zoneDB_ctrl;
dojo.behavior.add({
	"#zoneDB" : {
		found : function(node) {
			node.animIn = dojo.animateProperty({
				node		: node,
				duration	: 400,
				properties	: { height: 250, unit: "px" }
			});
			node.animOut = dojo.animateProperty({
				node: node,
				duration	: 400,
				properties	: { height: 55, unit: "px" }
			});
			node.AnimHandler = function(){
				if (dojo.style(node, 'height') == 55) {
					node.animOut.stop();
					node.animIn.play();
					if (!zoneDB_ctrl) {
						zoneDB_ctrl = 1;
						ajax('init', null);
					}
				} else {
					node.animIn.stop();
					node.animOut.play();
				}
			};
			dojo.connect(dojo.query('#bt_db', node)[0], 'onclick', node.AnimHandler);
		},
		onmouseenter : function(e) {
			this.animOut.stop();
			this.animIn.play();
			if (!zoneDB_ctrl) {
				zoneDB_ctrl = 1;
				ajax('init', null);
			}
		},					
		onmouseleave : function(e) {
			this.animIn.stop();
			this.animOut.play();
		}
	}
});



/* Logo */
dojo.behavior.add({
	"#logo .hover"	: {
		found	: function(node) {
			node.opacityIn = dojo.animateProperty({
				node		: node,
				duration	: 200,
				properties	: { opacity: 1 }
			});
			node.opacityOut = dojo.animateProperty({
				node: node,
				duration	: 400,
				properties	: { opacity: 0 }
			});
		},
		onmouseenter	: function(e) {
			this.opacityOut.stop();
			this.opacityIn.play();
		},					
		onmouseleave	: function(e) {
			this.opacityIn.stop();
			this.opacityOut.play();
		}
	}
});



/* Recherche rapide */
dojo.behavior.add({
	"#zone_fs"	: {
		found	: function(node) {
			node.styleIn = dojo.animateProperty({
				node		: node,
				duration	: 200,
				properties	: { height: 0, unit: "px" }
			});
		},
		onmouseleave	: function(e) {
			this.styleIn.play();
		}
	}
});



/* Réactions des fiches */
dojo.behavior.add({
	".nbr_reaction"	: {
		found	: function(node) {
			node.styleClick = dojo.animateProperty({
				node		: dojo.query("#ajax_reaction_"+node.id)[0],
				duration	: 400,
				properties	: { height: 110, unit: "px" }
			});
		},
		onclick	: function(e) {
			this.styleClick.play();
			ajax('reaction_read', this.id);
		}
	}
});



/* Video */
dojo.behavior.add({
	".video"	: {
		onclick	: function(e) {
			if ((dojo.style(dojo.query('.video_play', this)[0], 'visibility')) == 'hidden') {
				dojo.style(dojo.query('.video_play', this)[0], 'visibility', 'visible');
				ajax('video_load', dojo.query('.video_play', this)[0].id);
			}
			else if ((dojo.style(dojo.query('.video_play', this)[0], 'visibility')) == 'visible') {
				ladiv = dojo.query('.video_play', this)[0];
				ladiv.innerHTML = '';
				dojo.style(dojo.query('.video_play', this)[0], 'visibility', 'hidden');
			}
		}
	}
});



/* Video */
dojo.behavior.add({
	".video_iframe"	: {
		onclick	: function(e) {
			if ((dojo.style(dojo.query('.video_play', this)[0], 'visibility')) == 'hidden') {
				dojo.style(dojo.query('.video_play', this)[0], 'visibility', 'visible');
				ladiv = dojo.query('.video_play', this)[0];
				ladiv.innerHTML = '<iframe border="0" src="/app/ajax_video.php?mode=video_load&var1=' + dojo.query('.video_play', this)[0].id +  '"><p>Your browser does not support iframes.</p></iframe>';
			}
			else if ((dojo.style(dojo.query('.video_play', this)[0], 'visibility')) == 'visible') {
				ladiv = dojo.query('.video_play', this)[0];
				ladiv.innerHTML = '';
				dojo.style(dojo.query('.video_play', this)[0], 'visibility', 'hidden');
			}
		}
	}
});

// console.debug(dojo.style(dojo.query('.video_play', this)[0], 'visibility'));
