$(document).ready(function( ){
	
	$("#testemonials_box").myscroll("testemonials_box", true);
	$("#press_and_media_box").myscroll("press_and_media_box", false);
	
	$.Placeholder.init();
	
});

jQuery.fn.myscroll = function(root_div, auto)
{
	var root;
	var next_button;
	var prev_button;
	var group_items;
	var next_index;
	var timer;
	
	var items = new Array();
	var current_index=0;
	
	var is_locked=false;
	
	if (auto) {
		timer = setInterval(go_next, 7000);
	}
	
	init();
	
	function init()	{
		root = $("#"+root_div);
		
		next_button =  root.find(".title .scroll_next");
		prev_button =  root.find(".title .scroll_prev");
		group_item = root.find("#items");
		
		group_item.children().each (function(){
			items.push($(this).attr("id"));
		});
		
		next_button.click(function()	{
			if (!is_locked) 
				go_next();
		});
		
		prev_button.click(function()	{
			if (!is_locked)
				go_prev();
		});
		
		show_current();
		
		
	}
	
	function go_next()	{
		
		if (items.length <= (current_index+1))	{
			next_index = 0;
			
		} else {
			next_index = current_index + 1;
		}
		
		is_locked=true;
		var current_name = items[current_index];
		
		//$("#" + current_name).hide();
		$("#" + current_name).fadeOut("fast", function(){
			current_index = next_index;
			
			show_current();
		});
	}
	
	function go_prev()	{
		
		if (current_index == 0)	{
			next_index = items.length-1;
		}else {
			next_index = current_index - 1;
		}
		
		is_locked=true;
		var current_name = items[current_index];
	
		$("#" + current_name).fadeOut("fast", function(){
			current_index = next_index;
			
			show_current();
		});
	
	}
	
	function show_current()	{
	
		var current_name = items[current_index];
		
		$("#" + current_name).fadeIn("fast", function(){
			
			is_locked=false;
		});
		
	}
};
