﻿// Webthor utilites classes

function LinkedList() {}

LinkedList.prototype = {
	length: 0,
	first: null,
	last: null
};

LinkedList.Circular = function() {};
LinkedList.Circular.prototype = new LinkedList();

LinkedList.Circular.prototype.append = function(node) {
if(this.first == null){
	node.prev = node;
	node.next = node;
	this.first = node;
	this.last = node; 
} else {
	node.prev = this.last;
	node.next = this.first;
	this.first.prev = node;
	this.last.next = node;
	this.last = node;
}
this.length++;
};

LinkedList.Circular.prototype.insertAfter = function(node, newNode) {
  newNode.prev = node;
  newNode.next = node.next;
  node.next.prev = newNode;
  node.next = newNode;
  if (newNode.prev == this.last) { this.last = newNode; }
  this.length++;
};

LinkedList.Circular.prototype.remove = function(node) {
  if (this.length > 1) {
    node.prev.next = node.next;
    node.next.prev = node.prev;
    if (node == this.first) { this.first = node.next; }
    if (node == this.last) { this.last = node.prev; }
  } else {
    this.first = null;
    this.last = null;
  }
  node.prev = null;
  node.next = null;
  this.length--;
};

LinkedList.Node = function(data) {
  this.prev = null; this.next = null;
  this.data = data;
};

/*
String functions:
*/

String.format = function()
{
	if(arguments.length == 0)
		return null;
	var str = arguments[0];
	for(var i=1;i<arguments.length;i++){
		var re = new RegExp('\\{' + (i-1) + '\\}','gm');
		str = str.replace(re,arguments[i]);
	}
	return str;
}

var News = {
	Expand : function(val,cb){
		$(cb).parent().siblings(".newsabstract").hide();
		$(cb).parent().siblings(".load").show();
		$.getJSON(JSONService,{ action : "getNews", id : val },
		function(json){
			$(cb).parent().parent().siblings().children(".news").hide();
			$(cb).parent().parent().siblings().children(".newsabstract").show();
			$(cb).parent().siblings(".newsabstract").hide();
			$(cb).parent().siblings(".load").hide();
			$(cb).parent().siblings(".newstext").html(json.Text).show();
		});
	}
};

jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};
