
/** BANNER **/

function Banners() {
  // Private property

  return {
	activeBanner: $('#topbannerimg1'),
	timer: null,
	init: function() {
	
	},
	showNextBanner: function () {
		var activeBanner=null;
		var nextBanner=null;
		var foundActiveBanner = false;
		$.each($('div.banner'), function(index, value) {
			if(index == 0) {
				nextBanner = $(this);
			}
			if ($('div.banner').get(index).style.display == "block" || $('div.banner').get(index).style.display == "") {
				foundActiveBanner = true;
				activeBanner = $(this);
			} else if(foundActiveBanner) {
				nextBanner = $(this);
				foundActiveBanner = false;
			}
		});
		this.activeBanner = nextBanner;
		this.fadeDivs(activeBanner,nextBanner);
		this.showActiveButton();
		
	},
	showActiveButton: function () {
		var activeBanner = banners.activeBanner.attr('id');
		$.each($('div.testimonial'), function(index, value) {
			$(this).hide();
		});
		$.each($('div.banners').find('div.button'), function(index, value) {
			$(this).removeClass('buttonHover');
			if($(this).attr('banner') == activeBanner) {
				$(this).addClass('buttonHover');
				$('#' + $(this).attr('testimonial')).show();
			}
		});
		
	},
	fadeDivs: function (from,to) {
		from.fadeOut("slow");  
		to.fadeIn("slow");
	}
  };
}

var banners=null;
$(window).load(function() {
	banners = new Banners();
	banners.init();		
			
	banners.timer = $.timer(function() {
		banners.showNextBanner();
		showNextTestimonial();
	});


	banners.timer.set({ time : 6000, autostart : true });

	$.each($('div.banners').find('div.button'), function(index, value) {
		$(this).bind('click', function() {
			banners.fadeDivs(banners.activeBanner,$('#' +$(this).attr('banner')));
			banners.activeBanner = $('#' +$(this).attr('banner'));
			banners.showActiveButton();
		});
	});

	
	$("div.banners").bind("mouseover", function() {
		banners.timer.pause();
	}).bind("mouseout", function() {
		banners.timer.reset();
	});
});
	



/** TESTIMONIALS **/
//var timer = $.timer(function() {
//		showNextTestimonial();
//});

//timer.set({ time : 2000, autostart : true });
$(window).load(function() {
	$("#testimonials").bind("mouseover", function() {
		banners.timer.pause();
	}).bind("mouseout", function() {
		banners.timer.reset();
	});
});


function showNextTestimonial() {
	var activeTestimonial=null;
	var nextTestimonial=null;
	var firstTestimonial=null;
	var foundActiveTestimonial = false;
	$.each($('div.testimonial'), function(index, value) {
		if(index == 0) {
			nextTestimonial = $(this);
		}
		if ($('div.testimonial').get(index).style.display == "block" || $('div.testimonial').get(index).style.display == "") {
			foundActiveTestimonial = true;
			activeTestimonial = $(this);
		} else if(foundActiveTestimonial) {
			nextTestimonial = $(this);
			foundActiveTestimonial = false;
		}
	});
	
	fadeDivs(activeTestimonial,nextTestimonial);
	
}

function fadeDivs(from,to) {
	from.fadeOut("slow");  
	to.fadeIn("slow");
	}


/** LOGO BANNER **/

$(window).load(function() {

			$("div#logoParade").smoothDivScroll({ 
					autoScrollingInterval: 45,
					autoScrollingStep: 1,
					autoScrollingMode: "",
					autoScrollingDirection: "endlessloopright"
			});
			
			$("div#logoParade").smoothDivScroll("startAutoScrolling");
			
		
			// Logo parade
			$("div#logoParade").bind("mouseover", function() {
				$("div#logoParade").smoothDivScroll("stopAutoScrolling");
			}).bind("mouseout", function() {
				$("div#logoParade").smoothDivScroll("startAutoScrolling");
				$("#logoParade").find("div.logo1 a").removeClass("hover");
			});

	});
