var minFontSize = 6;
var maxFontSize = 25;



jQuery(function() {
	jQuery(".wwtysr-carousel-gallery").jCarouselLite({
		btnNext: ".wwtysr-carousel-right",
		btnPrev: ".wwtysr-carousel-left",
		visible: 3,
		scroll: 3
	});
});



function checkEmail(email)
{
	var filter = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;

	if (!filter.test(email))
		return false;

	return true;
}

jQuery(document).ready(function() {
	initViewMenu();
	initMenu();

	var originalFontSize = jQuery('.article p').css('font-size');

	jQuery("#increaseFontSize").click(function() {
		var currentFontSize = jQuery('.article p').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);

		if ((currentFontSizeNum + 1) <= maxFontSize)
		{
			var newFontSize = currentFontSizeNum + 1;
			newFontSize += 'px';

			jQuery('.article p').css('font-size', newFontSize);
			jQuery('.article').css('font-size', newFontSize);
		}

		return false;
	});

	jQuery("#decreaseFontSize").click(function() {
		var currentFontSize = jQuery('.article p').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);

		if ((currentFontSizeNum - 1) >= minFontSize)
		{
			var newFontSize = currentFontSizeNum - 1;
			newFontSize += 'px';

			jQuery('.article p').css('font-size', newFontSize);
			jQuery('.article').css('font-size', newFontSize);
		}

		return false;
	});

	jQuery("#resetFontSize").click(function(){
		jQuery('.article p').css('font-size', originalFontSize);
		jQuery('.article').css('font-size', originalFontSize);
	});

	jQuery("ul.pagination").each(function() {
		var tmp = jQuery("<div></div>");

		jQuery(this).find("*").wrap("<li></li>");
		jQuery(this).find("li").appendTo(tmp);

		jQuery(this).html("");

		tmp.find("li").appendTo(this);
	});

	jQuery("blockquote > p").each(function() {
		var align = jQuery(this).css("text-align");
		var margin_amt = "10px";

		jQuery(this).parent().css("float", align);

		if (align == "right")
			jQuery(this).parent().css("margin-left", margin_amt);
		else if (align == "left")
			jQuery(this).parent().css("margin-right", margin_amt);
	});

	if (jQuery(".sectionNewsPicture img").size())
	{
		jQuery(".sectionNewsPicture img").each(function() {
			if (!jQuery(this).attr("alt").length && !jQuery(this).attr("title").length)
				return;

			jQuery(this).parent().parent().append("<div class='sectionNewsPictureCaption'></div>");
			jQuery(this).parent().parent().find(".sectionNewsPictureCaption").text(jQuery(this).attr("alt") || jQuery(this).attr("title"));
		});
	}

	jQuery('.lg-polls-submit input[type="submit"]').click(function() {
		if (!jQuery(this).parent().parent().find('.lg-polls-answers:has(input:radio:checked)').size())
		{
			alert("Please make a selection before submitting!");
			return false;
		}

		return true;
	});

	jQuery('.comment-row input[type=submit]').click(function() {
			if (!jQuery('.comment-row input[name=name]').val().length)
			{
				alert("Please enter your name!");

				return false;
			}
			
			if (!jQuery('.comment-row input[name=email]').val().length)
			{
				alert("Please enter your e-mail address!");

				return false;
			}

			if (!checkEmail(jQuery('.comment-row input[name=email]').val()))
			{
				alert("Please enter a valid e-mail address!");

				return false;
			}

			if (!jQuery('.comment-row textarea').val().length)
			{
				alert("Please enter some comments!");

				return false;
			}

			/*
			if (!jQuery('.comment-box input[type=checkbox]').is(':checked'))
			{
				alert("Please agree to the terms of usage!");

				return false;
			}
			*/
	});

	if (jQuery('#email-print a:first').size())
		jQuery('#email-print a:first').facebox();

	if (jQuery('.agreement .toc').size())
		//jQuery('.agreement .toc').facebox();
		jQuery('.agreement .toc').click(function() {
			jQuery.facebox('<div class="terms-of-usage">' + jQuery('#terms-of-usage').html() + '</div>');
		});

	
	jQuery('.toggle-comments').toggle(function() {
		jQuery('.c5t_comment_list').hide();
	}, function() {
		jQuery('.c5t_comment_list').show();
	});

	jQuery('.toggle-form').toggle(function() {
		jQuery('.comment-box').hide();
	}, function() {
		jQuery('.comment-box').show();
	});
});

