$(document).ready(function() {

	var dropdown = '.sub-nav li';
		
	$(dropdown).hover(function() {
		$('ul', this).show();		
	}, function() {
		$('ul', this).hide();
	});
	
	$('.work-image').fancybox();
	
	$('.work-video').click(function() {
        $.fancybox({
            'padding'       : 0,
            'autoScale'     : false,
            'transitionIn'  : 'none',
            'transitionOut' : 'none',
            'title'         : this.title,
            'width'         : 800,
            'height'        : 600,
            'href'          : this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1'),
            'type'          : 'swf'
        });

        return false;
    });
    
    // get the title for each nav item and add it as a description
    $.each($('nav li a'), function() {
    	 var title = $(this).attr('title');
    	 $(this).append('<span>'+title+'</span>');
    });
    
    $('#ribbon').click(function() {
    	var ribbon 		= $(this);
    	var open_class 	= 'ribbon-open';
    	var popup		= $('#popup');
    	var speed 		= 500;
    	var startPos	= '-5px';
    	var endPos		= '75px';
    	
    	if (!ribbon.hasClass(open_class))
    	{
    		ribbon.animate({ 'top': endPos }, speed);
    		ribbon.addClass(open_class);
    		
    		popup.animate({ 'height': '80px' }, speed);
    	}
    	else
    	{
    		ribbon.animate({ 'top': startPos }, speed);
    		ribbon.removeClass(open_class);
    		
    		popup.animate({ 'height': '0px' }, speed);
    	}
    	
    	return false;
    });
	
});
