(function($){ 

$.fn.Slider = function(vars) {       

	var element 		= this;
	var timeOut     	= (vars.timeOut != undefined) ? vars.timeOut : 4000;
	var fadeInOutSpd	= 500;
	var currentIndex 	= 0;
	var timeOutFn   	= null;
	var animace   		= true;
	var mOver       	= false;
	var items       	= $("#" + element[0].id + "Content ." + element[0].id + "Image");
	var itemsSpan   	= $("#" + element[0].id + "Content ." + element[0].id + "Image .desc");
	var itemsURL   		= $("#" + element[0].id + "Content ." + element[0].id + "Image .url");


	items.each(function(i) {

	$(items[i]).click( function(){
		window.open( $(itemsURL[currentIndex]).text(), '_blank');
		//alert( $(itemsURL[currentIndex], this).text() );
	});


	$(items[i]).mouseover(function() {
		mOver = true;
		$(this).css('cursor','pointer');
		});

	$(items[i]).mouseout(function() {
		mOver   = false;
		nacasujAkci(true);
		});

	});


var nacasujAkci = function(mouseOutEvent) {
	var thisTimeOut = timeOut;

	//odjela mys
	if(mouseOutEvent) thisTimeOut = (thisTimeOut/2); 

	//animace 10ms, neanimace timeout
	if( animace ) thisTimeOut = 200;

	//jestlize jsou obrazky, nacasuje se fce
	if(items.length > 0) {
		if(timeOutFn) clearTimeout(timeOutFn);
		timeOutFn = setTimeout(Animate, thisTimeOut);
	}
}



var Animate = function() {

	if(animace) {
		//jestlize neni najeta mys
		if(!mOver) {
			//zobraz obrazek a pak hned popisek a pak nastav animaci na false //slideDown
			$(items[currentIndex]).fadeIn(fadeInOutSpd, function(){
				//  $(itemsSpan[currentIndex]).animate({ width: 'toggle', marginLeft: '10px', opacity: 0.25 },
				if( $(itemsSpan[currentIndex]).text() != "" ){
    					$(itemsSpan[currentIndex]).animate({ width: 'toggle', left: '0px'},fadeInOutSpd,function(){
						animace = false;
						if(!mOver)
						{
							nacasujAkci(false);
						}
					});
				}
				else
				{
					animace = false;
					nacasujAkci(false);
				}
			});
		}
	} 
	else //animace == false
	{
		if(!mOver) 
		{
			//vyjed textem nahoru, pak zmiz obrazek, nastav animaci na true...//slideUp
			$(itemsSpan[currentIndex]).slideUp(fadeInOutSpd, function() {
				$(items[currentIndex]).fadeOut(fadeInOutSpd, function() {
					$(itemsSpan[currentIndex]).css('left','720px');
					animace = true;
					currentIndex++;
					//pokud jsme dosahli konce, zaciname od zacatku
					if( currentIndex == items.length - 1 ) currentIndex = 0;
					nacasujAkci(false);
				});
			});

		}
	}
}


//pusti se na zacatku
Animate();



};  

})(jQuery); 



