function Content_Switcher(css_class, interval, start_index, indicator_class){
	var obj_ref = this;
	this.css_class = css_class;
	this.interval = interval;
	this.timerID;
	this.current_index = start_index;
	this.switch_objects = new Array();
	var switch_object_array = this.switch_objects;
		jQuery(("."+css_class)).each(function(){
			switch_object_array[switch_object_array.length] = this;
		});
	for(var i = 0; i < switch_object_array.length; i++){
		if(i != start_index){
			switch_object_array[i].style.display = "none";	
		}
		else{
			switch_object_array[i].style.display = "block";	
		}
	}
	if(this.switch_objects.length > 1 && indicator_class != null){
	this.indicator = new Indicator(this.switch_objects.length, indicator_class, start_index, obj_ref);
	}
	this.Increase_Index = function(){
		 if(this.current_index < (this.switch_objects.length - 1)){
			this.current_index ++; 
		 }
		 else{
			this.current_index = 0; 
		 }
	}
	this.Get_Previous_Object = function(){
		if(this.current_index == 0){
			return this.switch_objects[this.switch_objects.length - 1];	
		}
		else{
			return this.switch_objects[this.current_index - 1];
		}
	}
	this.Cycle = function(){
		var obj_ref = this;
		jQuery((this.Get_Previous_Object())).fadeOut(2000);
		jQuery((this.switch_objects[this.current_index])).fadeIn(2000, function(){
			if(this.indicator != null){
			obj_ref.indicator.Activate_Node(obj_ref.current_index);
			}
			obj_ref.Increase_Index();
			clearTimeout(obj_ref.timerID);
			obj_ref.timerID = setTimeout(function(){obj_ref.Cycle();},obj_ref.interval);
		});
		
	}
	//setTimeout(function(){obj_ref.Cycle();},this.interval);
	if(this.indicator != null){
	obj_ref.Cycle();
	}
	this.Stop_At = function(index){
		for(var i = 0; i < this.switch_objects.length; i++){
			this.switch_objects[i].style.display = "none";	
		}
		this.switch_objects[index - 1].style.display = "block";
		this.current_index = index;
	    clearTimeout(this.timerID);	
	}
	this.Resume = function(){
		if(this.current_index == this.switch_objects.length){
		this.Increase_Index();
		}
		this.timerID = setTimeout(function(){obj_ref.Cycle();},5000);	
	}
}

function Indicator(icons, css_class, start_index, owner){
		 var obj_ref = this;
		 this.owner = owner;
		 this.current_index = start_index;
		 this.dom_element = null;
		 jQuery("."+css_class).each(function(){
			  obj_ref.dom_element = this;
		 });
		 var i;
		 for(i = 0; i < icons; i++){
			 if(i != start_index){
			 	this.dom_element.innerHTML += "<span style='color:gray'>&#9679</span>";
			 }
			 else{
				this.dom_element.innerHTML += "<span style='color:black'>&#9679</span>";
			 }
		 }
		 for(i = 1; i < this.dom_element.childNodes.length; i++){
			 var this_node = this.dom_element.childNodes[i];
			 this_node.indexis = i;
			 this_node.onmouseover = function(){
				 obj_ref.owner.Stop_At(this.indexis);
				 document.body.style.cursor = "Pointer";
				 obj_ref.Activate_Node(this.indexis - 1);
			 }
			 this_node.onmouseout = function(){
				 obj_ref.owner.Resume();
				 document.body.style.cursor = "Auto";
			 }
		 }
		 this.Activate_Node = function(index){
			for(var i = 0; i < this.dom_element.childNodes.length; i++){
				var this_node = this.dom_element.childNodes[i + 1];
				if(this_node != null){
					if(i != index){
						this_node.style.color = "gray";	
					}
					else{
						this_node.style.color = "black";	
					}
				}
				else{
						
				}
			}
		 }
}
