$(document).ready(function() {

	//Initialize colorbox
	$('.colorbox').colorbox({scrolling: false});
    $('.contact-me').colorbox({scrolling: false, inline:true, href:"#contact_bio_popup"});
	$('.lets-talk').colorbox({scrolling: true, inline:true, href:"#lets_talk_popup"});
    $('.tell-a-friend').colorbox({scrolling: true, inline:true, href:"#email_a_friend_popup"});
    $('.article-tell-a-friend').colorbox({scrolling: true, onComplete:function(){		
			$("form.toValidate").each(function(){
				$(this).validate()
			})
			
			$('form#articles_email_a_friend').submit(function() {
				var email_to = Array();
				$('.recipients', this).each(function() {
					if ($(this).val()) {
						email_to.push($(this).val());
					}
				});			
				$('#recipient_email', this).val(email_to.join(", "));
			});
        }
    });
    
        
    //Random Hero Shot image on load;
    $('.fade-gal li img').hide();
	$('.main-home .intro-txt').hide();
    
	var images = Array();

    $('.fade-gal li img').each(function() {
        images.push($(this).attr('src'));
    });
	

	$('.fade-gal li img').eq(Math.floor(Math.random() * images.length)).addClass("active").show(function(){
		var id = $(this).attr('id');
		$('.main-home .intro-txt.' + id +' h1').not('.q1').css('opacity',0);
		$('.main-home .intro-txt.'+id).show().cycle({
			timeout: 6000,
			delay:  2000,
			speed: 2000,
			sync: 0,
			fx: 'custom', 
			cssBefore: { left: -50, display: "block" }, 
			animIn:  { left: 0, opacity: 1 }, 
			animOut: { opacity: 0 } 			
		});
	});
		

	//Attach print event
	$('a.print').click(function() {
		window.print();
		return false;
	});
	
	
	$('.directions').hide();
	
	$('.from-direction').click(function(event){
		event.preventDefault();
		$(this).next('div').toggle('slow');
	});
		
	$('form.signup').submit(function(){	
		var emailfilter=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
		var returnval=emailfilter.test($('form.signup #inpt-signup').val());
		if (returnval==false){
			alert('Please Enter Valid Email');
			return false;
		} 
	});
	
	$("form.toValidate").each(function(){
		$(this).validate()
	})
	
	/*
	* Attach logic to be executed on contact-US submit (to submit receipt email)
	*/
	
	/*$('form#contact_us').ajaxForm({
			beforeSubmit: function (formData, jqForm, options) {				
				$('form#contact_us').find("input, select, textarea").attr("disabled",true);				
				$('form#contact_us').fadeTo("slow",0.5);				
			},
			success: function (responseText, statusText, xhr) {
				$('form#contact_us').fadeTo("slow", 1);
				$('form#contact_us').html("<h2>Thank you for contacting Brightworth.</h2><h6>A member of our team will be in touch with you shortly.</h6>");
			}
	});*/

	/*
	* Attach logic to be executed on contact-ME submit (to submit receipt email)
	*/
	
	/*$('form#contact_me').ajaxForm({
			beforeSubmit: function (formData, jqForm, options) {				
				$('form#contact_me').find("input, select, textarea").attr("disabled",true);				
				$('form#contact_me').fadeTo("slow",0.5);
			},
			success: function (responseText, statusText, xhr) {
				$('form#contact_me').fadeTo("slow", 1);
				$('form#contact_me').html("<h2>Thank you for contacting Brightworth.</h2><h6>A member of our team will be in touch with you shortly.</h6>");
			}
	});*/
   
    
	$('#articles-search select').ieSelectStyle({    
		applyStyle : false
	});
	
});


function SearchByAuthor() {
     $('div#bycategory, div#bydate').hide();
     $('select#sel-category, select#sel-date').attr('disabled', true);
     $('select#sel-author').attr('disabled', false);
     $('div#byauthor').show();
}

function SearchByCategory() {
    $('div#byauthor, div#bydate').hide();
    $('select#sel-author, select#sel-date').attr('disabled', true);
    $('select#sel-category').attr('disabled', false);
    $('div#bycategory').show();
}

function SearchByDate() {
     $('div#byauthor, div#bycategory').hide();
     $('select#sel-author, select#sel-category').attr('disabled', true);
     $('select#sel-date').attr('disabled', false);
     $('div#bydate').show();
}
