var entrain = false;
var entrain_switch = "false";
var timeout;
var numos = 1;
window.addEvent('domready', function() {
	
	/* Slideshow - Pic Box in Sec NavBar */	
 if($('player')){
	
	slideshow1 = new SlideShow('playerItems',{
		delay: 2000,
		transition: 'pushLeft',
		duration: 100,
		controller: true,
		autoplay: false
	});
	
	var slideLabels = $$('ul.navPlayer a');
	
	var currentSlide = 0;
	$$('ul.navPlayer a.prev').addEvent('click', function(e){
		new Event(e).stop();
		currentSlide = currentSlide > 0 ? currentSlide-1 : slideshow1.slides.length - 1;
		slideshow1.show(currentSlide);
	});
	
	$$('ul.navPlayer a.next').addEvent('click', function(e){
		new Event(e).stop();
		currentSlide = currentSlide < slideshow1.slides.length-1 ? currentSlide+1 : 0;
		slideshow1.show(currentSlide);
	});
	
 }
	/* Fin slideshow */
	
	Element.implement({
		//implement show
		show: function() {
			this.setStyle('display','');
		},
		//implement hide
		hide: function() {
			this.setStyle('display','none');
		}
	});
	
	
	if($$('.btn_ban').length > 0)
	{
		timeout=setTimeout("changeBan('1')",5000);
		$$('.btn_ban').each(function(element){
			element.addEvent('click', function(e){
				new Event(e).stop();
				
				if(entrain == false)
				{
					entrain=true;
					if(timeout)
						clearTimeout(timeout);
						
					$$('.btn_ban').each(function(element2){
						element2.removeClass('hover');
					});
					
					element.addClass('hover');
					var myEffects = new Fx.Morph('ban_scroll', {
						duration: 'normal',
						transition: Fx.Transitions.Sine.easeOut,
						onComplete: function() {
							entrain=false;
							var numbs = parseInt(element.getAttribute('marge'))+1;
							if(numbs > 3)
							{
								numbs=0;
							}
							timeout=setTimeout("changeBan('"+numbs+"')",5000);
						}
					});
					
					myEffects.start({
						'margin-left': "-"+(element.getAttribute('marge')*960)+"px"
					});
				}
			});
		});
	}
	
	
	if($('scroller'))
	{
		timeout=setTimeout("changeProject('1')",3000);
	}
	
	
	if($$('.inputfile').length > 0)
	{
		var W3CDOM = (document.createElement && document.getElementsByTagName);
		
		if (!W3CDOM) return;
		var fakeFileUpload = document.createElement('div');
		fakeFileUpload.className = 'fakefile';
		fakeFileUpload.appendChild(document.createElement('input'));
		var image = document.createElement('img');
		image.src='img/button_select.jpg';
		fakeFileUpload.appendChild(image);
		var x = document.getElementsByTagName('input');
		for (var i=0;i<x.length;i++) {
			if (x[i].type != 'file') continue;
			if (x[i].parentNode.className != 'inputfile') continue;
			x[i].className = 'file hidden';
			var clone = fakeFileUpload.cloneNode(true);
			x[i].parentNode.appendChild(clone);
			x[i].relatedElement = clone.getElementsByTagName('input')[0];
			x[i].onchange = x[i].onmouseout = function () {
				this.relatedElement.value = this.value;
			}
		}
	}
	
	
	if($$('.link_client').length > 0)
	{
		$$('.link_client').each(function(element){
			element.addEvent('click', function(e) {
				new Event(e).stop();
				
				if(timeout)
					clearTimeout(timeout);
				
				if(entrain_switch == "false")
				{
					entrain=true;
					entrain_switch = "true";
					if($$('.link_client'))
					{
						$$('.link_client').each(function(element2){
							element2.removeClass('hover');
						});
					}
					element.addClass('hover');
					
					var myEffect2 = new Fx.Morph('descTHERE', {
						duration: 'normal',
						transition: Fx.Transitions.Back.easeOut,
						onComplete: function() {
							entrain_switch="false";
							entrain=false;
							timeout=setTimeout("changeProject('"+numos+"')",3000);
						}
					});
					
					var myEffect = new Fx.Morph('descTHERE', {
						duration: 'normal',
						transition: Fx.Transitions.Back.easeOut,
						onComplete: function() {
							var ctnAdd = $('descTHERE').empty();
							var req = new Request.HTML({
								evalScripts: true,
								method: 'get',
								url: element.get('href'),
								update: $('descTHERE'),
								onComplete: function(response) {
									myEffect2.start({
										'filter': 'alpha(opacity=100)',
										'-moz-opacity': '1.0',
										'opacity': '1.0'
									});
								}
							}).send();
						}
					});
					 
					myEffect.start({
						'filter': 'alpha(opacity=0)',
						'-moz-opacity': '0.0',
						'opacity': '0.0'
					});
				}
			});
		});
	}
});

function switchColorPic(idC,id,src){
	$('hiddenColor').set('value',idC);
	if(src != ''){
		$(id).set('src',src);
	}
}


function changeBan(numbs)
{
	if(entrain == false)
	{
		entrain=true;
		if(timeout)
			clearTimeout(timeout);
		
		var myEffects = new Fx.Morph('ban_scroll', {
			duration: 'normal',
			transition: Fx.Transitions.Sine.easeOut,
			onComplete: function() {
				entrain=false;
				var numbis = parseInt(numbs)+1;
				if(numbis > 3)
				{
					numbis=0;
				}
				timeout=setTimeout("changeBan('"+numbis+"')",5000);
			}
		});
		
		myEffects.start({
			'margin-left': "-"+(numbs*960)+"px"
		});
		
		x=0;
		$$('.btn_ban').each(function(element2){
			if(x == numbs)
			{
				element2.addClass('hover');
			}
			else
			{
				element2.removeClass('hover');
			}
			x++;
		});
	}
}



