/**
 * @author jay
 */
window.addEvent('domready', function () {
				N_ITEMS = 34;
				if (!$("nav_fcnews")) return;
				var myVerticalSlide = new Fx.Slide('nav_fcnews');
				myVerticalSlide.slideOut();
				var scrollFC_NEWS = $('scroll_fcnews');
				scrollFC_NEWS.addEvent('mouseenter', function (e) {
					
					//alert('ouch!');
					myVerticalSlide.slideIn();
				});
				scrollFC_NEWS.addEvent('mouseleave', function (e) {
					
					//alert('ouch!');
					myVerticalSlide.slideOut();
				});
				
				
				function greenIt () {
					this.setStyle('background-color', 'white');
					this.setStyle('color', 'red');
				}
				function resetBg () {
					this.setStyle('background-color', 'transparent');
					this.setStyle('color', 'white');
				}
				var navfc = $('nav_fcnews');
				var theUL = $$('#nav_fcnews ul')[0];
				var theContent = $$('#fcnews_content ul')[0];
				if (window.ie6 || window.ie7) 
					theContent.setStyle("margin-top", "8px");
				for (var i = 1; i<= N_ITEMS; i++) {
				
					var xx = new Element('li');
						
					xx.setProperty('id','btn_fc_'+i.toString());
					xx.setHTML(i.toString());
				
					xx.inject(theUL, "bottom");
					var item = new Element("li").setProperty("id", "fcthumb_"+i.toString()).setHTML("<img src='/images/stories/fc_mt_news/fc_news_"+i.toString()+".png' width='175' height='271' />").inject(theContent);
					if (window.ie6 || window.ie7) {
						item.setStyle("margin: 0 0 0 -20");
					}
					item.setStyle("cursor", "pointer");
					item.addEvent("click", function() {doDownload(this)});
					xx.addEvent("click", function (event) {doScroll(this, event)});
				}
				
				function doDownload (item) {
					var namePDF="http://www.fcmatera.it/images/stories/pdf/fcmatera_"+item.getProperty("id").split("_")[1]+".pdf";
					//console.log(name);
					scrollFC_NEWS.fireEvent("mouseleave", null, 500);
					window.open (namePDF, "fc_matera_news_pdf"); 
				}
				links_fc = $$('#nav_fcnews li');
				
				links_fc.each(function (el, i) {el.addEvent('mouseenter', greenIt);el.addEvent('mouseleave', resetBg)});
				var ulWrapper = new Element('div').setStyle('position', 'relative').inject(theUL, 'before').adopt(theUL);
				//ulWrapper.setStyle('width', '100%');
				ulWrapper.setProperty('id','fc_nav_wrapper');
				if (window.ie6 || window.ie7) {
					ulWrapper.setStyle("padding-top", "0px");
					ulWrapper.setStyle("height", "35px");
					ulWrapper.setStyle("margin-top", "12px");
				}
				
				var ulPrev = new Element('div', {'class': 'arrow-prev png'}).setHTML('<span>&lt;</span>').inject(navfc, "top");
				var ulNext = new Element('div', {'class': 'arrow-next png'}).setHTML('<span>&gt;</span>').inject(navfc);
				ulPrev.addEvents({'mouseenter' : greenIt, 'mouseleave' : resetBg});
				ulNext.addEvents({'mouseenter' : greenIt, 'mouseleave' : resetBg});
				ulNext.addEvent('click', function () {scrollNav(theUL.getParent(), true)});
				ulPrev.addEvent('click', function() {scrollNav(theUL.getParent(), false)});
				scrollCont = new Fx.Scroll($('fcnews_content'), {wait:false, duration:1000});
				ffscrol = new Fx.Scroll(theUL.getParent(), {duration:400});
				function doScroll(el, event) {
					event = new Event(event).stop();
					
					var theidx = el.getProperty("id").split("btn_fc_").join("").toInt();
					if (el.blur) el.blur();
					scrollCont.toElement($("fcthumb_"+theidx.toString()));
				}
				function scrollNav (ul, plus) {
					var scrollSize = 380;
				
					scrollAmount= ul.scrollLeft;
					if (plus)
						var scroll = scrollAmount+ 100;
					else 
						var scroll = scrollAmount - 100;
     				scroll = (scroll < 0) ? 0 : (scroll >= scrollSize) ? scrollSize: scroll;
					ffscrol.scrollTo(scroll, 0);
					//scrollNav.start(300,0);
				}
				fc_timer = setTimeout(delayedAdjust, 1800);
				fc_timer2 = setTimeout(delayedAdjust, 5000);
			window.fireEvent("delayed", null, 1800);				
});

function delayedAdjust () {
	fc_timer = null;
	var theItem = "fcthumb_"+N_ITEMS;
	var theB = "btn_fc_"+(N_ITEMS-5);
	scrollCont.toElement(theItem);
	ffscrol.toElement(theB);
};