//Set fonts family with Cufon
Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('h6');
Cufon.replace('#footer_grid1 h4'); 
Cufon.replace('#footer_grid2 h3');
Cufon.replace('#footer_grid3 h4'); 
Cufon.replace('#callout_content h3');
//Cufon.replace('#navigation li');

$(document).ready(function() {
   
   //Jcycle slides
   $('#pics').cycle({ 
    fx:    'fade', 
    pause:  1 
	});
	
	var timeout    = 500;
	var closetimer = 0;
	var ddmenuitem = 0;

	function nefnav_open()
	{  nefnav_canceltimer();
	   nefnav_close();
	   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

	function nefnav_close()
	{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

	function nefnav_timer()
	{  closetimer = window.setTimeout(nefnav_close, timeout);}

	function nefnav_canceltimer()
	{  if(closetimer)
	   {  window.clearTimeout(closetimer);
		  closetimer = null;}}

	$('#nefnav > li').bind('mouseover', nefnav_open)
	$('#nefnav > li').bind('mouseout',  nefnav_timer)

	document.onclick = nefnav_close;
	
	//Superfish the menu
   //$('ul.sf-menu').superfish({ 
   //     delay:       500,                              // one second delay on mouseout 
   //     animation:   {opacity:'show', height:'show'},  // fade-in and slide-down animation 
   //     speed:       'fast',                           // faster animation speed 
   //     autoArrows:  false,                            // disable generation of arrow mark-up 
   //     dropShadows: false                             // disable drop shadows 
   // });
	
	//JQuery UI Tabs
	//Default Action
	$(".tab_content").hide();                            //Hide all content
	$("ul.tabs li:first").addClass("active").show();     //Activate first tab
	$(".tab_content:first").show();                      //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active");           //Remove any "active" class
		$(this).addClass("active");                      //Add "active" class to selected tab
		$(".tab_content").hide();                        //Hide all tab content
		var activeTab = $(this).find("a").attr("href");  //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn();                           //Fade in the active content
		return false;
	});
	
	
	//******* AJAX ADMIN LOGIN *********//
	$("#login").click(function(event) {
		
		var username=$("#user").val();
		var password=$("#pass").val();
		
		$.post('http://www.newenglandfish.net/index.php/admin/login/', {user:username, pass:password}, function(data) {
			
			if(data == 'true'){
			
				window.location = 'http://www.newenglandfish.net';
				
			}else{
			
				$('#error').html('The username/password you entered is invalid.');
				
			}
		
		});
	});
	//***** END AJAX ADMIN LOGIN ******//
   
   //Ajax News letter Signup
   $('#newsletter').submit(function(event){
	
		var strname = $('.name').val();
		var stremail = $('.email').val();
		
		$.post('http://www.newenglandfish.net/index.php/newsletter/signup/', {name:strname, email:stremail}, function(data) {
			
			$.modal('<div class="msg">' + data.msg + '</div>', {
					
					containerCss:{
						backgroundColor:"#fff",
						borderColor:"#444",
						height:150,
						padding:0,
						width:350
						}
					});
			
			if(data.error == 'true'){
				
				$('.msg').addClass("error");
				
			}else{
				
				$('.msg').addClass("success");
				
				$('.name').val('Your Name...');
				
				$('.email').val('Your Email...');
			}
			
			$('.msg').css({ 'font-weight' : 'bold', 'height' : '90px', 'margin' : '10px', 'text-align' : 'center', 'padding-top' : '40px' });
			
		}, "json");
		
		return false;
	
   });
   
      $('#oysterclub').submit(function(event){
	
		var strname = $('.oystername').val();
		var stremail = $('.oysteremail').val();
		var bolinclude = $('#include').val();
		
		$.post('http://www.newenglandfish.net/index.php/newsletter/oysterclub/', {name:strname, email:stremail, include:bolinclude}, function(data) {
			
			$.modal('<div class="msg">' + data.msg + '</div>', {
					
					containerCss:{
						backgroundColor:"#fff",
						borderColor:"#444",
						height:150,
						padding:0,
						width:350
						}
					});
			
			if(data.error == 'true'){
				
				$('.msg').addClass("error");
				
			}else{
				
				$('.msg').addClass("success");
				
				$('.oystername').val('Your Name...');
				
				$('.oysteremail').val('Your Email...');
			}
			
			$('.msg').css({ 'font-weight' : 'bold', 'height' : '90px', 'margin' : '10px', 'text-align' : 'center', 'padding-top' : '40px' });
			
		}, "json");
		
		return false;
	
   });
   
   $('.name').focus(function(){
   
		$('.name').val('');
   
   });
   
   $('.name').blur(function(){
		
		if($('.name').val() == ''){
		
			$('.name').val('Your Name...');
		}
   });
   
   $('.email').focus(function(){
	
		$('.email').val('');
	
   });
   
   $('.email').blur(function(){
		
		if($('.email').val() == ''){
		
			$('.email').val('Your Email...');
		
		}
   
   });
   
   $('.oystername').focus(function(){
   
		$('.oystername').val('');
   
   });
   
   $('.oystername').blur(function(){
		
		if($('.oystername').val() == ''){
		
			$('.oystername').val('Your Name...');
		}
		
   });
   
   $('.oysteremail').focus(function(){
   
		$('.oysteremail').val('');
   
   });
   
   $('.oysteremail').blur(function(){
		
		if($('.oysteremail').val() == ''){
		
			$('.oysteremail').val('Your Email...');
		
		}
   
   });
 });

