// JavaScript Document
var itemsshown = 2;
var curritem = 0;
var maxitems = 0;
var socialcontainer = "social-items-container";
var currtop = 0;

function init(){
	var counter = 0;
	
	$(socialcontainer).getChildren().each(function(el){
		if(counter > (itemsshown-1)){
			el.setStyle('opacity', '0');
		}
		
		counter++;
	});
	
	maxitems = counter-1;
	
	if(curritem == 0){
		$("moveprev").addClass('moveprevdisabled');
		$("moveprev").removeClass('moveprev');
	}
	
	if(maxitems <= itemsshown){
		$("movenext").addClass('movenextdisabled');
		$("movenext").removeClass('movenext');
	}
}

function moveprev(){
	if(curritem > 0){
		$(socialcontainer).getChildren()[curritem+1].tween('opacity',0);
		$(socialcontainer).getChildren()[curritem-1].tween('opacity',1);

		currtop += parseInt($(socialcontainer).getChildren()[curritem-1].getStyle('height').replace("px",""))+20;
		$(socialcontainer).tween('top',currtop);

		curritem--;
	}

	if(curritem == 0){
		$("moveprev").addClass('moveprevdisabled');
		$("moveprev").removeClass('moveprev');
	}

	if(curritem < maxitems && maxitems > itemsshown){
		$("movenext").removeClass('movenextdisabled');
		$("movenext").addClass('movenext');
	}

	return false;
}

function movenext(){
	if((curritem+itemsshown) <= maxitems){
		$(socialcontainer).getChildren()[curritem+itemsshown].tween('opacity',1);
		$(socialcontainer).getChildren()[curritem].tween('opacity',0);

		currtop -= parseInt($(socialcontainer).getChildren()[curritem].getStyle('height').replace("px",""))+20;
		$(socialcontainer).tween('top',currtop);
		
		curritem++;
	}
	
	if((curritem+itemsshown) > maxitems){
		$("movenext").addClass('movenextdisabled');
		$("movenext").removeClass('movenext');
	}
	
	if(curritem > 0){
		$("moveprev").removeClass('moveprevdisabled');
		$("moveprev").addClass('moveprev');
	}

	return false;
}
