
$(document).ready(function() {

	$(function(){
		$('#slides').slides({
			/*preload: true,
			preloadImage: 'img/loading.gif',*/
			play: 5000,
			pause: 2500,
			hoverPause: true,
			animationStart: function(current){
				$('.caption').animate({
					bottom:-35
				},100);
				if (window.console && console.log) {
					// example return of current slide number
					console.log('animationStart on slide: ', current);
				};
			},
			animationComplete: function(current){
				$('.caption').animate({
					bottom:0
				},200);
				if (window.console && console.log) {
					// example return of current slide number
					console.log('animationComplete on slide: ', current);
				};
			},
			slidesLoaded: function() {
				$('.caption').animate({
					bottom:0
				},200);
			}
		});
		
		if ($('#slides').length) {
			$(document).keydown(function(e) {
				if (e.keyCode == 37){
					$('.firstFotoPrev').triggerHandler('click');
				} else if (e.keyCode == 39) {
					$('.firstFotoNext').triggerHandler('click');
				}
			});
		}
	});

	
	$(function(){
		function highlight( items ) {
			$(".topFotoOuterContainerShadow").html(items.filter(":eq(1)").html());		
			$(".topFotoOuterContainerShadow").find(".topFotoOuterContainerFon").fadeTo("slow",0);
			$(".topFotoOuterContainerShadow").find(".captionz").hide();
			$(".topFotoOuterContainerShadow").find(".captionz").slideDown();
		}
		function unhighlight( items ) {
			/*items.css({
				backgroundColor: "#fff",
				border: "0px",
				/*width	: 300,*/
				/*height	: 100,*/
				/*margin	: 3
			});*/ 
			//items.children(".caption").hide();
					//   items.children(".caption").hide();
		    //$(".topFotoOuterContainerFon").fadeTo("fast",0);
		//	items.removeClass("highlite zfirstFotoOuterContainerShadow");			           
			            	
		}
		
		$("#foo3").carouFredSel({
			auto: { pauseDuration: 5000 },
			items  : 3,
			pagination  : "#foo3_pag",
			scroll  : {
			    items: 1,
				onBefore: function(oldItems, newItems) {
					unhighlight( oldItems );
				},
				onAfter	: function(oldItems, newItems) {
					highlight( newItems );
				}
			    },	
			    prev    : {
			        button  : "#foo1_prev"
			    },
			    next    : {
			        button  : "#foo1_next"
			    }	
		});
		
		unhighlight( $("#foo3 > *") );
		highlight( $("#foo3 > *") );				
	});
	
	
	
	$('.news_gallery').each(function() {
		var $gallery = $(this);
	
		var currentPhoto = 0; 
		var $photoContainer = $gallery.find('.middleFotoInnerContainer');
		var $photos = $photoContainer.find('DIV');
		var $bullets = $gallery.find('.middleFotoBullets A');
							
		var navigateGallery = function(where, direct) {
			$bullets.eq(currentPhoto).find('IMG').removeClass('act');
		
			if (direct !== undefined) {
				currentPhoto = direct - 1;
			} else {
				currentPhoto = (currentPhoto + where + $photos.length) % $photos.length;
			} 
			
			$bullets.eq(currentPhoto).find('IMG').addClass('act');
			$photoContainer.css('margin-left', -currentPhoto * 476 + 'px');
		}
		
		$gallery.find('.arrow').click(function() {
			navigateGallery($(this).hasClass('left') ? -1 : 1); 
			return false;
		});
		
		$bullets.click(function() {
			navigateGallery(0, this.getAttribute('item'));		
		});
	
	});
	
	
	
	if ($('.news_gallery').length) {
		$(document).keydown(function(e) {
			if (e.keyCode == 37){
				$('.middleFotoPrev').triggerHandler('click');
			} else if (e.keyCode == 39) {
				$('.middleFotoNext').triggerHandler('click');
			}
		});
	}
	
	
	
});



	function ButtonEnable(name, isEnabled, isFlashing) {
		var $button = $('#' + name);
		
		$button.attr('disabled', isEnabled ? false : 'disabled'); 
	}
	
	
	function VerbalDigit(sum, one, four, many, skipNumber) {
        var perSum = sum % 100;
        var prefix = skipNumber ? '' : sum + ' ';
        
        if (perSum <= 10 || perSum >= 20) {
        	switch (perSum % 10) {
        		case 1: 
        			return prefix + one; 
        			break;
        		
        		case 2:	
        		case 3: 
        		case 4: 
        			return prefix + four;
        	}        	
        }
        
        return prefix + many;
    }
	
