(function($){
	$.fn.podiumlevel2 = function(options) {
		var defaults = {
			xml_path:"/xml/default.asp",
			schoolid:3,
			currentL1:0
		};
		var options = $.extend(defaults, options);
		
		var dataStore = {
			xml:""
		};
		
		return this.each(function() {
			var	obj = $(this);
			if(options.currentL1 != 0){
				$.ajax({
					type: "GET",
					url: options.xml_path+"?sid="+options.schoolid+"&type=menu&id="+options.currentL1,
					dataType: "xml",
					success: function(xml) {
						dataStore.xml = xml;
					},
					error: function(request,tStatus,eThrown){ 
						if(window.console && window.console.firebug){ 
							console.log("podiumlevel2 plugin error: request='"+request+"', tStatus='"+tStatus+"', eThrown='"+eThrown+"'"); 
						} 
					},
					complete: function(){
						var	$AllPages = $("<ul></ul>")
						$(dataStore.xml).find('item').each(function(){
							$L2item = $("<li></li>");
							var $aTag = $("<a></a>").attr("href",$(this).find("url").text())
							    		.attr("target",($(this).find("target").text()>0)?"_blank":"")
							    		.html("<span>"+$(this).find("title").text()+"</span>");
														
							if(options.pageid == parseInt($(this).find("id").text())){
								$aTag.addClass("on");
							}		
							
							$aTag.appendTo($L2item);		
							$L2item.appendTo($AllPages);
						});
						obj.append($AllPages);
					}
				});
			}
		});
	};
})(jQuery);