(function ($) {

/**
 * Front_Comments_List
 * @constructor jQuery
 * 
 */
$.widget('ui.Front_Comments_List', $.extend({}, $.ui.Component.prototype, {
	type: 'Front_Comments_List',
	_init: function () {

		$.ui.Component.prototype._init.call(this); // chain parent constructor
		var self = this

//		var Components = {}
//		Components.Front_Comments_List = self

		//Get our elements for faster access and set overlay width
		var div = $('div.commentList'),
		ul = $('#comments_list')//,
		// unordered list's left margin
//		ulPadding = 5//45;

		//Get menu width
//		var divHeight = div.height()

		//Remove scrollbars
		div.css({overflow: 'hidden'})

		//Find last image container
		var lastLi = ul.find('li:last-child')

//		var dot = div.offset().top

		//When user move mouse over menu
//		div.mousemove(function(e){
//			//As images are loaded ul width increases,
//			//so we recalculate it each time
//			var ulHeight = lastLi.offset().top + lastLi.outerHeight() + ulPadding - ul.offset().top
//
//			var top = (e.pageY - dot) * (ulHeight-divHeight) / (divHeight)*-1
////			alert(divHeight)
////			$("h3.white").text(lastLi.outerHeight())
//			ul.animate({top: top}, 0) //.scrollLeft(left) //
//		});

//		var ulHeight = lastLi.offset().top + lastLi.outerHeight() + ulPadding - ul.offset().top
//		var top = -divHeight * (ulHeight-divHeight) / (divHeight)
////		$("h3.white").text(top)
//
//		ul.animate({top: top}, 0)

		$(document).ready(function(){
			setTimeout(function(){
				var ui_value = $("#slider-vertical").slider("value")
				var ulHeight = lastLi.offset().top + lastLi.outerHeight() - $('div.commentList').height() - ul.offset().top
				var top = (ulHeight / 100) * (ui_value-100)
				ul.animate({top: top}, 0)
			}, 100)
		})

		var mutation = Math.floor(Math.random()*11)
		mutation = (10 + (mutation % 5))*1000;



		if(typeof(self.reload_triger) == "undefined" ){
			self.reload_triger = 1
		}

//		setTimeout(function(){
//			if(self.reload_triger==1){
//				self.reload()
//			}else{
//				self.reload_triger = 1
//			}
//		}, mutation)

		$('#post_btn').click(function (ev){
			setTimeout(function(){
				self.reload()
			}, 100)
			self.reload_triger = 2
		})

	}
}));

}).require('Component')(jQuery);