$(document).ready(function(){
	
		
		var tabs = ['main','sub'];
		$.each(tabs, function(i, elem){
			$('.' + elem + 'Tab:first').show();
			// On click event
			$('#' + elem + 'Tabs li a').click(function() {
				var activeTab = $(this).attr("rel");
				$('#' + elem + 'Tabs li').removeClass("tab_on");
				$(this).parent().addClass("tab_on");
				$('.' + elem + 'Tab').hide();
				$("#" + activeTab).fadeIn();
				return false;
			});		
		
		});

			
	//the acknowledge form
	$("#acknowledgeForm label").click(function(){
		var for_att = $(this).attr('for');
		$("#acknowledgeForm label").removeClass("active");
		$("#acknowledgeForm .radio").attr('checked',false);
		$("input#"+for_att).attr('checked','checked');
		$(this).addClass("active");
	});
	//the acknowledge form
	$('#contactForm').validate({
		errorElement:'div',
		   errorPlacement: function (error, element) { 
           error.insertBefore(element);    
        },  
		rules:{
			fullName:{required:true},
			emailAddress:{required:true, email:true},
			message:{required:true}
			},
		messages:{},
		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
			target: "#thankYou"
			});
			$("#contactForm").hide();
			$("#thankYou").show();
		}
		});
	
	var start_height = $(document).height();
	$(".list li:first .toggle").delay(500).slideDown('slow',function(){
			$(".list li:first h3 a").addClass('active');
			$(".list li:first .arrow").addClass('active');
		});

	$(".list li h3 a").click(function(){
			var target_top = $(this).offset().top;
			
			if ($(this).parent().parent().find('.toggle').is(':visible') ){
				$(this).parent().parent().find('.toggle').slideUp();
				$('.arrow').removeClass('active');
				$(this).removeClass('active');
			} else {
				$(".list li h3 a").removeClass('active');
				$(this).addClass('active');
				$('.arrow').removeClass('active');
				$('.arrow',this).addClass('active');
				$('.toggle:visible').slideUp('slow');
				$(this).parent().parent().find('.toggle').delay(500).slideToggle(function(){
					$('html, body').animate({scrollTop:target_top}, 1000);
				});
				sublimevideo.pause() 
			}
		return false;
		
		});
	
	
	$('.cycle').cycle({ 
    fx:     'fade', 
    speed:  'fast', 
    timeout: 6500, 
    pager:  '.nav' 
	});	
	
	// Reset videos after they play fully
	sublimevideo.ready(function(){

	  	sublimevideo.onEnd(function(sv){
			sublimevideo.stop();
		});
		
	  	sublimevideo.onStart(function(sv){

			$('.cycle').cycle('pause');
			//sublimevideo.pause(); 
			//sublimevideo.play(sv.element.id);

		});

		
	});
	
	$(".nav a").click(function(){
			$('.cycle').cycle('pause');
			sublimevideo.pause(); 
		});
	

	var projects = $(".current_projects .white a, .past_projects .white a");
	$(projects).hover(function(){
		$(this).stop().animate({"opacity":".8"});
		},function(){
		$(this).stop().animate({"opacity":"1"});
	
	});	


	$('#overviewControls a:first').addClass('syndicateMrtg');
	$('#overviewControls a:last').addClass('learnMore');
	
	
});

