// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
document.observe("dom:loaded", function() {
  
  
  // Open Link in Navi Logo By Clicking Anywhere, not just the link
  $$('div#navigation li').invoke('observe', 'click', naviClickAnywhere);
  function naviClickAnywhere(e) {
    e = Event.element(e);
    if(e.tagName == 'LI'){
      window.location = e.down('a').href;
    }
  }
  //
  
  //make current page's navi-icon stand out
  $$('div#navigation li').each(function(e){
    if( e.down('a').href == location ){
      e.setStyle({marginLeft:'-30px'}).childElements().invoke('setStyle', 'color: black;');
    }
  });
  
  
  //product entry show/hide
  function showhide(evt) {
    el = evt.target.next('.product-description');
    new Effect.toggle(el,'slide', {duration: 0.5});
  }
  [$$('.product-title'), $$('.entry img')].flatten().invoke('observe','click',showhide);
  
  
  // Website Name; Page Title
  bag_name = $('bag_name');
  page_title = $('page_title');
  function fit_elements_in_screen() {
    
    browser_height        = self.innerHeight;
    navi_height           = $('navigation').offsetHeight+50;
    container_w           = $('container').offsetWidth;
    
    var too_short_for_navigation_bar  = (browser_height < navi_height);
    var nav_is_abs_positioned         = ($('navigation').style.position !== "fixed");
    
    if( too_short_for_navigation_bar ){
      $('navigation').style.position = "absolute";
      }
    else if( nav_is_abs_positioned ){
      $('navigation').style.position = "fixed";
      }
    
    var not_wide_enough = (container_w < 800);
      
    if(not_wide_enough){
      bag_name.style.fontSize           = "11px";
      page_title.style.fontSize         = "1.6em";
     }else{
      bag_name.style.fontSize           = "16px";
      page_title.style.fontSize         = "2.1em";
      }
  }

  fit_elements_in_screen();
  window.onresize = fit_elements_in_screen;
  
  
});

function set_group_id(text, li) {
  $('calendar_group_remote_id').value = li.id;
}
