jQuery(document).ready(function(){
	/* Topnav Dropdown menu.	*/
	$('#topnav ul li').each(function(){
		if($(this).children('ul').length > 0) {
			$(this).addClass('withul');
			$(this).children('a').addClass('withula');
		
			$(this).hover(function(){
				$(this).addClass('withul-hover');
				$(this).children('ul').slideDown(200);
			},function(){
				$(this).removeClass('withul-hover');
				$(this).children('ul').slideUp(100);	
			});
		}
	});
	//fix menu in safari and chrome
	var userAgent = navigator.userAgent.toLowerCase(); 
	$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); 
	// Is this a version of Chrome?
	if($.browser.chrome){
	  // If it is chrome then jQuery thinks it's safari so we have to tell it it isn't
	  $.browser.safari = false;
	  $('#topnav li a ').css('padding-left','16px');
	  $('#topnav li a ').css('padding-right','17px');
	  $('#send-clear').css('margin-left','107px');
	  $('#send-clear').css('margin-top','-22px');
	  $('#send-email').css('margin-top','-20px');
	  $('#send-email').css('margin-left','55px');
	}
	// Is this a version of Safari?
	if($.browser.safari){
	  $('#topnav li a ').css('font-size','14px');
	  $('#topnav li a ').css('padding-left','13px');
	  $('#topnav li a ').css('padding-right','14px');
	  $('#send-clear').css('margin-left','102px');
	  $('#send-clear').css('margin-top','-22px');
	  $('#send-email').css('margin-left','45px');
	  $('#contact-buttons').css('margin-top','-15px');
	}
	//change logo to image with IE6 browser
	if (jQuery.browser.msie && jQuery.browser.version == '6.0') {
		$('#site-title').remove();
		$('#tagline').remove();
	}
	//menu white border
	$('#topnav ul ul li:first-child').css('border-top','1px solid #fff');
	$('.separator:last').css('border-top','none');
	//contact form
	$('form#contactForm').submit(function() {
		$('form#contactForm .error').remove();
		var hasError = false;
		var errorMsg ='';
		$('.requiredField').each(function() {
			if(jQuery.trim($(this).val()) == '') {
				var labelText = $(this).prev('label').text();
				$(this).parent().append('<span class="error">This field is required.</span>');
				hasError = true;
			} else if($(this).hasClass('email')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim($(this).val()))) {
					var labelText = $(this).prev('label').text();
					$(this).parent().append('<span class="error">You entered an invalid email address.</span>');
					hasError = true;
				}
			}
		});
		if(!hasError) {
			$('#response').fadeIn();
			var formInput = $(this).serialize();

			$.post($(this).attr('action'),formInput, function(data){
				$('#loading').slideUp("fast", function() {				   
					$(this).before('<p class="thanks">Your email was successfully sent.</p>');
				});
			});
		}
		return false;
	});
	if($.cookie("modal") != 'true')
    {
		$('#newsletter').fancybox({  
			'transitionIn'		: 'elastic',
			'transitionOut'	: 'elastic',
			'titleShow'			:false,
			'overlayShow'		:false
		}).trigger('click');
         $.cookie("modal", "true", { path: '/', expires: 7 });
    }
	$('.trignewsletter').fancybox({  
			'transitionIn'		: 'elastic',
			'transitionOut'	: 'elastic',
			'titleShow'			:false,
			'overlayShow'		:false
	});
});
