$.fn.ReloadUser = function () {

    	$(function() {
	// get width and height of imgs
	/* $("#imageScroller a img").each(function() {
		var widthor = $(this).attr('width');
		var heightor = $(this).attr('height');
	
	// set new var for resizing imgs
		var widthfix = 52;
		var heightfix = 60;
		
	// fill imgs with new var
		$(this).css({'width' : widthfix, 'height' : heightfix});
	});
	*/
	

			
	//create new container for images
	$("<div>").attr("id", "container").css({ position:"absolute"}).height($(".wrapper").length * 60).width(55).appendTo("div#viewer");
			  	
	//add images to container
	$(".wrapper").each(function() {
		$(this).appendTo("div#container");
		});

	//work out duration of anim based on number of images (1 second for each image)
	var duration = $(".wrapper").length * 5000;
				
	//store speed for later (distance / time)
	var speed = (parseInt($("div#container").height()) + parseInt($("div#viewer").height())) / duration;  
								
	//set direction
	var direction = "ttb";
				
	//set initial position and class based on direction
	(direction == "btt") ? $("div#container").css("top", $("div#viewer").height()).addClass("btt") : $("div#container").css("top", 0 - $("div#container").height()).addClass("ttb") ;
				
	//animator function
	var animator = function(el, time, dir) {
				 
		//which direction to scroll
		if(dir == "btt") {
					  
		  //add direction class
			el.removeClass("ttb").addClass("btt");
					 		
			//animate the el
			el.animate({ top:"-" + el.height() + "px" }, time, "linear", function() {
												
				//reset container position
				$(this).css({ top:$("div#imageScroller").height(), bottom:"" });
							
				//restart animation
				animator($(this), duration, "btt");
							
			});
		} else {
		
		  //add direction class
			el.removeClass("btt").addClass("ttb");
					
			//animate the el
			el.animate({ top:$("div#viewer").height() + "px" }, time, "linear", function() {
												
				//reset container position
				$(this).css({ top:0 - $("div#container").height() });
							
				//restart animation
				animator($(this), duration, "ttb");
				
			});
		}
	}
				
	//start anim
	animator($("div#container"), duration, direction);
	
	//show controls  
($("div#controls").length == 0) ? $("<div>").attr("id", "controls").appendTo("div#myuser").css({ opacity:1 }).slideDown("slow") : null ;  
($("a#ttb").length == 0) ? $("<a>").attr({ id:"ttb", href:"#", title:"ttb" }).appendTo("#controls") : null ;  
($("a#btt").length == 0) ? $("</a><a>").attr({ id:"btt", href:"#", title:"btt" }).appendTo("#controls") : null ;  
				

					
		//handler for ttb button  
		$("#ttb").live("click", function() {  
                                      
  		//stop anim  
  		$("div#container").stop(true);  
                  
  		//swap class names  
  		$("div#container").removeClass("btt").addClass("ttb");  
                                          
  		//work out total travel distance  
  		var totalDistance = parseInt($("div#container").height()) + parseInt($("div#viewer").height());  
                      
   			//work out remaining distance  
  			var distanceLeft = totalDistance - (parseInt($("div#container").css("top")) + parseInt($("div#container").height()));  
                      
  			//new duration is distance left / speed)  
  			var newDuration = distanceLeft / speed;  
                      
  			//restart anim  
  			animator($("div#container"), newDuration, "ttb");  
		}); 
		
		//handler for btt button  
			$("#btt").live("click", function() {  
                                          
  			//stop anim  
  			$("div#container").stop(true);  
                      
  			//swap class names  
  			$("div#container").removeClass("ttb").addClass("btt");  
                      
  			//work out total travel distance  
  			var totalDistance = parseInt($("div#container").height()) + parseInt($("div#viewer").height());  
  
  			//work out remaining distance  
  			var distanceLeft = totalDistance - (parseInt($("div#viewer").height()) - (parseInt($("div#container").css("top"))));  
                      
  			//new duration is distance left / speed)  
  			var newDuration = distanceLeft / speed;  
                  
  			//restart anim  
  			animator($("div#container"), newDuration, "btt");  
	});   							
});
}

$.fn.ReloadToplist = function (){
	
//Toplist
	// get width and height of imgs
	/* $("#videos img").each(function() {
		var tlwidthor = $(this).attr('width');
		//var tlheightor = $(this).attr('height');
	
		// set new var for resizing imgs
		var tlwidthfix = 87;
		//var tlheightfix = (tlwidthfix/tlwidthor) * tlheightor;
		
		// fill imgs with new var
		$(this).css({'width' : tlwidthfix});
	});
	*/
	
	// new Slider
	var scrollheight = ( $('#video_wrapper').height() - $('#videos').height() );
	var divcount = ( $('#video_wrapper img').length - 3 );
	var topscroll = ( scrollheight / divcount );
	var i = 0;
	
	$("#videos").removeClass('js_ie6').css("overflow", "hidden");
	$("#scroller").removeClass('nodisplay');
	$("#scroller").css({"display": "none"});
	
	if (divcount >= 1 && scrollheight > 0 ) {
		$("#scroller").css({"display": "block"});
		$(".down").click(function() {
			if (i < divcount) {
        	i++;
        	$("#video_wrapper").animate({
        	top: (0 - (i * topscroll)) + "px"}, 500 );
        	}
        });
        
        $(".up").click(function() {
			if (i >= 1) {
			i--;
        	$("#video_wrapper").animate({
        	top: (0 - (i * topscroll)) + "px"}, 500 );
        	}
        });	
	};

	
    
	$("#video_wrapper li").mouseover(function () {
		//get the position of the overlay element
  		$("ul", this).clone().prependTo("#overlay");
  		var pos = $(this).offset();  
  		var width = $("#overlay").width();
  		//position overlay and show it/hide it
  		$("#overlay").css({ "left": pos.left - 165 + "px", "top":pos.top - 10 + "px" }).removeClass("nodisplay").addClass("display");
  		}).mouseout(function () { 
		$("#overlay").removeClass("display").addClass("nodisplay").empty();	
	});
	}
