$(document).ready(function(){
    
    
    
    // CALL FUNCTIONS	
	otherdropdown();
	work_meta_team();
	work_meta_team_none();
	thumbnail_listing();
	contact_showhide();
	contact_submit()
	scroll_totop();
    
    
    
    //HOME PAGE PROJECT NAV
    $.get('/home/slideshow/', function(data){
        $('<ul class="prevnext_navigation"><li class="next"><a href="'+$(data).filter('div#first_link_target').html()+'">Next Project</a></li></ul>').prependTo('.home2 div#content_sec');
        hp_slideshow();
    });
    
    
    
}); 



//HOME PAGE PROJECT NAV
function hp_slideshow()
{
    $('.home2 ul.prevnext_navigation a').click(function(){
        
        var target = $(this).attr('href');
        
        // stop div form jumping about
        $('div#content_sec').height($('div#content_sec').height());
        
        //fade out the inner div
        $('div#homepage_featured').fadeOut('slow',function(){
            // load new contents
            $('div#content_sec').load(target+' div#ajax_wrapper', function(){
                   hp_slideshow();
            });
        });
        return false;
     });
}



// OTHER PROJECTS ON PROJECT/CASE STUDY PAGE
function otherdropdown()
{
    $('div#other_projects').hide();
	
	$("h4#other_projects_toggle").click(
		function () {
    		$("div#other_projects").slideToggle("middle");
    		$(this).toggleClass("down");
			return false;
		}
	);
}


		
// WORK SINGLE ENTRY META TEAM COUNT (used for styling)
function work_meta_team()
{
	var list_children = $('ul#project_team').children();
    $('ul#project_team').addClass('count'+list_children.length);
}



// WORK SINGLE ENTRY META TEAM COUNT - NO RELATED TEAM MEMBERS (hide the list and the previous heading)
function work_meta_team_none()
{
    // $('ul#project_team.count0').hide();
    $('ul#project_team.count0').prev('h5').hide();
}
	


// THUMBNAIL LISTING
function thumbnail_listing()
{
    $('ul.thumbs_list li a').click(
        function () {
            var new_href = $(this).attr('href');
            
            // SWAP IMAGES
            $('ul.thumbs_list').prev('img').attr({"src":new_href});
            
            //REMOVE CLASSES FROM ALL LIST ITEMS
            $('ul.thumbs_list li').removeClass('cur');
            
            // ADD CLASS TO CLICKED ON ITEM
            $(this).parent().addClass('cur');
            
            return false;
        }
    );
}



// CONTACT FORM SHOW/HIDE 
function contact_showhide()
{
    $('fieldset#contact_more').hide();
    
    $('div#contact_options ul li a').click(
		function () {
        	$('fieldset#contact_more').slideToggle('slow');
        	$(this).parent().toggleClass('less');
          	return false;
      	}  
    );
	
	$('div#contact_options ul li a').toggle(
		function () {
	    	$(this).text('Hide Form');
	    },
	    function () {
	        $(this).text('Extend Form');
	    }
	);
}



// CONTACT FORM SUBMIT BUTTON
function contact_submit()
{
	$('fieldset#contact_action input').click(
		function () {
			$(this).addClass('loading');
		}
	);
}



// FOOTER TO TOP SCROLL
function scroll_totop()
{
	$('p#to_top a').click(
	    function(){
    		$.scrollTo( '#branding', 500 );
    		return false;
    	}
    );
}
