// FLASH REPLACEMENT
var myriad = {
  src: 'http://www.frankrocheservices.ie/public/assets/swf/myriad-pro.swf'
};
 
sIFR.activate(myriad);
 
sIFR.replace(myriad, {
      selector: 'h3',
      css: [
      '.sIFR-root { font-size:24px; color: #ffffff; text-align: left;}'
      ],
      wmode: 'transparent'
});

sIFR.replace(myriad, {
      selector: '#enquiry-form h4',
      css: [
      '.sIFR-root { font-size:20px; color: #ffffff; text-align: left;}'
      ],
      wmode: 'transparent'
});

sIFR.replace(myriad, {
      selector: '.product-info h5',
      css: [
      '.sIFR-root { font-size:18px; color: #ffffff; text-align: left;}'
      ],
      wmode: 'transparent'
});

sIFR.replace(myriad, {
      selector: 'h6',
      css: [
      '.sIFR-root { font-size:16px; color: #ffffff; text-align: left;}'
      ],
      wmode: 'transparent'
});

$(function ()
{
	// DROPDOWNS
	$("#nav ul.sf-menu").superfish(); 
	
	// GALLERY THUMBNAIL SWAPPER
	if ($('.thumbs a'))
	{
		$('.thumbs a').click(function() 
		{
			$('.product-img img#big-photo').attr('src', $(this).attr('href') ).fadeIn("slow");
			return false;
		});
	}
	
	// NEWSTICKER
	if (!$.browser.msie) 
	{
		$("#ticker").jticker({
			delay: 5000,
			newwindow: false,
			url: "http://www.frankrocheservices.ie/index.php?rss.xml",
			transition: "fade",
			speed: "normal"
		});
	}
	
	// EXTERNAL LINKS
	$('A[rel="external"]').click(function()
	{
		window.open($(this).attr('href'));
		return false;
	});
	
	// SMALL ENQUIRY FORM VALIDATION
	if ($('#small-enquiry-form'))
	{
		$('input[name="commit_small"]').click(function()
		{
			var verdict		= true;
			
			// VALIDATE NAME
			var name		= $.trim($("#name").val());
			$('#name').attr('value', name);
			
			// VALIDATE EMAIL
			var emailReg	= /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
			var email		= $.trim($("#email").val());
			$('#email').attr('value', email);
			
			// VALIDATE PHONE
			var phoneReg	= /^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$/;
			var phone		= $.trim($("#phone").val());
			$('#phone').attr('value', phone);
			
			if (name == '') {
				$("#small-enquiry-form").fadeOut('slow', function() {
					$("#small-enquiry-form em").replaceWith('<em class="error">Name is required.</em>');
					$("#small-enquiry-form").fadeIn('slow');
				});
				verdict = false;
			} else if (email == '') {
				$("#small-enquiry-form").fadeOut('slow', function() {
					$("#small-enquiry-form em").replaceWith('<em class="error">Email is required</em>');
					$("#small-enquiry-form").fadeIn('slow');
				});
				verdict = false;
			} else if (!emailReg.test(email)) {
				$("#small-enquiry-form").fadeOut('slow', function() {
					$("#small-enquiry-form em").replaceWith('<em class="error">Check your email</em>');
					$("#small-enquiry-form").fadeIn('slow');
				});
				verdict = false;
			} else if (phone == '') {
				$("#small-enquiry-form").fadeOut('slow', function() {
					$("#small-enquiry-form em").replaceWith('<em class="error">Phone is required.</em>');
					$("#small-enquiry-form").fadeIn('slow');
				});

				verdict = false;
			} else if (!phoneReg.test(phone)) {
				$("#small-enquiry-form").fadeOut('slow', function() {
					$("#small-enquiry-form em").replaceWith('<em class="error">Check your phone number</em>');
					$("#small-enquiry-form").fadeIn('slow');
				});
				verdict = false;
			}
		
			return verdict;
		});
	}

});
