// Default opacity of project links (the ones w/ text)
opacity_faded_out = .80;
opacity_default = .95;

function works_init(){
    h4_a = $ES('div.project h4 a');

    // Set opacity for IE and other browsers that do not use CSS3 'opacity'
    h4_a.setOpacity(opacity_default);

    projects = $ES('div.project');

    project_links_fx_options = { 'wait': false, 'opacity': opacity_faded_out, 'duration': 1000};

    project_links = new Array();
    var i = 0;
    var inc = 0;
    if( projects.length == 7 ){
      ++inc;
      project_links[i++] = new Fx.Elements(h4_a[0]);
      project_rows_fn[0] = function(fx_els){
         fx_els.start({
             '0': project_links_fx_options
         });
      }.pass(project_links[0]);
      project_rows.chain(project_rows_fn[0]);
    }
    for(i; i < h4_a.length; i+=3 )
    {
         var link_index = (((i-inc)/3)+inc);
        // Grab elements
        project_links[link_index] = new Fx.Elements([h4_a[i], h4_a[i+1], h4_a[i+2]]);
        // Set animation sequence (so we can chain)
        project_rows_fn[link_index] = function(fx_els){
            fx_els.start({
                '0': project_links_fx_options,
                '1': project_links_fx_options,
                '2': project_links_fx_options
            })
        }.pass(project_links[link_index]);
        // Add to top level sequence of events
        project_rows.chain(project_rows_fn[link_index]);
    }
    project_rows.chain(attachMouseEvents);

    for(var i = 0; i < project_links.length; ++i )
    {
       project_rows.callChain.delay(3000+(i*350), project_rows);
    }
    project_rows.callChain.delay(3100+((project_links.length-1)*350), project_rows );

}
    project_rows_fn = new Array();

    // Sequence of events (fade each row then attach rollover effects)
    project_rows = new Chain();

    function attachMouseEvents(){
    projects.each(function(project){
        project.h4_a = $E('h4 a', project);
        project.h4_a_fx = new Fx.Style(project.h4_a, 'opacity',{'wait': false, duration: 250});
        project.addEvent('mouseenter', function(){
          // Fade the link into the default opacity onMouseOver
          this.h4_a_fx.start(opacity_default);

          // Change the color of the link to :hover for IE
          this.h4_a.addClass('hoverState');
        }) //.bind(project);

        project.addEvent('mouseleave', function(){
          // Fade the link into the faded out opacity onMouseOver
          this.h4_a_fx.start(opacity_faded_out);

          // Change the color of the link for IE
          this.h4_a.removeClass('hoverState');
        });
    });
    }

window.addEvent('domready', works_init);