﻿'use strict';
var $j = jQuery.noConflict(), $ = $j;

// Extensions

$j.fn.setFocus = function () {
  var $this = $j(this),
      $inputToFocus;

  if ($this.is(':input')) {
    $inputToFocus = $this;
  } else {
    $inputToFocus = $this.find(':input:visible:enabled:first');
  }

  if (!$inputToFocus.is(':radio') && !$inputToFocus.is(':checkbox') && !$inputToFocus.is('select')) {
    $inputToFocus.select();
  } else {
    $inputToFocus.focus();
  }
}

// End of Extensions

var site = (function ($) {

  function _log(message) {
    if (typeof console !== 'undefined' && console.log) {
      console.log(message);
    }
  }

  function _invoke(params, confirmation, callback) {
    if (typeof confirmation === 'function') { callback = confirmation; }
    if (typeof confirmation === 'string') { if (!confirm(confirmation)) { return false; } }
    $j.post(params.InvokeUrl ? params.InvokeUrl : window.location.path, params, function (data, textStatus) {
      if (typeof callback === 'function') { callback(data, textStatus); }
    });
    return true;
  }

  return {
    invoke: _invoke,
    log: _log
  };
})();

$j(function () {
  var currentClass = 'current';

  $j('.expandable-section .title').live('click', function () {
    var $title = $j(this),
					$section = $title.closest('.expandable-section'),
					$sectionBody = $section.find('.body'),
					$expandableGroup = $section.closest('.expandable-group');

    if ($sectionBody.is(':hidden')) {
      $expandableGroup.find('.expandable-section').removeClass(currentClass).find('.body').slideUp();
      $sectionBody.slideDown();
      $section.addClass(currentClass);
    }
  });

  $j('.expandable-section .body').slideUp();
});


//function Invoke(params, confirmation, callback) {
//  params.InvokeUrl = '\/cms\/controler.aspx';
//  site.invoke(params, confirmation, callback);
//}
