//dynamiclist_init = function () {};
jQuery(document).ready(
	function() {
		myBehaviors = new oAjaxAttacher(
			'#listings',					//linksource
			'#itemView',		//inktarget
			'#main',						//responseFilter,
			'.messages',					//submitResponseFilter
			[], //Preserve ids as classes
			[collapseAutoAttach, activeselectAutoAttach, uploadAutoAttach,dynamiclist_init],	//external js callbacks
			".messages:contains('updated'), .messages:contains('created'), .messages:contains('deleted')", //triggers
			archiveTrigger,		//triggercallback
			"Loading...",	//loading text,
			{'formLink' : '#main', 'listing' : '#itemView', 'listing active' : '#itemView'}, //specific filters(value) for links with classes(key)
			{0:'external'}	//exclude these classes from ajax loads
		);
		myBehaviors.linkTarget = jQuery(myBehaviors.linkTarget);
		myBehaviors.linkSource = jQuery(myBehaviors.linkSource);
		attachLinksToTarget(myBehaviors.linkSource, myBehaviors);
		
	}
);

function doNothing() {
	return;
}
var archiveTrigger = function (scope, oOptions) {
	var urlHalves = String(document.location).split('?');
	jQuery.ajax({
		oOptions : oOptions,
		url: location.href,//'/archive',
		data: urlHalves[1],
		dataType:"html",
		complete: function(res, status) {
			jQuery("#listings").html('Loading...');
			if ( status == "success" || status == "notmodified" ) {
				var responseText = res.responseText;
			
				//Hide the link target to our manipulations to it do not look messy.
				jQuery("#listings").hide();
				
				//Store the response in a temporary jQuery object so we can more easily operate on it
				var temp = jQuery("<div/>").prepend(responseText.replace(/<script(.|\s)*?\/script>/g, ""));
							
							
				//Filter the html response by the designated responseFilter.  If that element is not found, simply inject all the HTML
				if(jQuery('#listings', temp).length) {
					jQuery("#listings").html(jQuery('#listings', temp).html());
				}
				else {
					jQuery("#listings").html(temp.html());
				}
					
				
				jQuery("#listings").show("fast");
				attachLinksToTarget(jQuery("#listings"), this.oOptions);	
			}
			else {
				jQuery("#listings").html("Error loading page, please try again later.")
			}
		}
	});
}