var navSlideShow;
var page = 0;
var authPopup = '';
document.addEvent('domready', function(){
	
	// cache the navigation elements
	var navs = $('navigation-slideshow').getElements('a');
	// create a basic slideshow
	navSlideShow = new SlideShow('navigation-slideshow', {
		selector: 'div.slideDiv', // only create slides out of the images
		onShow: function(data){
			// update navigation elements' class depending upon the current slide
			navs[data.previous.index].removeClass('current');
			navs[data.next.index].addClass('current');
		},
		autoplay: true,
		transition: 'pushLeft'
	});
	navs.each(function(item, index){
		// click a nav item ...
		item.addEvent('click', function(event){
			event.stop();
			// pushLeft or pushRight, depending upon where
			// the slideshow already is, and where it's going
			var transition = (navSlideShow.index < index) ? 'pushLeft' : 'pushRight';
			// call show method, index of the navigation element matches the slide index
			// on-the-fly transition option
			navSlideShow.show(index, {transition: transition});
		});
	});
	
	$$('div.slideShowTextBackground').each(function(it){
		it.setStyle('opacity', .4);
	});
	
	
	
	// next & prev news
	newsPages = $$('div.oneNewsPage');
	nbNewsPages = newsPages.length;
	if(nbNewsPages > 1){
		$('prevNews').setStyle('display', '');
		$('prevNews').addEvent('click', function(){
			$('newsPage'+page).setStyle('display', 'none');
			page ++;
			if(page == nbNewsPages-1){$('prevNews').setStyle('display', 'none');}
			$('nextNews').setStyle('display', '');
			$('newsPage'+page).setStyle('display', '');
		});
		$('nextNews').addEvent('click', function(){
			$('newsPage'+page).setStyle('display', 'none');
			page --;
			if(page == 0){$('nextNews').setStyle('display', 'none');}
			$('prevNews').setStyle('display', '');
			$('newsPage'+page).setStyle('display', '');
		});
	}
	
	
	makeScrollbar( $('content1'), $('scrollbar1'), $('handle1') );
	
	if($('content2Table').getCoordinates().height > 411){
		makeScrollbar( $('content2'), $('scrollbar2'), $('handle2') );
	}else{
		$('content2').setStyle('width', '237px');
		$$('.datesInfosTD').each(function(td){
			td.setStyle('width', '232px');
		});
		$('content2Table').setStyle('width', '237px');
		$('scrollbar2').setStyle('display', 'none');
		$('handle2').setStyle('display', 'none');
	}
	/*
	$$('input[rel]').each(function(el){   
	    var prompt = el.get('rel');
	    var pass = el.get('type') == 'password';
	    el.addEvents({
	        focus: function(){
	            if (el.get('value') == prompt){
	                el.set({value:'','class':''});
	                if (pass) el.set('type','password');
	            }
	        },
	        blur: function(){
	            var val = el.get('value')
	            if (!val || val == prompt){
	               el.set({value:prompt,'class':'prompt'});
	               if (pass) el.set('type','text');
	            }
	        }
	    }).fireEvent('blur');
	});
*/
	authPopup = new Popup(SokleSingleton.config.baseURL+SokleSingleton.config.templateURL+"/pages/home/radio.html", {
    	'width':367,
    	'height':300,
    	'x':'center', 
    	'y':'center' 
	});
	
	$('radioSoyouz').addEvent('click', function(){
		authPopup.open();
	});
	
});


    function makeScrollbar (content,scrollbar,handle,horizontal,ignoreMouse){
    	var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
    	slider = new Slider(scrollbar, handle, {	
			steps: steps,
    		mode: (horizontal?'horizontal':'vertical'),
    		onChange: function(step){
    			// Scrolls the content element in x or y direction.
    			var x = (horizontal?step:0);
    			var y = (horizontal?0:step);
    			content.scrollTo(x,y);
    		}
    	}).set(0);
    	/*if( !(ignoreMouse) ){
    		// Scroll the content element when the mousewheel is used within the 
    		// content or the scrollbar element.
    		$$(content, scrollbar).addEvent('mousewheel', function(e){
    			e = new Event(e).stop();
    			var step = slider.step - e.wheel * 30;	
    			slider.set(step);					
    		});
    	}*/
    	// Stops the handle dragging process when the mouse leaves the document body.
    	//$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
    }

