$(document).ready(function() {

$('p.comment-form-author label').append(' <span style="color: #AAAAAA">(required)</span>');
$('p.comment-form-email label').append(' <span style="color: #AAAAAA">(not published)</span>');

$('body').removeClass('no-js'); // make sure stuff works without JS...

$('#slideshow0').cycle({
	fx:     'fade', 
	speed:  500, 
	timeout: 5000, 
	prev:   '#prev0', 
	next:   '#next0' 
	});
//menu effects	
	$("#access ul li:has(ul)").find("a:first").append(" &nbsp; ");

    $("#access ul li:has(ul)").hover(function(){
    
        $(this).addClass("hover");
    
        $('ul:first',this).stop(true, true).animate({
    opacity: 'show',height: 'toggle'
    }, 0); // timeout to 0 because the transition looks odd with the drop shadow 

    }, function(){
   
        $(this).removeClass("hover");
       $('ul:first',this).stop(true, true).slideUp(0);   
    });
	
// add and remove a few classes	
$('.home .block').find('p:first').addClass('first-child');
$('.block').first().addClass('first-child');
//$('#access li:first').addClass('hidden');
$('#colophon li:last').addClass('last-child');
$('#colophon li:last').prev().addClass('facebook');
$('.menu ul.sub-menu li:last-child').addClass('last-child');

$('.single-projects').find('li.page-item-50').addClass('current_page_item');
$('.single-casestudy').find('li.page-item-54').addClass('current_page_item');

$('img').each(function(){ // remove inline height and width attributes for images 
          $(this).removeAttr('width')
	        $(this).removeAttr('height');
	 				});
	 				
if (screen.availWidth<=480) {
//if (window.innerWidth<=480) { // just for testing with safari
			
	$("#access").hide();
  $("#access").before("<a id='mobile-nav' href='#'>Menu</a>");
	// $("#access ul li:has(ul)").append("<span class='m-button'>&raquo;</span> ");
				
	$("#mobile-nav").click(function(e) {
		$("#access").slideToggle('fast');
		$("#access ul li:has(ul)").unbind();  	//unbind hover drop down
		e.preventDefault();    		
	});
    	
   	// mobile menu 2nd level
   	
   	var dropButton = $("#access li span");
	
		dropButton.click(function(e) {
		var childMenu = $(this).parent("li").find("ul.sub-menu"); 		
		var grandDaddy = $(this).closest("li");
		var isClosed = grandDaddy.find("ul.sub-menu:first");

		childMenu.slideUp('fast');
		grandDaddy.siblings().find("ul.sub-menu").slideUp('fast');
		dropButton.removeClass("active");
		
		if ( isClosed.is(':hidden') == true ) {
			$(this).addClass('active');
			childMenu.slideDown('fast');
		}
		e.preventDefault();
	});	

}
	 				
});
    

