var FeedWidgetPaginator = function(name, widget) {
	this.name = name;
	this.widget = widget;
}

FeedWidgetPaginator.prototype.display = function(page) {
	element = $('#paginator_' + this.name); 
	if (element) {
		element.fadeOut("fast");
		element.load('/phpinclude/index.php', {
				controller: 'BlogWidget',
				action: 'paginator',
				cssId: element.id,
				id: this.widget.name,
				page: page,
				view: this.widget.view
		});
		element.fadeIn("fast");
	}
}

var FeedWidget = function(container, name, view) {
	this.container = container;
	this.name = name;
	this.view = view;
	this.paginators = [];
	if ($("#paginator_top").is(':visible'))
		this.paginators.push(new FeedWidgetPaginator('top', this));
	if ($("#paginator_bottom").is(':visible'))
		this.paginators.push(new FeedWidgetPaginator('bottom', this));
}

FeedWidget.prototype.displayEmbed = function(fromPage) {
	this.container.fadeOut("fast");
    this.container.load('/phpinclude/index.php', {
            controller: 'BlogWidget',
            action: 'embed',
            id: this.name,
            page: fromPage,
            view: this.view
        });
	this.container.fadeIn("normal");
	$("#embedButton").hide();
	$(".pagination#paginator_bottom").hide();
}

FeedWidget.prototype.displayPaginators = function(page) {
	for (i in this.paginators)
		this.paginators[i].display(page);
	$("#footer").show();
}

FeedWidget.prototype.displayPage = function(page) {
	this.container.fadeOut("fast");
	this.container.load('/phpinclude/index.php', {
            controller: 'BlogWidget',
            action: 'ajaxPostList',
            id: this.name,
            page: page,
            view: this.view
        });
	this.displayPaginators(page);
	this.container.fadeIn("fast");
	$("#embedButton").show();
	$(".pagination#paginator_bottom").show();
}

FeedWidget.prototype.displayVideo = function(post, fromPage) {
	this.container.fadeOut("fast");
    this.container.load('/phpinclude/index.php', {
            controller: 'BlogWidget',
            action: 'ajaxDisplayPlatformVideo',
            post: post,
            id: this.name,
            page: fromPage,
            view: this.view
        });
	$("#footer").hide();
	$("#embedButton").hide();
	$(".pagination#paginator_bottom").hide();
	this.container.fadeIn("normal");
}

FeedWidget.prototype.autoSelect = function(selectTarget) {
 	if(selectTarget != null && ((selectTarget.childNodes.length == 1
      && selectTarget.childNodes[0].nodeName == "#text") || (selectTarget.tagName == "INPUT"
      && selectTarget.type == "text"))) {
  		if(selectTarget.tagName == 'TEXTAREA' || (selectTarget.tagName == "INPUT" && selectTarget.type == "text")) {
  			 selectTarget.select();
  		} else if(window.getSelection) { // FF, Safari, Opera
   			var sel = window.getSelection();
   			var range = document.createRange();
   			range.selectNode(selectTarget.firstChild);
   			sel.removeAllRanges();
   			sel.addRange(range);
  		} else { // IE
   			document.selection.empty();
   			var range = document.body.createTextRange();
   			range.moveToElementText(selectTarget);
   			range.select();
  		}
 	}
}


	
