$('html').addClass('js');

$(document).ready(function(){


	// Form Validation
	$('form:has(.required)').submit(function(){
       var ok = true;
       $('.required',this).each(function(){
           if (!$(this).val()) {
               $(this).addClass('warn');
           } else {
               $(this).removeClass('warn');
           }
           ok=ok&&!!$(this).val();
       });
       
       if(!ok) {
           var buttons = $('.buttons',this);
           buttons.children('.form_notify').remove();
           buttons.append('<label for="submit"class="form_notify" >Please fill in all required fields.</label>');
       }
       
       return ok;
   });
   
   $('.required').focus(function(){
		$(this).removeClass('warn');
		
	});

   // End Validation
   
	// FAQ Answer Expand
	$('dt').click(function(){
		$(this).next('dd').slideToggle("fast");
	})
	
	if(document.location.hash){
  	 $(document.location.hash.toString()).click();
	}
	
	// End Answer Expand
	
	// Main Menu Expand
	$("ul.mainmenu h3")
		.css('cursor', 'pointer')
		.hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
		})
		.click(function(){
			var $li = $(this).parent('li');
			$li.toggleClass('open')
				.children('ul')
				.slideToggle("fast");
			
			$.cookie($li.attr('id'), $li.hasClass('open') ? 'on' : 'off');
		})
		.parent('li')
		.each(function(){
			
			$(this).addClass('open');
			
			if( $.cookie($(this).attr('id')) == 'on' ) {
				$(this).addClass('open').children('ul').show();
			} else if ( $.cookie($(this).attr('id')) == 'off' ) {
				$(this).removeClass('open').children('ul').hide();
			}
		});
		
		//console.log($("ul.mainmenu li.open").length);
		
		if ( !$("ul.mainmenu li.open").length ) {
			//$('ul.mainmenu>li').addClass('open').children('ul').show();
			console.log('expand all');
		}
	//End Menu Expand
	
	//IE6 PNG Fix
	$("img[@src$=png], #brand_new_site").pngfix();
	
	// Network Button Expand
	$(".networkbutton").attr('href', '#');
	
	$(".networkbutton").click(function(){
		$("#dropdown").slideToggle("fast");
	});
	// End Network Button
	
	$('ul#adnetworks').innerfade({
		speed: 500,
		timeout: 5000,
		type: 'sequence',
		containerheight: '62px'
	});
		
});
