var size = "12px";
var counter = 0;

$(document).ready(function(){
$(".main").each(function() {
counter = counter +1;
var dot = 0;
var counti = 0;
var i = 0;
var fulltext = $(this).html();
var total = fulltext.length;
var sub_fulltext = fulltext.substr(0,150);

var len = sub_fulltext.length;

for(i=len;i>0;i--)
{
	if(dot != 1)
	{
	
	if(sub_fulltext.substr(i,1) == ". ")
	{
	dot = 1;
	counti = i;
	}
	
	}
}
if(counti == 0) {
	for(i=len;i>0;i--)
	{
    		if(dot != 1)
    		{
    			if(sub_fulltext.substr(i,1) == " ")
    		{
    		dot = 1;
    		counti = i;
    	}
    
    }
}
}

var view_text = sub_fulltext.substr(0,counti+1);
var more_text = fulltext.substr(counti+1,total);
$(this).html("<div  class='text'>"+view_text+"</div>"+"<div style='display: none' class='reveal'>"+more_text+"</div>"+"<a href='#' class='show'>More...</a>");
});

		//VIEW MORE
		$("a.show").click(function(){
			var text = $(this).text();
			
			var attr = $(this).prev("div").css('display');
			
			$(this).text(
			text == "Less..." ? "More..." : "Less...");
			
			if(attr == "none") {
				$(this).prev("div").slideDown();
			} else {
				$(this).prev("div").slideUp();
			}
			
			return false;
		});

	//Cookies stored for text size.
	$('ul#sizes a').click(function (){
		size = $(this).attr("id");
		$.cookie('size', size, { path: '/', expires: 14 });
		$("div#page").css('font-size', size);
	});
	if ($.cookie('size')) {
		size = $.cookie('size');
	}
	$("div#page").css('font-size', size);
	var global = "1";
	// initialize scrollable together with the autoscroll plugin
	var root = $(".scrollable").scrollable({circular: true, onSeek : function() {
var temp = this.getIndex() + 1;

if(temp != global){ 
		
	$("#caption" + temp).show("slide", { direction: "down" }, 500);
	$("#caption" + global).fadeOut(500);

       // $("#caption" + temp).fadeIn("fast");
       // $("#caption" + global).fadeOut("fast");
        global = temp;
        } 
        else {
        //$("#caption" + temp).fadeOut("fast");
        //$("#caption" + global).fadeIn("fast");	

	$("#caption" + temp).fadeOut(500);
	$("#caption" + global).show("slide", { direction: "down" }, 500);
        }
}, onBeforeSeek : function() {}

}).navigator().autoscroll(6000).navigator("#main_navi");
	
	// provide scrollable API for the action buttons
	window.api = root.data("scrollable");
		
});
