// global vars
//images_path_np = 'modules/mod_gk_fcs_np_30/images/';
news_amount_np = 0;
news_table_np = [];
actual_news_np = 1;
bao_np = {};
news_width_np = $E('.gk_fcs_np_news_container_main').getStyle('width');
news_height_np = $E('.gk_fcs_np_news_container_main').getStyle('height');
animation_actually_np = false;

// ANIMATION PACK START
animation_pack_conf_np = {
	anims : [],
	anim_1 : {
		first_news_display : 'block',
		rest_news_display : 'block',
		news_float : 'left',
		next : function(){
			if(actual_news_np == news_amount_np){
				actual_news_np = 1;
				ef = new Fx.Scroll($('fcs3_np_overflown'));
				ef.toElement(news_table_np[1] );
			}
			else{
				actual_news_np++;
				ef = new Fx.Scroll($('fcs3_np_overflown'));
				ef.toElement(news_table_np[actual_news_np] );
			}
		},
		prev : function(){
			if(actual_news_np == 1){
				actual_news_np = news_amount_np;
				ef = new Fx.Scroll($('fcs3_np_overflown'));
				ef.toElement(news_table_np[news_amount_np] );
			}
			else{
				actual_news_np--;
				ef = new Fx.Scroll($('fcs3_np_overflown'));
				ef.toElement(news_table_np[actual_news_np] );
			}
		},
		news : function(num){
			actual_news_np = num;
			ef = new Fx.Scroll($('fcs3_np_overflown'));
			ef.toElement(news_table_np[num] );
		}
	},
	anim_2 : {
		first_news_display : 'block',
		rest_news_display : 'block',
		news_float : '',
		next : function(){
			if(actual_news_np == news_amount_np){
				actual_news_np = 1;
				ef = new Fx.Scroll($('fcs3_np_overflown'));
				ef.toElement(news_table_np[1] );
			}
			else{
				actual_news_np++;
				ef = new Fx.Scroll($('fcs3_np_overflown'));
				ef.toElement(news_table_np[actual_news_np] );
			}
		},
		prev : function(){
			if(actual_news_np == 1){
				actual_news_np = news_amount_np;
				ef = new Fx.Scroll($('fcs3_np_overflown'));
				ef.toElement(news_table_np[news_amount_np] );
			}
			else{
				actual_news_np--;
				ef = new Fx.Scroll($('fcs3_np_overflown'));
				ef.toElement(news_table_np[actual_news_np] );
			}
		},
		news : function(num){
			actual_news_np = num;
			ef = new Fx.Scroll($('fcs3_np_overflown'));
			ef.toElement(news_table_np[num] );
		}	
	},
	anim_3 : {
		first_news_display : 'block',
		rest_news_display : 'block',
		news_float : 'left',
		next : function(){
			if(actual_news_np == news_amount_np){
				actual_news_np = 1;
				ef = new Fx.Scroll($('fcs3_np_overflown'),{duration: 1});
				ef1 = new Fx.Style(news_table_np[news_amount_np],'opacity');
				ef2 = new Fx.Style(news_table_np[1],'opacity');
				ef2.set(0);
				ef1.start(1,0);
				(function(){ef.toElement(news_table_np[1]);ef2.start(0,1);}).delay(500);
				(function(){ef1.set(1);}).delay(1000);
			}
			else{
				actual_news_np++;
				ef = new Fx.Scroll($('fcs3_np_overflown'),{duration: 1});
				ef1 = new Fx.Style(news_table_np[actual_news_np-1],'opacity');
				ef2 = new Fx.Style(news_table_np[actual_news_np],'opacity');
				ef2.set(0);
				ef1.start(1,0);
				(function(){ef.toElement(news_table_np[actual_news_np]);ef2.start(0,1);}).delay(500);
				(function(){ef1.set(1);}).delay(1000);
			}
		},
		prev : function(){
			if(actual_news_np == 1){
				actual_news_np = news_amount_np;
				ef = new Fx.Scroll($('fcs3_np_overflown'),{duration: 1});
				ef1 = new Fx.Style(news_table_np[1],'opacity');
				ef2 = new Fx.Style(news_table_np[news_amount_np],'opacity');
				ef2.set(0);
				ef1.start(1,0);
				(function(){ef.toElement(news_table_np[news_amount_np]);ef2.start(0,1);}).delay(500);
				(function(){ef1.set(1);}).delay(1000);
			}
			else{
				actual_news_np--;
				ef = new Fx.Scroll($('fcs3_np_overflown'),{duration: 1});
				ef1 = new Fx.Style(news_table_np[actual_news_np+1],'opacity');
				ef2 = new Fx.Style(news_table_np[actual_news_np],'opacity');
				ef2.set(0);
				ef1.start(1,0);
				(function(){ef.toElement(news_table_np[actual_news_np]);ef2.start(0,1);}).delay(500);
				(function(){ef1.set(1);}).delay(1000);
			}
		},
		news : function(num){
			if(actual_news_np !== num){
				actual_news_np = num;
				ef = new Fx.Scroll($('fcs3_np_overflown'),{duration: 1});
				(num !== 1) ? ef1 = new Fx.Style(news_table_np[num-1],'opacity') : ef1 = new Fx.Style(news_table_np[news_amount_np-1],'opacity');
				ef2 = new Fx.Style(news_table_np[num],'opacity');
				ef2.set(0);
				ef1.start(1,0);
				(function(){ef.toElement(news_table_np[num]);ef2.start(0,1);}).delay(500);
				(function(){ef1.set(1);}).delay(1000);
			}
		}	
	}
}

animation_pack_conf_np.anims = [animation_pack_conf_np.anim_1,animation_pack_conf_np.anim_2,animation_pack_conf_np.anim_3];
// ANIMATION PACK END

// Initialize function
window.addEvent("load",function(){
	// test cookie
	
	// generating base anim object
	bao_np = animation_pack_conf_np.anims[fcs3_np_animation-1];
	
	// preparing divs
	divs_preparing_np(bao_np.first_news_display,bao_np.rest_news_display,bao_np.news_float);
	
	// creating panel with buttons
	code1_np = '<img src="'+template_path+'images/style'+style+'/previous_button.gif" alt="&laquo;" class="prev_button" /> <img src="'+template_path+'images/style'+style+'/next_button.gif" alt="&raquo;" class="next_button" /><img src="'+template_path+'images/style'+style+'/play_button.gif" alt="play" class="play_button" /><img src="'+template_path+'images/style'+style+'/pause_button.gif" alt="pause" class="pause_button" />';
	
	$E('.fcs3_np_panel').setHTML(code1_np);
	$E('.fcs3_np_panel .next_button').addEvent('click',function(){bao_np.next();pause_np();});
	$E('.fcs3_np_panel .prev_button').addEvent('click',function(){bao_np.prev();pause_np();});
	$E('.fcs3_np_panel .play_button').addEvent('click',function(){play_np();});
	$E('.fcs3_np_panel .pause_button').addEvent('click',function(){pause_np();});
	
	// if auto animation enabled
	if(fcs3_np_auto_animation == 1){
		fcs3_np_timer = (function(){bao_np.next();}).periodical(fcs3_np_anim_speed);
		$E('.fcs3_np_panel .play_button').setStyle('display','none');
		animation_actually_np = true;
	}
	else{
		$E('.pause_button').setStyle('display','none');
		animation_actually_np = false;
	}
	
	$$('.fcs3_np_panel img').each(function(element){
		var src = element.src;
		element.addEvent('mouseover',function(){element.src = src.substr(0,((src.length)-1)-3)+'-h.gif';});
		element.addEvent('mouseout',function(){element.src = src.substr(0,((src.length)-1)-3)+'.gif';});
	});

	$E('.gk_fcs_np_news_container_main2').setStyle('width',news_amount_np * news_width_np.toInt() + 'px');
});

function play_np(){
	if(animation_actually_np === false){
		fcs3_np_timer = (function(){bao_np.next();}).periodical(fcs3_np_anim_speed);
		animation_actually_np = true;
		$E('.fcs3_np_panel .pause_button').setStyle('display','block');
		$E('.fcs3_np_panel .play_button').setStyle('display','none');
	}
}

function pause_np(){
	$clear(fcs3_np_timer);
	animation_actually_np = false;
	$E('.fcs3_np_panel .play_button').setStyle('display','block');
	$E('.fcs3_np_panel .pause_button').setStyle('display','none');
}

function divs_preparing_np(fnd,rnd,nf){
	news_amount_np = 0;
	
	document.getElementsBySelector('.gk_fcs_np_news_container').each(function(element){
		// setting news display
		if(news_amount_np == 0){
			news_table_np[news_amount_np+1] = element;
			element.setStyle('display',fnd);
		}
		else{
			news_table_np[news_amount_np+1] = element;
			element.setStyle('display',rnd);
		}
		// setting news float
		element.setStyle('float',nf);
		// increase variable
		news_amount_np++;
	});
}

function fcs3np_change_style(style){
	code1_np = '<img src="'+template_path+'/images/style'+style+'/previous_button.gif" alt="&laquo;" class="prev_button" /> <img src="'+template_path+'images/style'+style+'/next_button.gif" alt="&raquo;" class="next_button" /><img src="'+template_path+'images/style'+style+'/play_button.gif" alt="play" class="play_button" /><img src="'+template_path+'images/style'+style+'/pause_button.gif" alt="pause" class="pause_button" />';
	
	$E('.fcs3_np_panel').setHTML(code1_np);
	$E('.fcs3_np_panel .next_button').addEvent('click',function(){bao_np.next();pause_np();});
	$E('.fcs3_np_panel .prev_button').addEvent('click',function(){bao_np.prev();pause_np();});
	$E('.fcs3_np_panel .play_button').addEvent('click',function(){play_np();});
	$E('.fcs3_np_panel .pause_button').addEvent('click',function(){pause_np();});
	
	// if animation enabled
	if(animation_actually_np){
		fcs3_np_timer = (function(){bao_np.next();}).periodical(fcs3_np_anim_speed);
		$E('.fcs3_np_panel .play_button').setStyle('display','none');
	}
	else{
		$E('.pause_button').setStyle('display','none');
	}
	
	$$('.fcs3_np_panel img').each(function(element){
		var src = element.src;
		element.addEvent('mouseover',function(){element.src = src.substr(0,((src.length)-1)-3)+'-h.gif';});
		element.addEvent('mouseout',function(){element.src = src.substr(0,((src.length)-1)-3)+'.gif';});
	});
}