// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var JugoApp = Class.create({
  
  
  // LOCATIONS FUNCTIONALITY
  // ===========================================================
  setup_location_select: function(){
    $$('#location_drop_downs select').each(function(select) {
      select.observe('change', function(e){
        window.location = $F(this);
      });
    });
  },
  
  questions_show_hide: function(){
    $$("#previous_questions dl dt").each(function(q) {
      q.observe('click', function(e){$(this).next().toggle(); $(this).up().toggleClassName('open')});
    });
  },
  
  
  
  
  // CAROUSEL FUNCTIONALITY
  // ===========================================================
  setup_carousel: function(){
    
  },
  observe_carousel: function(){
    
  },
  select_menu_item: function(item_id){

  },
  
  embed_bobbleheads: function(){
    if($('bobbleheads')){
      var flashvars = {initialURL: "/flash/data/bobbleheads.xml", speed: ".005", startId: "5"};
      var params = {wmode: "transparent"};
      var attributes = {};
      swfobject.embedSWF('/flash/perpetual_scroller.swf', "bobbleheads", 710, 380, '9.0.124', "/flash/expressInstall.swf", flashvars, params, attributes);
    }
  },
  
  enable_offsite_links: function(){
    $$('#social_tools a').each(function(link) {
      link.target = "_blank";
    });
  },

  apply_advanced_css: function(){
    $$('#main h1 + .flash_piece').each(function(elem) {
      elem.addClassName('hanging_flash');
    });
  },
  

  initialize: function() {
    // alert('hi')
    this.apply_advanced_css();
    this.embed_bobbleheads();
    this.setup_location_select();
    this.questions_show_hide();
    this.enable_offsite_links();
  }
});

var flash_link_data = {
  
  
  // Home
  meetTheTeam: "/about-jugo/meet-the-jugo-team",
  feature: "/menu/smoothies/orange-squeeze", 
  createYourOwnSmoothie: "/jugo-fun/create-your-own-smoothie",

  // Menu
  superfoods: "/menu/superfood-smoothies",
  highQualityFruit: "/menu",
  instance5: "/menu",
  sorbetFree: "/the-smoothie-evolved/why-we-re-better",
  smoothieEvolved: "/the-smoothie-evolved/the-smoothie-evolved-2",
  
  // About Jugo
  teamSign: "/about-jugo/meet-the-jugo-team",
  jugoDay: "/about-jugo/jugo-day",
  history: "/about-jugo/history",
  founders: "/about-jugo/the-founders",

  // Jugo Fun
  createYourOwn: "/jugo-fun/create-your-own-smoothie",
  downloads: "/jugo-fun/downloads",
  contests: "/jugo-fun/contests",
  askADietician: "/jugo-fun/ask-a-dietician",
  newsletter: "/jugo-fun/newsletter", 
  
  // Product Lines
  snackin: "/menu/snackin-size-smoothies",
  smoothies: "/menu/smoothies",
  juices: "/menu/fresh-pressed-juices",
  superfood: "/menu/superfood-smoothies",
  protein: "/menu/protein-shakes",
  wraps: "/menu/grilled-wraps",
  flatBreads: "/menu/grilled-flatbreads"
  
}



function swfItemSelected(name)
{
  // console.log(name);
  if(flash_link_data[name] != "undefined" || flash_link_data[name] == ''){
    window.location = flash_link_data[name];
  }else{
    console.log(name);
  }
}

Event.observe(window, 'load', function(){
  jugo_app = new JugoApp();
})