/*
 * The Institute EXP
 * experimental js by the apprentice
 * to be merged
 */

$(function() {
    // For about.php: Hide about paragraph when hovering in sidebar
    $('div#mineWrap').hover(
        function() {
            $('p.fact').fadeOut(100);
            $('div.factWrap').fadeTo(100,0.0);
        },
        function() {
            $('p.fact').fadeIn (100);
            $('div.factWrap').fadeTo(100,1.0);
        }
    );

    //for directors.php hide content and video gallery for dirNav2 hover
    //$('div.utility div.commDirectorList').hover(
    //    function() {
    //        $('h1.sectionTitle, div.utility a.shareheart').fadeTo(200, 0.0);
    //        //$('div.commDirectorList').fadeIn(300);
    //    },
    //    function() {
    //        $('h1.sectionTitle, div.utility a.shareheart').fadeTo(200, 1.0);
    //        //$('div.commDirectorList').fadeOut(300);
    //    }
    //);
    
    // For browse.php: hide browse elements when watching clip
    $('a.videoLink, a#playAll').click(
        function() {
            $('div#vidBrowseControlWrapper').fadeTo(300, 0.0),
            
            $('img#canvas').fadeTo(30, 0.0),
            $('div#buzz').fadeTo(30, 0.0),
            $('a#clientLogin').fadeTo(30, 0.0),
            $('div#navigation').fadeTo(30, 0.2);
            $('div#navigation ul#social').fadeTo(30, 0.0);
        }
    );
    
    $('a[rel="close"]').click(
        function() {
            //$('div#vidBrowseControlWrapper').fadeTo(300, 1.0),
            $('img#canvas').fadeTo(300, 1.0),
            
            $('img#canvas').fadeTo(30, 1.0),
            $('div#buzz').fadeTo(30, 1.0),
            $('a#clientLogin').fadeTo(30, 1.0),
            $('div#navigation').fadeTo(30, 1.0);
            $('div#navigation ul#social').fadeTo(30, 1.0);
        }
    );

    
    $('a#directorList, div.commDirectorList').hover(
        function() {
            $('div.commDirectorList').css('display','block');
        },
        function() {
            $('div.commDirectorList').css('display','none');
        }
    );
    
    // init scrollpange for director's page
    //$('div#videoGallery').jScrollPane();

    //for social nav beauty
    $('ul#social li#favorites div#favoritesSummary a#favoritesSendEmail').click(
        function(){
            $(this).css('color','#00aaff')
        }
    );
    
    $('ul#social a.addMessage').click(
        function(){
            $(this).css('display','none'),
            $('ul#social span.theMessage').css('display','block')
        }
    );
    
    // directors reel -- get number of clips and insert result into html
    
    var vidCount = $('a.videoLink').size();
    
    $('span.vidCount').html(vidCount);
    
    //$('a.videoLink').size(
    //    function(){
    //        $('span.vidCount').html('$this');
    //    }
    //);
    
    // play all reel
    //$('a#playAll').click(
    //    function(e){
    //        e.preventDefault();
    //    
    //        session.currentVideoIndex = -1;
    //        
    //        playNextVideoQuicktime();
    //    } 
    //);
    
    // browse: dim the thumbs
    
    $('div.browseFilterControls div.commDirectorList').hover(
        function(){
            $('div#browseWrapper').fadeTo(200, 0.1);
        },
        function(){
            $('div#browseWrapper').fadeTo(200, 1.0);
        }
    );
    
    
    //for about
    /*$('div.riley ul li.more a').click(
        function(){ 
            $('div#main').fadeOut(0)
            $('div#rileybio').fadeIn(0)
        }
    );
    
    $('div.jehoshua ul li.more a').click(
        function(){
            if ($('div#rileybio').css != ('display', 'block')){
                $('div#main').fadeOut(0)
                $('div#jehoshuabio').fadeIn(0);
            }
            
            else{
                $('div#rileybio').fadeOut(0)
                $('div#jehoshuabio').fadeIn(0);
            };
        }
    );

    
    $('div.section a.close').click( 
        function(){ 
            $(this).parent('div.section').fadeOut(0)    
            $('div#main').fadeIn(0)
        }
    ); */
    
    
    // hide the initial message so it doesn't double up
    $('div#main').hide();
    // fade out the main container and set it's HTML
    // to the initial message's HTML, then fade it back in
    $('div#contactContent').fadeTo(1, 0.001, function() {
        // load initial welcome message thing
        $(this)
            .empty()
            .html( $('div#main').html() )
            .fadeTo( 1, 1.0 );
    });
    // remove any other click handlers that might be on these links (shouldnt be but was acting weird)
    $('a.more').unbind( 'click' );
    // assign click handler to each bio link
    $('a.more').click( function(e) {
        // don't follow the default URL action, i.e. the href="#"
        e.preventDefault();
        // grab the name of our target bio div (like "#bioname")
        // toString() needed because $() returns jQuery object, but we just need text
        var target = ('#' + $(this).attr('rel').toString());
        // fade out the main content area, fill it with our target div's bio content, then fade back in
        $('div#contactContent').fadeTo('fast', 0.001, function() {
            $(this)
                .empty()
                .html( $(target).html() )
                .fadeTo( 'slow', 1.0, function() {
                    // since we messed with the DOM, we have to reassign event handlers
                    // remove any pre-existing click handlers for .close
                    $('div#contactView a.close').unbind( 'click' );
                    // assign the close click handler
                    $('div#contactView a.close').click( function(e) {
                        e.preventDefault();
                        // fade out the main container and set it's HTML
                        // to the initial message's HTML, then fade it back in
                        $('div#contactContent').fadeTo(1, 0.001, function() {
                            // load initial welcome message thing
                            $(this)
                                .empty()
                                .html( $('div#main').html() )
                                .fadeTo( 'slow', 1.0 );
                        });
                    });
                });
        });
    });
    
});
