function WCCCarousel(width, height, tabwidth, tablocation, id) {

	this.jquery = null;
	this.width = width;
	this.height = height;
	this.id = id ? id : "wcccarousel";
	this.tabwidth = tabwidth ? tabwidth : 100;
	this.tablocation = tablocation ? tablocation : 'right';

	this.obj = document.createElement('div');
	this.bg = document.createElement('div');
	this.contentdiv = document.createElement('div');
	this.tabdiv = document.createElement('div');
	this.statusdiv = document.createElement('div');
	this.status = document.createTextNode('');

	this.tabs = [];
	this.contents = [];

	this.tabheight = 0;
	this.activetab = 0;
	this._rotateint = 0;
	this._rotatetime = 6000;


	this.build = function() {


		// Build the basic document elements and set their styles


		document.write('<div id="' + this.id + '"></div>');
		this.obj = document.getElementById(this.id);

		this.obj.style.width = this.width + 'px';
		this.obj.style.height = this.height + 'px';

		this.bg.id = 'bg';
		this.bg.style.width = this.width + 'px';
		this.bg.style.height = this.height + 'px';

		this.contentdiv.id = 'content-bg';
		this.contentdiv.style.position = 'absolute';
		this.contentdiv.style.width = (this.width - this.tabwidth) + 'px';
		this.contentdiv.style.height = this.height + 'px';

		this.tabdiv.id = 'tab-bg';
		this.tabdiv.style.position = 'absolute';
		this.tabdiv.style.width = this.tabwidth  + 'px';
		this.tabdiv.style.height = this.height + 'px';

		switch(this.tablocation){
			case 'right':
			this.tabdiv.style.marginLeft = (this.width - this.tabwidth) + 'px';
			break;
			case 'left':
			this.contentdiv.style.marginLeft = this.tabwidth + 'px';
			break;
		}



		this.statusdiv.id = 'status';
		this.statusdiv.style.display = 'none';
		this.statusdiv.style.position = 'absolute';
		this.statusdiv.style.zIndex = 1;
		this.statusdiv.appendChild(this.status);
	
		this.bg.appendChild(this.statusdiv);
		this.bg.appendChild(this.contentdiv);
		this.bg.appendChild(this.tabdiv);

		this.obj.appendChild(this.bg);

	}


	this.addTab = function(t, url, html) {

		var isobject = t.constructor == Object;
		var isarray = t.constructor == Array;
		var newtab = Object();
		var c = this;

		if(isobject){

			url = isarray ? t[1] : t.url;
			html = isarray ? t[2] : t.html;
			t = isarray ? t[0] : t.title;

		}

		newtab.title = t;
		newtab.url = url;
		newtab.html = html;

		newtab.content = document.createElement('div');
		newtab.content.innerHTML = newtab.html;

		newtab.tab = document.createElement('div');
		newtab.tab.innerHTML = newtab.title;

		this.tabs.push(newtab);
		this.tabheight = (this.height / this.tabs.length);


		// Add the tab to the display object


		var tcon = document.createElement('div');
		var ctab = this.tabs[this.tabs.length - 1];

		tcon.style.display = 'table';
		tcon.style.width = this.tabwidth + 'px';

		ctab.tab.className = 'tab';
		ctab.tab.style.display = 'table-cell';
		ctab.tab.style.width = '100%';
		ctab.tab.style.height = '100%';
		ctab.tab.style.verticalAlign = 'middle';
		ctab.tab.style.cursor = 'default';

		if(window.attachEvent) ctab.tab.attachEvent('onclick', function(e){ c.clickTab(e); });
		else if(window.addEventListener) ctab.tab.addEventListener('click', function(e){ c.clickTab(e); }, false);
		else ctab.tab.onclick = c.clickTab(window.event);

		ctab.content.className = 'content';
		ctab.content.style.display = this.tabs.length > 1 ? 'none' : 'block';
		ctab.content.style.position = 'absolute';
		ctab.content.style.height = this.height + 'px';
		ctab.content.style.width = (this.width - this.tabwidth) + 'px';
		ctab.content.style.cursor = 'default';

		tcon.appendChild(ctab.tab);
		this.tabdiv.appendChild(tcon);
		this.contentdiv.appendChild(ctab.content);


		for(var i=0; i<this.tabdiv.childNodes.length; i++){

			this.tabdiv.childNodes[i].style.height = this.tabheight + 'px';

		}


		if(!this.activetab) this.changeTab(ctab.tab);
		if(!this._rotateint && this.tabs.length > 1) this._rotateint = setInterval(function(){ c.rotateTab(); }, this._rotatetime);

	}

	this.setjQuery = function(jq) {

		this.jquery = jq;

	}

	this.getContent = function(url, params) {

		if(!this.jquery.ajax) return;

		var c = this;

		this.showStatus("Loading...");

		params = "&params=" + encodeURIComponent(params);
		this.jquery.ajax({url: url, dataType: 'json', processData: false, data: params, type: 'POST', success: function(data){ c.onGetContent(data, status); } });

	}

	this.onGetContent = function(data, status) {

		this.hideStatus();

		var d = data.obj;

		for(var i=0; i<d.length; i++){

			this.addTab(d[i]);

		}

	}

	this.changeTab = function(targ) {

		for(var i in this.tabs){

			var t = this.tabs[i];

			if(targ == t.tab) {
				t.tab.className = 'tab activetab';
				this.showTab(t.content);
			}
			if(t.tab == this.activetab) {
				t.tab.className = 'tab';
				this.hideTab(t.content);
			}

		}

		this.activetab = targ;

	}

	this.clickTab = function(e) {

		var targ;

		if(!e) return;
		if(e.target) targ = e.target;
		else if (e.srcElement) targ = e.srcElement;
		if(targ.nodeType == 3) // defeat Safari bug
			targ = targ.parentNode;

		while( targ.className.indexOf('tab') < 0 ) targ = targ.parentNode;

		if(this._rotateint) clearInterval(this._rotateint);
		if(targ == this.activetab) return;

		this.changeTab(targ);

	}

	this.rotateTab = function(){

		var targ;
		var t = this.tabs;
		var j = 0;

		for(var i=0; i<t.length; i++){

			if(t[i].tab == this.activetab){

				j = i == t.length - 1 ? 0 : i + 1;
				targ = t[j].tab;
				break;

			}

		}

		this.changeTab(targ);

	}

	this.showTab = function(tab) {

		if(this.jquery) this.jquery(tab).fadeIn();
		else tab.style.display = 'block';

	}

	this.hideTab = function(tab) {
		if(this.jquery) this.jquery(tab).fadeOut();
		else tab.style.display = 'none';
	}

	this.showStatus = function(str) {
		this.status.nodeValue = str;
		this.statusdiv.style.display = 'block';
	}

	this.hideStatus = function() {
		this.statusdiv.style.display = 'none';
	}


	// Initialize the Javascript Object



	function init(o) {

		o.build();

	}

	init(this);

}
