var _CMP_CREATIONS;

var galleryConfig = {
  leftNavMargin : '0',
  rightNavMargin : '48px'
};

_CMP_CREATIONS = {
  showForm : function (element, displayTarget) {
    var target = jQuery(element);
    var displayTarget = jQuery(displayTarget);
    if (target.length > 0 && displayTarget.length > 0) {
      target.click(function () {
        var scope = jQuery(this);
        scope.toggleClass('opened');
        if (scope.hasClass('opened') == false) {
          var resetForm = displayTarget.find('form').validate({
          })
          resetForm.resetForm();
          displayTarget.css('z-index', '1');
          displayTarget.animate({
            right : '171'
          }, 250, function () {
          });w2q1
        } else if (scope.hasClass('opened') == true) {
          displayTarget.animate({
            right : '-46'
          }, 250, function () {
            displayTarget.css('z-index', '6');
          });
        }
      });
    }
  },
  sendForm : function (element, displayTarget) {
    var target = jQuery(element);
    var displayTarget = jQuery(displayTarget);
    if (target.length > 0) {
      target.click(function (e) {
        var targetForm = jQuery(this).parent();
        if (targetForm.length > 0) {
          targetForm.validate({
            errorPlacement : function (error, element) {
              error.insertBefore(element);
            },
            submitHandler : function (form) {
              var nameVal = jQuery('#name').val();
              var emailVal = jQuery('#email').val();
              var textVal = jQuery('#message').val();
              jQuery.ajax({
                url : "includes/contact-process.php",
                type : 'GET',
                data : 'name=' + nameVal + '&email=' + emailVal + '&message=' + textVal,
                success : function () {
                  displayTarget.html('<h3 class="thanks">Thanks! I will be in touch within 24 hours.</h3>');
                }
              });
            }
          });
        }
      });
    }
  },
  textHover : function (target, showTarget) {
    var target = jQuery(target);
    var showDescription = showTarget;
    if (target.length > 0) {
      target.each(function () {
        var current = jQuery(this);
        var image = current.find('img');
        var description = current.find(showDescription);
        current.hover(function (event) {
        current.addClass('animated');
          image.stop(true, true).animate({
            opacity : .09
          },
          {
            duration: 200,
            complete: function() {
              if(current.hasClass('animated')){
                description.animate({top : 0});
              }
              
            }
          })
        }, function () {
          current.removeClass('animated');
          description.animate({
            top : '-230px'
          }, {
            duration: 200,
            complete: function() {
              image.animate({opacity : 1})
            }
          });
        });
      });
    }
  },
  rotation : function (target, next, previous) {
    var target = jQuery(target);
    if (target.length > 0) {
      var nextButton = jQuery(next);
      var previousButton = jQuery(previous);
      var parentUL = target.parent();
      var navigationControl = function (elem) {
        elem.click(function () {
          jQuery(this).unbind('click');
          var first = parentUL.find('li:first');
          var last = parentUL.find('li.last');
          var navItemMargin;
          if (jQuery(this).attr('id') == 'right-nav') {
            navItemMargin = galleryConfig.rightNavMargin;
            var lastLI = parentUL.find('li:last');
            last.animate({
              width : 0
            }, {
              queue : true,
              duration : 250,
              complete : function () {
                first.removeClass('first');
                last.removeClass('last')
                last.addClass('invisibility');
                last.removeAttr('style');
                last.prev().addClass('last');
                lastLI.removeAttr('style');
                lastLI.addClass('first');
                lastLI.detach();
                lastLI.prependTo(parentUL);
                lastLI.animate({
                  width : '222px'
                }, {
                  queue : true,
                  duration : 200,
                  complete : function () {
                    jQuery(this).removeClass('invisibility').removeAttr('style');
                    navigationControl(elem);
                  }
                });
              }
            });
          } else if (jQuery(this).attr('id') == 'left-nav') {
            navItemMargin = galleryConfig.leftNavMargin;
            var next = last.next();
            first.animate({
              width : 0
            }, {
              queue : true,
              duration : 250,
              complete : function () {
                first.removeClass('first');
                first.next().addClass('first');
                first = parentUL.find(':first');
                first.detach();
                first.appendTo(parentUL);
                first.addClass('invisibility');
                first.removeAttr('style');
                last.removeAttr('class').removeAttr('style');
                next.animate({
                  width : '222px'
                }, {
                  queue : true,
                  duration : 300,
                  complete : function () {
                    next.removeClass('invisibility').removeAttr('style').addClass('last');
                    navigationControl(elem);
                  }
                });
              }
            });
          }
        });
      }
      navigationControl(previousButton);
      navigationControl(nextButton);
    }
  },
  logoHoverEffect : function () {
    var headerLogo,headerLogoEffect;
    headerLogo = jQuery('.canvas h1.logo');
    //var headerLogoEffect = jQuery('div.logo-effect');

    headerLogo.each(function() {
      var current = jQuery(this);
      headerLogoEffect = current.parent().find('div.logo-effect');
      if (headerLogoEffect.length > 0) {
        current.mouseenter(function () {
          current.animate({
            opacity : 0
          }, {
            queue : false,
            duration : 200
          });
        });
        current.mouseleave(function () {
          current.animate({
            opacity : 1
          }, {
            queue : false,
            duration : 200
          });
        });
      }
    });
  },
  showCaseSummaries : function(target) {
    var target = jQuery(target);
    if (target.length > 0) {
      target.each(function() {
        var currentTarget = jQuery(this);

        function hoverHandler(event) {
          var liveTarget = jQuery(this);
          liveTarget.unbind('mouseenter');
          var child = jQuery(this).find('a');
          child.animate({
            top : 0
          }, 200, function () {
            jQuery(this).effect("bounce", {direction:'down', times:1 }, 100);
          });
          child.bind('mouseleave', exitHandler);
        }

        ;
        function exitHandler() {
          var exitTarget = jQuery(this);
          exitTarget.animate({
            top : '100%'
          }, 200, function () {
            currentTarget.bind('mouseenter', hoverHandler);
          });
        }
        currentTarget.bind('mouseenter', hoverHandler);
      });
    }
  }
};


