/* ################################################################# */
/*                                                                   */
/*  TITLE:        GLOBAL.JS                                          */
/*  SITE:         nbcnewyork.com                                     */
/*  VERSION:      0.05                                               */
/*  LAST UPDATED: 2008/09/09                                         */
/*  UPDATED BY:   Brian Maniere                                      */
/*                                                                   */
/*  NAMESPACE: G                                                     */
/*                                                                   */
/*  PUBLIC DEFINITIONS:                                              */
/*    preloadImgs()                                                  */
/*    postloadImgs()                                                 */
/*    toggleImgs()                                                   */
/*                                                                   */
/*  PUBLIC FUNCTIONS:                                                */
/*    prepSearchForm()                                               */
/*    outputHTML()                                                   */
/*    outputDebug()                                                  */
/*    navTo()                                                        */
/*                                                                   */
/*  PREREQUISTES:                                                    */
/*    U.preloadImgs                                                  */
/*    U.loadImg                                                      */
/*    U.postloadImgs                                                 */
/*    U.toggleImgs                                                   */
/*    U.toggleImg                                                    */
/*    U.isDomBrowser                                                 */
/*    U.$                                                            */
/*    U.doLoadImgs                                                   */
/*    U.addEvent                                                     */
/*    U.doDoLoadImgs                                                 */
/*    U.insertAfter                                                  */
/*                                                                   */
/* ################################################################# */


(function() {

if(!window.G) {
  window['G'] = {};
}

  // preloadImgs definition
U.preloadImgs = (
  new U.loadImg("NBC_main_v6_A-1.jpg")
);

  // postloadImgs definition
U.postloadImgs = (
  new U.loadImg("btn_go_h.gif")
);

  // toggleImgs definition.  Use toggle button css id as the array identifier when adding to this array
U.toggleImgs["searchSubmit"] = new U.toggleImg("btn_go.gif","btn_go_h.gif");

  // behaviors for search form
function prepSearchForm() {
  if (U.isDomBrowser) {
    if (U.$("searchForm")) {
      var searchForm = U.$("searchForm");
      var searchText = U.$("searchText");
      searchText.onfocus = function() {
        if (this.value=='Search') {
          this.value='';
        }
      }
      searchText.onkeypress = function(e) {
        if (U.enterKeyPressed(e)) {
				  searchForm.submit();
				}
		  }
      U.$("searchSubmit").onmouseover = function() {
        this.src = U.imagePath + U.toggleImgs["searchSubmit"]["hoverImg"];
      }
      U.$("searchSubmit").onmouseout = function() {
        this.src = U.imagePath + U.toggleImgs["searchSubmit"]["defaultImg"];
      }
    }
    return true;
  }
  return false;
}
window['G']['prepSearchForm'] = prepSearchForm;

	// writes markup to screen within specified divID.  Used by Media Viewer.
function outputHTML(markup, divID) {
	if (U.$(divID)) {
		var targetNode = U.$(divID);
		targetNode.innerHTML = markup;
	}
}
window['G']['outputHTML'] = outputHTML;

	// writes debug information to screen.  Outputs the msg param to the div matching with the id in the divID param
function outputDebug(msg, divID) {
  if (U.$(divID)) {
	  var parentNode = U.$(divID);
  	if (!U.$("debug")) {
  		var div = document.createElement("div");
			div.setAttribute("id","debug");
			U.insertAfter(div, parentNode);
		}
		var d = U.$("debug");
		var p = document.createElement("p");
		p.innerHTML = msg;
		d.appendChild(p);
	}
}
window['G']['outputDebug'] = outputDebug;

	// writes debug information to screen.  Outputs the msg param to the div matching with the id in the divID param
function navTo(nextURL) {
  document.location.replace(nextURL);
}
window['G']['navTo'] = navTo;

})();

  // load image(s) before window.onload
U.doLoadImgs(U.preloadImgs);

  // load image(s) upon window.onload
U.addEvent(window,'load',U.doDoLoadImgs);

  // prep forms upon window.onload
U.addEvent(window,'load',G.prepSearchForm);
