/**
 * This module helps merchant to social media links of facebook,googleplus,linkedin,twitter,pinterest,tumblr in side menu on home screen 
 *
 * NOTICE OF LICENSE
 * 
 * Each copy of the software must be used for only one production website, it may be used on additional
 * test servers. You are not permitted to make copies of the software without first purchasing the
 * appropriate additional licenses. This license does not grant any reseller privileges.
 * 
 * @author    José Gonçalves
 * @copyright 2007-2025  José Gonçalves
 * @license   MIT license
 */

var jq =  jQuery.noConflict(true);

(function (jq) {
  'use strict';

  // Main function
  jq.contactButtons = function( options ){
    
    // Define the defaults
    var defaults = { 
      effect  : '', // slide-on-scroll
      buttons : {
        'facebook':   { class: 'facebook',  use: false, icon: 'facebook',    link: '', title: 'Follow on Facebook' },
        'twitter':    { class: 'twitter',   use: false, icon: 'twitter',     link: '', title: 'Follow on Twitter' },
        'tumblr':     { class: 'tumblr',    use: false, icon: 'tumblr',      link: '', title: 'Visit our Tumblr Page' },
        'google':     { class: 'gplus',     use: false, icon: 'google-plus', link: '', title: 'Visit our Google Plus Page' },
        'youtube':    { class: 'youtube',   use: false, icon: 'youtube',      link: '', title: 'Visit our Youtube Page' },
        'instagram':  { class: 'instagram', use: false, icon: 'instagram',   link: '', title: 'Visit our Instagram Page' },
        'linkedin':   { class: 'linkedin',  use: false, icon: 'linkedin',    link: '', title: 'Visit our LinkedIn Page' },
        'pinterest':  { class: 'pinterest', use: false, icon: 'pinterest',   link: '', title: 'Follow on Pinterest' },
        'vk':  		  { class: 'vk',        use: false, icon: 'vk',          link: '', title: 'Follow on VK' },
        'phone':      { class: 'phone',     use: false, icon: 'phone',       link: '', title: 'Call us', type: 'phone' },
        'email':      { class: 'email',     use: false, icon: 'envelope',    link: '', title: 'Send us an email', type: 'email' }
      }
    };

    // Merge defaults and options
    var s,
        settings = options;
    for (s in defaults.buttons) {
      if (options.buttons[s]) {
        settings.buttons[s] = jq.extend( defaults.buttons[s], options.buttons[s] );
      }
    }
    
    // Define the container for the buttons
    var oContainer = jq("#contact-buttons-bar");

    // Check if the container is already on the page
    if ( oContainer.length === 0 ) {
      
      // Insert the container element
      jq('body').append('<div id="contact-buttons-bar">');
      
      // Get the just inserted element
      oContainer = jq("#contact-buttons-bar");
      
      // Add class for effect
      oContainer.addClass(settings.effect);
      
      // Add show/hide button
      var sShowHideBtn = '<button class="contact-button-link show-hide-contact-bar"><span class="fa fa-angle-left"></span></button>';
      oContainer.append(sShowHideBtn);
      
      var i;
      for ( i in settings.buttons ) {
        var bs = settings.buttons[i],
            sLink = bs.link,
            active = bs.use;
        
        // Check if element is active
        if (active) {
          
          // Change the link for phone and email when needed
          if (bs.type === 'phone') {
            sLink = 'tel:' + bs.link;
          } else if (bs.type === 'email') {
            sLink = 'mailto:' + bs.link;
          }
          
          // Insert the links
          var sIcon = '<span class="fa fa-' + bs.icon + '"></span>',
              sButton = '<a href="' + sLink + 
                          '" class="contact-button-link cb-ancor ' + bs.class + '" ' + 
                          (bs.title ? 'title="' + bs.title + '"' : '') + 
                          (bs.extras ? bs.extras : '') + 
                          '>' + sIcon + '</a>';
          oContainer.append(sButton);
        }
      }
      
      // Make the buttons visible
      setTimeout(function(){
        oContainer.animate({ left : 0 });
      }, 200);
      
      // Show/hide buttons
      jq('body').on('click', '.show-hide-contact-bar', function(e){
        e.preventDefault();
        e.stopImmediatePropagation();
        jq('.show-hide-contact-bar').find('.fa').toggleClass('fa-angle-right fa-angle-left');
        oContainer.find('.cb-ancor').toggleClass('cb-hidden');
      });
    }
  };
  
  // Slide on scroll effect
  jq(function(){
    
    // Define element to slide
    var el = jq("#contact-buttons-bar.slide-on-scroll");
    
    // Load top default
    el.attr('data-top', el.css('top'));
    
    // Listen to scroll
    jq(window).scroll(function() {
      clearTimeout( jq.data( this, "scrollCheck" ) );
      jq.data( this, "scrollCheck", setTimeout(function() {
        var nTop = jq(window).scrollTop() + parseInt(el.attr('data-top'));
        el.animate({
          top : nTop
        }, 500);
      }, 250) );
    });
  });
  
 }( jq ));
