var slideTimeInterval;
var ieMenuSetTimeOut = 0;

function slideIt() {
	var element = $('logotypy');
	var childs = $(element).getElements('li');
	
	var firstChild = childs[0];
	var secondChild = childs[1];
	var lastChild = childs[childs.length-1];

	var hide = function() {
		effect = new Fx.Tween($(element), {
			duration: 1000,
			fps: 30
		});
		effect.start('opacity', 0);
	}
	
	var change = function() {
		secondChild.inject(lastChild, 'after');
		firstChild.inject(lastChild, 'after');	
	}
	
	var show = function() {
		effect = new Fx.Tween($(element), {
			duration: 1000,
			fps: 30
		});
		effect.start('opacity', 1);	
	}

	var x = new Chain();
	x.chain(hide);
	x.chain(change);
	x.chain(show);
	x.callChain.delay(0, x);
	x.callChain.delay(1000, x);
	x.callChain.delay(1000, x);
}

function slideIt2() {
	var element = $('czyWieszBox');
	var txtEl = $('czyWieszBox').getElement('.txtOutbox');
	
	var childs = $(element).getElements('li');
	
	var firstChild = childs[0];
	var lastChild = childs[childs.length-1];

	var hide = function() {
		effect = new Fx.Tween($(txtEl), {
			duration: 1000,
			fps: 30
		});
		effect.start('opacity', 0);
	}
	
	var change = function() {
		//secondChild.inject(lastChild, 'after');
		firstChild.inject(lastChild, 'after');	
	}
	
	var show = function() {
		effect = new Fx.Tween($(txtEl), {
			duration: 1000,
			fps: 30
		});
		effect.start('opacity', 1);	
	}

	var x = new Chain();
	x.chain(hide);
	x.chain(change);
	x.chain(show);
	x.callChain.delay(0, x);
	x.callChain.delay(1000, x);
	x.callChain.delay(1000, x);
}


window.addEvent('domready', function(){

	/* IE6 topMenu */
	if(Browser.Engine.trident && Browser.Engine.version == 4) {
		var liElem = $('topMenu').getChildren('li');
		var allAElems = $('topMenu').getElements('a');
		
		$each(liElem, function(li) {

			var ulElem = $(li).getElement('ul');
			var aElem = $(li).getElement('a');

			if(ulElem !== null) {
				li.addEvent('mouseover', function() {
					$each(allAElems, function(allAElem) {
						allAElem.removeClass('hover');
					});
					$(ulElem).setStyle('display', 'block');
				});
				
				li.addEvent('mouseout', function() {
					$(ulElem).setStyle('display', 'none');
					$(this).parentNode.getElement('a').removeClass('hover');
				});		
				
				ulElem.addEvent('mouseover', function() {
					$(this).parentNode.getElement('a').addClass('hover');
				});	
			}	
		});
	} 
	/* IE6 topMenu END */

	
	/* topMenu */

	var liElem = $('topMenu').getChildren('li');
	var topCoords = $('top').getCoordinates();
	
	var ulElemPadding = 50;


	$each(liElem, function(li) {

		var ulElem = li.getElement('ul');

		if(ulElem !== null) {

			var itemsNum = ulElem.getChildren('li').length;
			
			var width = 0;
			var ulElemChildrens = ulElem.getChildren('li');

			if(itemsNum>0) {

				var liElemCoords = li.getCoordinates();

				var ulElemWidth = 0;
				$each(ulElemChildrens, function(ulElemChildren) {
				
					if(ulElemChildren.getChildren('ul').length == 0) {	
						var size = ulElemChildren.measure(function(){
						ulElemWidth += this.getSize().x;
						});			
					} else {
						ulElemWidth += 150;
					}	
				});				

				ulElemWidth = ulElemWidth + (itemsNum*10);
				ulElem.setStyle('width', ulElemWidth + 'px');	

				if((liElemCoords.left + ulElemWidth + ulElemPadding) > topCoords.right) {
					if(liElemCoords.right - (ulElemWidth + ulElemPadding) > topCoords.left) {
						ulElem.setStyle('right', (topCoords.right - liElemCoords.right) + 'px');
					} else {
						ulElem.setStyle('right', 0);
					}
				}

			}
		}
	});

	/* topMenu END */

	/* searchBoxInput */
	
	$('searchBoxInput').addEvent('click', function(){$(this).value = '';});
	
	/* searchBoxInput END */
	
	
	/* newsletterBoxInput */
	
	if($('newsletterBoxInput')) $('newsletterBoxInput').addEvent('click', function(){$(this).value = '';});
	
	/* newsletterBoxInput END */	
	

	/* linki */
	
	var links=$(document.body).getElements('a[href^=http],a[rel=external]');
	$each(links, function(link) {
		link.addEvent('click', function(){
			window.open(link.get('href'),'_blank');
			return false;
		});
	});
	
	/* linki END */


	/* czy wiesz ze */
	if($('czyWieszBox')) {
	
	var czyWieszLength = $('czyWieszBox').getElements('li').length;

	if($('czyWieszBox') && czyWieszLength>1) {
		slideTimeInterval=setInterval("slideIt2()", 4000);
	}
	}
	/* czy wiesz ze END */
	
	
	
/* logotypy */
	
	if($('logotypy')) {
	
	var logotypyLength = $('logotypy').getElements('a').length;
	
	if($('logotypy') && logotypyLength>2) {

		var logotypyWidth = 0;
		var logotypes = $('logotypy').getElements('a');

		$each(logotypes, function(logotyp) {
			var size = logotyp.measure(function(){
			logotypyWidth += this.getSize().x + 50;
			});			
		});		
		

		var obj;
		function startMoorquee() {
		obj = new mooquee($('logotypy'), {marWidth: (logotypyWidth-50)});
		}
		startMoorquee(); 	

	}
	}

	/* logotypy END */
	
	
});



			


