// JavaScript Document

function ActivateSlideInPlace() {

  $('.slideinplace').each( function(index) {
    var self = $(this);	

	self.css('position','relative');
	self.animate({
		   left: '+=' + self.data("left"),
		   top: '+=' + self.data("top")
		},0)
		.animate({
		   left: '-=' + self.data("left"),
		   top: '-=' + self.data("top")
		},self.data("speed"))
  })
}



function ActivateAccessibilityTab() {
	
	    $('.accessibilitytab .tab').click( function() {
				var sidebar = $(this).parent();
				var tab = $(this);
				var content = sidebar.children('.content');
				var shiftamount = content.css("width");

                if (this.active) {
				  sidebar.animate({marginLeft: "+=" + shiftamount},300, function() {
				    content.css("visibility","hidden");					  
				  });
				}
				else {
				  content.css("visibility","visible");					  
 				  sidebar.animate({marginLeft: "-=" + shiftamount},300);
				}

				this.active = !this.active;
	  });
	
	
	
	$('.accessibilitytab .fontsizerup').click( function() {
	  currentSize = parseFloat($("body").css("font-size"),10);
	  if (currentSize < 30) $("body").css("font-size", currentSize * 1.2); 
	})  

	$('.accessibilitytab .fontsizerdown').click( function() {
	  currentSize = parseFloat($("body").css("font-size"),10);
	  if (currentSize > 12) $("body").css("font-size", (currentSize / 6) * 5); 
	})  

	$('.accessibilitytab .fontsizerreset').click( function() {
	  $("body").css("font-size",""); 
	})  

	$('.schemereset').click( function() {
	  $("body").removeClass("schemeblack"); 
	  $("body").removeClass("schemewhite"); 
	  $("body").removeClass("schemeblue"); 
	  $("body").removeClass("schemegrey"); 
	})  

	$('.schemeblack').click( function() { 
	  $("body").removeClass("schemeblack"); 
	  $("body").removeClass("schemewhite"); 
	  $("body").removeClass("schemeblue"); 
	  $("body").removeClass("schemegrey"); 
	  $("body").addClass("schemeblack"); 
	})  

	$('.schemewhite').click( function() { 
	  $("body").removeClass("schemeblack"); 
	  $("body").removeClass("schemewhite"); 
	  $("body").removeClass("schemeblue"); 
	  $("body").removeClass("schemegrey"); 
	  $("body").addClass("schemewhite"); 
	})  

	$('.schemeblue').click( function() { 
	  $("body").removeClass("schemeblack"); 
	  $("body").removeClass("schemewhite"); 
	  $("body").removeClass("schemeblue"); 
	  $("body").removeClass("schemegrey"); 
	  $("body").addClass("schemeblue"); 
	})  

	$('.schemegrey').click( function() { 
	  $("body").removeClass("schemeblack"); 
	  $("body").removeClass("schemewhite"); 
	  $("body").removeClass("schemeblue"); 
	  $("body").removeClass("schemegrey"); 
	  $("body").addClass("schemegrey"); 
	})  

}


function ActivateHoverCyclers() {
  $('.hovercycler').each( function(index) {
    var self = $(this);	
	this.selected = false;

	self.mouseenter( function() { 
		  self.css('cursor','pointer'); 
		  if (!self.selected) self.cycle(1);
		}
     )
	 self.mouseleave( function() { 
		  self.css('cursor','normal');
		  if (!self.selected) self.cycle(0);
		}
     )
	 
	 this.exclusiveSelect = function() {
		 $(this).siblings().each( function() {
			 this.deselect();
		 });
		 self.selected = true;
		 self.cycle(1);
	 }
	  
	 this.deselect = function() {
		 self.selected = false;
		 self.cycle(0);
	 }
		 
	self.cycle({fx:"fade", speed:400, timeout:0, cleartype:true, cleartypeNoBg:true })	  
  });
  
  
  $('.hovercycler>a').each ( function(index) {
	  var self = $(this);
	  self.click( function() {
		  $(this).parent()[0].exclusiveSelect();
	  });
  });
}


function ActivateCyclers() {

  $('.cycler').each( function(index) {
    var self = $(this);	
	self.cycle({
		fx:            self.data("fx"),
		speed:         self.data("speed"),
		timeout:       self.data("timeout"),
		delay:         500,
		cleartype:     true,
		cleartypeNoBg: true 
	})	  
  })
}



function ActivateCarousels() {
  $('.carousel').each( function(index) {
	var self = $(this);
	
	// read parameters from the DOM element
	self.duration    = self.data("duration");
	self.pause       = self.data("pause");
    self.orientation = self.data("orientation");
    self.predelay    = self.data("predelay");
    self.scrollpane  = null;
	
	// Create a div (scrollpane) of the correct orientation that is WIDER or LONGER than this div, so that we can pan it
	if (self.orientation == 'horizontalleft') self.scrollpane =  $('<div style="position:relative; width:200%"></div>');
	if (self.orientation == 'verticalup')     self.scrollpane =  $('<div style="position:relative; height:200%"></div>');   
	
	// Move all the current children INTO the scrollpane, then add the scrollpane a child
  	self.scrollpane.append(self.children());
	self.append(self.scrollpane);

    // Create a function to cycle myself
	self.cycle = function(){
 	       var scrollpanefirstchild  = this.scrollpane.children(':nth-child(1)');
           var amountleft = '-=0';
		   var amountup = '-=0';           
		   
		   if (this.orientation == 'horizontalleft') amountleft = '-=' + this.scrollpane.children(':nth-child(2)').position().left;
		   if (this.orientation == 'verticalup')     amountup   = '-=' + this.scrollpane.children(':nth-child(2)').position().top;

		   this.scrollpane.animate({left: amountleft, top: amountup  },self.duration,"linear",
		                   function(me) {
			                 setTimeout(function() {self.cycle()},self.pause);
		                     self.scrollpane.append(scrollpanefirstchild); 
							 self.scrollpane.animate({left: 0, top: 0},0);
		                   });
	}

    setTimeout(function() {self.cycle()},self.predelay);
  })
}

