var drambuie = 
{
	generateSliders : function()
	{
		var sliderControls = $(document.body).getElements('.slider_control');
		for(i=0; i< sliderControls.length; i++)
		{
			 radioSlider($(sliderControls[i].getProperty('id')));
		}

		function radioSlider(fieldset)
		{	
			fieldset.getParent().setStyle('margin-bottom', '4em');		
			fieldset.addClass('hidden');
			var statusLabel = new Element('p',{'class': 'status_label'});
			var slider = new Element('div',{'class': 'slider'});
			var knob      = new Element('div',{'class': 'knob'});
			knob.inject(slider);
			var statusBar = new Element('div',{'class': 'status_bar'});
			statusBar.inject(slider);
			var sliderWrapper = new Element('div',{'class': 'slider_wrapper'});
			statusLabel.inject(sliderWrapper);
			slider.inject(sliderWrapper);
			sliderWrapper.inject(fieldset, 'after');
			var elements    = fieldset.getElements('label');
			
			new Slider
			(
				slider,
				knob,
				{
					snap :true,
					steps: elements.length-1,
					range: [0, elements.length-1],
					onChange: function(value)
					{
						fieldset.getElements('input').setProperty('checked', '');
						elements[value].getNext().checked="checked";
						statusLabel.innerHTML = elements[value].innerHTML;
						statusBar.setStyle('width', value * (slider.getStyle('width').toInt()/this.steps) + "px");
					}
				}
			);

			for (var i=0; i<elements.length; i++)
			{
				if (elements[i].getNext().getAttribute('checked'))
				{
					statusBar.setStyle('width', i * (slider.getStyle('width').toInt()/elements.length-1) + "px");
					knob.setStyle('left', i * (slider.getStyle('width').toInt()/elements.length-1) -10 + "px");
					statusLabel.innerHTML = elements[i].innerHTML;
				}
			}

		}
	},
	deleteRequest: function()
	{
		var requestAnchors = $$('a[rel=request]');
		requestAnchors.each
		(
			function(link)
			{
				link.addEvent
				(
					'click',
					function(e)
					{
						var swapElement = link.getParent('.swap');
						if(swapElement)
						{
							e.preventDefault();
							var dimensions = swapElement.getSize();
							swapElement.setStyles({width:dimensions.x, height:dimensions.y});
							makeRequest(swapElement, link.get('href'));
						}
					}
				)
			}
		);
		
		function makeRequest(swapElement, url)
		{
			new Request.HTML
			(
				{
					url: url + "?ajax=true",
					method: 'post',
					evalScripts: true,
					onSuccess: function(html)
					{
						swapElement.highlight('#6A0000');
						swapElement.set('text', '');
						swapElement.adopt(html);
					},
					onFailure: function()
					{
						swapElement.set('text', 'The was an error making this request');
					}
				}
			).send();
		}
	},
	init: function()
	{
		this.generateSliders();
		this.deleteRequest();
	}
};


/*------------------------------------------------------------------
REGISTER MAIN EVENTS
------------------------------------------------------------------*/
window.addEvent
(
	'domready',
	function()
	{
		drambuie.init();
	}
);



/*------------------------------------------------------------------
sIFR REPLACEMENT
------------------------------------------------------------------*/
                     
var kipp    = {src: '/public/frontend/swf/fonts/kipp.swf'};
var calisto = {src: '/public/frontend/swf/fonts/calisto_mt.swf'};
sIFR.activate(kipp);
sIFR.activate(calisto);
sIFR.replace(kipp,    {wmode: 'transparent', selector: '#pursuit_parties h2',  css:['.sIFR-root {color:#ffffff; font-size:24px;}'], tuneHeight:'-5'});
sIFR.replace(kipp,    {wmode: 'transparent', selector: '.day .spotlight h3',   css:['.sIFR-root {color:#ffffff; font-size:24px;}'], tuneHeight:'-5'});
sIFR.replace(kipp,    {wmode: 'transparent', selector: '.day h2',              css:['.sIFR-root {color:#816749; font-size:24px;}'], tuneHeight:'-5'});
sIFR.replace(kipp,    {wmode: 'transparent', selector: '.day h3',              css:['.sIFR-root {color:#816749; font-size:24px;}'],  tuneHeight:'-5'});
sIFR.replace(kipp,    {wmode: 'transparent', selector: '.day .dr_header h1',   css:['.sIFR-root {color:#ffffff; font-size:30px;}'], tuneHeight:'-5'});
sIFR.replace(calisto, {wmode: 'transparent', selector: '.night .spotlight h3', css:['.sIFR-root {color:#ffffff; font-size:20px;}'], tuneHeight:'-5'});
sIFR.replace(calisto, {wmode: 'transparent', selector: '.night h2',            css:['.sIFR-root {color:#f5eac8; font-size:20px;}'], tuneHeight:'-5'});
sIFR.replace(calisto, {wmode: 'transparent', selector: '.night h3',            css:['.sIFR-root {color:#f5eac8; font-size:20px;}'], tuneHeight:'-5'});

/*-------------------------------------------------------------------
External links and Pop-ups
-------------------------------------------------------------------*/

window.onload = function() { 
   // check to see that the browser supports the getElementsByTagName method 
   // if not, exit the loop 
   if (!document.getElementsByTagName) { 
      return false; 
   } 
   // create an array of objects of each link in the document 
   var popuplinks = document.getElementsByTagName("a"); 
   // loop through each of these links (anchor tags)     
   for (var i=0; i < popuplinks.length; i++) 
   {    
      // if the link has a class of "popup"...    
      if (popuplinks[i].className == "popup") 
      {    
         // add an onclick event on the fly to pass the href attribute    
         // of the link to our second function, openPopUp     
         popuplinks[i].onclick = function() 
         {    
             openPopUp(this.getAttribute("href"));    
             return false;     
         }      
      } 
         
      if (popuplinks[i].className == "external") 
      { 
         // add an onclick event on the fly to open a new browser window 
         popuplinks[i].onclick = function() 
         { 
             window.open(this.getAttribute("href")); 
             return false; 
         } 
      } 
   } 
} 

function openPopUp(linkURL) { 
   window.open(linkURL,'popup','width=400,height=200') 
}


  function encode_utf8( s )
  {
    return unescape( encodeURIComponent( s ) );
  }
  
  function decode_utf8( s )
  {
    return decodeURIComponent( escape( s ) );
  }
 
  function urlencode (str) {
    str = escape(str);
    return str.replace(/[*+\/@]|%20/g,
    function (s) {
      switch (s) {
        case "*": s = "%2A"; break;
        case "+": s = "%2B"; break;
        case "/": s = "%2F"; break;
        case "@": s = "%40"; break;
        case "%20": s = "+"; break;
      }
      return s;
    }
    );
  }
  