var testimonialsHeights = new Hash();
var selectedTestimonial = 0;
var isTestimonialSelectionBusy = false;
var selectedTestimonialWrapper;
//====================================
function hideTestinonialMore(obj)
{
    obj.getNext().className = 'main_job_more hidden';
    isTestimonialSelectionBusy = false;
}
//====================================
function showTestimonialMore(obj)
{
    obj.getNext().className = 'main_job_more';
    isTestimonialSelectionBusy = false;
}
//====================================
window.addEvent('domready', function() {

        $$('.testimonial_container').each( function ( obj ) {
             var testimonial_wrapper = obj.getFirst();
             var testimonial_content = testimonial_wrapper.getFirst().getLast();
             var more_div = obj.getLast();
             var wrap_height = testimonial_content.getStyle('height');
		     wrap_height = wrap_height.substring(0, wrap_height.length-2)*1;
		     if (wrap_height > 60)
		     {
		         more_div.className = 'main_job_more';
		         testimonialsHeights.set(obj.id, wrap_height);
		     }

		     //select testimonial
		     obj.addEvent('click', function() {
                     if (isTestimonialSelectionBusy) {return;}
			         var testimonialId = obj.id.substring(22, obj.id.length)*1;
			         if (selectedTestimonial != testimonialId)
			         //select
			         {
				         if ((selectedTestimonial != 0) && (testimonialsHeights.get('testimonial_container_'+selectedTestimonial) != null))
				         {
				             var jobsMoreEffects = new Fx.Tween(selectedTestimonialWrapper, {duration: 500, transition: Fx.Transitions.Cubic.easeInOut, onComplete: showTestimonialMore});
				             isTestimonialSelectionBusy = true;
				             jobsMoreEffects.start('height', '60px');
				         }
				         if( testimonialsHeights.get(obj.id) != null)
				         {
				             var jobsMoreEffects = new Fx.Tween(testimonial_wrapper, {duration: 500, transition: Fx.Transitions.Cubic.easeInOut, onComplete: hideTestinonialMore});
				             isTestimonialSelectionBusy = true;
				             jobsMoreEffects.start('height', testimonialsHeights.get(obj.id)+'px');
				         }
				         selectedTestimonial = testimonialId;
				         selectedTestimonialWrapper = testimonial_wrapper;
			         }
			         else
			         //unselect
			         {
				         if( testimonialsHeights.get(obj.id) != null)
				         {
				             var jobsMoreEffects = new Fx.Tween(testimonial_wrapper, {duration: 500, transition: Fx.Transitions.Cubic.easeInOut, onComplete: showTestimonialMore});
				             isTestimonialSelectionBusy = true;
				             jobsMoreEffects.start('height', '60px');
				         }
				         selectedTestimonial = 0;
				         selectedTestimonialWrapper = null;
			         }

		     });
        });


        $$('.main_job_more').each( function ( obj ) {
	 	     obj.addEvent('mouseover', function () {
	             obj.setStyle('text-decoration','underline');
	         });

	         obj.addEvent('mouseout', function () {
	             obj.setStyle('text-decoration','none');
	         });

        });
});