
var Page = Class.create(
{
  isMessageOpen: false,
  countryMenu:  '', 
  
	initialize: function() 
	{
	  var allLinks      = $$('a');
  	var listItemLinks = $$('li.link');
    var countryLinks  = $$('li.flag');
    
    this.messageBox   = new MessageBox(); 


		var formElements = $A(document.getElementsByTagName('form'));

		formElements.each(function(form)
		{
	  
		  if (form.id && form.id.match && form.id.match(/^paypal_form_/))
		  {
  		
  		  Element.observe(form, 'submit', function(e)
    		{
    		  window.open('', 'paypal', 'width=810,height=400,scrollbars=yes');
    		  Event.element(e).target = 'paypal';
    		});
		  }
		});
		
  	allLinks.each(function(link)
  	{		
  		if (link.hasClassName('blank'))
  		{
  			Element.observe(link, 'click', function(e) 
  			{
  				window.open(link.href);
  				Event.stop(e);
  			});
  		}

  		if (link.hasClassName('scroll'))
  		{
        Element.observe(link, 'click', function(e)
        {
          var target = link.hash.replace('#', '');

          // Scroll to appropriate section.
      		new Effect.ScrollTo($(target), 
      		{ 
      		  duration: 1.0, 
      		  transition: Effect.Transitions.EaseFromTo
      		});
      		Event.stop(e);
        });
  	  }
  	}.bind(this));

  	countryLinks.each(function(link)
  	{
  	  var message = '';

  	  link.observe('click', function(e)
  	  {
  	    if (this.countryMenu == link.id)
  	    {
  	      this.messageBox.close();
  	      this.countryMenu = '';
  	    }
  	    else
  	    {
  	      switch (link.id)
      	  {
      	    case 'menuFrench':
      	      message = "<p>Bienvenue sur notre site et vous remercions de nous jusqu'à la recherche. Nous sommes en mesure de fournir nos produits dans le monde entier, de sorte s'il vous plaît contactez-nous pour de plus amples informations.</p><p>Nos coordonnées sont indiquées ci-dessous:</p>";
      	      break;
            case 'menuGerman':
            case 'menuSwiss':
            case 'menuAustrian':
      	      message = "<p>Herzlich Willkommen auf unserer Website und danken Ihnen für freuen uns. Wir sind in der Lage zu liefern unsere Produkte weltweit, so bitten wir Sie, kontaktieren Sie uns für weitere Informationen.</p><p>Unsere Kontaktdaten sind wie folgt:</p>";
      	      break;
            case 'menuItalian':
      	      message = "<p>Benvenuti nel nostro sito e vi ringrazio per noi fino alla ricerca. Siamo in grado di fornire i nostri prodotti in tutto il mondo, si prega di fare in modo di contattarci per ulteriori informazioni.</p><p>I nostri recapiti sono i seguenti:</p>";
      	      break;
      	  }
      	  message += '<p id="messageContact"><a href="mailto:info'; // Break up email 
      	  message += '@snokart.com">info@sno';                      // address to foil harvesters
      	  message += 'kart.com</a><br/>+44(0)1442 877298</p>';

          this.messageBox.setMessage(message);
          this.messageBox.open();
                    
          this.countryMenu = link.id;
  	    }        	  
  	  }.bind(this));
  	}.bind(this));

  	listItemLinks.each(function(link)
  	{
  	  var listLink = new ListLink(link);
    });

    if (globals.isCommentPreview)
    {
      Element.scrollTo('headingPreview');
    }
  },
  
  getMessageBox: function()
  {
    return this.messageBox;
  }
});

var MessageBox = Class.create(
{
  isOpen: false,
  
  initialize: function()
  {
    if (!$('message')) $('blockMessage').insert({ top: '<div id="message"></div'});
    $('blockMessage').hide();
  },
  
  setMessage: function(message)
  {
    $('message').innerHTML = '<p>'+message+'</p>';
  },
  
  open: function(delay)
  {    
    if (!this.isOpen) 
    {
      if (!delay) delay = 0;
      new Effect.SlideDown('blockMessage', { delay: delay, duration: 0.5 });
    }
    this.isOpen = true;
  },
  
  close: function(delay)
  {    
    if (this.isOpen) 
    {
      if (!delay) delay = 0;
      new Effect.SlideUp('blockMessage', { delay: delay, duration: 0.5 });
    }
    this.isOpen = false;
  }
});

document.observe("dom:loaded", function() 
{
  page = new Page();
});

var ListLink = Class.create(
{
	initialize: function(link) 
	{	  
		//this.linkElement 	= linkElement;
		 
		link.insert({ bottom: '<div class="overlay"></div>' });
		
		this.overlay = link.select('.overlay')[0];
		this.overlay.setOpacity(0);
		
		this.linkElement = link.select('a')[0];

		Element.observe(link, 'mouseover', function(e) 
		{		
			if (this.isMouseLeaveOrEnter(e, link))
			{
				link.addClassName('over');
				this.overlay.setStyle({ width: link.offsetWidth + 'px', height: link.offsetHeight + 'px' });
				new Effect.Appear(this.overlay, { duration: 0.1, to: 0.1 });
			}
			
			Event.stop(e);
		}.bind(this));		
		
		Element.observe(link, 'mouseout', function(e) 
		{		
			if (this.isMouseLeaveOrEnter(e, link))
			{
				link.removeClassName('over');
				new Effect.Fade(this.overlay, { duration: 0.1 });
			}
			
			Event.stop(e);
		}.bind(this));
		
		Element.observe(link, 'click', function(e) 
		{		
			location.href = this.linkElement.href;
			Event.stop(e);
			
		}.bind(this));
	},
	
	isMouseLeaveOrEnter: function(e, handler) 
	{ 
		if (e.type != 'mouseout' && e.type != 'mouseover') return false; 
		
		var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement; 

		while (reltg && reltg != handler && reltg.parentNode) reltg = reltg.parentNode; 

		return (reltg != handler); 
	}
	
});
/* 
transitions.js
Based on Easing Equations v2.0 
(c) 2003 Robert Penner, all rights reserved. 
This work is subject to the terms in http://www.robertpenner.com/easing_terms_of_use.html
Adapted for Scriptaculous by Ken Snyder (kendsnyder ~at~ gmail ~dot~ com) June 2006 
*/

// Overshooting Transitions 

// Elastic (adapted from "EaseOutElastic") 
Effect.Transitions.Elastic = function(pos) { 
    return -1*Math.pow(4,-8*pos) * Math.sin((pos*6-1)*(2*Math.PI)/2) + 1; 
}; 
// SwingFromTo (adapted from "BackEaseInOut") 
Effect.Transitions.SwingFromTo = function(pos) { 
    var s = 1.70158; 
    if ((pos/=0.5) < 1) return 0.5*(pos*pos*(((s*=(1.525))+1)*pos - s)); 
    return 0.5*((pos-=2)*pos*(((s*=(1.525))+1)*pos + s) + 2); 
}; 
// SwingFrom (adapted from "BackEaseIn") 
Effect.Transitions.SwingFrom = function(pos) { 
    var s = 1.70158; 
    return pos*pos*((s+1)*pos - s); 
}; 
// SwingTo (adapted from "BackEaseOut") 
Effect.Transitions.SwingTo = function(pos) { 
    var s = 1.70158; 
    return (pos-=1)*pos*((s+1)*pos + s) + 1; 
};


// Bouncing Transitions 

// Bounce (adapted from "EaseOutBounce") 
Effect.Transitions.Bounce = function(pos) { 
    if (pos < (1/2.75)) { 
        return (7.5625*pos*pos); 
    } else if (pos < (2/2.75)) { 
        return (7.5625*(pos-=(1.5/2.75))*pos + 0.75); 
    } else if (pos < (2.5/2.75)) { 
        return (7.5625*(pos-=(2.25/2.75))*pos + 0.9375); 
    } else { 
        return (7.5625*(pos-=(2.625/2.75))*pos + 0.984375); 
    } 
}; 
// BouncePast (new creation based on "EaseOutBounce") 
Effect.Transitions.BouncePast = function(pos) { 
    if (pos < (1/2.75)) { 
        return (7.5625*pos*pos); 
    } else if (pos < (2/2.75)) { 
        return 2 - (7.5625*(pos-=(1.5/2.75))*pos + 0.75); 
    } else if (pos < (2.5/2.75)) { 
        return 2 - (7.5625*(pos-=(2.25/2.75))*pos + 0.9375); 
    } else { 
        return 2 - (7.5625*(pos-=(2.625/2.75))*pos + 0.984375); 
    } 
};
 
//Gradual Transitions 
 
// EaseFromTo (adapted from "Quart.EaseInOut") 
Effect.Transitions.EaseFromTo = function(pos) { 
    if ((pos/=0.5) < 1) return 0.5*Math.pow(pos,4); 
    return -0.5 * ((pos-=2)*Math.pow(pos,3) - 2);    
}; 
// EaseFrom (adapted from "Quart.EaseIn") 
Effect.Transitions.EaseFrom = function(pos) { 
    return Math.pow(pos,4); 
}; 
// EaseTo (adapted from "Quart.EaseOut") 
Effect.Transitions.EaseTo = function(pos) { 
    return Math.pow(pos,0.25); 
};