window.addEvent('domready', function(){

/*************************************
	PRODUCTS
**************************************/

var szNormal = 160, szSmall  = 160, szFull   = 415;
var products = $$("#products .product");
var descriptions = $$("#products .product .text");

var productsSlider = new Fx.Elements(products, {wait: false, duration: 300, transition: Fx.Transitions.Back.easeOut});


descriptions.each(function(description, i) {
	description.setStyle('display','block');
});



var descriptionToggler = new Fx.Elements(descriptions, {wait: 0, duration: 100});


products.each(function(product, i) {
	product.addEvent("mouseenter", function(event) {
		var o = {};
		var t = {};
		
		o[i] = {width: [product.getStyle("width").toInt(), szFull]}
		
		
		products.each(function(other, j) {
			if(i != j) {
				var w = other.getStyle("width").toInt();
							
				if(w != szSmall)	o[j] = {width: [w, szSmall]};
			}
		});
		
		productsSlider.start(o);		
	});
	
	if(i==0)
	{
		product.fireEvent('mouseenter',0);
	}
});


/*******************************************
	CUSTOMERS
********************************************/

var customers = $$(".customer");
var read_more_link = $('customer_read-more');
var effect_type = 'left'; 
var effect_duration = 200;
var show_time = 10000;
var max_value = 0;
var min_value = -588;


customers.each(function(customer, i) {
	customer.setStyle('left',min_value);
	customer.setStyle('display','none');
});

function displayElement(index) {

	var opacity = customers[index].effect(effect_type, {duration:effect_duration})	
	customers[index].setStyle('display','block');		
	
	opacity.start(min_value,max_value);			
	
	$('customer_read-more').setProperty('href', 'alias.html?id='+customers[index].id); 
	
	hideElement.delay(show_time,'',(index));
			
}

function hideElement(index)
{
	customers[index].effect(effect_type, {duration:effect_duration}).start(max_value,-min_value);
	noneElement.delay(effect_duration,'',customers[index]);
		
	if((index+1)<customers.length)
		displayElement.delay(effect_duration,'',index+1);
	else
		displayElement.delay(effect_duration,'',0);			
}

function noneElement(element) {element.setStyle('display','none');}

displayElement(0);

});

/*******************************************
	INSERT IMAGE
********************************************/

function InsertImage(imageId, imageDescription)
{
	var path = '../../images/';
	
	if(imageId)
		document.write('<img src="'+path+imageId+'" alt="'+imageDescription+'" />');
	else
		return;
}