$(document).ready(function() {
	var bannerId = 4;
	var fnAction = true;
	var timer = setInterval(fadeBanner, 4000);
    
	function fadeBanner() {
        //first image rel should be the same as the first image tags rel attr
		if(bannerId == 1) fnAction = false;
        //number needs to be 1 above how many images are contained
		if(bannerId == 5) fnAction = true;
		(fnAction == true) ? fadeOutBanner() : fadeInBanner();
	}//end function fadebanner
	
	function fadeOutBanner() {
		$('.banner[rel='+ bannerId +']').fadeOut(1000);	
		bannerId--;		
	}//end fadeOutBanner
	function fadeInBanner() {
        bannerId = (bannerId == 1) ? 2:bannerId;
		$('.banner[rel='+bannerId +']').fadeIn(1000);
		bannerId++;		
	}//end fadeInBanner
    
    $('.replyRantTrig').click(function() {
        var user = $(this).attr('rel');
        var id = $(this).attr('user');
        $('#input-comment').focus();
        $('#input-comment').html('@' + user + '\n\n');
        if('#replyfield') {
            $('#replyfield').remove();
        }
        $('form').append('<input type="hidden" id="replyfield" value="' + id + '" name="reply"/>');                
    });
	
$('.subscribeTrig').click(function() {
	$('#paypal_sub').submit();								   
});                                                                                 


/**
------------------------------------------------||
                                                ||
                                                ||
           News letter sign up controls         ||
                                                ||
                                                ||
------------------------------------------------||                                                
                                                    **/
$('#newsletterTrig').click(function(){  
        
   Shadowbox.open({
        content:    $('#mailhider').html(),
        player:     "html",
        height:     481,
        width:      357
    });                
    setTimeout(bindNewsletterFns, 2000);
});

function bindNewsletterFns() {    
    $('input[name="fname"]').bind('focus', function() {
        var nameVal = $(this).attr("value");  
        if(nameVal == 'First Name') {               
            $(this).attr("value","");         
        }});                                  
    $('input[name="fname"]').bind('blur',function() {                                           
        var nameVal = $(this).attr("value");                                            
        if(nameVal == "" || nameVal == "First Name") {                                        
            $(this).attr("value", "First Name");                                                                                                                                  
        }//end if                                                                       
    });
    
    $('input[name="lname"]').bind('focus', function() {
        var nameVal = $(this).attr("value");  
        if(nameVal == 'Last Name') {               
            $(this).attr("value","");         
        }});                                  
    $('input[name="lname"]').bind('blur',function() {                                           
        var nameVal = $(this).attr("value");                                            
        if(nameVal == "" || nameVal == "Last Name") {                                        
            $(this).attr("value", "Last Name");                                                                                                                                  
        }//end if                                                                       
    });
    
    
    $('input[name="email"]').bind('focus', function() {
        var nameVal = $(this).attr("value");  
        if(nameVal == 'Email') {               
            $(this).attr("value","");         
        }});                                  
    $('input[name="email"]').bind('blur',function() {                                           
        var nameVal = $(this).attr("value");                                            
        if(nameVal == "" || nameVal == "Email") {                                        
            $(this).attr("value", "Email");                                                                                                                                  
        }//end if                                         
    });
    
    $('input[name="address"]').bind('focus', function() {
        var nameVal = $(this).attr("value");  
        if(nameVal == 'Address') {               
            $(this).attr("value","");         
        }});                                  
    $('input[name="address"]').bind('blur',function() {                                           
        var nameVal = $(this).attr("value");                                            
        if(nameVal == "" || nameVal == "Address") {                                        
            $(this).attr("value", "Address");                                                                                                                                  
        }//end if                                         
    });
    
    $('input[name="city"]').bind('focus', function() {
        var nameVal = $(this).attr("value");  
        if(nameVal == 'City') {               
            $(this).attr("value","");         
        }});                                  
    $('input[name="city"]').bind('blur',function() {                                           
        var nameVal = $(this).attr("value");                                            
        if(nameVal == "" || nameVal == "City") {                                        
            $(this).attr("value", "City");                                                                                                                                  
        }//end if                                         
    });
    
    
    $('input[name="state"]').bind('focus', function() {
        var nameVal = $(this).attr("value");  
        if(nameVal == 'State') {               
            $(this).attr("value","");         
        }});                                  
    $('input[name="state"]').bind('blur',function() {                                           
        var nameVal = $(this).attr("value");                                            
        if(nameVal == "" || nameVal == "State") {                                        
            $(this).attr("value", "State");                                                                                                                                  
        }//end if                                         
    });
    
    
    $('input[name="zip"]').bind('focus', function() {
        var nameVal = $(this).attr("value");  
        if(nameVal == 'ZIP') {               
            $(this).attr("value","");         
        }});                                     
   
    $('input[name="zip"]').bind('blur',function() {                                           
        var nameVal = $(this).attr("value");                                            
        if(nameVal == "" || nameVal == "ZIP") {                                        
            $(this).attr("value", "ZIP");                                                                                                                                  
        }//end if                                         
    });
    
    $('#mailing-list-subscription input[type="image"]').bind('click',function() {  
        $.post('ajax.submitsubscription.php', $('#mailing-list-subscription form').serialize(), function(data) {
            //alert(data);
            $('#mailing-list-subscription .form').html(data);
            setTimeout(bindNewsletterFns, 2000);
        });
    });
    
    }
    



});//end main document

