$("document").ready(function() {
	

	
	//-----------------newsRotator---------------------//
	function newsRotator(){
		this.old = null;
		this.length = $('#newsRotator .content ul li').length
		this.wfu = new waitForUser(this);
		
		this.toggle = function(ID){
			if(nrttr.old != null){
				$('#newsRotator .content ul li:eq('+nrttr.old+')').removeClass('selected');
			}
			$('#newsRotator .content ul li:eq('+ID+')').addClass('selected');
			
			nrttr.old = ID;
		}
		
		this.swap = function(dir){
			//alert("5");
			if(dir == 'next'){
				if(nrttr.old == nrttr.length-1){
					nrttr.checkPos(0);
					nrttr.toggle(0);
				} else {
					nrttr.checkPos(nrttr.old+1);
					nrttr.toggle(nrttr.old+1);
				}
			} 
			if(dir == 'back'){
				if(nrttr.old == 0){
					nrttr.checkPos(nrttr.length-1);
					nrttr.toggle(nrttr.length-1);
				} else {
					nrttr.checkPos(nrttr.old-1);
					nrttr.toggle(nrttr.old-1);
				}
			}
		}
		
		this.checkPos = function(ID){
			//alert("1");
			this.imgw = 202;
			this.pos = (ID*-this.imgw)+this.imgw;
			if(this.pos>0){
				this.pos = 0;
			}
			if(this.pos<(nrttr.length-4)*-this.imgw){
				this.pos = (nrttr.length-4)*-this.imgw;
			}
		
			$('#newsRotator ul').animate({ left: nrttr.pos+'px' }, 250);
		}
		
		$('#newsRotator .left').click(function(){
			//alert("2");
			nrttr.swap('back');
			nrttr.wfu.init();
		});
		$('#newsRotator .right').click(function(){
			//alert("3");
			nrttr.swap('next');
			nrttr.wfu.init();
		});
		$('#newsRotator ul li').hover(function(){
			//alert("4");
			nrttr.toggle($('#newsRotator ul li').index(this));
			nrttr.wfu.init();
		});
	}
	////////////////////////////
	var nrttr = new newsRotator();
	nrttr.toggle(0);
	//newsRotator close
	
	
	
	//-----------------waitForUser---------------------//
	function waitForUser(obj){
		this.played = true;
		this.resume = null;
		
		this.init = function(){
			this.played = false;
			clearInterval(this.resume);
			this.resume = setInterval(this.playAgain,9000);
		}
		
		this.playAgain = function(){
			obj.wfu.played = true;
			clearInterval(obj.wfu.resume);
		}
		
	}
	////////////////////////////
	//waitForUser close
	
	
	
	//$('.tools li a').tipsy({fade: true, gravity: 's'});
	

	
});//document ready function cloese-------------------------



