$(document).ready(function(){
	$('#clientLogos').jcarousel({
        auto: 1,
		wrap: 'circular',
		animation: 45000,
		easing:'linear',
		scroll:1 
    });
	
	//homepage tabs
	$.featureList(
		$("#tabs li a"),
		$("#output li"), {
			start_item : 0,
			transition_interval: 5000
		});
	$("#anniversaryWidget").click(function(){
		var color = $(this).css("backgroundImage");
		if (color.search(/purp/i) > -1){
			$(this).css("background-image","url(images/anniv_red.png)")
		}else{
			$(this).css("background-image","url(images/anniv_purp.png)")
		};
	});


$("#contactUs").validate({
		rules:{
			name:{required:true},
			email:{required:true,email:true},
			phone:{required:true},
			message:{required:true}
		},
		messages:{
			name:{required:""},
			email:{required:""},
			phone:{required:""},
			message:{required:""}
		},
		submitHandler: function(form) {
			
			var datastring = $(form).serialize()
			$.ajax({
                type:"post",
                url: '/services/bankertek.cfc?method=sendEmail',
                data: datastring,
                success: function(data) {
                    console.log(data)
					var obj = $.parseJSON(data);
                    var sent = obj.SENT;

					//clear out the form after submission
					$(':input', form).each(function() {

						var type = this.type;
						var tag = this.tagName.toLowerCase(); // normalize case
						// it's ok to reset the value attr of text inputs,
						// password inputs, and textareas
						if (type == 'text' || type == 'password' || tag == 'textarea')
							this.value = "";
							// checkboxes and radios need to have their checked state cleared
							// but should *not* have their 'value' changed
						else if (type == 'checkbox' || type == 'radio')
							this.checked = false;
							// select elements need to have their 'selectedIndex' property set to -1
							// (this works for both single and multiple select elements)
						else if (tag == 'select')
						this.selectedIndex = -1;
					});
					
					$("#confirmEmail").show();
                }
            });
		}
	});	
	
	$("#careers").validate({
		rules:{
			firstname:{required:true},
			lastname:{required:true},
			email:{required:true,email:true},
			phone:{required:true},
			resume:{required:true,accept:"doc|docx|pdf"}
		},
		messages:{
			firstname:{required:""},
			lastname:{required:""},
			email:{required:""},
			phone:{required:""},
			resume:{required:"",accept:""}
		}
	});	
	
	//expand/collapse sections
	$("p.product").click(function(){
		var plusMinus = $(this).children('span.expandCollapse').html();
		
		$(this).next("div.collapseContent").toggle();
		
		if (plusMinus == "-"){
			$(this).children('span.expandCollapse').html("+")
		}else{
			$(this).children('span.expandCollapse').html("-")
		}
		
		
	});	
	
	$("#toggleClients").click(function(){
		var thisContent = $(this).html();
		if (thisContent == "View BankerTek Clients"){
			$(this).html("Hide BankerTek Clients");
			$("#clientsWrapper").css('visibility','')
		} else{
			$(this).html("View BankerTek Clients");
			$("#clientsWrapper").css('visibility','hidden')
		}
	});
			
});
