// JavaScript Document

// For adding/removing active (i.e. "focus") styles

sfFocus = function() {
	var sfEls = document.getElementsByTagName("INPUT");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" sffocus";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfFocus);

jQuery.noConflict();

// Add last-child class to last child elements of li
// Helpful for old browsers that do not support the last-child pseudo-class
jQuery(document).ready(function($){
	$("ul.sub-menu li:last-child").addClass('last-child');  
});

var active_color = '#dcdcdc'; // Colour of user provided text
var inactive_color = '#b3b2b2'; // Colour of default text

// For clearing/reinstating textarea/input default values
jQuery(document).ready(function($){ 
  $('#newsletter-form input[type="text"]').css("color", inactive_color);
  var default_values = new Array();
  $('#newsletter-form input[type="text"]').focus(function() {
    if (!default_values[this.id]) {
      default_values[this.id] = this.value;
    }
    if (this.value == default_values[this.id]) {
      this.value = '';
      this.style.color = active_color;
	  this.style.fontStyle = 'normal';
    }
    $(this).blur(function() {
      if (this.value == '') {
        this.style.color = inactive_color;
	    this.style.fontStyle = 'italic';
        this.value = default_values[this.id];
      }
    });
  });
});

// For scrolling clients list
jQuery(document).ready(function($){
	$("#chained").scrollable({circular: true, mousewheel: false}).navigator().autoscroll({
		interval: 4500
	});
	$("#chained").scrollable({ next: '#home-clients-scroller .next', prev: 'home-clients-scroller .prev' });
});

// For home page testimonials
jQuery(document).ready(function($){
	$("#home-testimonials").scrollable({circular: true, mousewheel: false}).navigator().autoscroll({
		interval: 15000
	});
	$("#chained").scrollable({ next: '#home-testimonials .next', prev: 'home-testimonials .prev' });
});

// OLD - for home page testimonials
// uses old testimonial-scroller.js, switched to jQuery Tools effect because it's prettier and renders properly in old versions of IE
/*jQuery(document).ready(function($){
	$('#home-testimonials').innerfade({
		animationtype: 'slide',
		speed: 750,
		timeout: 15000,
		type: 'sequence',
		containerheight: '1em'
	});
});*/

// For Send to Friend Fancybox
jQuery(document).ready(function($){
	
	$("a#send-to-friend").fancybox({
		'type'           : 'inline',
		'centerOnScroll' : true,
		'transitionIn'   : 'fade',
		'transitionOut'  : 'fade'
	});
	
	function formatTitle(title, currentArray, currentIndex, currentOpts) {
		 return '<div class="fancybox-video-name">' + title + '</div>' + '<div class="fancybox-video-num">Video ' +  (currentIndex + 1) + ' of ' + currentArray.length + '</div><div class="clearboth"></div>'; }
	
	$("a[rel=fancybox-video-gallery]").fancybox({
		// commented onComplete is a trick I finally discovered to make $.fancybox.next() and prev work:		
		//'onComplete'   : function() {$("#fancybox-wrap").unbind('mousewheel.fb'); $('div.todd-next').click(function() { $.fancybox.next() }); $('div.todd-prev').click(function() { $.fancybox.prev() });} ,
		'onComplete'     : function() {$("#fancybox-wrap").unbind('mousewheel.fb'); $("#fancybox-wrap").addClass("video-fancybox");} ,
		'centerOnScroll' : true,
		'transitionIn'   : 'fade',
		'transitionOut'  : 'fade',
		'type'           : 'inline',
		'titlePosition'  : 'inside',
		'scrolling'      : 'no',
		'titleFormat'    : formatTitle
	});
	
	$("a#ie-warning-anchor").fancybox({
		'type'           : 'inline',
		'centerOnScroll' : true,
		'transitionIn'   : 'fade',
		'transitionOut'  : 'fade',
		'autoDimensions' : false,
		'width'          : 400,
		'height'         : 140
	}).trigger('click');
	
});
