// JavaScript Document

//CAROUSEL START
jQuery(document).ready(function() {
	jQuery('#feature_wrap').show();
    jQuery('.jcarousel-skin-tango').jcarousel({
        auto: 5,
		scroll: 1,
		visible: 1,
		size: 5,
		wrap: 'last',
		buttonNextHTML: null,
		buttonPrevHTML: null,
        initCallback: mycarousel_initCallback,
		itemVisibleInCallback: {
            onBeforeAnimation: navNotification1
        },
		itemVisibleOutCallback: {
			onBeforeAnimation: navNotification2
        }
    });

	$(".accordion").accordion({ header: "h3", autoHeight: false, collapsible: true });
	

});
 
function mycarousel_initCallback(carousel) {
	
	jQuery('#feature_nav li').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
	 
    /*jQuery('#feature_nav_right').bind('click', function() {
        carousel.next();
        return false;
    });
 
    jQuery('#feature_nav_left').bind('click', function() {
        carousel.prev();
        return false;
    });*/

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};


function navNotification1(carousel, item, idx, state) {
	document.getElementById('f' + idx).style.backgroundPosition = '0px -22px';
};

function navNotification2(carousel, item, idx, state) {
	document.getElementById('f' + idx).style.backgroundPosition = '0px 0px';
};
//CAROUSEL END

//LOGO SCROLLER START
$(function() {
			
	//remove js-disabled class
	$("#viewer").removeClass("js-disabled");
	
	//create new container2 for images *** 	ADD/REMOVE 222 SLIGHTLY WHEN ADDING/SUBTRACKING LOGOS, WHEN EXPEDIA WAS ADDED IT CHANGED FROM 220 TO 222 ***
	$("<div>").attr("id", "container2").css({ position:"absolute"}).width($(".wrapper").length * 222).height(50).appendTo("div#viewer");
	
	//add images to container2
	$(".wrapper").each(function() {
		$(this).appendTo("div#container2");
	});
	
	//work out duration of anim based on number of images (1 second for each image)
	var duration = $(".wrapper").length * 2000;
	//store speed for later (distance / time)
	var speed = (parseInt($("div#container2").width()) + parseInt($("div#viewer").width())) / duration;
					
	//set direction
	var direction = "rtl";
	
	//set initial position and class based on direction
	
	//start with gap on left side
	(direction == "rtl") ? $("div#container2").css("left", $("div#viewer").width()).addClass("rtl") : $("div#container2").css("left", 0 - $("div#container2").width()).addClass("ltr") ;

	//start with no gap
	(direction == "rtl") ? $("div#container2").css("left", 0).addClass("rtl") : $("div#container2").css("left", 0).addClass("ltr") ;
	
	//animator function
	var animator = function(el, time, dir) {
	 
		//which direction to scroll
		if(dir == "rtl") {
		  
		  //add direction class
			el.removeClass("ltr").addClass("rtl");
				
			//animate the el
			el.animate({ left:"-" + (el.width()/2) + "px" }, time, "linear", function() {
									
				//reset container2 position
				$(this).css({ left:40, right:"" });
				//restart animation
				animator($(this), duration, "rtl");
				//hide controls if visible
				//($("div#controls").length > 0) ? $("div#controls").slideUp("slow").remove() : null ;			
								
			});
		} else {
		
		  //add direction class
			el.removeClass("rtl").addClass("ltr");
		
			//animate the el
			el.animate({ left:$("div#viewer").width()/2 + "px" }, time, "linear", function() {
									
				//reset container2 position
				$(this).css({ left:0 - $("div#container2").width() });
				
				//restart animation
				animator($(this), duration, "ltr");
				
				//hide controls if visible
				//($("div#controls").length > 0) ? $("div#controls").slideUp("slow").remove() : null ;			
			});
		}
	}
	
	//start anim
	animator($("div#container2"), duration, direction);
	
	//pause on mouseover
	/*$("a.wrapper").live("mouseover", function() {
	  
		//stop anim
		$("div#container2").stop(true);
		
		//show controls
		($("div#controls").length == 0) ? $("<div>").attr("id", "controls").appendTo("div#outerContainer").css({ opacity:0.7 }).slideDown("slow") : null ;
		($("a#rtl").length == 0) ? $("<a>").attr({ id:"rtl", href:"#", title:"rtl" }).appendTo("#controls") : null ;
		($("a#ltr").length == 0) ? $("<a>").attr({ id:"ltr", href:"#", title:"ltr" }).appendTo("#controls") : null ;
		
		//variable to hold trigger element
		var title = $(this).attr("title");
		
		//add p if doesn't exist, update it if it does
		($("p#title").length == 0) ? $("<p>").attr("id", "title").text(title).appendTo("div#controls") : $("p#title").text(title) ;
	});
	
	//restart on mouseout
	$("a.wrapper").live("mouseout", function(e) {
	  
		//hide controls if not hovering on them
		(e.relatedTarget == null) ? null : (e.relatedTarget.id != "controls") ? $("div#controls").slideUp("slow").remove() : null ;
		
		//work out total travel distance
		//var totalDistance = parseInt($("div#container2").width()) + parseInt($("div#viewer").width());
		var totalDistance = parseInt($("div#container2").width()) + parseInt($("div#viewer").width());
											
		//work out distance left to travel
		var distanceLeft =  (totalDistance - (parseInt($("div#viewer").width()) + (parseInt($("div#container2").css("left"))))) ;
		
		//new duration is distance left / speed)
		var newDuration = distanceLeft / speed;
		
		//restart anim
		animator($("div#container2"), newDuration, $("div#container2").attr("class"));
	
	});*/
});
// LOGO SCROLLER END

// TRUNCATION START
jQuery.fn.shorten = function(settings) {
  var config = {
    showChars : 100,
    ellipsesText : "...",
    moreText : "more",
    lessText : "less"
  };
 
  if (settings) {
    $.extend(config, settings);
  }
 
  $('.morelink').live('click', function() {
    var $this = $(this);
    if ($this.hasClass('less')) {
      $this.removeClass('less');
      $this.html(config.moreText);
    } else {
      $this.addClass('less');
      $this.html(config.lessText);
    }
    $this.parent().prev().toggle();
    $this.prev().toggle();
    return false;
  });
 
  return this.each(function() {
    var $this = $(this);
 
    var content = $this.html();
    if (content.length > config.showChars) {
      var c = content.substr(0, config.showChars);
      var h = content.substr(config.showChars , content.length - config.showChars);
      var html = c + '<span class="moreellipses">' + config.ellipsesText + '&nbsp;</span><span class="morecontent"><span>' + h + '</span>&nbsp;&nbsp;<a href="javascript://nop/" class="morelink">' + config.moreText + '</a></span>';
      $this.html(html);
      $(".morecontent span").hide();
    }
  });
}

$(document).ready(function(){
	$(".more-less").shorten({
	    "showChars" : 418,
	    "moreText"  : "more >",
	    "lessText"  : "< less"
	});
});

/*$(document).ready(function() {
    var showChar = 100;
    var ellipsestext = "...";
    var moretext = "more";
    var lesstext = "less";
    $('.more').each(function() {
        var content = $(this).html();
 
        if(content.length > showChar) {
 
            var c = content.substr(0, showChar);
            var h = content.substr(showChar-1, content.length - showChar);
 
            var html = c + '<span class="moreellipses">' + ellipsestext+ '&nbsp;</span><span class="morecontent"><span>' + h + '</span>&nbsp;&nbsp;<a href="" class="morelink">' + moretext + '</a></span>';
 
            $(this).html(html);
        }
 
    });
 
    $(".morelink").click(function(){
        if($(this).hasClass("less")) {
            $(this).removeClass("less");
            $(this).html(moretext);
        } else {
            $(this).addClass("less");
            $(this).html(lesstext);
        }
        $(this).parent().prev().toggle();
        $(this).prev().toggle();
        return false;
    });
});*/

// The height of the content block when it's not expanded
/*$(document).ready(function(){
	var adjustheight = 93;
	// The "more" link text
	var moreText = "More";
	// The "less" link text
	var lessText = "Less";
	
	// Sets the .more-block div to the specified height and hides any content that overflows
	$(".more-less .more-block").css('height', adjustheight).css('overflow', 'hidden');
	
	// The section added to the bottom of the "more-less" div
	$(".more-less p").append('<a href="#" class="adjust"></a>');
	
	$("a.adjust").text(moreText);
	
	$(".adjust").toggle(function() {
			$(this).parents("div:first").find(".more-block").css('height', 'auto').css('overflow', 'visible');
			// Hide the [...] when expanded
			$(this).parents("div:first").find("p.continued").css('display', 'none');
			$(this).text(lessText);
		}, function() {
			$(this).parents("div:first").find(".more-block").css('height', adjustheight).css('overflow', 'hidden');
			$(this).parents("div:first").find("p.continued").css('display', 'block');
			$(this).text(moreText);
	});
});*/
// TRUNCATION END


// FANCYBOX START

$(document).ready(function() {

	$("a.lightbox_livechat").fancybox({
		'padding'			: 0,
		'autoScale'			: false,
		'width'				: 800,
		'height'			: 450,
		'overlayOpacity'	: .7,
		'overlayColor'		: '#333',
		'titleShow'			: true,
		'titlePosition'		: 'inside',
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'swf'				: {wmode: 'window'}
	});
	
	$("a.lightbox_accessassistant").fancybox({
		'padding'			: 0,
		'autoScale'			: false,
		'width'				: 800,
		'height'			: 615,
		'overlayOpacity'	: .7,
		'overlayColor'		: '#333',
		'titleShow'			: true,
		'titlePosition'		: 'inside',
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'swf'				: {wmode: 'window'}
	});
	
	$("a.lightbox_platform").fancybox({
		'padding'			: 0,
		'autoScale'			: false,
		'width'				: 900,
		'height'			: 500,
		'overlayOpacity'	: .7,
		'overlayColor'		: '#333',
		'titleShow'			: true,
		'titlePosition'		: 'inside',
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'swf'				: {wmode: 'window'}
	});
	
	$("a.lightbox_humanemulation").fancybox({
		'padding'			: 0,
		'autoScale'			: false,
		'width'				: 1015,
		'height'			: 650,
		'overlayOpacity'	: .7,
		'overlayColor'		: '#333',
		'titleShow'			: true,
		'titlePosition'		: 'inside',
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'swf'				: {wmode: 'window'}
	});
	
	$("a.lightbox_webinar").fancybox({
		'padding'			: 0,
		'autoScale'			: false,
		'width'				: 950,
		'height'			: 540,
		'overlayOpacity'	: .7,
		'overlayColor'		: '#333',
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'type'				: 'iframe'
	});
	
});



// FANCYBOX END
