


(function($)
{
  if (typeof $_GET == 'undefined')
  {
    var $_GET = {};

    document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function() 
    {
      function decode(s) 
      {
        return decodeURIComponent(s.split("+").join(" "));
      }

      $_GET[decode(arguments[1])] = decode(arguments[2]);
    });
  }
  
  var image_cache = [];

  $.preLoadImages = function() 
  {
    for (var i = arguments.length; i--;) 
    {
      var img = document.createElement('img');
      img.src = arguments[i];
      image_cache.push(img);
    }
  }
  
  $(document).ready(function()
  {
    siga.init();
  });  
  
  var siga = {
    
    slide_timer: 5000,
    
    slide_interval: null,
    
    slide_current: 1,
    
    init: function()
    {
      $.preLoadImages(
        '/content/feature-1.jpg'
        ,'/content/feature-2.jpg'
        ,'/content/feature-3.jpg'
        ,'/content/feature-4.jpg'
        ,'/theme/img/header.jpg'
        ,'/theme/img/bg.jpg'
      );

      $('#q')
        .val('Search SIGA.com')
        .focus(function(event)
        {
          $(this).val('');
        });

      siga.slide_setup();

      SimplyButtons.init();
    },
    
    slide_setup: function()
    {
      if ($('#featured-slides').length == 0)
      {
        return false;
      }
      
      siga.slide_interval = setInterval(siga.slides, siga.slide_timer); 
      
      $('#featured-slides').hover(
        function()
        {
          clearInterval(siga.slide_interval);
        }
        ,function()
        {
          siga.slide_interval = setInterval(siga.slides, siga.slide_timer); 
        }
      );
    },
    
    slides: function()
    {
      $('#featured-slides .slide-' + siga.slide_current + ':first')
        .css({
          'z-index': 1000
        })
        .fadeOut('fast');
      
      $('#featured-slides .control-' + siga.slide_current + ':first').removeClass('conrtol-selected');

              
      siga.slide_current++;
      
      if (siga.slide_current > 3)
      {
        siga.slide_current = 1;
      }
      
      $('#featured-slides .slide-' + siga.slide_current + ':first')
        .css({
          'z-index': 2000
          ,'visible': 'visible'
          ,'display': 'none'
        })
        .fadeIn('fast');
        
      $('#featured-slides .control-' + siga.slide_current + ':first').addClass('conrtol-selected');
      
    }
  }
  
})(jQuery);



//  Simply Buttons, version 2.0
//  (c) 2007-2011 Kevin Miller
//
//  This script is freely distributable under the terms of an MIT-style license.
// 
/*-----------------------------------------------------------------------------------------------*/
// 
// * Adjusts the buttons so that they will not have an outline when they are pressed.
// * If the browser is mobile then we replace the buttons with inputs for compatibility.
// * Disables the text in the buttons from being selected.
// * The default styles here are meant for use with the Sliding Doors technique http://alistapart.com/articles/slidingdoors/
//     to be used for IE so we can have nice states with a horrid browser too!
//
/*-----------------------------------------------------------------------------------------------*/

var SimplyButtons = {
  
  options : {
    hyperlinkClass : 'button'
    ,activeButtonClass : 'button_active'
    ,states : {
      outer : {
        active : {
          backgroundPosition : 'bottom left'
        }
        ,inactive : {
          backgroundPosition : 'top left'
        }
      }
      ,inner : {
        active : {
          backgroundPosition : 'bottom right'
        }
        ,inactive : {
          backgroundPosition : 'top right'
        }
      }
    }
    ,iphone : {
      replaceButtons : true
    }
  }
  
  ,buttons : []
  
  ,iphone : false
  
  ,init : function(options)
  {
    for (var property in options)
    {
      this.options[property] = options[property];
    }
    
    this.iphone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i));
    
    this.process(document.getElementsByTagName('button'), false);
    this.process(document.getElementsByTagName('a'), true);
    
    if (this.iphone && this.options.iphone.replaceButtons)
    {
      this.remove();
    }
  }

  ,process : function(elements, links)
  {
    var linkTest = new RegExp('\\b' + this.options.hyperlinkClass + '\\b');
    for (var a = 0; a < elements.length; a++)
    {
      if ((links && linkTest.test(elements[a].className)) || !links)
      {
        if (this.iphone && !links)
        {
          this.mobile(elements[a]);
        }
        else
        {
          this.disable(elements[a]);
          this.setup(elements[a]);
        }
        
        if (!links)
        {
          this.buttons.push(elements[a]);
        }
      }
    }
  }
  
  ,mobile : function(element)
  {
    var input = document.createElement('input');
    input.setAttribute('type', element.getAttribute('type') == 'submit' ? 'submit' : 'button');
    
    var attributes = new Array('id', 'name', 'value', 'class', 'onclick', 'onmouseover', 'onmouseout', 'onpress', 'onfocus', 'onblur', 'onmouseup', 'onmousedown');
    for (var a = 0; a < attributes.length; a++)
    {
      if (element.getAttribute(attributes[a]))
      {
        input.setAttribute(attributes[a], element.getAttribute(attributes[a]));       
      }
    }
    
    input.style.marginLeft = element.style.marginLeft;
    input.style.marginRight = element.style.marginRight;

    element.parentNode.insertBefore(input, element);
    
  }
  
  ,remove : function()
  {
    for (var a = 0; a < this.buttons.length; a++)
    {
      this.buttons[a].parentNode.removeChild(this.buttons[a]);
    }      
  }
   
  ,disable : function(element)
  {
    element.onselectstart = function() { return false; };
    element.style.MozUserSelect = 'none';
    element.style.KhtmlUserSelect = 'none';
    element.style.UserSelect = 'none';
    element.style.cursor = 'default';
  }
  
  ,setup : function(element) 
  {
    if (document.all)
    {
      if (element.tagName == 'BUTTON')
      {
        element.attachEvent('onfocus', this.bind(this.toggle, this, element));
      }
      else
      {
        element.attachEvent('onmousedown', this.bind(this.toggle, this, element));
      }
      element.attachEvent('onmouseup', this.bind(this.toggle, this, element));
    }
    else
    {
      element.onfocus = function() { this.blur(); };
    }
  }
  
  ,toggle : function(o, element)
  {
    if (element.tagName != 'BUTTON' && element.tagName != 'A')
    {
      while (element.tagName != 'A')
      {
        element = element.parentNode;
      }
    }
    if (event.type == 'focus' || event.type == 'mousedown')
    {
      element.className += ' ' + o.options.activeButtonClass;
      o.style(element.childNodes[0], o.options.states.inner.active);
      o.style(element.childNodes[0].childNodes[0], o.options.states.outer.active);
      element.blur();
    } 
    else
    {
      element.className = element.className.replace(o.options.activeButtonClass, '');
      o.style(element.childNodes[0], o.options.states.inner.inactive);
      o.style(element.childNodes[0].childNodes[0], o.options.states.outer.inactive);
    }
  }
  
  ,style : function(element, styles)
  {
    for (var property in styles)
    {
      element.style[property] = styles[property];
    }    
  }
  
  ,bind : function(func)
  {
    var args = [];
    for (var a = 1; a < arguments.length; a++)
    {
      args.push(arguments[a]);
    }
    return function() { return func.apply(this, args); };
  }

};
