$(document).ready(function(){

	// gallery images
	var current_image = 0;
	getPage();
	
	$('.archive_btSubmit').live('click', function(){
		getPage();
		return false;
	});
	
	$('#archive-btLeft a').live('click', function(){
		image_count = $('.archive-galleryImage').size();
		if(current_image>=1) 
			current_image--;
		else current_image = image_count-1;
		$('.archive-galleryImage').hide();
		$('.archive-galleryImage:eq('+current_image+')').show();
		return false;
	});
	$('#archive-btRight a').live('click', function(){
		image_count = $('.archive-galleryImage').size();
		if(current_image<(image_count-1)) 
			current_image++;
		else current_image = 0;
		$('.archive-galleryImage').hide();
		$('.archive-galleryImage:eq('+current_image+')').show();
		return false;	
		return false;
	});
	
	// hover buttons
	$('.hover').hover(function(){
	   var new_img = $(this).attr('src').substr(0, $(this).attr('src').length-4)+"_on.gif";
	   $(this).attr('src', new_img);
	}, function(){
 	   var new_img = $(this).attr('src').substr(0, $(this).attr('src').length-7)+".gif";
 	   $(this).attr('src', new_img);
	});

});

function textAnimate()
{
	
	var duration = $('#archive-testimonialsScroller').height() / 0.01;

	$('#archive-testimonialsScroller').hide().css('top', '90px').show();
	$('#archive-testimonialsScroller').animate({
		top: (-$('#archive-testimonialsScroller').height())
		}, duration, "linear", function(){
			textAnimate();
		});
}

function textAnimate2()
{
	var duration2 = $('#archive-participantsScroller').height() / 0.01;

	$('#archive-participantsScroller').hide().css('top', '90px').show();
	$('#archive-participantsScroller').animate({
		top: (-$('#archive-participantsScroller').height())
		}, duration2, "linear", function(){
			textAnimate2();
		});
}

function getPage(){
	
	// id and language of requested doc
	var id = $('#archive_list').val();
	var lang = $('#archive-langID').val();

	// ajax call
	$.ajax({
		type: "POST",
		url: 'http://ibhouse.net/assets/snippets/archive/ajax.php',
		data: 'id='+id+'&lang='+lang,
		success: function(data){
			current_image = 0;
			$('#archive-wrapper').html(data);
			$('.archive-galleryImage:gt(0)').hide();
			textAnimate();
			textAnimate2();
		},
		error: function(){
			alert('Sorry, we are experiencing technical problems. Please, come back later.')
		}
	});

}