/*
  Formalize - version 1.1

  Note: This file depends on the jQuery library.
*/

// Module pattern:
// http://yuiblog.com/blog/2007/06/12/module-pattern
var FORMALIZE = (function($, window, document, undefined) {
  // Private constants.
  var PLACEHOLDER_SUPPORTED = 'placeholder' in document.createElement('input');
  var AUTOFOCUS_SUPPORTED = 'autofocus' in document.createElement('input');
  var IE6 = !!($.browser.msie && parseInt($.browser.version, 10) === 6);
  var IE7 = !!($.browser.msie && parseInt($.browser.version, 10) === 7);

  // Expose innards of FORMALIZE.
  return {
    // FORMALIZE.go
    go: function() {
      for (var i in FORMALIZE.init) {
        FORMALIZE.init[i]();
      }
    },
    // FORMALIZE.init
    init: {
      // FORMALIZE.init.ie6_skin_inputs
      ie6_skin_inputs: function() {
        // Test for Internet Explorer 6.
        if (!IE6 || !$('input, select, textarea').length) {
          // Exit if the browser is not IE6,
          // or if no form elements exist.
          return;
        }

        // For <input type="submit" />, etc.
        var button_regex = /button|submit|reset/;

        // For <input type="text" />, etc.
        var type_regex = /date|datetime|datetime-local|email|month|number|password|range|search|tel|text|time|url|week/;

        $('input').each(function() {
          var el = $(this);

          // Is it a button?
          if (this.getAttribute('type').match(button_regex)) {
            el.addClass('ie6-button');

            /* Is it disabled? */
            if (this.disabled) {
              el.addClass('ie6-button-disabled');
            }
          }
          // Or is it a textual input?
          else if (this.getAttribute('type').match(type_regex)) {
            el.addClass('ie6-input');

            /* Is it disabled? */
            if (this.disabled) {
              el.addClass('ie6-input-disabled');
            }
          }
        });

        $('textarea, select').each(function() {
          /* Is it disabled? */
          if (this.disabled) {
            $(this).addClass('ie6-input-disabled');
          }
        });
      },
      // FORMALIZE.init.autofocus
      autofocus: function() {
        if (AUTOFOCUS_SUPPORTED || !$(':input[autofocus]').length) {
          return;
        }

        $(':input[autofocus]:visible:first').focus();
      },
      // FORMALIZE.init.placeholder
      placeholder: function() {
        if (PLACEHOLDER_SUPPORTED || !$(':input[placeholder]').length) {
          // Exit if placeholder is supported natively,
          // or if page does not have any placeholder.
          return;
        }

        FORMALIZE.misc.add_placeholder();

        $(':input[placeholder]').each(function() {
          var el = $(this);
          var text = el.attr('placeholder');

          el.focus(function() {
            if (el.val() === text) {
              el.val('').removeClass('placeholder-text');
            }
          }).blur(function() {
            FORMALIZE.misc.add_placeholder();
          });

          // Prevent <form> from accidentally
          // submitting the placeholder text.
          el.closest('form').submit(function() {
            if (el.val() === text) {
              el.val('').removeClass('placeholder-text');
            }
          }).bind('reset', function() {
            setTimeout(FORMALIZE.misc.add_placeholder, 50);
          });
        });
      }
    },
    // FORMALIZE.misc
    misc: {
      // FORMALIZE.misc.add_placeholder
      add_placeholder: function() {
        if (PLACEHOLDER_SUPPORTED || !$(':input[placeholder]').length) {
          // Exit if placeholder is supported natively,
          // or if page does not have any placeholder.
          return;
        }

        $(':input[placeholder]').each(function() {
          var el = $(this);
          var text = el.attr('placeholder');

          if (!el.val() || el.val() === text) {
            el.val(text).addClass('placeholder-text');
          }
        });
      }
    }
  };
// Alias jQuery, window, document.
})(jQuery, this, this.document);

// Automatically calls all functions in FORMALIZE.init
jQuery(document).ready(function() {
  FORMALIZE.go();
});;
/**
 * @todo
 */

Drupal.omega = Drupal.omega || {};

(function($) {
  /**
   * @todo
   */
  var current;
  var previous;
  
  /**
   * @todo
   */
  var setCurrentLayout = function (index) {
    index = parseInt(index);
    previous = current;
    current = Drupal.settings.omega.layouts.order.hasOwnProperty(index) ? Drupal.settings.omega.layouts.order[index] : 'mobile';

    if (previous != current) {      
      $('body').removeClass('responsive-layout-' + previous).addClass('responsive-layout-' + current);      
      $.event.trigger('responsivelayout', {from: previous, to: current});
    }
  };
  
  /**
   * @todo
   */
  Drupal.omega.getCurrentLayout = function () {
    return current;
  };
  
  /**
   * @todo
   */
  Drupal.omega.getPreviousLayout = function () {
    return previous;
  };
  
  /**
   * @todo
   */
  Drupal.omega.crappyBrowser = function () {
    return $.browser.msie && parseInt($.browser.version, 10) < 9;
  };
  
  /**
   * @todo
   */
  Drupal.omega.checkLayout = function (layout) {
    if (Drupal.settings.omega.layouts.queries.hasOwnProperty(layout) && Drupal.settings.omega.layouts.queries[layout]) {
      var output = Drupal.omega.checkQuery(Drupal.settings.omega.layouts.queries[layout]);
      
      if (!output && layout == Drupal.settings.omega.layouts.primary) {
        var dummy = $('<div id="omega-check-query"></div>').prependTo('body');       

        dummy.append('<style media="all">#omega-check-query { position: relative; z-index: -1; }</style>');
        dummy.append('<!--[if (lt IE 9)&(!IEMobile)]><style media="all">#omega-check-query { z-index: 100; }</style><![endif]-->');
        
        output = parseInt(dummy.css('z-index')) == 100;

        dummy.remove();
      }
      
      return output;
    }

    return false;
  };
  
  /**
   * @todo
   */
  Drupal.omega.checkQuery = function (query) {
    var dummy = $('<div id="omega-check-query"></div>').prependTo('body');       
    
    dummy.append('<style media="all">#omega-check-query { position: relative; z-index: -1; }</style>');
    dummy.append('<style media="' + query + '">#omega-check-query { z-index: 100; }</style>');

    var output = parseInt(dummy.css('z-index')) == 100;
    
    dummy.remove();

    return output;
  };
  
  /**
   * @todo
   */
  Drupal.behaviors.omegaMediaQueries = {
    attach: function (context) {
      $('body', context).once('omega-mediaqueries', function () {
        var primary = $.inArray(Drupal.settings.omega.layouts.primary, Drupal.settings.omega.layouts.order);
        var dummy = $('<div id="omega-media-query-dummy"></div>').prependTo('body');

        dummy.append('<style media="all">#omega-media-query-dummy { position: relative; z-index: -1; }</style>');
        dummy.append('<!--[if (lt IE 9)&(!IEMobile)]><style media="all">#omega-media-query-dummy { z-index: ' + primary + '; }</style><![endif]-->');

        for (var i in Drupal.settings.omega.layouts.order) {
          dummy.append('<style media="' + Drupal.settings.omega.layouts.queries[Drupal.settings.omega.layouts.order[i]] + '">#omega-media-query-dummy { z-index: ' + i + '; }</style>');
        }

        $(window).bind('resize.omegamediaqueries', function () {
          setCurrentLayout(dummy.css('z-index'));
        }).load(function () {
          $(this).trigger('resize.omegamediaqueries');
        });
      });
    }
  };
})(jQuery);;
/**
 * @todo
 */

(function($) {
  /**
   * @todo
   */
  Drupal.behaviors.omegaEqualHeights = {
    attach: function (context) {
      $('body', context).once('omega-equalheights', function () {
        $(window).bind('resize.omegaequalheights', function () {
          $($('.equal-height-container').get().reverse()).each(function () {
            var elements = $(this).children('.equal-height-element').css('height', '');
            
            if (!Drupal.behaviors.hasOwnProperty('omegaMediaQueries') || Drupal.omega.getCurrentLayout() != 'mobile') {
              var tallest = 0;

              elements.each(function () {    
                if ($(this).height() > tallest) {
                  tallest = $(this).height();
                }
              }).each(function() {
                if ($(this).height() < tallest) {
                  $(this).css('height', tallest);
                }
              });
            }
          });
        }).load(function () {
          $(this).trigger('resize.omegaequalheights');
        });
      });
    }
  };
})(jQuery);;
/**
 * This is part of a patch to address a jQueryUI bug.  The bug is responsible
 * for the inability to scroll a page when a modal dialog is active. If the content
 * of the dialog extends beyond the bottom of the viewport, the user is only able
 * to scroll with a mousewheel or up/down keyboard keys.
 *
 * @see http://bugs.jqueryui.com/ticket/4671
 * @see https://bugs.webkit.org/show_bug.cgi?id=19033
 * @see /views_ui.module
 * @see /js/jquery.ui.dialog.min.js
 *
 * This javascript patch overwrites the $.ui.dialog.overlay.events object to remove
 * the mousedown, mouseup and click events from the list of events that are bound
 * in $.ui.dialog.overlay.create
 *
 * The original code for this object:
 * $.ui.dialog.overlay.events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','),
 *  function(event) { return event + '.dialog-overlay'; }).join(' '),
 *
 */

(function ($, undefined) {
  if ($.ui && $.ui.dialog) {
    $.ui.dialog.overlay.events = $.map('focus,keydown,keypress'.split(','),
                                 function(event) { return event + '.dialog-overlay'; }).join(' ');
  }
}(jQuery));
;

(function ($) {

/**
 * Attaches the autocomplete behavior to all required fields.
 */
Drupal.behaviors.headerHover = {
  attach: function (context, settings) {
    var docWidth    = $(window).width()
    var docHeight   = $(window).height()
    
    var itemWidth   = $('.section-header').width();
    var itemHeight   = $('.section-header').height();
    
    var containerWidth = $('.wicked-cool-trees').width();
    var sceneWidth = $('.trees-1').width();
    
    
    if(sceneWidth > containerWidth) {
      // scene is wider than the container
      var sceneOffset = Math.round((sceneWidth - containerWidth)/2);
      var sceneType = 'negative';
    }
    else {
      // scene is narrower than the container
      var sceneOffset = Math.round((containerWidth - sceneWidth)/2);
      var sceneType = 'positive';
    }
          
    //console.log('docWidth : ' + docWidth + ', docHeight : ' + docHeight);
    // add parallaxable elements
    var pList  = [
                   // tree objects
                   { 'obj'    : $('.trees-top'),
                     'xStart' : 0,
                     'yStart' : 0,
                     'xRange' : 150,
                     'yRange' : 0,
                     'invert' : true
                   },
                   { 'obj'    : $('.trees-4'),
                     'xStart' : 0,
                     'yStart' : 0,
                     'xRange' : 80,
                     'yRange' : 20,
                     'invert' : true
                   },
                   { 'obj'    : $('.trees-3'),
                     'xStart' : 0,
                     'yStart' : 0,
                     'xRange' : 60,
                     'yRange' : 40,
                     'invert' : true
                   },
                   { 'obj'    : $('.trees-2'),
                     'xStart' : 0,
                     'yStart' : 0,
                     'xRange' : 40,
                     'yRange' : 60,
                     'invert' : true
                   },
                   { 'obj'    : $('.trees-1'),
                     'xStart' : 0,
                     'yStart' : 0,
                     'xRange' : 20,
                     'yRange' : 80,
                     'invert' : true
                   },
                   // grass objects
                   { 'obj'    : $('.grass-dark'),
                     'xStart' : 0,
                     'yStart' : 0,
                     'xRange' : 0,
                     'yRange' : 0,
                     'invert' : true
                   },
                   { 'obj'    : $('.grass-medium'),
                     'xStart' : 0,
                     'yStart' : 0,
                     'xRange' : 0,
                     'yRange' : 0,
                     'invert' : true
                   },
                   { 'obj'    : $('.grass-light'),
                     'xStart' : 0,
                     'yStart' : 0,
                     'xRange' : 0,
                     'yRange' : 0,
                     'invert' : true
                   },
                 ]
    
    // set the initial locations, used for mathmatical reference
    
    $.each(pList, function(index,value) {
      // let's actually set a real position for these 
      if(sceneType == 'negative') {
        value.obj.css('left', -sceneOffset);
      }
      else {
        value.obj.css('left', sceneOffset);
      }
      //console.log('docWidth : ' + docWidth + ', docHeight : ' + docHeight);
      //console.log('itemWidth : ' + itemWidth + ', itemHeight : ' + itemHeight);
      
      
      var position = value.obj.position();
      //console.log(position);
      value.xStart = position.left
      value.yStart = position.top
      //console.log('xStart : ' + value.xStart + ', yStart : ' + value.yStart);
      
    });
    
    /**
      * Uncomment below to enable the crazy movable trees. :)
      */
    
    /*
    $('.section-header').mousemove(function(e){
      //console.log(e);
      //$('#status').html('<span class="label">pageX:</span> ' + e.pageX +'<span class="label">, pageY:</span> '+ e.pageY);
      var x      = e.pageX
      var y      = e.pageY
      var hRatio = Math.round((x/itemWidth)*100)/100
      var vRatio = Math.round((y/itemWidth)*100)/100
      
      $.each(pList, function(index,value) {
        if(value.invert != true){
          value.obj.css('left',value.xStart + (value.xRange*hRatio))
          value.obj.css('top',value.yStart + (value.yRange*vRatio))
        } else {
          value.obj.css('left',value.xStart - (value.xRange*hRatio))
          value.obj.css('top',value.yStart - (value.yRange*vRatio))
        }
      })      
    });
    */
    
    
    $(window).resize(function(e){
      docWidth  = $('.section-header').width()
      docHeight = $('.section-header').height()
      
      containerWidth = $('.wicked-cool-trees').width();
      sceneWidth = $('.trees-1').width();
      
      
      // Must repeat some steps to keep the trees "centered" on resize
      if(sceneWidth > containerWidth) {
        // scene is wider than the container
        sceneOffset = Math.round((sceneWidth - containerWidth)/2);
        sceneType = 'negative';
      }
      else {
        // scene is narrower than the container
        sceneOffset = Math.round((containerWidth - sceneWidth)/2);
        sceneType = 'positive';
      }
      $.each(pList, function(index,value) {
        // let's actually set a real position for these 
        if(sceneType == 'negative') {
          value.obj.css('left', -sceneOffset);
        }
        else {
          value.obj.css('left', sceneOffset);
        }
        
        
        
        
      });
    });
    }
  };

  
})(jQuery);;
(function ($) {
/**
 * Formatting & Effects for Featured Speaker view(s)
 */
 
Drupal.behaviors.countdownTimer = {
  attach: function(context, settings) {
    $('#countdown_dashboard').countDown({
			targetDate: {
				'day': 		29,
				'month': 	10,
				'year': 	2011,
				'hour': 	8,
				'min': 		0,
				'sec': 		0
			},
			omitWeeks: true
		});
  }
};
Drupal.behaviors.featuredSpeakers = {
  attach: function (context, settings) {
    // first fade out all but the first rotator item.
    $('.attachment .view-featured-speakers .item-list ul li:not(:first-child)').fadeTo(250, 0.10);
    // setup a click event for the thumbnails
    $('.attachment .view-featured-speakers .item-list ul li').click(function(){
      // find the index of the item that was clicked in the thumbnails
      var clickItem = $('.attachment .view-featured-speakers .item-list ul li').index(this);
      item = clickItem + 1;
      
      // setup the appropriate fade in/out on the thumbnails
      // first fade out the others
      $('.attachment .view-featured-speakers .item-list ul li').fadeTo(100, 0.10);
      // now fade in the clicked one
      $(this).fadeTo(100, 1);
      
      // now, let's do the same for out top level (large) images/data
      // first fade out the others
      $('.view-display-id-home_block > .view-content .item-list ul li').fadeOut(250);
      // now fade in the clicked one
      $('.view-display-id-home_block > .view-content .item-list ul li:eq('+clickItem+')').fadeIn(500);
    }); // end click function
    
    
    
    
    // now setup an automated rotation    
    // "Poll" every 5000ms, iterating over each element until none are left, then start over.
    var item = 1;
    var elem = $('.attachment .view-featured-speakers .item-list ul li')
    var over = 'nope';
    $('.block-featured-speakers-home-block').hover(function(){
      over = 'yep';
    }, function(){
      over = 'nope';
    });
    elem
      .doTimeout(5000, function(){
        if (!$('body').hasClass('responsive-layout-mobile')) {
          //console.log('body DOES NOT HAVE responsive-layout-mobile class... CONTINUE');
          var elem = this.eq( item++ );
          if ( elem.length ) {
            if (over == 'nope') {
              elem.click();
            }
            else {
              // fix for hover state
              item--;
            }
            return true;
          }
          else {
            elem = $('.attachment .view-featured-speakers .item-list ul li:eq(0)');
            elem.click();
            item = 1;
            return true;
          }
        }
        else {
          //console.log('body has responsive-layout-mobile class... abort');
          return true;
        }
      });
  }
};

})(jQuery);

;

