/*
----------------------------------------------------------------------------------------------------
Accessible News Slider
----------------------------------------------------------------------------------------------------
Author:
Brian Reindel, modified and adapted by Andrea Ferracani

Author URL:
http://blog.reindel.com, http://www.micc.unifi.it/ferracani

License:
Unrestricted. This script is free for both personal and commercial use.
*/

jQuery.fn.accessNews = function( settings ) {
settings = jQuery.extend({
headline : "Top Stories",
speed : "normal",
slideBy : 2
}, settings);
return this.each(function() {
jQuery.fn.accessNews.run( jQuery( this ), settings );
});
};

jQuery.fn.accessNews.run = function( $this, settings ) {
jQuery( ".javascript_css", $this ).css( "display", "none" );
var ul = jQuery( "ul:eq(0)", $this );
var li = ul.children();
if ( li.length > settings.slideBy ) {
var $next = jQuery( ".next > a", $this );
var $back = jQuery( ".back > a", $this );
var liWidth = jQuery( li[0] ).width();
var animating = false;
ul.css( "width", ( 270 ) );
$next.click(function() {
if ( !animating ) {
animating = true;
offsetLeft = parseInt( ul.css( "left" ) ) - ( liWidth * settings.slideBy );
if ( offsetLeft + ul.width() > 0 ) {
$back.show();
ul.animate({
left: offsetLeft
}, settings.speed, function() {
if ( parseInt( ul.css( "left" ) ) + ul.width() <= liWidth * settings.slideBy ) {
}
animating = false;
});
} else {
animating = false;
}
}
return false;
});
$back.click(function() {
if ( !animating ) {
animating = true;
offsetRight = parseInt( ul.css( "left" ) ) + ( liWidth * settings.slideBy );
if ( offsetRight + ul.width() <= ul.width() ) {
$next.show();
ul.animate({
left: offsetRight
}, settings.speed, function() {
if ( parseInt( ul.css( "left" ) ) == 0 ) {

}
animating = false;
});
} else {
animating = false;
}
}
return false;
});

$next.show();
jQuery(".description").hide();
jQuery(".date").hide();
jQuery( ".back").appendTo('.view_all');
jQuery( ".next").appendTo('.view_all');
var date = jQuery('<div></div>');

para = jQuery('<div class="przytnij_duze"></div>');
para.appendTo("#container");

var firstimg = jQuery( "ul li:eq(0) img", $this );
img = jQuery('<img></img>')
img.appendTo(".przytnij_duze");
img.attr('src', firstimg.attr('src'));



para = jQuery('<div></div>');
para.appendTo("#container");
var firstli = jQuery( "#newsslider ul li:eq(0)");
para.html('<div id="tlo_text"><p id="paraText"><p class="date">' + jQuery('p.date', firstli).html() + "</p>" + jQuery('p.description', firstli).html() + "</p></div>");
firstli.addClass('selected');
li.hover(
function () {
li.removeClass('selected')
var current = jQuery(this);
current.addClass('selected');
img.attr('src', current.find('img').attr('src'));
para.html('<div id="tlo_text"><p id="paraText"><p class="date">' + jQuery('p.date', current).html() + "</p>" + jQuery('.description', current).html() + "</p></div>");
},
function () {
current.parent().css('backgroundColor', 'transparent');
}
);
}
};
