var width 		= 220;
var height 		= 180;
var animation 	= 'horizontal';
/*
	Available animations:
		-horizontal
		-vertical
		-fade
*/
var slidetime 	= 1000;
var interval 	= 5000;

var children = new Array();
var current = 0;

$(document).ready(function(){
	$('#blogscroller').css('position','relative');
	$('#blogscroller').css('overflow','hidden');
	$('#blogscroller').children().first('ul').css('list-style','none'); //remove list-style
	$('#blogscroller').children().first('ul').css('padding','0px'); //remove list padding
	$('#blogscroller').children().first('ul').css('margin','0px'); //remove list margin
	$('#blogscroller').children().first('ul').css('position','absolute'); //put on top
	$('#blogscroller').children().first('ul').attr('id','scroll_container');	//give list a id
	
	var counter = 0; //variable for assigning children to array
	$('#scroll_container').children('li').each(function(){ //loop for children
		children[counter] = this; //store into array
		
		//getting highest height
		if(parseInt($(this).css('height').replace('px','')) > height)
		{
			height = parseInt($(this).css('height').replace('px',''));
		}
		
		//append correct css
		$(this).attr('class','blogscrollitem');
		$(this).css('position','absolute');
		$(this).css('width',width + 'px');
		
		switch(animation)
		{
			case 'horizontal':
				if(counter != 0) $(this).css('left',width + 'px');
				break;
			case 'vertical':
				if(counter != 0) $(this).css('top',height + 'px');
				break;
			case 'fade':
				if(counter != 0) $(this).css('opacity',0);
				break;
		}	
		
		//increase array ide
		counter++;
	});
	$('#blogscroller').css('width',width + 'px'); //set width
	$('#blogscroller').css('height',height + 'px'); //set height
	setTimeout("scroll()",interval);
});

function scroll()
{
	setTimeout("scroll()",interval);
	switch(animation)
	{
		case 'horizontal':
			return scrollhorizontal();
			break;
		case 'vertical':
			return scrollvertical();
			break;	
		case 'fade':
			return fade();
			break;	
	}
}

function scrollhorizontal()
{
	c = get_current_scroll_item();
	n = get_next_scroll_item();
	var w = (width - (width *2));
	
	$(n).animate({
		left: 0
	},slidetime);
	
	$(c).animate({
		left: w
	},slidetime,function(){
		$(c).css('left',width + 'px');
		if(current == children.length -1)
		{
			current = 0;
		} else current++;
	});
}

function scrollvertical()
{
	c = get_current_scroll_item();
	n = get_next_scroll_item();
	var h = (height - (height *2));
	
	$(n).animate({
		top: 0
	},slidetime);
	
	$(c).animate({
		top: h
	},slidetime,function(){
		$(c).css('top',height + 'px');
		if(current == children.length -1)
		{
			current = 0;
		} else current++;
	});
}

function fade()
{
	c = get_current_scroll_item();
	n = get_next_scroll_item();
	
	$(n).animate({
		opacity: 1
	},slidetime);
	
	$(c).animate({
		opacity: 0
	},slidetime,function(){
		if(current == children.length -1)
		{
			current = 0;
		} else current++;
	});
}

function get_next_scroll_item()
{
	if(current == children.length -1) return $('#scroll_container').children('li').first();
	return children[(current +1)];
}

function get_current_scroll_item()
{
	return children[current];
}


