YAHOO.namespace("eviesays");

YAHOO.util.Event.onDOMReady(
  function () {
      // Instantiate a Panel from markup
    function quick_pop_up(id) {
       return new YAHOO.widget.Panel(id, { width:"320px", visible:false, constraintoviewport:true, draggable:false } );
    }
    YAHOO.eviesays.sharepop = quick_pop_up('share_popup');
    YAHOO.eviesays.sharepop.render();
    YAHOO.eviesays.calpop = quick_pop_up('send_to_calendar_popup');
    YAHOO.eviesays.calpop.render();
    YAHOO.eviesays.friendpop = quick_pop_up('send_to_friend_popup');
    YAHOO.eviesays.friendpop.render();
    
    YAHOO.util.Event.on("evie_share", "click", YAHOO.eviesays.sharepop.show, YAHOO.eviesays.sharepop, true);
    YAHOO.util.Event.on("evie_send_cal", "click", YAHOO.eviesays.calpop.show, YAHOO.eviesays.calpop, true);
    YAHOO.util.Event.on("evie_send_friend", "click", YAHOO.eviesays.friendpop.show, YAHOO.eviesays.friendpop, true);
    YAHOO.util.Event.on("evie_print_event", "click", print);
    
    YAHOO.util.Dom.removeClass(['share_popup','send_to_calendar_popup', 'send_to_friend_popup'], 'hidden');
  });


YAHOO.util.Event.onDOMReady(
  function (ev) {
    // Get the image link from within its (parent) container.
    function getImage(parent) {
      var el = parent.firstChild;
      
      while (el) {  // walk through till as long as there's an element
        if (el.nodeName.toUpperCase() == "IMG") { // found an image
          // flickr uses "_s" suffix for small, and "_m" for big images respectively
          return el.src.replace(/-100x100\.jpg$/, "-300x300.jpg");
        }
        el = el.nextSibling;
      }
      
      return "";
    }
                                                                        
    // Instantiate a Panel from script
    var image_window = new YAHOO.widget.Panel("evie_image_popup", { width:"320px", fixedcenter:true,visible:false, draggable:false, close:true } );
    image_window.setHeader("　");
    image_window.setBody(" ");
    image_window.render('evie_render_image');

    var carousel = new YAHOO.widget.Carousel("evie_image_carousel"),
    spotlight = YAHOO.util.Dom.get('evie_spotlight');
    if (carousel && spotlight) {
      carousel.on("itemSelected", function (index) {
                    var item = carousel.getElementForItem(index);
                    if (item) {
                      image_window.setBody( '<img src=\"' + getImage(item) + '\">' );
                    }
                  });

      YAHOO.util.Event.on( carousel.getElementForItems(), 'click', function(e){ image_window.show(); });
      carousel.render(); // get ready for rendering the widget
      carousel.show();   // display the widget
    }
  });



