var Xslider = {
	
	/**
	* @property
	*/
	counter: 0,

	/**
	* Initialize vars, set timer
	* @function
	*/
	init: function( image_holder, title_holder, slides, interval ){

		this.image_holder = image_holder;
		this.title_holder = title_holder;
		this.slides = slides;
		this.slide_length = slides.length;
		this.interval = interval;

		var self = this;
			
		this.rotate(0);

		setInterval(function(){
			self.rotate();
		}, this.interval);
	
	},
	
	/**
	* Fade out and fade in images/titles, increase counter or restore it
	* @function
	*/
	rotate: function(index){

		var index = index || this.counter,
			main_image = 'http://www.cornellwomenshealth.org/static_local/images/' + this.slides[index].main_image,
			image_position = 'http://www.cornellwomenshealth.org/static_local/images/' + this.slides[index].image_position, 
			title_holder_element = this.title_holder + ' span',
			image_title = this.slides[index].image_title;

		$(this.image_holder).fadeOut(950, function(){
				$(this).css('background-image', 'url(' + main_image + ')').fadeIn(950);
			});
	
		$(this.title_holder).slideUp(950, function(){
				$(title_holder_element).text(image_title);
				$('img', this).attr('src', image_position);
				$(this).slideDown(950);				
			});
			
		this.counter = index === (this.slide_length - 1) ? 0 : this.counter + 1;
				
	}
};











