(function($){
  $.fn.shuffle = function() {
    return this.each(function(){
      var items = $(this).children();
      return (items.length)
        ? $(this).html($.shuffle(items))
        : this;
    });
  }
 
  $.shuffle = function(arr) {
    for(
      var j, x, i = arr.length; i;
      j = parseInt(Math.random() * i),
      x = arr[--i], arr[i] = arr[j], arr[j] = x
    );
    return arr;
  }
})(jQuery);

$(document).ready(function() {
	$('#primenav li:first').hide();
	
	$('#headerslider').cycle({ 
	    timeout: 8000, 
	    speed: 1500
	});
	$('#randomquotes').shuffle();
	$('#randomquotes div').removeClass("h");
	$('#randomquotes').cycle({ 
	    timeout: 12000, 
	    speed: 500
	});
	$('#randomquotes2').shuffle();
	$('#randomquotes2 div:first').removeClass("h");
	$(function() {
		$(".ec .jcl").jCarouselLite({
		    visible: 3,
		    start: 0,
			speed: 1300,
			easing: "easeOutBack",
		    btnGo: [".ec .1", ".ec .2",".ec .3", ".ec .4", ".ec .5", ".ec .6", ".ec .7", ".ec .8", ".ec .9", ".ec .10", ".ec .11", ".ec .12", ".ec .13", ".ec .14", ".ec .15"]
		});
	});
	$('#controls button').click(function(){
		$('#controls > button').removeClass("active");
		$(this).addClass("active");
	});
	$('#controls button').hide();
	$('#controls button:eq(0)').show();
	$('#controls button:eq(3)').show();
	$('#controls button:eq(6)').show();
	$('#controls button:eq(9)').show();
	$(function() {
		$(".ec2 .jcl2").jCarouselLite({
		    visible: 1,
			speed: 1300,
		    start: 0,
			easing: "easeOutBack",
		    btnGo: [".ec2 .1", ".ec2 .2",".ec2 .3", ".ec2 .4", ".ec2 .5", ".ec2 .6", ".ec2 .7", ".ec2 .8", ".ec2 .9", ".ec2 .10", ".ec2 .11", ".ec2 .12", ".ec2 .13", ".ec2 .14", ".ec2 .15", ".ec2 .16", ".ec2 .17", ".ec2 .18", ".ec2 .19", ".ec2 .20"]
		});
	});
	$('#controls2 button').click(function(){
		$('#controls2 > button').removeClass("active");
		$(this).addClass("active");
	});


	$(function() {
		$(".ec3 .jcl3").jCarouselLite({
		    visible: 1,
		    start: 0,
		    speed: 1300,
			easing: "easeOutBack",
		    btnGo: [".ec3 .1", ".ec3 .2",".ec3 .3", ".ec3 .4", ".ec3 .5", ".ec3 .6", ".ec3 .7", ".ec3 .8", ".ec3 .9", ".ec3 .10", ".ec3 .11", ".ec3 .12", ".ec3 .13", ".ec3 .14", ".ec3 .15", ".ec3 .16", ".ec3 .17", ".ec3 .18", ".ec3 .19", ".ec3 .20"]
		});
	});
	$('#controls3 button:first').addClass("active");
	$('#controls3 button').click(function(){
		$('#controls3 > button').removeClass("active");
		$(this).addClass("active");
	});
	/* $('#deepnav a:last').css("background-image","none");*/
	$("a[href$=pdf]").each(
	   function(){
	      $(this).attr('target', '_blank');
	});
	$("a[href^=http]").each(
	   function(){
		  if(this.href.indexOf(location.hostname) == -1) { 
	      $(this).attr('target', '_blank');
	    }
	});
});
