// JavaScript Document
(function($){   
  
  $.extend({
	preloadCssImages : function(settings){
	//overrideable defaults
	settings = $.extend({
		 imgDir: 'images'
	}, settings);

	//dump all the css rules into one string
	var sheets = document.styleSheets;
	var cssPile = '';
	for(var i = 0; i<sheets.length; i++){
		if(!$.browser.msie){
			var thisSheetRules = document.styleSheets[i].cssRules;
			for(var j = 0; j<thisSheetRules.length; j++){
				cssPile+= thisSheetRules[j].cssText;
			}
		}
		else {
			cssPile+= document.styleSheets[i].cssText;
		}
	}
	//parse string for image urls and load them into the DOM
	var allImgs = [];//new array for all the image urls  
	//var imgUrls = cssPile.match(/[^\/]+\.(gif|jpg|jpeg|png)/g);//reg ex to get a string of between a "/" and a ".filename"
	var iRegX=new RegExp(settings.imgDir+"\/.+\.(gif|jpg|jpeg|png)","g");
	var imgUrls = cssPile.match(iRegX);//reg ex to get a string of between a "/" and a ".filename"
	if(imgUrls != null && imgUrls.length>0 && imgUrls != ''){//loop array
		var arr = $.makeArray(imgUrls);//create array from regex obj
		$(arr).each(function(k){
			allImgs[k] = new Image(); //new img obj
			allImgs[k].src = settings.imgDir +'/'+ this;
		});
	}else{
		//$("loading-img").html("NONE");
	}
	return allImgs;
}
    });   
})(jQuery);  
(function($){   
$.fn.stulorscroll = function(options) {   
	var defaults = {   
   speed: 1,   
   imageWidth: 100,   
   imageHeight: 100,   
   pad: 3,
   showimages:5
  };   
  options = $.extend(defaults, options);
  options.showimages=5;
  this.width("0px");
  this.find("img").each(function(){$(this).css({"padding":"0px","margin":"0px","border":"0px"});});
  this.prepend("<div id=\"inner1\"></div>");
  inner=$(this).children("#inner1");
  inner.css({"position":"relative","display":"block","width":"auto","height":(options.imageHeight+(options.pad*2))+"px","left":"0px"});
  iw=0;
  images=0;
  totalWidth=options.imageWidth+(2*options.pad);
  totalHeight=options.imageHeight+(2*options.pad);
  this.children(":not(:first)").each(function() {  
  		obj = $(this);
		obj.wrap("<div></div>");
		l=(images>=4?(totalWidth*4):(totalWidth*images));
		obj.parent().css({"left":l+"px","width":totalWidth-(2*options.pad)+"px","height":totalHeight-(2*options.pad)+"px","display":"inline","position":"absolute"});
		obj.css({"width":"100%","height":"100%"});
		var wrapdiv=obj.parent().clone();
		inner.append(wrapdiv);
		iw+=wrapdiv.outerWidth(true);
		images++;
		obj.parent().remove();
    });
  	images--;
	if(images<6){inner.remove();return false;}
  	inner.css({"width":iw+"px"});
	this.width(((options.showimages*2)*options.pad)+(options.showimages*options.imageWidth));
	this.css({"overflow":"hidden","padding-top":"10px"});
	//set start state
	var tw=totalWidth-(2*options.pad);
	for(x=0;x<=images;x++){
		switch(x){
			case 2:
				//do nothing
				break;
			case 3:
			case 1:
				inner.children(":eq("+x+")").children(0).css({"width":"90%","height":"90%"});
				p2=Math.floor((tw-(tw*.9))/2);
				inner.children(":eq("+x+")").children(0).css({"padding":p2+"px"}).fadeTo(0,.7);
			
				break;
			case 0:
			case 4:
			default:
				inner.children(":eq("+x+")").children(0).css({"width":"80%","height":"80%"});
				p1=Math.floor((tw-(tw*.8))/2);
				//inner.children(":eq("+x+")").children(0).css({"padding":p1+"px","opacity":".5"}).fadeTo(0,(x>4?0:.5));
				inner.children(":eq("+x+")").children(0).css({"padding":p1+"px"}).fadeTo(0,(x>4?0:.5));
				break;
		}
	}
	this.show();
	function anim(){
		for(x=0;x<inner.children().length;x++){
		switch(x){
			case 2:
			case 4:
				p2=Math.floor((tw-(tw*.9))/2);
				//inner.children(":eq("+x+")").animate({"left":"-="+(totalWidth)+"px"},{"duration":1500,"queue":false}).children(0).animate({"padding":p2+"px","width":"90%","height":"90%","opacity":".7"},{"duration":1500,"queue":false});
				inner.children(":eq("+x+")").animate({"left":"-="+(totalWidth)+"px"},{"duration":1500,"queue":false}).children(0).animate({"padding":p2+"px","width":"90%","height":"90%"},{"duration":1500,"queue":false}).fadeTo(1500,.7);
				//do nothing
				break;
			case 3:
				//inner.children(":eq("+x+")").animate({"left":"-="+(totalWidth)+"px"},{"duration":1500,"queue":false}).children(0).animate({"padding":0+"px","width":"100%","height":"100%","opacity":"1"},{"duration":1500,"queue":false});
				inner.children(":eq("+x+")").animate({"left":"-="+(totalWidth)+"px"},{"duration":1500,"queue":false}).children(0).animate({"padding":0+"px","width":"100%","height":"100%"},{"duration":1500,"queue":false}).fadeTo(1500,1);;
				break;
			case 1:
				p2=Math.floor((tw-(tw*.8))/2);
				//inner.children(":eq("+x+")").animate({"left":"-="+(totalWidth)+"px"},{"duration":1500,"queue":false}).children(0).animate({"padding":p2+"px","width":"80%","height":"80%","opacity":".5"},{"duration":1500,"queue":false});
				inner.children(":eq("+x+")").animate({"left":"-="+(totalWidth)+"px"},{"duration":1500,"queue":false}).children(0).animate({"padding":p2+"px","width":"80%","height":"80%"},{"duration":1500,"queue":false}).fadeTo(1500,.5);;
				//do nothing
				break;
			case 0:
//				inner.children(":eq("+x+")").children(0).animate({"opacity":0},{"duration":1500,"queue":false,"complete":function(){
//						var ob=inner.children(":first").clone();
//						ob.css("left",l+"px");
//						inner.append(ob);
//						inner.children(":first").remove();
//						}
//				});
				
				inner.children(":eq("+x+")").children(0).fadeTo(1500,0,function(){
						var ob=inner.children(":first").clone();
						ob.css("left",l+"px");
						inner.append(ob);
						inner.children(":first").remove();
						
				});

				break;
			case 5:
				p2=Math.floor((tw-(tw*.8))/2);
//				inner.children(":eq("+x+")").children(0).animate({"padding":p2+"px","width":"80%","height":"80%","opacity":".5"},{"duration":1500,"queue":false,"complete":function(){return window.setTimeout(anim,3000);}});
				inner.children(":eq("+x+")").children(0).animate({"padding":p2+"px","width":"80%","height":"80%"},{"duration":1500,"queue":false,"complete":function(){return window.setTimeout(anim,3000);}}).fadeTo(1500,.5);
				//do nothing
				break;
			default:
				break;
		}
		}
	}
	anim();
	};   
})(jQuery);  

function addCourseNav1(){
	$("#course_nav1").find("a").each(function(){
		$(this).click(function(){
			//do ajax
			var reg=/course_offset=(\d{1,4})/;
			var matchme=$(this).attr("href").match(reg);
			$.ajax({ 
				method: "get",url: "ajax/coursetm.php",data: "course_offset="+matchme[1], 
				beforeSend: function(){	
					$("#course_nav1").hide();
					$("#course_refresh").show();
				}, //show loading just when link is clicked 
				complete: function(){ $("#course_refresh").hide();}, //stop showing loading when the process is complete 
				error:function (XMLHttpRequest, textStatus, errorThrown) {
					  // typically only one of textStatus or errorThrown 
					  // will have info
					  //this; // the options for this ajax request
					  alert("Ajax "+XMLHttpRequest+"\n" + errorThrown + "\n" +textStatus +"  occured.");
				},
				success: function(html){ //so, if data is retrieved, store it in html 
					$("#thismonth_holder").html(html);
				} 
			});
			//ajax finished
			
			return false;
		});
	});
}
function addExternalClickHandler(element){
	if ( element === undefined ) {
	  element = "body";
	}
	$(element).find("a[rel*=external]").each( function() {
		$(this).click(function(){
			window.open( $(this).attr('href') );
			return false;
		});
	});
//$.ajaxHistory.initialize();
};
function addHelp(){
	$(".help").each(function(){
		if($(this).hasClass("helpon")){return;}
		var ht=$(this).html();
		$(this).html(ht + "<a href=\"/help/get.php?source="+urlencode(ht)+"\" title=\""+ht+" FAQ\" class=\"remote\" rel=\"no-index,no-follow\"><img src=\"images/icons/help.gif\" border=\"0\" alt=\""+ht+" FAQ\" /></a>");
		$(this).addClass("helpon");
	
	});
	$(".remote").each(function(){
		$(this).click(function(){
			//do ajax
			$.ajax({ 
				method: "get",url: $(this).attr("href"),data: "", 
				beforeSend: function(){$("#doc").block({message:$("#ajax_loading")});}, //show loading just when link is clicked 
				complete: function(){ /*$("#doc").unblock();*/}, //stop showing loading when the process is complete 
				error:function (XMLHttpRequest, textStatus, errorThrown) {
					  // typically only one of textStatus or errorThrown 
					  // will have info
					  //this; // the options for this ajax request
					  $("#doc").unblock();
					  alert("Ajax " + txtStatus +" error occured.");
				},
				success: function(html){ //so, if data is retrieved, store it in html 
					$("#tmp").html(html);
					$("#doc").block({message:$("#tmp")});
					$(".blockMsg").css("cursor","default");
				} 
			});
			//ajax finished
			return false;
		});
	 });
}
function urlencode(s) {
	//php compatable
  s = encodeURIComponent(s);
  return s.replace(/~/g,'%7E').replace(/%20/g,'+');
}
