/////////   Created by Fugu design - 21/07/2008

	
var CurrentId = 1;
var CurrentImage = 0;
var isMasked = false;

Event.observe(window, 'dom:loaded', init, false);

function init() 
{
	// Formulaire de contact
	if ($("contact_form"))
	{
		new my_form("contact_form", {
			fields_call: "#field",
			obligatories: ["name", "firstname", "mail"],
			empty_message: "Merci de saisir l'intégralité des champs obligatoires.\n(Signalés en rouge)",
			after_initialize: function()
			{
				Event.observe("contact_submit", "click", this.validate.bind(this), false);
			},
			execute_action: function()
			{
				new Ajax.Request(this.form_obj.action, { 
					method: 'post', 
					parameters: this.form_obj.serialize(), 
					evalScripts:true,
					onLoading:function() {
						var loading_img = new Image();
						this.form_obj.up("#form_container").insert({bottom:Builder.node("div", { id: "ajaxResponse" }, " ")}).hide();
						this.form_obj.up("#form_container").insert({bottom:Builder.node("div", { id: "loadingPane" }, " ")}).show();
					}.bind(this),
					onComplete:function(transport) {
						if (transport.responseText.match(/SUCCESS/)) { this.empty_fields(); msg_timeout = 12000; } else { msg_timeout = 4000; }
						$("loadingPane").remove();
						$("ajaxResponse").update(transport.responseText).show();
						setTimeout(function(){ $("ajaxResponse").fade({afterFinish:function(){ $("ajaxResponse").remove(); }}); }, msg_timeout);
					}.bind(this)
				});
			}
		});
	}
}

function changePicture(link,picture) {
	$(link).src = 'images/skin_08/buttons/'+picture;
}

function initList(prev, table_id) 
{
	if (table_id)
	{
		var num = null;
		$$('a').each(function(item)
		{
			if (item.getAttribute("rel") == 'item' && item.getAttribute("itemid") == prev) 
				num = Number(item.getAttribute("inc"));
		});
		var this_table = $(table_id);
		if (num)
		{
			var xPos = initPos-((Number(num)-1)*SizeBase);
			CurrentId = num;
		}
		new Effect.Move (this_table,{ x: 0, y: xPos, mode: 'absolute', duration : 0	});
		if (num) displayGoodItem("link" + num);
		if (num) checkArrows();
		if (document.all) addReflections();
	}

}

function moveListToNext(table, direction, coeff) 
{
	if ((CurrentId > 1 && direction == 'up') || (CurrentId < MaxList && direction == 'down'))
	{
		if (direction == 'up') { var item = CurrentId-1; }
		if (direction == 'down') { var item = CurrentId+1; }
		moveListToItem(table, item, coeff);
	}
}

function moveListToItem(table, num, coeff)
{
	var xPos = initPos-((Number(num)-1)*SizeBase);
	if (!coeff) var coeff = (Math.abs(CurrentId-num)+2)/10;
	new Effect.Move ($(table),{ x: 0, y: xPos, mode: 'absolute', duration : coeff	});
	$('link'+CurrentId).className = 'list_link';
	displayGoodItem('link' + num);
	CurrentId = Number(num);
	checkArrows();
	if (document.all) addReflections();
}

function displayGoodItem(Link) 
{
	var GoodTitle = $(Link);
	changeImage(GoodTitle.getAttribute('inc'));
	GoodTitle.className = 'current_list_link';
	var linkto = Number(GoodTitle.getAttribute('linkto'));
	if (linkto) $('list_details_link_opak').href = GoodTitle.href
}

function changeImage(inc) 
{
	$('preview1').hide();
	$('preview'+CurrentId).hide();
	$('preview'+inc).show();
}

function checkArrows() 
{
	if (CurrentId == 1) 
		$('arrow_top').src = 'images/skin_08/buttons/arrow_top_disable.gif';
	else
		$('arrow_top').src = 'images/skin_08/buttons/arrow_top.gif';
		
	if (CurrentId == MaxList) 
		$('arrow_bottom').src = 'images/skin_08/buttons/arrow_bottom_disable.gif';
	else
		$('arrow_bottom').src = 'images/skin_08/buttons/arrow_bottom.gif';
		
}

function showMore(val) 
{
	if (val == 0)
		$('show_more').hide();
	else
		new Effect.Appear('show_more', { duration:0.2, to:val });
}

function toggleImage(inc) 
{
	$('image'+CurrentImage).hide();
	changeBtnsProjectImages(inc);
	if (inc == 0) showMore(0.8); else showMore(0); 
	new Effect.Appear('image'+inc, {duration:0.5}); 
	CurrentImage = inc;
}

function changeBtnsProjectImages(num) 
{
	var images_links = Array();
	$$('a').each(function(item)
	{
		if (item.getAttribute('num'))
			images_links[item.getAttribute('num')] = item;
	});
	$A(images_links).each(function(item)
	{
		if (item.getAttribute('num') == num)
			item.className = 'current_image';
		else
			item.className = '';
	});
}

