$(document).ready(function() {
  var slider = $('#banner-rotator').royalSlider({
    imageScaleMode:"none",
    imageAlignCenter:false,
    directionNavEnabled: true,
    directionNavAutoHide: true,
    slideTransitionSpeed:500,
    preloadNearbyImages:false,
    hideArrowOnLastSlide:true,
    slideshowPauseOnHover: true,
    slideshowEnabled: false,
    slideshowDelay:5200,
    welcomeScreenEnabled: true,
    autoScaleSlider: true,
    autoScaleSliderWidth: 980,
    autoScaleSliderHeight: 480
  });

// CUSTOM BLOCK THAT ALLOWS HOME PANEL TO LINK TO OTHER PANELS.  DOES NOT PLAY NICE WITH MODAL WINDOWS.  CONTENT WILL DISAPPEAR UPON MODAL CLOSE.

  // $('.royalCaptionItem a').click(function() {
  //   var slide = parseInt($(this).attr('data-target'));
  //   slider.data("royalSlider").goTo(slide);
  // });
});

// FADE LINKS
// $(document).ready(function(){
// $(".cta,a").hover(
// function() {
// $(this).stop().animate({"opacity": "0.7"}, "fast");
// },
// function() {
// $(this).stop().animate({"opacity": "1"}, "fast");
// });
//
// $(".dark").hover(
// function() {
// $(this).stop().animate({"opacity": "0.9"}, "fast");
// },
// function() {
// $(this).stop().animate({"opacity": "1"}, "fast");
// });
//
// });

// AUTO RESIZE SIDE COLUMN FOR BACKGROUND BLUE
$(document).ready(function() {setHeight('.twocol');});

var maxHeight = 0;
function setHeight(column) {
    //Get all the element with class = col
    column = $(column);
    //Loop all the column
    column.each(function() {
        //Store the highest value
        if($(this).height() > maxHeight) {
            maxHeight = $(this).height();;
        }
    });
    //Set the height
    column.height(maxHeight);
}

// HOMEPAGE "SEE MORE" HOVER
// $("ul.clients").hover(function() {
//   $(".seeourclients").fadeToggle("slow", "linear");
// });


// SWIRLY
$(document).ready(function() {setTimeout("animation()",300);});

function animation(){sun_raft();}

function sun_raft(){$(".swirlyone").animate({left:"+=40px"},5000).animate({left:"-=40px"}, 5000);
  $(".swirlytwo").animate({left:"-=200px"},25000).animate({left:"+=200px"}, 25000);
  setTimeout("sun_raft()",2000);
}

// TWITTER FEED
// jQuery(function($) {
//   $(".tweet").tweet({
//     count: 2,
//     username: ["freewheel"],
//     loading_text: "searching twitter...",
//     refresh_interval: 300,
//   }).bind("loaded",function() {
//     $(this).find("a").attr("target","_blank");
//   });
//   $(".tweetModal").tweet({
//     count: 5,
//     username: ["freewheel"],
//     loading_text: "searching twitter...",
//     refresh_interval: 300,
//     }).bind("loaded",function() {
//       $(this).find("a").attr("target","_blank");
//   });
// });

// LEGACY PARTNER PAGE TOOLTIPS
$(document).ready(function() {
$('li a.cp').cluetip({local:true, cursor:'pointer', arrows: true, positionBy: 'bottomTop', dropShadow: false, showTitle: false});
});

$(document).ready(function() {
$('li a.cp2').cluetip({local:true, cursor:'pointer', arrows: true, positionBy: 'bottomTop', dropShadow: false, showTitle: false});
});

// VALIDATE FORMS
$(document).ready(function(){$("#contact").validate();});

// VALIDATE FORMS
$(document).ready(function(){$("#reportdownload").validate();});

// TOGGLE REPORT ARCHIVES
$(document).ready(function(){
    $(".slidingDiv").hide();
    $(".show_hide").show();

    $('.show_hide').click(function(){$(".slidingDiv").slideToggle();});
});

// HIDES EVENTS ON ROUNDUP OVERVIEW PAGE, SHOWS WHEN "EVENTS" LINK IS CLICKED
$(document).ready(function() {
  // hides onload
  $(".section.all.events").hide();
  // clicking all adds hide class to events
  $("a[rel$='all']").click(function () {$(".section.all.events").addClass("hide");});
  // clicking events removes hide tag
  $("a[rel$='events']").click(function () {$(".section.all.events").removeClass("hide");});
});

// ROUNDUP FILTER LIST
  $(function() {
  var newSelection = "";
  $("#roundup-nav a").click(function(){
      $("#roundup").fadeTo(200, 0.10);
    $("#roundup-nav a").removeClass("current");
    $(this).addClass("current");
    newSelection = $(this).attr("rel");
    $(".section").not("."+newSelection).slideUp();
    $("."+newSelection).slideDown();
      $("#roundup").fadeTo(600, 1);
  });
});

$(document).ready(function() {
  $('.technology.rpm a.tab-trigger').click(function() {
    var tab = $(this).attr('data-tab');
    var elm = $('dl.tabs.rpm dd')[tab];
    $(elm).find('a').trigger('click');
  });

  $('.technology.mrm a.tab-trigger').click(function() {
    var tab = $(this).attr('data-tab');
    var elm = $('dl.tabs dd')[tab];
    $(elm).find('a').trigger('click');
  });
});

$(document).ready(function() {
  // static modals
  $('a[data-modal-id]').each(function() {
    var $link = $(this),
        modalId = $link.attr('data-modal-id'),
        $modal = $('#' + modalId), $caption;
    $modal.dialog({
      autoOpen: false,
      modal: true,
      width: 'auto',
      height: 'auto',
      show: {effect: 'blind', duration: 250},
      hide: {effect: 'blind', duration: 250},
      open: function() {
        $('.ui-widget-overlay').bind('click', function() {$modal.dialog('close');});
      }
    });
    $caption = $modal.find('.caption:first');
    if ($caption.length > 0) {
      $modal.dialog('option', 'title', $caption.html());
      $caption.hide();
    }
    if ($link.hasClass('client') || $.inArray(modalId, ['twitterModal', 'linkedinModal']) >= 0) {
      $modal.siblings('.ui-dialog-titlebar').removeClass('ui-widget-header').css('padding', '0px');
      $modal.siblings('.ui-dialog-title').remove();
    }
    $link.click(function() {$modal.dialog('open');});
  });

  // partner modals
  $('a[class~=partner-logo]').each(function() {
    var $link = $(this),
        $modal = $($link.attr('href'));
    $modal.dialog({
      autoOpen: false,
      modal: true,
      title: $link.attr('title'),
      width: 'auto',
      height: 'auto',
      show: {effect: 'blind', duration: 250},
      hide: {effect: 'blind', duration: 250},
      open: function() {
        $('body').scrollTop(0);
        $('.ui-widget-overlay').bind('click', function() {$modal.dialog('close');});
      }
    });
    $link.click(function() {
      $modal.dialog('open');
      $('body').scrollTop(0);
    });
  });

  // generic video modals
  $('a[class~=video-link]').each(function() {
    var $link = $(this),
        $modal = $($link.attr('href')), embed;
    $modal.dialog({
      autoOpen: false,
      modal: true,
      title: $link.attr('title'),
      width: 'auto',
      height: 'auto',
      show: {effect: 'blind', duration: 250},
      hide: {effect: 'blind', duration: 250},
      open: function() {
        $('.ui-widget-overlay').bind('click', function() {$modal.dialog('close');});
      },
      close: function() {
        // stop video by brute force
        var iframe = $(this).find('iframe:first'),
            src = iframe.attr('src');
        iframe.attr('src', '');
        iframe.attr('src', src);
      }
    });
    embed = $modal.find('object embed:first');
    if (embed.length > 0) {
      // attempt to resize
      $modal.dialog('option', {
        width: $(embed).attr('width'),
        height: $(embed).attr('height')
      });
    }
    $link.click(function() {$modal.dialog('open');});
  });

  // ooyala videos
  $('a[class~=ooyala-link]').each(function() {
    var $link = $(this),
        url = '/theroundup/videos/' + $link.attr('data-url'),
        options = 'width=780,height=440,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,copyhistory=no,resizable=yes';
    $link.click(function() {
      window.open(url, '_blank', options); // ie8
    });
  });

  // image gallery modals
  $('.gallery-link').each(function() {
    var $link = $(this),
        id = $link.attr('data-gallery-id'),
        $modal = $('#' + id),
        $gallery = $modal.children('.gallery-container:first'),
        prevId = 'prev' + id,
        nextId = 'next' + id,
        prevNext = "<a id='" + prevId + "' href='#'>prev</a> <a id='" + nextId + "' href='#'>next</a>";
    $modal.dialog({
      autoOpen: false,
      modal: true,
      height: 'auto',
      width: 'auto',
      show: {effect: 'blind', duration: 250},
      hide: {effect: 'blind', duration: 250},
      open: function() {
        $('.ui-widget-overlay').bind('click', function() {$modal.dialog('close');});
      },
    });
    $modal.prev('.ui-dialog-titlebar').children('.ui-dialog-title').after(prevNext)
    $gallery.cycle({
      prev: '#' + prevId,
      next: '#' + nextId,
      timeout: 0,
      before: function() {
        $modal.dialog('option', {
          title: this.alt,
          width: this.getAttribute('width'),
          height: this.getAttribute('height')
        });
      }
    });
    $link.click(function() {$modal.dialog('open');});
  });

  // home gallery modals
  $('.slider-video-link').each(function() {
    var $link = $(this);
    var id = $link.attr('data-slider-video-id');
    var $modal = $('#' + id);
    $modal.dialog({
      autoOpen: false,
      modal: true,
      height: 'auto',
      width: 'auto',
      show: {effect: 'blind', duration: 250},
      hide: {effect: 'blind', duration: 250},
      open: function() {
        $('.ui-widget-overlay').bind('click', function() {$modal.dialog('close');});
      },
    });
    $link.click(function() {$modal.dialog('open');});
  });
});

// CLIENT ROTATOR HOMEPAGE
$(document).ready(function() {
  $('.clientrotator').cycle({
    fx:    'fade',
    speed:  2500
 });
});

$(".clientrotator img,.seeourclients").hover(
    function() {$(".seeourclients").toggle();});