(function ($) {

/**
 * Attach handlers to evaluate the strength of any password fields and to check
 * that its confirmation is correct.
 */
Drupal.behaviors.password = {
  attach: function (context, settings) {
    var translate = settings.password;
    $('input.password-field', context).once('password', function () {
      var passwordInput = $(this);
      var innerWrapper = $(this).parent();
      var outerWrapper = $(this).parent().parent();

      // Add identifying class to password element parent.
      innerWrapper.addClass('password-parent');

      // Add the password confirmation layer.
      $('input.password-confirm', outerWrapper).parent().prepend('<div class="password-confirm">' + translate['confirmTitle'] + ' <span></span></div>').addClass('confirm-parent');
      var confirmInput = $('input.password-confirm', outerWrapper);
      var confirmResult = $('div.password-confirm', outerWrapper);
      var confirmChild = $('span', confirmResult);

      // Add the description box.
      var passwordMeter = '<div class="password-strength"><div class="password-strength-text" aria-live="assertive"></div><div class="password-strength-title">' + translate['strengthTitle'] + '</div><div class="password-indicator"><div class="indicator"></div></div></div>';
      $(confirmInput).parent().after('<div class="password-suggestions description"></div>');
      $(innerWrapper).prepend(passwordMeter);
      var passwordDescription = $('div.password-suggestions', outerWrapper).hide();

      // Check the password strength.
      var passwordCheck = function () {

        // Evaluate the password strength.
        var result = Drupal.evaluatePasswordStrength(passwordInput.val(), settings.password);

        // Update the suggestions for how to improve the password.
        if (passwordDescription.html() != result.message) {
          passwordDescription.html(result.message);
        }

        // Only show the description box if there is a weakness in the password.
        if (result.strength == 100) {
          passwordDescription.hide();
        }
        else {
          passwordDescription.show();
        }

        // Adjust the length of the strength indicator.
        $(innerWrapper).find('.indicator').css('width', result.strength + '%');

        // Update the strength indication text.
        $(innerWrapper).find('.password-strength-text').html(result.indicatorText);

        passwordCheckMatch();
      };

      // Check that password and confirmation inputs match.
      var passwordCheckMatch = function () {

        if (confirmInput.val()) {
          var success = passwordInput.val() === confirmInput.val();

          // Show the confirm result.
          confirmResult.css({ visibility: 'visible' });

          // Remove the previous styling if any exists.
          if (this.confirmClass) {
            confirmChild.removeClass(this.confirmClass);
          }

          // Fill in the success message and set the class accordingly.
          var confirmClass = success ? 'ok' : 'error';
          confirmChild.html(translate['confirm' + (success ? 'Success' : 'Failure')]).addClass(confirmClass);
          this.confirmClass = confirmClass;
        }
        else {
          confirmResult.css({ visibility: 'hidden' });
        }
      };

      // Monitor keyup and blur events.
      // Blur must be used because a mouse paste does not trigger keyup.
      passwordInput.keyup(passwordCheck).focus(passwordCheck).blur(passwordCheck);
      confirmInput.keyup(passwordCheckMatch).blur(passwordCheckMatch);
    });
  }
};

/**
 * Evaluate the strength of a user's password.
 *
 * Returns the estimated strength and the relevant output message.
 */
Drupal.evaluatePasswordStrength = function (password, translate) {
  var weaknesses = 0, strength = 100, msg = [];

  var hasLowercase = password.match(/[a-z]+/);
  var hasUppercase = password.match(/[A-Z]+/);
  var hasNumbers = password.match(/[0-9]+/);
  var hasPunctuation = password.match(/[^a-zA-Z0-9]+/);

  // If there is a username edit box on the page, compare password to that, otherwise
  // use value from the database.
  var usernameBox = $('input.username');
  var username = (usernameBox.length > 0) ? usernameBox.val() : translate.username;

  // Lose 5 points for every character less than 6, plus a 30 point penalty.
  if (password.length < 6) {
    msg.push(translate.tooShort);
    strength -= ((6 - password.length) * 5) + 30;
  }

  // Count weaknesses.
  if (!hasLowercase) {
    msg.push(translate.addLowerCase);
    weaknesses++;
  }
  if (!hasUppercase) {
    msg.push(translate.addUpperCase);
    weaknesses++;
  }
  if (!hasNumbers) {
    msg.push(translate.addNumbers);
    weaknesses++;
  }
  if (!hasPunctuation) {
    msg.push(translate.addPunctuation);
    weaknesses++;
  }

  // Apply penalty for each weakness (balanced against length penalty).
  switch (weaknesses) {
    case 1:
      strength -= 12.5;
      break;

    case 2:
      strength -= 25;
      break;

    case 3:
      strength -= 40;
      break;

    case 4:
      strength -= 40;
      break;
  }

  // Check if password is the same as the username.
  if (password !== '' && password.toLowerCase() === username.toLowerCase()) {
    msg.push(translate.sameAsUsername);
    // Passwords the same as username are always very weak.
    strength = 5;
  }

  // Based on the strength, work out what text should be shown by the password strength meter.
  if (strength < 60) {
    indicatorText = translate.weak;
  } else if (strength < 70) {
    indicatorText = translate.fair;
  } else if (strength < 80) {
    indicatorText = translate.good;
  } else if (strength <= 100) {
    indicatorText = translate.strong;
  }

  // Assemble the final message.
  msg = translate.hasWeaknesses + '<ul><li>' + msg.join('</li><li>') + '</li></ul>';
  return { strength: strength, message: msg, indicatorText: indicatorText }

};

/**
 * Field instance settings screen: force the 'Display on registration form'
 * checkbox checked whenever 'Required' is checked.
 */
Drupal.behaviors.fieldUserRegistration = {
  attach: function (context, settings) {
    var $checkbox = $('form#field-ui-field-edit-form input#edit-instance-settings-user-register-form');

    if ($checkbox.size()) {
      $('input#edit-instance-required', context).once('user-register-form-checkbox', function () {
        $(this).bind('change', function (e) {
          if ($(this).attr('checked')) {
            $checkbox.attr('checked', true);
          }
        });
      });

    }
  }
};

})(jQuery);
;

(function($) {

/**
 * Drupal FieldGroup object.
 */
Drupal.FieldGroup = Drupal.FieldGroup || {};
Drupal.FieldGroup.Effects = Drupal.FieldGroup.Effects || {};
Drupal.FieldGroup.groupWithfocus = null;

Drupal.FieldGroup.setGroupWithfocus = function(element) {
  element.css({display: 'block'});
  Drupal.FieldGroup.groupWithfocus = element;
}

/**
 * Implements Drupal.FieldGroup.processHook().
 */
Drupal.FieldGroup.Effects.processFieldset = {
  execute: function (context, settings, type) {
    if (type == 'form') {
      // Add required fields mark to any fieldsets containing required fields
      $('fieldset.fieldset', context).once('fieldgroup-effects', function(i) {
        if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
          $('legend span.fieldset-legend', $(this)).eq(0).append(' ').append($('.form-required').eq(0).clone());
        }
        if ($('.error', $(this)).length) {
          $('legend span.fieldset-legend', $(this)).eq(0).addClass('error');
          Drupal.FieldGroup.setGroupWithfocus($(this));
        }
      });
    }
  }
}

/**
 * Implements Drupal.FieldGroup.processHook().
 */
Drupal.FieldGroup.Effects.processAccordion = {
  execute: function (context, settings, type) {
    $('div.field-group-accordion-wrapper', context).once('fieldgroup-effects', function () {
      var wrapper = $(this);

      wrapper.accordion({
        autoHeight: false,
        active: '.field-group-accordion-active',
        collapsible: true,
        changestart: function(event, ui) {
          if ($(this).hasClass('effect-none')) {
            ui.options.animated = false;
          }
          else {
            ui.options.animated = 'slide';
          }
        }
      });

      if (type == 'form') {
        // Add required fields mark to any element containing required fields
        wrapper.find('div.accordion-item').each(function(i){
          if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
            $('h3.ui-accordion-header').eq(i).append(' ').append($('.form-required').eq(0).clone());
          }
          if ($('.error', $(this)).length) {
            $('h3.ui-accordion-header').eq(i).addClass('error');
            var activeOne = $(this).parent().accordion("activate" , i);
            $('.ui-accordion-content-active', activeOne).css({height: 'auto', width: 'auto', display: 'block'});
          }
        });
      }
    });
  }
}

/**
 * Implements Drupal.FieldGroup.processHook().
 */
Drupal.FieldGroup.Effects.processHtabs = {
  execute: function (context, settings, type) {
    if (type == 'form') {
      // Add required fields mark to any element containing required fields
      $('fieldset.horizontal-tabs-pane', context).once('fieldgroup-effects', function(i) {
        if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
          $(this).data('horizontalTab').link.find('strong:first').after($('.form-required').eq(0).clone()).after(' ');
        }
        if ($('.error', $(this)).length) {
          $(this).data('horizontalTab').link.parent().addClass('error');
          Drupal.FieldGroup.setGroupWithfocus($(this));
          $(this).data('horizontalTab').focus();
        }
      });
    }
  }
}

/**
 * Implements Drupal.FieldGroup.processHook().
 */
Drupal.FieldGroup.Effects.processTabs = {
  execute: function (context, settings, type) {
    if (type == 'form') {
      // Add required fields mark to any fieldsets containing required fields
      $('fieldset.vertical-tabs-pane', context).once('fieldgroup-effects', function(i) {
        if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
          $(this).data('verticalTab').link.find('strong:first').after($('.form-required').eq(0).clone()).after(' ');
        }
        if ($('.error', $(this)).length) {
          $(this).data('verticalTab').link.parent().addClass('error');
          Drupal.FieldGroup.setGroupWithfocus($(this));
          $(this).data('verticalTab').focus();
        }
      });
    }
  }
}

/**
 * Implements Drupal.FieldGroup.processHook().
 *
 * TODO clean this up meaning check if this is really
 *      necessary.
 */
Drupal.FieldGroup.Effects.processDiv = {
  execute: function (context, settings, type) {

    $('div.collapsible', context).once('fieldgroup-effects', function() {
      var $wrapper = $(this);

      // Turn the legend into a clickable link, but retain span.field-group-format-toggler
      // for CSS positioning.

      var $toggler = $('span.field-group-format-toggler:first', $wrapper);
      var $link = $('<a class="field-group-format-title" href="#"></a>');
      $link.prepend($toggler.contents());

      // Add required field markers if needed
      if ($(this).is('.required-fields') && $(this).find('.form-required').length > 0) {
        $link.append(' ').append($('.form-required').eq(0).clone());
      }

      $link.appendTo($toggler);

      // .wrapInner() does not retain bound events.
      $link.click(function () {
        var wrapper = $wrapper.get(0);
        // Don't animate multiple times.
        if (!wrapper.animating) {
          wrapper.animating = true;
          var speed = $wrapper.hasClass('speed-fast') ? 300 : 1000;
          if ($wrapper.hasClass('effect-none') && $wrapper.hasClass('speed-none')) {
            $('> .field-group-format-wrapper', wrapper).toggle();
          }
          else if ($wrapper.hasClass('effect-blind')) {
            $('> .field-group-format-wrapper', wrapper).toggle('blind', {}, speed);
          }
          else {
            $('> .field-group-format-wrapper', wrapper).toggle(speed);
          }
          wrapper.animating = false;
        }
        $wrapper.toggleClass('collapsed');
        return false;
      });

    });
  }
};

/**
 * Behaviors.
 */
Drupal.behaviors.fieldGroup = {
  attach: function (context, settings) {
    if (settings.field_group == undefined) {
      return;
    }

    // Execute all of them.
    $.each(Drupal.FieldGroup.Effects, function (func) {
      // We check for a wrapper function in Drupal.field_group as
      // alternative for dynamic string function calls.
      var type = func.toLowerCase().replace("process", "");
      if (settings.field_group[type] != undefined && $.isFunction(this.execute)) {
        this.execute(context, settings, settings.field_group[type]);
      }
    });

    // Fixes css for fieldgroups under vertical tabs.
    $('.fieldset-wrapper .fieldset > legend').css({display: 'block'});
    $('.vertical-tabs fieldset.fieldset').addClass('default-fallback');

  }
};

})(jQuery);;
/*
 * @author
 *   Thomas Torfs - Savant Media - www.savantmedia.be 
 */

(function($) {

  $.fn.loginFancybox = function(data) {
    $('.lnkAjaxLoginFancybox').fancybox($('body').data('fancyboxSettings'));
  }
  
  $.fn.loginCloseFancybox = function(data) {
    $.fancybox.close();
  }
  
  Drupal.behaviors.aristide_loginform = {
    attach: function(context, settings) {
      // Redirect if yelmoredirect property is set
      if (settings.aristide_loginform_reload) {
        page = $.getUrlHash('page');
        console.log(page);
        if(page == Drupal.settings.basePath + 'user/login') $.clearHash();
        window.location.reload();
      }
    },
  };
  
}) (jQuery);
;
/**
 * @file
 *   Adds main javascript functionality to the Aristide website
 * 
 * @author
 *   Thomas Torfs - Savant Media - www.savantmedia.be 
 *  
 */

(function ($) { 
	$(document).ready(function(e) {
    // remove layerX and layerY, bug in Chrome
    var all = $.event.props,
        len = all.length,
        res = [];
    while (len--) {
      var el = all[len];
      if (el != 'layerX' && el != 'layerY') res.push(el);
    }
    $.event.props = res;
	  
	  // tell the HTML we're using jquery
	  $('body').removeClass('no-jquery');
	  
	  // adjust the margin for the client menu
	  if($('body').hasClass('clientmenu')) {
	    marginV = 85;
	  } else {
	    marginV = 66;
	  }
	  
    // @TODO: incorporate with fancybox
    $.extend({
      loadOverlayPage : function(el) {
        // define variables
        var loadingTimer, loadingFrame = 1, href = $(el).attr('href');
        
        // define the loader functions
        showPageLoader = function() {
          clearInterval(loadingTimer);
          loading.fadeIn(100);
          loadingTimer = setInterval(animatePageLoader, 66);
        }
        animatePageLoader = function() {
          if (!loading.is(':visible')){
            clearInterval(loadingTimer);
            return;
          }
    
          $('div', loading).css('top', (loadingFrame * -40) + 'px');
    
          loadingFrame = (loadingFrame + 1) % 12;
        }
        hidePageLoader = function() {
          loading.hide();
        }
        
        // remove the existing loader
        $('#pageLoader').remove();
        
        // make the loader element, based on the content of the overlay
        if($('#pageNav')) {
          loading = $('<div id="pageLoader" class="inCol2_2"><div></div></div>');
        } else {
          loading = $('<div id="pageLoader"><div></div></div>');
        }
        
        // append it to the fancybox page
        $('#page').append(loading);
        
        // add the loader and fadeout the existing content
        showPageLoader();
        $('#pageContent').fadeOut(100, loadContent);
        
        // load the new content
        function loadContent() {
          $('#pageContentWrapper').load(href + ' #pageContent', '', showNewContent);
        }
        // show it
        function showNewContent() {
          $.setNewHash(href);
          $('#pageContent').hide();
          $('#pageContent').fadeIn(100, hideLoader);
        }
        // hide the loader
        function hideLoader() {
          hidePageLoader();
        }
      },
      
      clearHash : function() {
        window.location.hash = '';
      },
      
      
      setNewHash : function(href) {
        
        if( $.isCurrentPage(href)){
          window.location.hash = '';
        } else {
          window.location.hash = 'page=' + href;
        }
      },
      
      isCurrentPage : function(href) {
        var currentUrl = window.location.href.split('#')[0];
        return (currentUrl.indexOf(href, currentUrl.length - href.length) !== -1);
      },
      
      getUrlHashes : function() {
        var vars = {}, hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('#') + 1).split('#');
        for(var i = 0; i < hashes.length; i++)
        {
          hash = hashes[i].split('=');
          vars[hash[0]] = hash[1];
        }
        return vars;
      },
      
      getUrlHash : function(hash) {
        return $.getUrlHashes()[hash];
      },
      
      getUrlVars: function() {
        var vars = {}, hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++)
        {
          hash = hashes[i].split('=');
          vars[hash[0]] = hash[1];
        }
        return vars;
      },
      
      getUrlVar: function(name) {
        return $.getUrlVars()[name];
      }
      
    });
	  
	  
	  // global fancybox settings
	  var fancyboxSettings = {
      'overlayShow' : false,
      'transitionIn' : 'elastic',
      'transitionOut' : 'elastic',
      'autoScale' : false,
      'autoDimensions' : false,
      'speedIn' : 100,
      'speedOut' : 100,
      'changeSpeed' : 100,
      'changeFade' : 100,
      'width' : 1000,
      'height' : 540,
      'padding' : 0,
      'marginV' : marginV,
      'marginH' : 0,
      //'type' : 'iframe',
      'scrolling' : 'no',
      'opacity' : true,
      'titleShow' : false,
      'ajax' : {
        /*dataFilter: function(data) {
          return $(data).find('#page')[0];
        }*/
      },
      'onClosed' : function() {
        $('#colorBandWrapper').focus();
      },
      'onComplete' : function() {
        
        var completeSettings = fancyboxSettings;
        delete completeSettings.href;
        
        Drupal.attachBehaviors($('#fancybox-content'), Drupal.settings);
        
        $('#fancybox-content form').each(function(e){
          Drupal.attachBehaviors(this);
        });
        
        $('#fancybox-content input').each(function(e){
          Drupal.attachBehaviors(this);
        });
        
        $('#fancybox-content .inputClear').inputClear();
        
        // fabrics
        $('#fancybox-content #lnkFabricAdd').click(function(e) {
          e.preventDefault();
          aid = $(this).attr('name');
          if(!isNaN(aid)) {
            $('#projectBox').projectBox('osAddFabric', aid, $('#fancybox-content #fabricCtrls'), showFabricControlsRemove);
          }
          else {
            $('#aristide-messages-wrapper').aristideMessages('show', Drupal.t('The sample could not be added to the Project Box because it is invalid.'), 'error');
          }
        });
        
        $('#fancybox-content #lnkFabricRemove').click(function(e) {
          e.preventDefault();
          aid = $(this).attr('name');
          if(!isNaN(aid)) {
            $('#projectBox').projectBox('osRemoveFabric', aid, $('#fancybox-content #fabricCtrls'), showFabricControlsAdd);
          }
          else {
            $('#aristide-messages-wrapper').aristideMessages('show', Drupal.t('The sample could not be added to the Project Box because it is invalid.'), 'error'); 
          }
        });
        
        $('#fancybox-content #fabricPhotoImage').finezoom({
          'maxZoom' : 4,
          'smoothMove' : 10,
          'zoomStep' : 1.2,
          'toolbar' : true,
          'toolbarPos': ['right','bottom']
        });
        
        $('#fancybox-content #lnkFabricPhoto').click(function(e){
          e.preventDefault();
        });
        
        // add page navigation functionality
        $('#fancybox-content .nav a').fancybox(completeSettings);
        
        // login page
        $('#edit-passtext').show();
        $('#edit-pass').hide();
        
        $('#edit-passtext').focus(function() {
            $('#edit-passtext').hide();
            $('#edit-pass').show();
            $('#edit-pass').focus();
            $('#edit-pass').css('text-align', 'left');
        });
        $('#edit-pass').blur(function() {
            if($('#edit-pass').val() == '') {
                $('#edit-passtext').show();
                $('#edit-pass').hide();
            }
        });
        $('#edit-name').data('value', $('#edit-name').val());
        $('#edit-name').focus(function() {
          if($('#edit-name').val() == $('#edit-name').data('value')) {
            $('#edit-name').attr('value', '');
            $('#edit-name').css('text-align', 'left');
          }
        });
        $('#edit-name').blur(function() {
          if($('#edit-name').val() == '') {
            $('#edit-name').attr('value', $('#edit-name').data('value'));
            $('#edit-name').css('text-align', 'right');
          }
        });
        $('#lnkLoginRegister').fancybox(completeSettings);
        
        
        // pageflips
        $('#fancybox-content .pageflip').booklet({
          width:            946,
          height:           473,
          pagePadding:      0,
          startingPage:     1,
          speed:            200,
          closed:           true
        });
        
        /*$('#fancybox-content .pageflip').swipe({
          swipeLeft: function() { $('#pageflip').booklet('next') },
          swipeRight: function() { $('#pageflip').booklet('prev') }
        });*/
        
        // carousels
        $('#fancybox-content .imageCarousel').carousel({
          itemsPerPage: 3, // number of items to show on each page
          itemsPerTransition: 3, // number of items moved with each transition
          pagination: false, // whether pagination links will be included
          speed: 100, // animation speed
          direction: 'horizontal'
        });
        $('#fancybox-content .listCarousel').carousel({
          itemsPerPage: 10, // number of items to show on each page
          itemsPerTransition: 10, // number of items moved with each transition
          pagination: false, // whether pagination links will be included
          speed: 100, // animation speed
          direction: 'vertical'
        });
        $('#fancybox-content .carousel li a').fancybox(completeSettings);
        
        // backlink
        $('#fancybox-content a.lnkBack').fancybox(completeSettings);
        
        // scrollbar
        $('#scrollContainer').mCustomScrollbar("vertical",200,"easeOutCirc",1.25,"fixed","yes","no",0);
        /* function to fix the -10000 pixel limit of jquery.animate */
        $.fx.prototype.cur = function(){
            if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
              return this.elem[ this.prop ];
            }
            var r = parseFloat( jQuery.css( this.elem, this.prop ) );
            return typeof r == 'undefined' ? 0 : r;
        }
        
        // tipsy
        $('#fancybox-content .tipsy').tipsy({
          gravity: 's',
          delayIn: 0,
          delayOut: 0
        });
        
        // user profile edit navigation
        $('#lstProfileNav a').click(function(e){
          e.preventDefault();
          $('.editProfile .field-group-div').hide();
          $('.' + $(this).attr('name')).show();
          $('#lstProfileNav a').removeClass('active');
          $(this).addClass('active');
        });
        $('.editProfile .field-group-div').hide();
        $('#lnkAccountSettings').click();
        
        // order page - user profile fields
        if($('#edit-field-user-delivery-use input').is(':checked')) {
          $('#orderForm form').animate({width:'100%'});
          $('.group-user-delivery-address').fadeIn();
        }
        $('#edit-field-user-delivery-use input').change(function(e){
          if($(this).is(':checked')) {
            $('#orderForm form').animate({width:'100%'});
            $('.group-user-delivery-address').fadeIn();
          }
          else {
            $('#orderForm form').animate({width:'605px'});
            $('.group-user-delivery-address').fadeOut();
          }
        });
        
        // re-order link
        $('#fancybox-content #lnkReorder').fancybox(completeSettings);
      },
	  };
	  $('body').data('fancyboxSettings', fancyboxSettings);
	  
    
    
    /**
     * ##################
     * Project Box plugin
     * ##################
     */
    var projectBoxMethods = {
      init: function() {
        // more info: http://stackoverflow.com/questions/5095307/jquery-json-response-always-triggers-a-parseerror
        $.ajax({
          type: "POST",
          url: Drupal.settings.basePath + "json/order/get",
          dataType: "text json",
          success: function(data){
            // if the order session was successfully loaded
            $(data.ordersession).each(function(e) {
              $(this).projectBox('pbAddFabric', this.nid, this.aid, this.url, this.thumb);
            });
            var projectBoxSettings = jQuery.extend({}, fancyboxSettings);
            projectBoxSettings.onStart = function() {
              if($('#projectBox .color').length) {
                return true;
              }
              else {
                $('#aristide-messages-wrapper').aristideMessages('show', Drupal.t('Please add at least one sample to the project box in order to continue.'), 'error');
                return false;
              }
            }
            // project box ordering
            $('#lnkProjectBoxOrder').fancybox(projectBoxSettings);
            return 1;
          },
          error: function(jqXHR, textStatus, errorThrown) {
            $('#aristide-messages-wrapper').aristideMessages('show', data.message, 'error');
            
            console.log(jqXHR);
            console.log(textStatus);
            console.log(errorThrown);
            return 0;
          }
        });
        
        // the project box has been initiated
        $(this).data('projectBox', 1);
      },
      /**
       * Clears the project box
       */
      pbClear: function() {
        $(this).find('.lnkRemove').each(function(e) {
          nid = $(this).data('nid');
          aid = $(this).data('aid');
          
          if(nid && aid) {
            $(this).projectBox('pbRemoveFabric', nid, aid);
          }
        });
      },
      /**
       * Adds a fabric to the order session
       * 
       * @param   aid   the acode id
       * @param   throbberParent    the parent element for the throbber 
       */
      osAddFabric: function(aid, throbberParent, callback) {
        $(throbberParent).throbber();
  
        // more info: http://stackoverflow.com/questions/5095307/jquery-json-response-always-triggers-a-parseerror      
        $.ajax({
          type: "POST",
          url: Drupal.settings.basePath + "json/order/add/" + aid,
          dataType: "text json",
          success: function(data){
            $(throbberParent).throbber('destroy');
            // if the fabric was added to the order session successfully, add it to the project box
            if(data.status) {
              $(this).projectBox('pbAddFabric', data.fabric.nid, data.fabric.aid, data.fabric.url, data.fabric.thumb);
              if($.isFunction(callback)) callback();
              return 1;
            }
            // if an error occurred
            else {
              $('#aristide-messages-wrapper').aristideMessages('show', data.message, 'error');
              return 0;
            }
          },
          error: function(jqXHR, textStatus, errorThrown) {
            $(throbberParent).throbber('destroy');
            $('#aristide-messages-wrapper').aristideMessages('show', data.message, 'error');
            
            console.log(jqXHR);
            console.log(textStatus);
            console.log(errorThrown);
            return 0;
          }
        });
      },
      
      /**
       * Remove a fabric from the order session
       * 
       * @param   aid   the acode id
       * @param   throbberParent    the parent element for the throbber
       */
      osRemoveFabric: function(aid, throbberParent, callback) {
        $(throbberParent).throbber();
  
        // more info: http://stackoverflow.com/questions/5095307/jquery-json-response-always-triggers-a-parseerror      
        $.ajax({
          type: "POST",
          url: Drupal.settings.basePath + "json/order/remove/" + aid,
          dataType: "text json",
          success: function(data){
            $(throbberParent).throbber('destroy');
            // if the fabric was removed from the order session successfully, also remove it from the project box
            if(data.status) {
              $(this).projectBox('pbRemoveFabric', data.fabric.nid, data.fabric.aid);
              if($.isFunction(callback)) callback();
              return 1;
            }
            // if an error occurred
            else {
              $('#aristide-messages-wrapper').aristideMessages('show', data.message, 'error');
              return 0;
            }
          },
          error: function(jqXHR, textStatus, errorThrown) {
            $(throbberParent).throbber('destroy');
            $('#aristide-messages-wrapper').aristideMessages('show', data.message, 'error');
            
            console.log(jqXHR);
            console.log(textStatus);
            console.log(errorThrown);
            return 0;
          }
        });
      },
          
      /**
       * Adds a fabric to the project box
       * 
       * @param   nid         the fabric node id
       * @param   aid         the fabric acode id
       * @param   pbUrl       the fabric URL   
       * @param   pbThumb     the fabric project box thumbnail
       */
      pbAddFabric: function(nid, aid, pbUrl, pbThumb) {
        
        // set the colorband fabric to added
        $cbWrapper = $('#colorBandWrapper');
        if($cbWrapper.data('colorBand')) {
          cbId = $cbWrapper.colorBand('getFabricId', nid);
          if(cbId.length) $cbWrapper.colorBand('cbFabricSetAdded', cbId);
        }
        
        // generate a new ID based on the retrieved id's
        newId = 'pbn' + nid;
        
        // create the projectbox color
        pbColor = $('<div id="' + newId + '" class="color loadSmall" />');
        pbImage = $('<img src="' + pbThumb + '" />');
        ctrls = $('<div class="ctrls" />');
        pbHole = $('<span class="labelHole">&nbsp;</span>');
        lnkRemove = $('<a href="#" class="lnkRemove">' + Drupal.t('Remove sample from the Project Box') + '</a>');
        lnkInfo = $('<a href="' + pbUrl + '" class="lnkInfo">' + Drupal.t('Show sample information') + '</a>');
  
        $(lnkRemove).data('nid', nid);
        $(lnkRemove).data('aid', aid);
  
        $(lnkRemove).click(function(e) {
          e.preventDefault();
          $(this).projectBox('osRemoveFabric', $(this).data('aid'), $(this).parents('.color'), showFabricControlsAdd);
        });
        
        $(lnkInfo).fancybox(fancyboxSettings);
        
        ctrls.append(lnkRemove);
        ctrls.append(lnkInfo);
        
        pbColor.hover(function(){
          $(this).children('.ctrls').css('display', 'block');
        },function(){
          $(this).children('.ctrls').css('display', 'none');
        });
        
        pbColor.append(pbImage);
        pbColor.append(ctrls);
        pbColor.append(pbHole);
        
        // add it to the project box
        $('#projectBox').append(pbColor);
      },
      
      /**
       * Removes a fabric from the project box
       * 
       * @param   nid         the fabric node id
       * @param   aid         the fabric acode id
       */
      pbRemoveFabric: function(nid, aid) {
        // set the colorband fabric to notadded
        $cbWrapper = $('#colorBandWrapper');
        if($cbWrapper.data('colorBand')) {
          cbId = $cbWrapper.colorBand('getFabricId', nid);
          if(cbId.length) $cbWrapper.colorBand('cbFabricSetNotAdded', cbId);
        }
        
        // remove from the Project Box
        pbColor = $('#pbn' + nid);
        pbColor.remove();
      }
    };
    
    /**
     * projectBox plugin
     */
    $.fn.projectBox = function(method) {
      // Method calling logic
      if ( projectBoxMethods[method] ) {
        return projectBoxMethods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
      } else if ( typeof method === 'object' || ! method ) {
        return projectBoxMethods.init.apply( this, arguments );
      } else {
        $.error( 'Method ' +  method + ' does not exist on jQuery.projectBox' );
      }
    }
    
    // init the project box plugin
    $('#projectBox').projectBox();

    
    /**
     * ##################
     * throbber plugin
     * ##################
     */
    var throbberMethods = {
      /**
       * add an ajax throbber to an element
       * 
       * @param   el    the element an ajax throbber has to be attached to
       * 
       * @return  the throbber element if it was attached succesfully
       */
      init: function() {
        $this = $(this);
        if($this) {
          //randomID = $(this).throbber('generateRandomID');
          //ajaxThrobber = $('<div id=' + randomID + ' class="throbberWrapper"><div class="throbber">Loading...</div></div>');
          ajaxThrobber = $('<div class="throbberWrapper"><div class="throbber">' + Drupal.t('Loading...') + '</div></div>');
          $this.append(ajaxThrobber);
          //$this.data('throbber', ajaxThrobber);
          
          return ajaxThrobber;
        }
        else {
          return false;
        }
      },
      /**
       * remove an ajax throbber from an element
       * 
       * @param   el    the element an ajax throbber has to be attached to
       */
      destroy: function() {
        $this = $(this);
        $this.find('.throbberWrapper').remove();
        $this.removeData('throbber');
      },
      /**
       * generate a random ID
       * 
       * @return  id  a random ID
       */
      generateRandomID: function() {
        var chars = "abcdefghjklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW";
        var string_length = 8;
        var myrnd = [], pos;
        
        // loop as long as string_length is > 0
        while (string_length--) {
            // get a random number between 0 and chars.length - see e.g. http://www.shawnolson.net/a/789/make-javascript-mathrandom-useful.html
            pos = Math.floor(Math.random() * chars.length);
            // add the character from the base string to the array
            myrnd.push(chars.substr(pos, 1));
        }
        
        // join the array using '' as the separator, which gives us back a string
        randomID = myrnd.join(''); // e.g "6DMIG9SP1KDEFB4JK5KWMNSI3UMQSSNT"
        
        if($('#' + randomID).length) {
          randomID = generateRandomID();
        }
        else {
          return randomID;
        }
      }
    };
    /**
     * throbber plugin
     */
    $.fn.throbber = function(method) {
      // Method calling logic
      if ( throbberMethods[method] ) {
        return throbberMethods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
      } else if ( typeof method === 'object' || ! method ) {
        return throbberMethods.init.apply( this, arguments );
      } else {
        $.error( 'Method ' +  method + ' does not exist on jQuery.throbber' );
      }
    }
    
    
    /**
     * ############################
     * auto form value clear plugin
     * ############################
     */
    var inputClearMethods = {
      init: function() {
        if(!$(this).data('inputClear')) {
          $(this).data('value', $(this).val());
          $(this).focus(function() {
            if($(this).val() == $(this).data('value')) {
              $(this).attr('value', '');
            }
          });
          $(this).blur(function() {
            if($(this).val() == '') {
              $(this).attr('value', $(this).data('value'));
            }
          });
          
          $(this).data('inputClear', 1);
        }
      }
    };
    
    /**
     * auto form value clear plugin
     */
    $.fn.inputClear = function(method) {
      // Method calling logic
      if ( inputClearMethods[method] ) {
        return inputClearMethods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
      } else if ( typeof method === 'object' || ! method ) {
        return inputClearMethods.init.apply( this, arguments );
      } else {
        $.error( 'Method ' +  method + ' does not exist on jQuery.inputClear' );
      }
    }
    $('.inputClear').inputClear();


    
    /**
     * Shows the add sample link on the fabric detail
     */
    showFabricControlsAdd = function() {
      $('#fancybox-content #lnkFabricAdd').show();
      $('#fancybox-content #lnkFabricRemove').hide();
    }
    
    /**
     * Shows the add sample link on the fabric detail
     */
    showFabricControlsRemove = function() {
      $('#fancybox-content #lnkFabricAdd').hide();
      $('#fancybox-content #lnkFabricRemove').show();
    }
    
    // update the acode search form
    $('#edit-acode').data('value', $('#edit-acode').val());
    $('#edit-acode').focus(function() {
      if($('#edit-acode').val() == $('#edit-acode').data('value')) {
        $('#edit-acode').attr('value', '');
        $('#edit-acode').mask('***-***');
      }
    });
    $("#edit-acode").keypress(function(e) {
      if(e.which == 13){ 
        $('#aristide-acode-search-block .form-submit').trigger('mousedown'); //try trigger submit button even on enter
        return false; //doesn't work regardless of return
      }
    });
    
    $("#nav a").fancybox(fancyboxSettings);
    $("#nav a").click(function(e){
      e.preventDefault();
      $("#nav").animate({opacity: 'hide', height: 'hide'}, 100);
    });
    
    $(".userFancybox").fancybox(fancyboxSettings);
    $(".userFancybox").click(function(e){
      e.stopPropagation();
      e.preventDefault();
      $("#userMenu").animate({opacity: 'hide', height: 'hide'}, 100);
    });
    
    // main menu fading
    $("#navWrapper").hover(function(e) {
      e.preventDefault();
      $("#nav").css('height', 0);
      $("#nav").hoverFlow(e.type, {opacity: 'show', height: '486px'}, 100);
    }, function(e) {
      e.preventDefault();
      $("#nav").hoverFlow(e.type, {opacity: 'hide', height: 'hide'}, 100);
    });
    
    // filter menu fading
    $("#filterWrapper").hover(function(e) {
      e.preventDefault();
      if(!e.target.form) { // fix for firefox "select click on hover"-bug
        $("#filter").css('height', 0);
        $("#filter").hoverFlow(e.type, {opacity: 'show', height: '486px'}, 100);
      }
    }, function(e) {
      e.preventDefault();
      if(!e.target.form) { // fix for firefox "select click on hover"-bug
        $("#filter").hoverFlow(e.type, {opacity: 'hide', height: 'hide'}, 100);
      }
    });
    
    // user menu fading
    $("#userMenuWrapper").hover(function(e) {
      e.preventDefault();
      $("#userMenu").css('height', 0);
      $("#userMenu").hoverFlow(e.type, {opacity: 'show', height: '486px'}, 100);
    }, function(e) {
      e.preventDefault();
      $("#userMenu").hoverFlow(e.type, {opacity: 'hide', height: 'hide'}, 100);
    });
    
    // login
    $('#lnkLogin').fancybox(fancyboxSettings);
    $('#lnkMyProjects').fancybox(fancyboxSettings);
    
    // automatically load other pages
    var hash = window.location.hash;
    var autoSettings = fancyboxSettings;
    
    if(typeof $.getUrlHash('page') != 'undefined') {
      autoSettings.href = $.getUrlHash('page');
      $.fancybox(autoSettings);
    } else {
      if($('body').hasClass('not-front')) {
        autoSettings.href = '#page';
        $.fancybox(autoSettings);
      }
    }
    
    // preventive deleting of the href parameter
    delete fancyboxSettings.href;
    
	});
})(jQuery);
;
/**@license
 * Overscroll v1.4.8
 *  A jQuery Plugin that emulates the iPhone scrolling experience in a browser.
 *  http://azoffdesign.com/overscroll
 *
 * Intended for use with the latest jQuery
 *  http://code.jquery.com/jquery-latest.js
 *
 * Copyright 2011, Jonathan Azoff
 * Dual licensed under the MIT or GPL Version 2 licenses.
 *  http://jquery.org/license
 *
 * For API documentation, see the README file
 *  https://github.com/azoff/Overscroll/blob/master/README.md
 *
 * Date: Sunday, September 25th 2011
 */

/*jslint onevar: true, strict: true */

/*global window, jQuery */

"use strict";

(function (w, m, $, o) {

    // adds overscroll from a jQuery object
    o = $.fn.overscroll = function (options) {
        options = options || {};
        return this.each(function () {
            o.init($(this), options);
        });
    };

    // removes overscroll from a jQuery object
    $.fn.removeOverscroll = function (options) {
        return this.each(function () {
            var remover = $(this).data(o.removerKey);
            if ($.isFunction(remover)) {
                remover();
            }
        });
    };
    
    // adds overscroll scrollto function
    o = $.fn.scrollTo = function (x, y, speed) {
        return this.each(function () {
            o.scrollTo($(this), x, y, speed);
        });
    };
    
    // adds overscroll scrollto function
    o = $.fn.overscrollCenter = function () {
        return this.each(function () {
            o.overscrollCenter($(this));
        });
    };
    
    $.extend(o, {

        // events handled by overscroll
        events: {
            start: "select mousedown touchstart",
            drag: "mousemove touchmove",
            end: "mouseup mouseleave touchend",
            ignored: "dragstart drag"
        },

        // to save a couple bits
        div: '<div/>',
        removerKey: 'overscroll-remover',

        // constants used to tune scroll-ability
        constants: {
            driftFrequency: 10,
            // 20 FPS
            driftSequences: 50,
            driftDecay: 1.15,
            driftTimeout: 500,
            timeout: 500,
            captureThreshold: 20,
            scrollDelta: 15
        },

        // main initialization function
        init: function (target, options) {

            var data = {
                sizing: o.getSizing(target)
            };

            options = $.extend({
                cursor: 'move',
                scrollDelta: o.constants.scrollDelta,
                direction: 'multi',
                cancelOn: ''
            }, options);

            options.scrollDelta = m.abs(options.scrollDelta);

            // remove any old bindings and set up a deconstructor
            target.removeOverscroll();
            target.data(o.removerKey, o.remover(target, data));
            
            $(target).parents().css({
              'position': 'relative',
              'top': 0,
              'left': 0
            });

            target.css({
                position: 'absolute',
                overflow: 'hidden',
                left: 0,
                top: 0,
                cursor: options.cursor
            }).bind(o.events.start, data, o.start)
              .bind(o.events.end, data, o.stop)
              .bind(o.events.ignored, false);

            data.target = target;
            data.options = options;
        },

        remover: function (target, data) {
            return function () {
                target.css({
                    overflow: 'auto',
                    cursor: 'default'
                }).unbind(o.events.start, data, o.start)
                  .unbind(o.events.end, data, o.stop)
                  .unbind(o.events.ignored, false);
            };
        },

        triggerEvent: function (event, data) {
            data.target.trigger('overscroll:' + event);
        },

        // sets a position object
        setPosition: function (event, position, index) {
            position.x = event.pageX;
            position.y = event.pageY;
            position.time = o.time();
            position.index = index;
            return position;
        },

        // starts the drag operation and binds the mouse move handler
        start: function (event) {

            o.clearInterval(event.data.target);

            event.data.startTarget = $(event.target);

            if (!event.data.startTarget.is(event.data.options.cancelOn)) {
                event.data.target.bind(o.events.drag, event.data, o.drag).stop(true, true).data('dragging', false).data('dragged', false);
                event.data.position = o.setPosition(event, {});
                event.data.capture = o.setPosition(event, {}, 2);
                o.triggerEvent('dragstart', event.data);
            }

        },

        // updates the current scroll location during a mouse move
        drag: function (event, ml, mt, left, top) {

            event.data.target.data('dragged', true);

            //scrollleft = this.scrollLeft - (event.pageX - event.data.position.x);
            //scrolltop = this.scrollTop - (event.pageY - event.data.position.y);
            
            //this.scrollLeft = scrollleft;
            //this.scrollTop = scrolltop;
            //console.log(this);
            var scrollleft = $(this).position().left + (event.pageX - event.data.position.x);
            var scrolltop = $(this).position().top + (event.pageY - event.data.position.y);
            
            var viewportwidth;
            var viewportheight;
     
            if (typeof window.innerWidth != 'undefined') {
              viewportwidth = window.innerWidth;
              viewportheight = window.innerHeight;
            } else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
              viewportwidth = document.documentElement.clientWidth;
              viewportheight = document.documentElement.clientHeight;
            } else {
              viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
              viewportheight = document.getElementsByTagName('body')[0].clientHeight;
            }
            
            // if the width is smaller than the window width
            if($(this).width() < viewportwidth) {
              scrollleft = (viewportwidth - $(this).outerWidth()) / 2;
            }
            // else set the bounding box
            else {
              if(scrollleft > 0) scrollleft = 0;
              if(scrollleft < -($(this).outerWidth() - viewportwidth /*+ 200*/)) scrollleft = -($(this).outerWidth() /*+ 200*/ - viewportwidth);
            }
            
            // if the height is smaller than the window height
            if($(this).height() < viewportheight) {
              scrolltop = (viewportheight - $(this).outerHeight()) / 2;
            }
            // else set the bounding box
            else {
              if(scrolltop > 0) scrolltop = 0;
              if(scrolltop < -($(this).outerHeight() - viewportheight /*+ 200*/)) scrolltop = -($(this).outerHeight() /*+ 200*/ - viewportheight);
            }
            
            $(this).css({
              'left': scrollleft,
              'top': scrolltop
            });
            
            //console.log($(this).outerHeight());

            o.setPosition(event, event.data.position);

            if (--event.data.capture.index <= 0) {
                event.data.target.data('dragging', true);
                o.setPosition(event, event.data.capture, o.constants.captureThreshold);
            }

        },

        time: function () {
            return (new Date()).getTime();
        },

        // defers target click event's for one iteration
        deferClick: function (target) {
            var events = target.data('events');
            if (events && events.click && events.click.length) {
                events = events.click.slice();
                target.unbind('click').one('click', function (event) {
                    event.preventDefault();
                    $.each(events, function (i, event) {
                        target.click(event);
                    });
                });
            }
        },

        // ends the drag operation and unbinds the mouse move handler
        stop: function (event, dx, dy, d) {

            if (event.data.position) {

                event.data.target.unbind(o.events.drag, o.drag);

                o.triggerEvent('dragend', event.data);

                if (event.data.target.data('dragging')) {
                    o.drift(this, event, function (data) {
                        data.target.data('dragging', false);
                    });
                }

                // only if we moved, and the mouse down is the same as
                // the mouse up target do we defer the event
                if (event.data.target.data('dragged') && $(event.target)[0] === event.data.startTarget[0]){ // && $(event.target).is(event.data.startTarget)) {
                    event.data.target.data('dragged', false);
                    o.deferClick(event.data.startTarget);
                    event.data.startTarget = null;
                }

                event.data.capture = event.data.position = undefined;

            }

        },

        clearInterval: function (target) {
            target = $(target);
            var interval = target.data('overscroll-interval');
            if (interval) {
                w.clearInterval(interval);
            }
            target.data('overscroll-interval', null);
        },

        setInterval: function (target, interval) {
            o.clearInterval(target);
            $(target).data('overscroll-interval', interval);
        },

        // sends the overscrolled element into a drift
        drift: function (target, event, callback) {
            // only drift on intended drifts
            if ((o.time() - event.data.capture.time) > o.constants.driftTimeout) {
                return callback.call(null, event.data);
            }
            
            target = $(target);
            
            var dx = event.data.options.scrollDelta * (event.pageX - event.data.capture.x),
                dy = event.data.options.scrollDelta * (event.pageY - event.data.capture.y),
                xMod = dx / o.constants.driftSequences,
                yMod = dy / o.constants.driftSequences,
                decay = o.constants.driftDecay;
                
            var viewportwidth;
            var viewportheight;
     
            if (typeof window.innerWidth != 'undefined') {
              viewportwidth = window.innerWidth;
              viewportheight = window.innerHeight;
            } else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
              viewportwidth = document.documentElement.clientWidth;
              viewportheight = document.documentElement.clientHeight;
            } else {
              viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
              viewportheight = document.getElementsByTagName('body')[0].clientHeight;
            }
            
            var maxX = 0;
            var maxY = 0;
            var minX = -($(target).outerWidth() /*+ 200*/ - viewportwidth);
            var minY = -($(target).outerHeight() /*+ 200*/ - viewportheight);

            o.triggerEvent('driftstart', event.data);

            o.setInterval(target, w.setInterval(function () {
              
                var done = true,
                    min = 1,
                    max = -1;

                if (target.position().top > minY && target.position().top < maxY && (yMod > min || yMod < max)) {
                    done = false;
                    var targettop = target.position().top + yMod;
                    if(targettop < minY) targettop = minY;
                    if(targettop > maxY) targettop = maxY;
                    target.css('top', targettop);
                    yMod /= decay;
                }

                if (target.position().left > minX && target.position().left < maxX && (xMod > min || xMod < max)) {
                    done = false;
                    var targetleft = target.position().left + xMod;
                    if(targetleft < minX) targetleft = minX;
                    if(targetleft > maxX) targetleft = maxX;
                    target.css('left', targetleft);
                    xMod /= decay;
                }

                if (done) {
                    o.clearInterval(target);
                    o.triggerEvent('driftend', event.data);
                    callback.call(null, event.data);
                }

            }, o.constants.driftFrequency));

        },
        
        scrollTo: function(target, x, y, speed) {
          
            var viewportwidth;
            var viewportheight;

            if (typeof window.innerWidth != 'undefined') {
              viewportwidth = window.innerWidth;
              viewportheight = window.innerHeight;
            } else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
              viewportwidth = document.documentElement.clientWidth;
              viewportheight = document.documentElement.clientHeight;
            } else {
              viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
              viewportheight = document.getElementsByTagName('body')[0].clientHeight;
            }
            
            var maxX = 0;
            var maxY = 0;
            var minX = -($(target).outerWidth() /*+ 200*/ - viewportwidth);
            var minY = -($(target).outerHeight() /*+ 200*/ - viewportheight);
            
            if(x < minX) x = minX;
            if(x > maxX) x = maxX;
            if(y < minY) y = minY;
            if(y > maxY) y = maxY;
            
            $(target).animate({
              'left': x,
              'top': y
            }, speed);
        },

        // gets sizing for the container
        getSizing: function (container) { 
          
            var sizing = {}, 
                parent = container.get(0),
                container = sizing.container = {
                  width: container.outerWidth(),
                  height: container.outerHeight()
                };

            container.scrollWidth = container.width >= parent.scrollWidth ? container.width : parent.scrollWidth;
            container.scrollHeight = container.height >= parent.scrollHeight ? container.height : parent.scrollHeight

            return sizing;

        },
        
        overscrollCenter: function (target) {
          var scrollleft = $(target).position().left;
          var scrolltop = $(target).position().top;
          
          var viewportwidth;
          var viewportheight;
   
          if (typeof window.innerWidth != 'undefined') {
            viewportwidth = window.innerWidth;
            viewportheight = window.innerHeight;
          } else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
            viewportwidth = document.documentElement.clientWidth;
            viewportheight = document.documentElement.clientHeight;
          } else {
            viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
            viewportheight = document.getElementsByTagName('body')[0].clientHeight;
          }
          
          // if the width is smaller than the window width
          if($(target).width() < viewportwidth) {
            scrollleft = (viewportwidth - $(target).outerWidth()) / 2;
          }
          // else set the bounding box
          else {
            if(scrollleft > 0) scrollleft = 0;
            if(scrollleft < -($(target).outerWidth() - viewportwidth /*+ 200*/)) scrollleft = -($(target).outerWidth() /*+ 200*/ - viewportwidth);
          }
          
          // if the height is smaller than the window height
          if($(target).height() < viewportheight) {
            scrolltop = (viewportheight - $(target).outerHeight()) / 2;
          }
          // else set the bounding box
          else {
            if(scrolltop > 0) scrolltop = 0;
            if(scrolltop < -($(target).outerHeight() - viewportheight /*+ 200*/)) scrolltop = -($(target).outerHeight() /*+ 200*/ - viewportheight);
          }
          
          $(target).css({
            'left': scrollleft,
            'top': scrolltop
          });
        }

    });

})(window, Math, jQuery);
;

(function ($) { 
	$(document).ready(function(e){    
    
	});
})(jQuery);;

(function($) {
  
  var methods = {
    init: function(options) {
      
      $this = $('#aristide-messages-wrapper');
      
      $this.data('aristideMessagesOptions', options);
      
      /* jQuery UI Enhancements */
      if (options.jquery_ui != null) {
        if (options.jquery_ui.draggable == '1') { $this.draggable(); }
      }
    
      /* Popup Message handling */
      if (!$this.hasClass("aristide-messeges-processed")) {
        /* Determine Popup Message position */
        $this.css('width', options.width);
        var vertical = options.vertical; var horizontal = options.horizontal;
        switch (options.position) {
          case 'center':
            vertical = ( $(window).height() - $this.height() ) / 2;
            horizontal = ( $(window).width() - $this.width() ) / 2;
            $this.css({"top":vertical + 'px', "left":horizontal + 'px'});
            break;
          case 'tl':
            $this.css({"top":vertical + 'px', "left":horizontal + 'px'});
            break;
          case 'tr':
            $this.css({"top":vertical + 'px', "right":horizontal + 'px'});
            break;
          case 'bl':
            $this.css({"bottom":vertical + 'px', "left":horizontal + 'px'});
            break;
          case 'br':
            $this.css({"bottom":vertical + 'px', "right":horizontal + 'px'});
            break;
        }
              
        /* Here we control closing and opeing effects and controls */
        if(options.open_after_load) {
          if (options.opendelay != 0) {
            setTimeout( function() {$this.aristideMessages('open')}, options.opendelay * 1000 );
          } else { $this.aristideMessages('open'); }
          if (options.autoclose != 0) {
            $this.aristideMessages('countDownClose', options.autoclose);
          }
          if (options.hover_autoclose == '1') {
            $this.hover(function() {
              clearTimeout(options.countDown);
              $('.message-timer').fadeOut('slow');
              }, function() {
                /* Suggest something to do here! */
              }
            );
          }
        }
        
        $('a.message-close').data('aristideMessages', $this);
        $('a.message-close').click(function() { $(this).data('aristideMessages').aristideMessages('close');  return false; });
        /* Esc key handler for closing the message. This doesn't work on Safari or Chrome
           See the issue here: http://code.google.com/p/chromium/issues/detail?id=14635
        */
        $(document).keypress(function(e){
          if(e.keyCode==27){  
            $this.aristideMessages('close');
            return false; 
          }
        });
      
        /* Determine Popup Message position for IE6 bug with fixed display */
        if (options.fixed == '1' && !($.browser.msie && $.browser.version == '6.0')) {
          $this.css({"position":"fixed"});
        }
        else { /* IE6 handing */
          $this.css({"position":"absolute"});
          $(window).scroll(function() { this.stop().css({top:($(window).scrollTop() + vertical) + 'px'});});
        }
      }
    },
    destroy: function() {
      
    },
    open: function() {
      $messageHtml = $('#aristide-messages .messages').html();
      if($messageHtml && $messageHtml.length) {
        $this = $('#aristide-messages-wrapper');
        options = $this.data('aristideMessagesOptions');
        
        switch (options.popin.effect) {
          case 'fadeIn': $this.fadeIn(options.popin.duration);
            break;
          case 'slideDown': $this.slideDown(options.popin.duration);
            break;
          default: $this.fadeIn(options.popin.duration);
            break;
        }
      }
    },
    close: function() { 
      $this = $('#aristide-messages-wrapper');
      options = $this.data('aristideMessagesOptions');
      
      switch (options.popout.effect) {
        case 'fadeOut': $this.fadeOut(options.popout.duration);
          break;
        case 'slideUp': $this.slideUp(options.popout.duration);
          break;
        default: $this.fadeOut(options.popout.duration);
          break;
      }
      this.addClass("aristide-messeges-processed");
    },
    show: function(message, type) {
      $this = $('#aristide-messages-wrapper');
      options = $this.data('aristideMessagesOptions');
      
      if($('#aristide-messages .content').is(':visible')) $this.aristideMessages('close');
      
      $('#aristide-messages .content').html('');
      $('#aristide-messages .content').html('<div class="messages ' + type + '">' + message + '</div>');
      
      $this.aristideMessages('open');
    },
    countDownClose: function(seconds) {
      $this = $('#aristide-messages-wrapper');
      options = $this.data('aristideMessagesOptions');
      
      if(seconds > 0) {
        seconds--;
        if (options.show_countdown == '1') {
          $('.message-timer').text(Drupal.t('Closing in' + ' ' + seconds + ' ' + Drupal.t('seconds')));
        }
        if(seconds > 0) {
          options.countDown = setTimeout( function() {$this.aristideMessages('countDownClose', seconds);}, 1000 );
        }
        else {
          $this.aristideMessages('close');
        }
      }
    }

  }
  
  $.fn.aristideMessages = function(method) {
    
    // Method calling logic
    if ( methods[method] ) {
      return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
    } else if ( typeof method === 'object' || ! method ) {
      return methods.init.apply( this, arguments );
    } else {
      $.error( 'Method ' +  method + ' does not exist on jQuery.aristideMessages' );
    }    
  
  };
  
	Drupal.behaviors.aristideMessages = {
		attach: function (context) {
  		// initiate the message box
			$('#aristide-messages-wrapper').aristideMessages(Drupal.settings.aristideMessages);
		}
	}
	
})(jQuery);


;
/*
 * @file
 * JavaScript for ajax_example.
 *
 * See @link ajax_example_dependent_dropdown_degrades @endlink for
 * details on what this file does. It is not used in any other example.
 */

(function($) {

  $.fn.acodeFancybox = function(data) {
    $('.acode-box').fancybox($('body').data('fancyboxSettings'));
  }

  // Re-enable form elements that are disabled for non-ajax situations.
  Drupal.behaviors.enableFormItemsForAjaxForms = {
    attach: function() {
    // If ajax is enabled.
	 
    }
  };

})(jQuery);


;

