// file: /js/nwp.js
// This should contain JavaScript for our public pages.
// General JS functions should go in /js/general.js

var bannersInfo = {
   troughton : {
        name : 'Charlie Troughton',
        txt : 'Principal <br />Corning High School, Corning, California',
        project : 'Northern Calfornia Writing Project',
        quote : '&#8220;I tell teachers the writing project was the best professional development I have ever experienced.&#8221;'
    },
    perez : {
        name : 'Dolores Perez',
        txt : 'Fifth Grade Teacher <br />Cromack Elementary School, Brownsville, Texas',
        project : 'Sabal Palms Writing Project',
        quote : '&#8220;The writing project helps me teach my students to think, to process information, and to create new ways of looking at the world.&#8221;'
    },
    heyler : {
        name : 'Dick Heyler',
        txt : 'Eighth Grade Teacher <br />Harlan Rowe Junior High, Athens, Pennsylvania',
        project : 'Endless Mountains Writing Project',
        quote : '&#8220;The writing project is high-interest and research-based, so teachers really appreciate it.&#8221;'
    },
    robinson : {
        name : 'Mia Robinson',
        txt : 'Kindergarten Teacher <br />Dartmouth Elementary School, Denver, Colorado',
        project : 'Denver Writing Project',
        quote : '&#8220;The writing project offered me purpose, clear direction, and a focus on writing and reading.&#8221;'
    },
    tsang : {
        name : 'Chris Tsang',
        txt : 'Seventh and Eighth Grade Humanities Teacher <br />Harbor School, Boston, Massachusetts',
        project : 'Boston Writing Project',
        quote : '&#8220;Being with other urban teachers gives my work context. I have opportunities to share practices and to receive mentorship&#8221;'
    },
    hammond : {
        name : 'Diana Hammond',
        txt : 'Eighth Grade Communication Arts Teacher <br />Ritenour School District, St. Louis, Missouri',
        project : 'Gateway Writing Project',
        quote : '&#8220;I came away from the writing project summer institute with confidence, new ideas, and a strong support system.&#8221;'
    },
    willis : {
        name : 'Margie Willis',
        txt : 'Elementary School Principal <br />George L. Hawkins Elementary, Hattiesburg, Mississippi',
        project : 'South Mississippi Writing Project',
        quote : '&#8220;&#8221;'
    },
    mcdermott : {
        name : 'James McDermott',
        txt : 'Assistant Professor and Curriculum Developer <br />Clark University, Worcester, Massachusetts',
        project : 'Central Massachusetts Writing Project',
        quote : '&#8220;&#8221;'
    },
    larson : {
        name : 'Kim Larson',
        txt : 'Reading&#47Writing Director, State Department of Education, <br />Nebraska Department of Education, Omaha, Nebraska',
        project : 'Nebraska Writing Project',
        quote : '&#8220; &#8221;'
    },
    aldaco : {
        name : 'Jose Aldaco',
        txt : 'Middle School Principal <br />Waterford Middle School, Waterford, California',
        project : 'Great Valley Writing Project',
        quote : '&#8220; &#8221;'
    },
    kajiwara : {
        name : 'Susan Kajiwara-Ansai',
        txt : 'Reading Coach <br />Chicago Public Schools Area 9, Chicago, Illinois',
        project : 'Chicago Area Writing Project',
        quote : '&#8220;Their dream of becoming authors has already come true.&#8221;'
    },
    mitchell : {
        name : 'Sandra Mitchell',
        txt : 'Associate Superintendent for Instruction <br />Fauquier County Public Schools, Warrenton, Virginia',
        project : 'Northern Virginia Writing Project',
        quote : '&#8220; &#8221;'
    },
    paul : {
        name: 'Paul Epstein',
        txt: 'Writing and Technology Teacher <br />Ruffner Elementary School, Charleston, West Virginia', 
        project : 'Central West Virginia Writing Project',
        quote : '&#8220; &#8221;'
    },
    katherine : {
        name : 'Katherine Suyeyasu',
        txt : 'History and English Teacher <br />ASCEND School, Oakland, California',
        project : 'Bay Area Writing Project',
        quote : '&#8220; &#8221;'
    },
    david : {
        name : 'David Brown',
        txt : 'ESL Teacher  <br />John H. Webster Elementary School, Philadelphia, Pennsylvania ',
        project : 'Philadelphia Writing Project',
        quote : '&#8220; &#8221;'
    },
    joel: {
        name : 'Joel Malley',
        txt : 'English Teacher <br />Cheektowaga Central High School, Cheektowaga, New York',
        project : 'Western New York Writing Project',
        quote : '&#8220; &#8221;'
    }
}

var banners = ['troughton','perez','heyler','robinson','tsang','hammond','willis','mcdermott','larson','aldaco','kajiwara','mitchell','paul','katherine','david','joel'];


// Randomizes the banner image on the home page.
// Gets called automatically when the home page is ready.
function randomBanner() {
    if($('body.subpage').length == 0) {
        var bannerID = banners[Math.ceil(Math.random()*banners.length)-1];
        var banner = bannersInfo[bannerID];
        var bannerE = $('div.banner');

        var fass = $('#findasite').attr('href');
        var fast = $('#findasite').html();

        bannerE.
            attr('id',bannerID).  // This effectively changes the image.
            empty().
            append($('<h1>' + banner.quote + '</h1><div class="cap"><h2>' + banner.name + '</h2>' + banner.txt + '<br /><em>' + banner.project + '</em></div><a id="findasite" href="' + fass + '">'+ fast + '</a>'));
    }
}

// Sets some text, sets a handler to show/unshow events by type
// Gets called automatically when the calendar page is ready

// Sets some text, sets a handler to show/unshow events by type
// Gets called automatically when the calendar page is ready
function initCalendar() {
    $('#swapcalnav').click(function(){
        var btn = $(this);
        $('#buttons, #jumptomonth').toggle();

        if ( btn.is('.formview') ) {
            btn.html('Search by month&#160;&#8250;');
        }
        else {
            btn.html('Browse by month&#160;&#8250;');
        }
        btn.toggleClass('formview');
        return false;
    });

    $('#eventtypes dl').css('cursor','pointer').click(function(){
        var ida = $(this).attr('id').split('-');
        var this_event = ida[1];
        var this_color_id;
        var colors = ['green', 'red', 'orange', 'purple', ''];
        var types = ['openevent', 'sitereporting', 'siteopp', 'leadershipmeeting', 'all'];
        for ( i = 0; i < types.length; i++ )
        {
            if ( this_event == "all" )
             {
              $('.'+types[i]).css("display", "");
             }
            else if ( types[i] != this_event )
            {
            // $('.'+types[i]).toggle();
            $('.'+types[i]).css("display", "none");
             }
             else
             {
             this_color_id = i;
            $('.'+types[i]).css("display", "");
             }        
         }
         // $(this).toggleClass('closed');      
          $(this).css("color", colors[this_color_id]);
          //alert (colors[this_color_id]);
          return false;
    });
}

// this is the  renamed initCalendar()
// function initCalendar_old() {
//    $('#swapcalnav').click(function(){
//        var btn = $(this);
 //       $('#buttons, #jumptomonth').toggle();
//
//        if ( btn.is('.formview') ) {
 //           btn.html('Search by month&#160;&#8250;');
 //       }
 //       else {
//            btn.html('Browse by month&#160;&#8250;');
//        }
 //       btn.toggleClass('formview');
//        return false;
//    });
//
//    $('#eventtypes dl').css('cursor','pointer').click(function(){
 //       var ida = $(this).attr('id').split('-');
 //       $('.'+ida[1]).toggle();
 //       $(this).toggleClass('closed');
 //       return false;
 //   });
// }

// jQuery.fn.Randomize = function(images, imgdir) {
//     $(this).attr('src',imgdir + images[Math.ceil(Math.random()*images.length)-1]);
// }
jQuery.fn.slideshow = function(swfpath, xmlpath, w, h)
{
    this.each(function(i) {
        var id = $(this).attr('id');
        if (id) {
            var so = new SWFObject( webroot + swfpath, id, w, h, "6", "#ffffff" );
            so.addVariable( "imagesXml", webroot + xmlpath );
            so.write( id );
        }
    })
}

function autoPrint() {
    print();
}

// Set up functions to launch when the page is ready
$(document).ready(function() {
    if ($('#home')) randomBanner();             // Launch the randomBanner function if it's the home page
    if ($('#calendar')) initCalendar();         // Launch the initCalendar function if it's the calendar
    if (location.href.indexOf('x-print_friendly=1') != -1) autoPrint();
    $('a').click(function(){$(this).blur()});
});


function searchFocus(searchbox) {
    if (searchbox.value == 'Search NWP') { searchbox.value = ''; }
    searchbox.style.color = '#000';
}

function searchBlur(searchbox) {
    if (searchbox.value == '') {
        searchbox.style.color = '#777';
        searchbox.value = 'Search NWP';
    }
}

// Launch a pop-up window for the current URL with an extra CGI
// variable signaling print-friendliness to the header.
function prettyPrint() {
    var url = location.href;
    if (url.indexOf('?') != -1) {
        url += "&x-print_friendly=1";
    }
    else {
        url += "?x-print_friendly=1";
    }

    popUp(url, 'printfriendly', 'width=800,height=600,status=yes,resizable=yes,scrollbars=yes');
}

// Email to a friend
function emailToFriend() {
    var currentURL = location.href;
    // chop off any # from the URL
    if (currentURL.indexOf("#") != -1) {
        currentURL = currentURL.substr(0, currentURL.indexOf("#"));
    }
    // IE puts the # in the title, too
    var currentTitle = document.title;
    if (currentTitle.indexOf("#") != -1) {
        currentTitle = currentTitle.substr(0, currentTitle.indexOf("#"));
    }
    currentURL    = encodeURIComponent(currentURL);
    currentTitle  = encodeURIComponent(currentTitle);
    location.href = '/email.csp?t=' + currentTitle + '&u=' + currentURL;
}

