window.addEvent('domready', function() {
  url = window.location.pathname;
  
  if (url.match('home'))
  {
    if (GetSwfVer() != -1)
    {
      if (oldEnough() == "Yes"){formValue = 1}else{formValue=0};
      swfPath = "images/flashMenu.swf?oldEnough=" + formValue;
      
      swfobject.embedSWF(swfPath, "homepage", "943", "489", "7.0.0", "images/expressInstall.swf");
    }
    else
    {
      $('homepage').setHTML("<div id='mousemove'><div class='inside move'></div></div> <script>nonFlashVersion();</script>");
    }
  }
  
  $$(".feature").each(function(link) {
    link.addEvent('click', function() {
      link.tween("opacity", 50);
      showId = link.id + "_box";

      $$(".feature_box").each(function(box) {
        if(box.id != showId) {
          box.fade("out");
        }
      });

      $(showId).fade("in");
      
    });
  });
});
  
function nonFlashVersion()
{
  window.addEvent('domready', function() {
 
    var scroll2 = new Scroller('mousemove', {area: 200, velocity: 0.06});

    // Mousemove
    $('mousemove').addEvent('mouseover', scroll2.start.bind(scroll2));
    $('mousemove').addEvent('mouseout', scroll2.stop.bind(scroll2));

  });
}

function flashMovieLegal(remember)
{
  //show the links on the HTML of the page
  showLinks();
  
  //set a cookie for this session so links appear on homepage again
  Cookie.set('legalDrinkingAgeTemporary', 'Yes');
  //if remember = yes then run the function to set the cookie
  if (remember == "rememberYes"){rememberLegal("flash")};
  
}

function showLinks()
{
  $$('.navigation ul').each(function(element){
    element.removeClass('homepage_hide');
  })
}


function oldEnough()
{
  //check either cookie contains legal drinking age in order to skip form
  if (Cookie.get('legalDrinkingAge') == 'Yes' || Cookie.get('legalDrinkingAgeTemporary') == 'Yes'){return "Yes"}
}


function rememberLegal(type)
{
  //only check for the input box if this function is being called outside of flash
  if (type == "nonFlash"){
    if ($('rememberLegal').getProperty('checked') == true){
      Cookie.set('legalDrinkingAge', 'Yes', {duration: 365});
    }
  }
  else
  { 
    //if its inside of flash just set the cookie
    Cookie.set('legalDrinkingAge', 'Yes', {duration: 365});
  }
  //set a cookie for this session so links appear on homepage again
  Cookie.set('legalDrinkingAgeTemporary', 'Yes');
}

function popup(filename) {
  
  window.open(filename, "popup", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=600");
}


function submitForm(form) {
  new Element('p', {html : '<strong>Thank You</strong><br/>Please wait while we process your registration'}).replaces($(document.body).getElement("input[type=submit]"));
}


//index actions
window.addEvent('domready', function() {
  url = window.location.pathname;
  if (url == "/" || url.match('index') || url =="/clients/tiopepe/")
  {
    //if flash is detected or if a cookie is already set then redirect to home
    if (GetSwfVer() != -1 || Cookie.get('legalDrinkingAge') == 'Yes')
    {
      document.location.href='home.html'
    }
    else
    {
      $('index').setStyle('display','block');
    }
  }


//home page checks for cookie
  if (url.match("home") && oldEnough() == 'Yes'){showLinks();};
});

//update total on singular product for2
window.addEvent('domready', function() {

  if (window.location.pathname.match('order'))
  {
    //get total from price column
    var price = $('price').get('text').trim();
    
    price = parseFloat(price.replace(/^./, ""));

    //set listener on select

    $$('select').addEvent('change', function(){
  
    //get select value
    quantity = parseFloat($('item_quantity_1').getProperty('value'));

    sub_total = price * quantity
    
    //replace price with new total
    $('price').setHTML("&pound;" + sub_total.round(2));

    var grand_total = (price * quantity + 12);

    //replace grand total with new total
    $('grand_total').setHTML("&pound;" + grand_total.round(2));

    });
  }
});