
/*
----------------------------------------------------------------------------------------------------
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 : 3
}, 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 liHeight = 40;
var animating = false;
//ul.css( "width", ( li.length * liWidth ) );
ul.css( "height", ( li.length * liHeight ) );
$next.click(function() {
if ( !animating ) {
animating = true;
//offsetLeft = parseInt( ul.css( "left" ) ) - ( liWidth * settings.slideBy );
offsetTop = parseInt( ul.css( "top" ) ) - ( liHeight * settings.slideBy );
if ( offsetTop + ul.height() > 0 ) {
$back.show();
ul.animate({
top: offsetTop
}, settings.speed, function() {
if ( parseInt( ul.css( "top" ) ) + ul.height() <= liHeight * settings.slideBy ) {
}
animating = false;
});
} else {
animating = false;
}
}
return false;
});
$back.click(function() {
if ( !animating ) {
animating = true;
offsetBottom = parseInt( ul.css( "top" ) ) + ( liHeight * settings.slideBy );
if ( offsetBottom + ul.height() <= ul.height() ) {
$next.show();
ul.animate({
top: offsetBottom
}, settings.speed, function() {
if ( parseInt( ul.css( "top" ) ) == 0 ) {

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

$next.show();
jQuery(".description").hide();
jQuery(".thumb").hide();
//jQuery('#list').after( [ "<div class=\"view_all\"><span class=\"count\">", settings.headline, " - ", li.length, " total</span></div>" ].join( "" ) );
jQuery('#list').after( [ "<div class=\"view_all\"></div>" ].join( "" ) );
jQuery( ".back").appendTo('.view_all');
jQuery( ".next").appendTo('.view_all');
var date = jQuery('<div></div>');
//var firstimg = jQuery( "ul li:eq(0) img", $this );
//date.appendTo("#container").html("<p class='date'><strong>TODAY NEWS</strong>: 2009 december 28</p>");
//img = jQuery('<img></img>')
//img.appendTo("#container");
//img.attr('src', firstimg.attr('src'));

var firstli = jQuery( "#newsslider ul li:eq(0)");

var firstlink = jQuery('a.Target', firstli);
var Target = firstlink.attr('href');

//img.wrap('<a href="' + Target + '" />');

para = jQuery('<div></div>');
para.appendTo("#container");
para.html("<p>" +  jQuery('p.description', firstli).html() + "</p>");
//para.html("<h3>" +  jQuery('a.title', firstli ).text() + "</h3>" + "<p id='paraText'>" + jQuery('p.description', firstli).html() + "</p>");
firstli.addClass('selected');
li.hover(
function () {
li.removeClass('selected')
var current = jQuery(this);
current.addClass('selected');
//img.attr('src', current.find('img').attr('src'));

//var link = jQuery('a.Target', current);
//var Target = link.attr('href');
//img.wrap('<a href="' + Target + '" />');

para.html("<p>" +  jQuery('.description', current).html() + "</p>");
//para.html("<h1>" +  jQuery('.title', current).text() + "</h1>" + "<p id='paraText'>" + jQuery('.description', current).html() + "</p>");
},
function () {
current.parent().css('backgroundColor', 'transparent');
}
);
}
};

