$(document).ready(function(){
	
	$('.sequencer').cycle({
		timeout:       6000
	});
	
	//stripe table 
	$(".tableStripes tr").mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
	$(".tableStripes tr:even").addClass("even");
	
	$("ul.sf-menu").supersubs({ 
			minWidth:    12,   
            maxWidth:    28,   
            extraWidth:  1     
	}).superfish({
			animation:   {opacity:'show',height:'show'},
            speed:       'fast',
            autoArrows:  false,
            dropShadows: false
	});
	
	$("#accordion").accordion({ 
		header: "h3",
		autoHeight: false
	});
	
	/*$('.lightbox').lightBox({		
		imageLoading: '/source-ordered-code/scripts/lightbox/images/loading.gif',
		imageBtnClose: '/source-ordered-code/scripts/lightbox/images/close.gif',
		imageBtnPrev: '/source-ordered-code/scripts/lightbox/images/prev.gif',
		imageBtnNext: '/source-ordered-code/scripts/lightbox/images/next.gif'
	});	
	$('.lightboxGallery a').lightBox({		
		imageLoading: '/source-ordered-code/scripts/lightbox/images/loading.gif',
		imageBtnClose: '/source-ordered-code/scripts/lightbox/images/close.gif',
		imageBtnPrev: '/source-ordered-code/scripts/lightbox/images/prev.gif',
		imageBtnNext: '/source-ordered-code/scripts/lightbox/images/next.gif'
	});*/
	
	
	
	/*$(".carousel").jCarouselLite({
		vertical: true,
		hoverPause:true,
		mouseWheel: true,
		visible: 1,
		auto:6000,
		speed:1000
	});*/
	 
	//add class to each li in top menu
	$("ul.sf-menu > li").each(function (i) {
		i = i+1;
		$(this).addClass("nav-"+i);
	});
	
	/*$(".emailLink").emailencode();*/
	
	//add active class to left menu links
	$("#sideNav a").filter(function() {
      //Take the current URL and split it into chunks at each slash
      var currentURL = window.location.toString().split("/");
	  var pageURL = $(this).attr("href").toString().split("/");
	  if (pageURL[pageURL.length-1] != ""){
		  if((pageURL[pageURL.length-1] == currentURL[currentURL.length-1])){
			$(this).addClass("active");
		  }
	  } else {
		  if((pageURL[pageURL.length-2] == currentURL[currentURL.length-2])){
			$(this).addClass("active");
		  }
	  }
    });
	//$('#columnL ul li:last').addClass("last");
	
	// addSizes was written by Natalie Downe 
	// http://natbat.net/2008/Aug/27/addSizes/
	
	// Copyright (c) 2008, Natalie Downe under the BSD license
	// http://www.opensource.org/licenses/bsd-license.php
	
	$('a[href$=".pdf"], a[href$=".doc"],a[href$=".zip"]').each(function(){
		// looking at the href of the link, if it contains pdf, doc, zip, mp3, ogg, m4u, jpg, png, swf
		var link = $(this);
		var bits = this.href.split('.');
		var type = bits[bits.length -1];
		
		var url= "http://json-head.appspot.com/?url="+encodeURIComponent (this.href)+"&callback=?";
		//console.log(url);
	
		// then call the json thing and insert the size back into the link text
		 $.getJSON(url, function(json){
			if(json.ok && json.headers['content-length']) {
				var length = parseInt(json.headers['content-length'], 10);
				
				// divide the length into its largest unit
				var units = [
					[1024 * 1024 * 1024, 'GB'],
					[1024 * 1024, 'MB'],
					[1024, 'KB'],
					[1, 'bytes']
				];
				
				for(var i = 0; i < units.length; i++){
					
					var unitSize = units[i][0];
					var unitText = units[i][1];
					
					if (length >= unitSize) {
						length = length / unitSize;
						// 1 decimal place
						length = Math.ceil(length * 10) / 10;
						var lengthUnits = unitText;
						break;
					}
				}
				
				// insert the text directly after the link and add a class to the link
				// note: if you want to insert the size into the link rather than after it change the following 'after' to 'append'
				link.after(' <span class="quiet small">(' + type + ' ' + length + ' ' + lengthUnits + ')</span>');
				link.addClass(type);
			}
		});
	});
});



function clearField2(name) {
    var fn = eval("document.quick." + name);
	if ((fn.value=="")||(fn.value.length <5)){return;}
	else {
		var firstpart = fn.value.substring(0,4);
		if (firstpart=="Full" || firstpart=="Emai" || firstpart=="Comm") {fn.value="";}
		return;
	}
}
function unclearField2(name,defaultVal) {
    var fn = eval("document.quick." + name);
	if (fn.value==""){
		fn.value=defaultVal;
		return;
	}
}
function clearField3(name) {
    var fn = eval("document.search." + name);
	if ((fn.value=="")||(fn.value.length <5)){return;}
	else {
		var firstpart = fn.value.substring(0,4);
		if (firstpart=="sear") {fn.value="";}
		return;
	}
}
