// JavaScript Document

$(document).ready(function() {



// JavaScript Document

	$("a.fancybox").fancybox({
		'zoomSpeedIn': 300, 
		'zoomSpeedOut':	300, 
		'overlayShow': true,
		'overlayColor': '#000',
		'overlayOpacity': 0.8
	});


	//Overlay.Init();
	//Debug.Init();
	//Footer.Init();

//	$("#footer").fadeTo(FadeSpeed,0.25).mouseover(function() {
//		$(this).fadeTo(FadeSpeed,1); //.animate({bottom:'+=10px'}, { "duration": "fast" } );
//	}).mouseout(function() {
//		$(this).fadeTo(FadeSpeed,0.25); //.animate({bottom:'-=10px'});
//	});

});

var Debug = {
	build : 1,
	id : '#debug',
	timestamp : true,
	ts : new Date(),
	increment : 0,
	active : false,
	Init : function() {
		$('body').prepend('<div id="' + Debug.id.substr(1) + '"></div>');
		$(Debug.id).css({
			'position':'fixed',
			'width':'600px',
			'height':'200px',
			'background':'#000',
			'color':'#0F0',
			'font-family':'"Courier New", Courier, monospace',
			'font-size':'8pt',
			'border':'#F00 dashed 1px',
			'margin':'10px',
			'top':'0px',
			'right':'0px',
			'z-index':'9999',
			'display':'none',
			'overflow':'auto'});
		if (Debug.active) $(Debug.id).show().fadeTo(0,0.5).dblclick(function() {Debug.Clear();}).click(function() {Debug.Write('current to:' + Footer.sto);});
		Debug.Write('debug mode (build ' + Debug.build + ') init, ok.');
		//$(Debug.id).mouseover(function() { $(this).fadeTo(0,0.75)});
		//$(Debug.id).mouseout(function() { $(this).fadeTo(0,0.5)});
		//$(Debug.id).draggable();
	},
	Write : function(value) {
		if (!Debug.active) return false;
		Debug.increment++;
		if (Debug.timestamp) ts = Debug.ts.toGMTString() + ': ';
		$(Debug.id).prepend('<p id="value' + Debug.increment + '">[' + Debug.increment + ']' + ts + value + '</p>');
		$('#value' + Debug.increment + '').css({color:'#0F0'});
		$('#value' + (Debug.increment-1) + '').css({color:'#090'});
	},
	Clear : function() {
		$(Debug.id).html('');
	}
}

var Footer = {
	isOn : 0,
	FadeSpeed : 0,
	sto : 0,
	hauteur : 0,
	hauteur_min : 0,
	Init : function() {
		Footer.hauteur = parseInt($("#footer").height());
		Footer.hauteur_min = 20 - Footer.hauteur;
		//alert(hauteur);
		$("#footer").fadeTo(0,0.25).css({bottom: Footer.hauteur_min + 'px'});
		$("#footer,#footer > *").mouseover(function() {Footer.In()});
		$("#footer,#footer > *").mouseout(function() {Footer._Out()});
		Debug.Write('Footer is init.');
	},
	In : function() {
		Debug.Write('in:' + Footer.sto);
		clearTimeout(Footer.sto);
		if (Footer.IsOn==1) return false;
		Footer.isOn=1;
		$("#footer").fadeTo(Footer.FadeSpeed,1).animate({bottom:'0px'}, 500);
	},
	_Out : function() {
		Debug.Write('out:' + Footer.sto);
		//if (Footer.IsOn==0) return false;
		Footer.sto = setTimeout('Footer.Out()', 2000);
	},	
	Out : function() {
		Debug.Write('effective out:' + Footer.sto);
		clearTimeout(Footer.sto);
		Footer.isOn=0;
		$("#footer").fadeTo(Footer.FadeSpeed,0.25).animate({bottom: Footer.hauteur_min + 'px'}, 500);
		Footer.sto = 0;
	}
}

var jsonExterne = {
	build : 2,
	callback : new Array(),
	posttosend : new Array(),
	url : '/data/php/jsonp.php',
	Send : function() {
		jsonExterne.posttosend['data'] = 'cool';
		alert('send to:'+this.url);
		$.post(
			this.url,
			{
				'url' : 'api.createsend.com',
				'script' : '/api/api.asmx/Subscriber.Add',
				'ApiKey' : '2fccad9455fd060f1af4790edb382c3b',
				'ListID' : '054c6be04d7953e0a9d64c1c1eeda55c',
				'Email' : $("#newsletter_email").val(),
				'Name' : $("#newsletter_name").val()
			}, function(data) {
				if (data.Code == 0) alert('OK');
				if (data.Code == 1) alert('Invalid email address');
				if (data.Code == 100) alert('Invalid API Key');
				if (data.Code == 101) alert('Invalid ListID');
				if (data.Code == 204) alert('In SupressionList');	
			}, 'json');
	}
}

function newsletter_subscribe() {
	//alert('action:subscriber');
	jsonExterne.Send();

//	$.post(
//		'http://api.createsend.com/api/api.asmx/Subscriber.Add',
//		{
//			'ApiKey' : "4a40f85a8a5c3922c3ec0e01e1706c10",
//			'ListID' : "20A7F22572D25C44",
//			'Email' : $("#newsletter_email").val(),
//			'Name' : $("#newsletter_name").val()
//		}, function(data) {
//			alert("["+data+"]");
//			/*if (data.Code == 0) alert('OK');
//			if (data.Code == 1) alert('Invalid email address');
//			if (data.Code == 100) alert('Invalid API Key');
//			if (data.Code == 101) alert('Invalid ListID');
//			if (data.Code == 204) alert('In SupressionList');			*/
//		}, 'html'
//	);
}

function newsletter_open() {
	Overlay.Show();
	$("#overlay_up").show(); //.html('salut');
}

// Overlay Object
var Overlay = {
	Build : 1,
	Speed : 100,
	FadeOn : 0.8,
	Init : function() {
	  $('#overlay').fadeTo(Overlay.Speed, 0);
	},
	Show : function() {
	  $('#overlay').show(function() {
		$(this).fadeTo(Overlay.Speed, Overlay.FadeOn);
		});
	},
	Hide : function() {
	  $('#overlay').fadeTo(Overlay.Speed, 0, function() {
		$(this).hide();
	  })
	}        
  }