var App = function() {
  
  var _load = function() {
    var now = new Date();
        now = now.valueOf();
    for(var i=0; i<arguments.length; i++) {
      var opts = arguments[i];
      if( typeof(opts.selector)==='undefined' || $(opts.selector).length > 0 ) {
        var has_callback = (typeof(opts.callback)==='undefined') ? false : true;
        if( typeof(opts.worker)==='undefined' ) {
          if(has_callback) {
            $.getScript(opts.js, opts.callback);
          } else {
            $.getScript(opts.js);
          }
        } else if(has_callback) {
          opts.callback();
        }
      }
    }
  }; // App#load
  
  var _log = function(msg) {
    if(typeof(window.console)!=='undefined') { window.console.log(msg); }
  }; // App#log
  
  var _init = function() {
    DD_roundies.addRule('#sidebar #sub-nav ul li a', '5px');
     DD_roundies.addRule('ul#updates-nav li.ui-corner-top a, #main-content .post ul#inner-nav li.ui-corner-top a', '5px 5px 0 0');
    _load(
      {
        selector : '#events-updates, #inner-tabs',
        worker : $.fn.tabs,
        js : '/js/jquery-ui-1.8.2.custom.min.js',
        callback : function() { jQuery('#events-updates, #inner-tabs').tabs({
          show : function(event,ui) {
           jQuery('.ui-tabs-nav li').each(function(){
              if($(this).hasClass('ui-tabs-selected')) { $(this).children('ignore').show(); return; }
              $(this).children('ignore').hide();
            });
          }
        }); }
      },
      {
        selector : '#slideshow',
        worker : $.fn.cycle,
        js : '/js/jquery.cycle.lite.js',
        callback : function() { jQuery('#slideshow').cycle({ timeout : 7000, pause : 1 }); }
      },
      {
        selector : '.cboxElement, #menu-call-to-action-inside li a:first, #menu-call-to-action li a[href$="/about/facilities/"], #menu-call-to-action-inside li a[href$="/about/facilities/"]',
        worker : (typeof(Modals)==='undefined') ? undefined : Modals,
        js : '/js/modals.js'
      },
      {
        selector : '#menu-primary-nav',
        worker : $.fn.dropdowns,
        js : '/js/dropdowns.js'
      }
    );
  }; // App#init
  
  return {
    init : _init,
    load : _load,
    log : _log
  };
  
}(); // App

$(document).ready(
	//DD_roundies.addRule('#primary-actions ul#menu-call-to-action li a', '5x 5px');
  function($) { App.init(); checkContactForm(); }
);

function checkContactForm()
{
    if(window.location.hash == '#\wpcf7-f1-p19-o1')
    {
        if($('.wpcf7-mail-sent-ok').html().length > 1)
        {
            try {
                _gaq.push(['_trackPageview', '/contact/thank-you.html']);
                console.log('sent');
            } catch(e){}
        }
    }
}
