/* Filename: /library/javascript/home.js */

function  jQueryStart () {

  // Dialog for calendar
  jQuery("#dialog-calendar").dialog({
        autoOpen: false,
	resizable: false,
	height: 600,
	width: 800,
	modal: true,
	buttons: { "Close": function() { jQuery(this).dialog("close"); } }
    });

  // Slideshow startup
  jQuery('.slideshow').cycle({
    fx: 'fade' // transition type, ex: fade, scrollUp, shuffle, etc...
  });

  jQuery("#special_links .item").mouseover(function () {
      jQuery(this).toggleClass("item_over");
    });

  jQuery("#special_links .item").mouseout(function () {
      jQuery(this).toggleClass("item_over");
    });

  jQuery("#special_links .item").click(function () {
      var sLocation = jQuery(this).find("a").attr("href");
      window.location = sLocation;
      return false;
    });

  jQuery("div.event").mouseover(function () {
      jQuery(this).toggleClass("event_over");
    });

  jQuery("div.event").mouseout(function () {
      jQuery(this).toggleClass("event_over");
    });

  jQuery("div.event").click(function () {

      // Adding an event
      if (jQuery(this).attr("id") == "add_event") {
	jQuery("#EventDialog").dialog("open");
	jQuery("#EventFrame").attr("src", "/add_event.htm");
      }

      // Standard event - go to events page
      else {
	window.location = "/events";
	return false;
      }
    });

  jQuery("#EventDialog").dialog({
      autoOpen: false,
      modal: true,
      height: 550,
      width: 600,
      position: "center",
      buttons: {
          "Exit":             function() { jQuery(this).dialog("close"); },
          "Submit New Event": function() { SaveNewEvent(false); }
          }
    });

    jQuery("#jQError, #jQMessage").dialog({
      autoOpen: false,
      modal: true,
      height: 150,
      width: 300,
      position: "center",
      buttons: { "OK" : function() { jQuery(this).dialog("close"); } }
    });

}

function SaveNewEvent () {
  jQuery("#EventFrame").attr("contentWindow").SubmitForm();
}

function AddNewEvent () {
  jQuery("#EventDialog").dialog("open");
  jQuery("#EventFrame").attr("src", "event.htm");
}

function OpenDialog (sSelect, sTitle, sMessage) {
  jQuery(sSelect).dialog("close");
  jQuery(sSelect).dialog("option", "title", sTitle);
  if (sMessage != null) { jQuery(sSelect).html(sMessage); }
  jQuery(sSelect).dialog("open");
}

function CloseEvent (sMessage) {
  jQuery("#EventDialog").dialog("close");
  if (sMessage) {
    OpenDialog("#jQMessage", "Event update", sMessage);
  } 
}

function NotifyDialog (sTitle, sMessage) {
  OpenDialog("#jQMessage", "Event update", sMessage);
}

function OpenCalendar () {
  jQuery("#dialog-calendar").html('<iframe src="https://www.google.com/calendar/embed?title=BikeCarrboro%20Calendar&amp;showTitle=0&amp;showDate=0&amp;showPrint=0&amp;showTabs=0&amp;showCalendars=0&amp;showTz=0&amp;height=500&amp;wkst=1&amp;bgcolor=%233366cc&amp;src=bikecarrboro%40gmail.com&amp;color=%23A32929&amp;ctz=America%2FNew_York" style=" border-width:0 " width="780" height="500" frameborder="0" scrolling="no"></iframe>');
  jQuery("#dialog-calendar").dialog("open");
}

