var adrotator={
	ajaxloadingmsg: '<div style="margin: 1em; font-weight: bold"> Fetching Content. Please wait...</div>', //customize HTML to show while fetching Ajax content
	defaultbuttonsfade: 0.4,
	configholder: {},
	num: 1,
	
	loadRemotePanel:function($, config){ 
		if (adrotator.num == 1) {
			var ajaxElement = config.$content1
			
		} else {
			var ajaxElement = config.$content2
		}
		//ajaxElement.hide()
		ajaxElement.html('Loading...')
		//config.$gallery.fadeOut(1000)
		$.ajax({
			url: config.loadurl, //path to external content
			async: true,
			error:function(ajaxrequest){
				ajaxElement.html('Error fetching content.<br />Server Response: '+ajaxrequest.responseText)
			},
			success:function(content){
				ajaxElement.html(content)
				//adrotator.fadeAd($, config)
				//adrotator.loadAd($, config)
				//config.steptimer=setTimeout(function(){adrotator.loadRemotePanel($, config)}, config.timing.pause)
				config.steptimer=setTimeout(function(){adrotator.loadAd($, config)}, 7000) 
			}
		})
	},
	
	stopautostep:function(config){
		clearTimeout(config.steptimer)
		//clearTimeout(config.resumeautostep)
	},
	
	fadeAd:function($, config) {
		if (adrotator.num == 1) {
			config.$content2.fadeOut(1000, function () {
				//config.$content2.hide()
				//config.$content1.show()
				config.$content1.fadeIn(1000);
				adrotator.num = 2
				adrotator.loadRemotePanel($, config)
			})
			 
		} else {
			config.$content1.fadeOut(1000, function () {
				//config.$content1.hide()
				//config.$content2.show()
				config.$content2.fadeIn(1000);
				adrotator.num = 1
				adrotator.loadRemotePanel($, config)
			})
			
			
		}
	},
	
	loadAd:function($, config){
		adrotator.fadeAd($, config)
		

		//config.steptimer=setTimeout(function(){adrotator.loadAd($, config)}, 7000) 
	},

	setup:function(config){
		jQuery(document).ready(function($){
			config.$gallery=$('#'+config.galleryid)
			config.$content1=config.$gallery.find('.content1')
			config.$content2=config.$gallery.find('.content2')
			adrotator.configholder[0]=config 
			adrotator.loadRemotePanel($, config)
			//config.steptimer=setTimeout(function(){adrotator.loadAd($, config)}, 7000) 
			//adrotator.loadAd($, config)
		})
	}
}


