﻿// JScript File

// JScript File

function createButton(opts) {
  var button = document.createElement('A');
  button.innerHTML = opts.label;
  button.href = '#';
  button.id = opts.id;
  var menu = opts.menu;
  button.onclick = function() { menu.show(); return false; }
  document.getElementById(opts.parent).appendChild(button);
  menu.render(opts.parent);
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}


function menuRedirect(e_name,e_obj,which) {
  //location.href = '?' + which;
  //var cnames = {filter_boards:'fpb',filter_text:'fptxt',content:'fpc'};
  //createCookie(args[0],args[1],30);
  var cb = { success: function(o) { eval(o.responseText); } };
  var transaction = YAHOO.util.Connect.asyncRequest('GET', '?' + which, cb, null);
  // uncheck items within the same group
  var menuItems = this.parent.getItemGroups();
  for(var i in menuItems[this.groupIndex]) {
  	 menuItems[this.groupIndex][i].cfg.setProperty("checked", false);
  }
  this.cfg.setProperty("checked", true);
  return false;
}

var filterButtonMenu = new YAHOO.widget.Menu("filtermenu",{iframe:false,width:"200px",context:["filter-container","tr","br"]});
filterButtonMenu.addItems([
  [ 
    { text: "Show All Boards", checked: false, onclick: { fn: menuRedirect, obj: 'filter_boards=all' } },
    { text: "Show Adult Boards Only", checked: false, onclick: { fn: menuRedirect, obj: 'filter_boards=nws' } },
    { text: "Show Worksafe Boards Only", checked: false, onclick: { fn: menuRedirect, obj: 'filter_boards=ws' } },
    { text: "Show All Boards (Classic)", checked: false, onclick: { fn: menuRedirect, obj: 'filter_boards=allc' } }
  ],
  [ { text: "Show Text Boards", checked: false, onclick: { fn: menuRedirect, obj: 'filter_text=show' } },
   { text: "Hide Text Boards", checked: false, onclick: { fn: menuRedirect, obj: 'filter_text=hide' } } ],
   [ {text: "Use Frames", url: 'http://www.4chan.org/frames/', target: '_top' } ]
]);


var filterButton = createButton({id:'filter-button', label:'filter', parent:'filter-container', menu:filterButtonMenu});

var optionButtonMenu = new YAHOO.widget.Menu("optionsmenu",{iframe:false,width:"275px",context:["options-container","tr","br"]});
optionButtonMenu.addItems([
    { text: "Show Worksafe Content &amp; Images Only", checked: false, onclick: { fn: menuRedirect, obj: 'content=ws' } },
    { text: "Show Adult Content &amp; Images Only", checked: false, onclick: { fn: menuRedirect, obj: 'content=nws' }  },
    { text: "Show All Content &amp; Images", checked: false, onclick: { fn: menuRedirect, obj: 'content=all' }  }
]);

var optionButton = createButton({id:'option-button', label:'options', parent:'options-container', menu:optionButtonMenu});

function initTooltips() {
	var previewTooltipWS = new YAHOO.widget.Tooltip("preview-tooltip-ws", { autodismissdelay: 30000, effect:
	    {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25}, context: YAHOO.util.Dom.getElementsByClassName("tooltiplink-ws", "a") });
	var previewTooltipNWS = new YAHOO.widget.Tooltip("preview-tooltip-nws", { autodismissdelay: 30000, effect:
	    {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25}, context: YAHOO.util.Dom.getElementsByClassName("tooltiplink-nws", "a") });
}
initTooltips();


