function check_length(id, maxLen) {
	//maxLen = sz; // max number of characters allowed
	var doc = document.getElementById(id);
	if (doc.value.length >= maxLen) {
		// Alert message if maximum limit is reached.
		// If required Alert can be removed.
		var msg = "You have reached the maximum limit of characters allowed";
		alert(msg);
		// Reached the Maximum length so trim the textarea
		doc.value = doc.value.substring(0, maxLen);
	} else {
		// Maximum length not reached so update the value of my_text counter
		document.getElementById('txt_num').value = (maxLen - doc.value.length)-1;
	}
}

$(document).ready( function () {

	$("a.zoom").fancybox();

	
	//	#	BANNERS
	
    bannerStartIdx = 1;
	bannerPath = "img/imgV1-iface-20100107/banner/";
	var bannerTimer = {};
	
    $("#banner1").click(function () {
		var newImageSource = $(this).find("a").attr("title");
			$("#bannerSection").find("img").attr("src", newImageSource);
		
		var newImageAlt = $(this).find("img").attr("alt");
			$("#bannerSection").find("img").attr("alt", newImageAlt);

		resetBannerNumbers(  );
		stopSlideTimer( 1 );
		$(this).find("img").attr("src", bannerPath+"1_on.png");
		bannerStartIdx = 2;
	});
	
    $("#banner2").click(function () {
		var newImageSource = $(this).find("a").attr("title");
			$("#bannerSection").find("img").attr("src", newImageSource);
		
		var newImageAlt = $(this).find("img").attr("alt");
			$("#bannerSection").find("img").attr("alt", newImageAlt);

		resetBannerNumbers(  );
		stopSlideTimer( 2 );
		$(this).find("img").attr("src", bannerPath+"2_on.png");
		bannerStartIdx = 3;
		
	});
	
    $("#banner3").click(function () {
		var newImageSource = $(this).find("a").attr("title");
			$("#bannerSection").find("img").attr("src", newImageSource);
		
		var newImageAlt = $(this).find("img").attr("alt");
			$("#bannerSection").find("img").attr("alt", newImageAlt);

		resetBannerNumbers(  );
		stopSlideTimer( 3 );
		$(this).find("img").attr("src", bannerPath+"3_on.png");
		bannerStartIdx = 4;
	});

    $("#banner4").click(function () {
		var newImageSource = $(this).find("a").attr("title");
			$("#bannerSection").find("img").attr("src", newImageSource);
		
		var newImageAlt = $(this).find("img").attr("alt");
			$("#bannerSection").find("img").attr("alt", newImageAlt);

		resetBannerNumbers(  );
		stopSlideTimer( 4 );
		$(this).find("img").attr("src", bannerPath+"4_on.png");
		bannerStartIdx = 5;
	});

    $("#banner5").click(function () {
		var newImageSource = $(this).find("a").attr("title");
			$("#bannerSection").find("img").attr("src", newImageSource);
		
		var newImageAlt = $(this).find("img").attr("alt");
			$("#bannerSection").find("img").attr("alt", newImageAlt);

		resetBannerNumbers(  );
		stopSlideTimer( 5 );
		$(this).find("img").attr("src", bannerPath+"5_on.png");
		bannerStartIdx = 6;
	});	 
    
    $("#banner6").click(function () {
		var newImageSource = $(this).find("a").attr("title");
			$("#bannerSection").find("img").attr("src", newImageSource);
		
		var newImageAlt = $(this).find("img").attr("alt");
			$("#bannerSection").find("img").attr("alt", newImageAlt);

		resetBannerNumbers(  );
		stopSlideTimer( 6 );
		$(this).find("img").attr("src", bannerPath+"6_on.png");
		bannerStartIdx = 7;
	});	 

	function resetBannerNumbers(  ) {

		$("#banner1").find("img").attr("src", bannerPath+"1_off.png");
		$("#banner2").find("img").attr("src", bannerPath+"2_off.png");
		$("#banner3").find("img").attr("src", bannerPath+"3_off.png");
		$("#banner4").find("img").attr("src", bannerPath+"4_off.png");
		$("#banner5").find("img").attr("src", bannerPath+"5_off.png");
		$("#banner6").find("img").attr("src", bannerPath+"6_off.png");
		
		
		
	}
	
	function slideBanner( num ) {
		var newImageSource = $("#banner"+num).find("a").attr("title");
		$("#bannerSection").find("img").attr("src", newImageSource);
		
		var newImageAlt = $(this).find("img").attr("alt");
			$("#bannerSection").find("img").attr("alt", newImageAlt);
	
		//alert(number);
		resetBannerNumbers(  );
		$("#banner"+num).find("img").attr("src", bannerPath+num+"_on.png");
		//bannerStartIdx = Number(number);
	}

	function startBannerSlide( num ) {
		
		if ( $("#banner").find("div.photo").find("#banner"+num) ) {
			bannerStartIdx++;
			if ( bannerStartIdx > 6 )
				bannerStartIdx = 1;
				
			slideBanner( num );
			
			bannerTimer = $.timer(5000, function() {
				startBannerSlide( bannerStartIdx );
			});
		} else {
			bannerStartIdx = 1;
			startBannerSlide( bannerStartIdx );
		}
		
	}
	
	function stopSlideTimer( num ) {
//		$("#banner").stop();
		bannerStartIdx = num;
		
		$.clearTimer(bannerTimer);
		
		bannerTimer = $.timer(8000, function() {
			startBannerSlide( bannerStartIdx );
		});
		//startBannerSlide( bannerStartIdx );		
	}

	startBannerSlide(1);

	
	//	#	TESTIMONIALS
	
	$("#prevQuote").click( function() {
		counter = 1;
		$("#quoteSection").find("div").each(function(i) {
			if ( counter > 0 ) {
				id = $(this).attr("id");
				if ( $("#"+id).css("display") === "block" ) {
					findId = id.split("_");
					findPrev = parseInt(findId[1])-1;
					if ( $("#testimonial_"+findPrev).length > 0 ) {
						$("#testimonial_"+findPrev).css("display", "block");
						$("#"+id).css("display", "none");
						$("#nextQuote").css("display", "block");
						if ( $("#testimonial_"+(parseInt(findPrev)-1)).length === 0 )
							$("#prevQuote").css("display", "none");
					} else {
						$("#prevQuote").css("display", "none");
					}
					counter--;
				}
			}
		});
	});

	$("#nextQuote").click( function() {
		counter = 1;
		$("#quoteSection").find("div").each(function(i) {
			if ( counter > 0 ) {
				id = $(this).attr("id");
				if ( $("#"+id).css("display") === "block" ) {
					findId = id.split("_");
					findNext = parseInt(findId[1])+1;
					if ( $("#testimonial_"+findNext).length > 0 ) {
						$("#testimonial_"+findNext).css("display", "block");
						$("#"+id).css("display", "none");
						$("#prevQuote").css("display", "block");
						if ( $("#testimonial_"+(parseInt(findNext)+1)).length === 0 )
							$("#nextQuote").css("display", "none");
					} else {
						$("#nextQuote").css("display", "none");
					}
					counter--;
				}
			}
		});
	});
	
	
	function startTestimonial() {
		$("#testimonial_0").css("display", "block");
		$("#prevQuote").css("display", "none");
	}
	startTestimonial();
	
	
	$("#usePreWritten").click( function() {
		$("textarea[@name='msg']").val('Thank you for showing me kindness.  It made my day!');
		var msg = $("textarea[@name='msg']").val();
		$("input[@name='txt_num']").val( (2000 - msg.length) );
	});
	
});
