/*
Infinite slider Lite
http://code.google.com/p/jquery-slider-lite/

Martin Conte Mac Donell <Reflejo@gmail.com>
*/

jQuery.fn.slider = function(options){
  // This is the huge dynamic container. This will be masked by sliderVisible
  var container = $('<div class="sliderContainer" />');
  var width = 0, height = 0;
  var images = this.find('img');
  var defaultOptions = {
    velocity: 50
  };
  
  // Create mask, set height/width and replace given object with our slider.
  var craftSlider = function(where) {
    var visible = $('<div class="sliderVisible" />');

    // Set container
    container.width(width)
             .height(height)
             .css('position', 'absolute');

    // Hide overflow and position "fixed" because img are absolutes.
    visible.css({
      overflow: 'hidden',
      position: 'relative'
    }).height(height);

    // Insert into page
    $(where).replaceWith(visible.append(container));
  };

  // Main loop, search for images inside given object
  options = $.extend(defaultOptions, options);
  $.each(images, function(i, obj) { 
    var img = $(obj);
    // Put image just after the last one.
    img.css({
      display: 'block',
      position: 'absolute',
      left: width
    });
    width += img.width();

    // Keep max height to set containers.
    height = Math.max(img.height(), height);

    // Add image into container
    container.append(img);
  });
  craftSlider(this);

  // Start first animation.
  container.animate(
    {left: (-container.width()) + 'px'}, 
    {
      easing: 'linear', 
      duration: 1200 * container.width() / options.velocity
    }
  );

  var mLeft = 0;
  var count = 0, last = images.length;

  // Check if images is outside the cointainer
  function move_images() {
    var container_left = container.position().left;
    var diff = mLeft - container_left;
    var firstImage = $(images[count]);

    // If our first images is outside the container, move it to the right
    if (diff >= firstImage.width())
    {
      // Resize container
      container.width(width + firstImage.width());

      // Move image
      firstImage.css('left', width);

      // Set next width
      width += firstImage.width();

      // Enqueue next animation.
      container.animate(
        {left: (-width) + 'px'}, 
        {
          easing: 'linear', 
          duration: 1200 * firstImage.width() / options.velocity
        }
      );

      //mLeft = container_left;
      mLeft -= firstImage.width();
      count = (count === (last - 1)) ? 0: count + 1;
      move_images();
    }
  }
  setInterval(move_images, 1000);

  return this;
}


// HOMEPAGE CLIENT SLIDER
 
 $(document).ready(function(){
        $(window).load(function() {
          $('.slider').slider();
        });
      });

var min_top, max_top;


$(window).scroll(function() {
  if (($(this).scrollTop() > min_top) && ($(this).scrollTop() < max_top))
    $('.sideCol').stop().animate({'top': $(this).scrollTop()-383 + "px"}, 'slow');
  else if ($(this).scrollTop() < max_top)
    $('.sideCol').stop().animate({'top': "0px"}, 'slow');

});



// RIGHT COLUMN SHARE OPTIONS
 
  function ToggleVideo() {
      if ($('#SocialDrawer').css('display') === 'none') {
//        $('.ShareSlider').css();
        $('#SocialDrawer').slideDown(200);
        $('a.btn-see-now').hide();
        $('a.btn-Socialclose').show();
      } else {
//        $('.ShareSlider').css({'background':'url(../images/bg-box.png) no-repeat'});
        $('#SocialDrawer').slideUp(200);
        $('a.btn-Socialclose').hide();
        $('a.btn-see-now').show();
      }
      return false;
  }
  function ToggleVideoEmail() {
      if ($('#EmailDrawer').css('display') === 'none') {
//          $('.EmailSlider').css();
          $('#EmailDrawer').slideDown(200);
          $('a.btn-email').hide();
          $('a.btn-Emailclose').show();
      } else {
//          $('.EmailSlider').css({ 'background': 'url(../images/bg-box.png) no-repeat' });
          $('#EmailDrawer').slideUp(200);
          $('a.btn-Emailclose').hide();
          $('a.btn-email').show();
      }
      return false;
  }
	$(document).ready(function () {
	    $('a.btn-see-now').click(ToggleVideo);
	    $('a.btn-Socialclose').click(ToggleVideo);
	    $('a.btn-email').click(ToggleVideoEmail);
	    $('a.btn-Emailclose').click(ToggleVideoEmail);
	    $('a.ShareClick').click(ToggleVideo);

  });
  
  
  
  
  // JavaScript Document
$(document).ready(function() {
  function filterPath(string) {
  return string
    .replace(/^\//,'')
    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
    .replace(/\/$/,'');
  }
 
  var locationPath = filterPath(location.pathname);
  $('a[href*=#]').each(function() {
    var thisPath = filterPath(this.pathname) || locationPath;
    if (  locationPath == thisPath
    && (location.hostname == this.hostname || !this.hostname)
    && this.hash.replace(/#/,'') ) {
      var $target = $(this.hash), target = this.hash;
      if (target) {
        var targetOffset = $target.offset().top;
        $(this).click(function(event) {
          event.preventDefault();
          $('html, body').animate({scrollTop: targetOffset}, 400, function() {
            location.hash = target;
          });
        });
      }
    }
  });
});
  
