function ScrollerPanel() {
	var THIS_INSTANCE = this;
	var ITEM_INDEX = 0;
	this.Init = function(sTargetId, itemIndex) {
		THIS_INSTANCE.Panel.Init(sTargetId);
		THIS_INSTANCE.Panel.OpenItem(itemIndex);
	};
	this.Utils = function () {
		return {addListener:function (element, type, expression, bubbling) {
			bubbling = bubbling || false;
			if (window.addEventListener) {
				element.addEventListener(type, expression, bubbling);
				return true;
			} else if (window.attachEvent) {
				element.attachEvent('on'+type, expression);
				return true;
			} else {
				return false;
			}
		}, removeListener:function (element, type, fReference) {
			if (window.removeEventListener) {
				element.removeEventListener(type, fReference);
				return true;
			} else if (window.detachEvent) {
				element.detachEvent('on'+type, fReference);
				return true;
			} else {
				return false;
			}
		}};
	}();
	this.Button = function () {
		return {Create:function (itemIndex) {
			var objButton = document.createElement('a');
			objButton.itemIndex = itemIndex;
			objButton.innerHTML = (THIS_INSTANCE.Panel.PANELITEMLIST[itemIndex].title.length>0) ? THIS_INSTANCE.Panel.PANELITEMLIST[itemIndex].title : itemIndex+1;
			THIS_INSTANCE.Panel.PANELITEMLIST[itemIndex].title = "";
			objButton.href = 'javascript:;';
			THIS_INSTANCE.Utils.addListener(objButton, 'click', function (eObjEvent) {
				THIS_INSTANCE.Button.Click(eObjEvent);
			}, false);
			THIS_INSTANCE.Panel.PANELBUTTONLISTTARGET.appendChild(objButton);
			
			
		}, Click:function (objEvent) {
			if (objEvent.target != null) {
				objEvent.srcElement = objEvent.target;
			}
			THIS_INSTANCE.Panel.OpenItem(objEvent.srcElement.itemIndex);
		}};
	}();
	this.Panel = function () {
		return {TWEEN:null, MAINTARGET:null, PANELLISTSCROLLERTARGET:null, PANELLISTTARGET:null, PANELITEMLIST:null, PANELBUTTONLISTTARGET:null, OpenItem:function (itemIndex) {
			var objButtonList = null;
			try {
				if (THIS_INSTANCE.Panel.PANELITEMLIST.length>itemIndex) {
					if (THIS_INSTANCE.Panel.TWEEN != null) {
						THIS_INSTANCE.Panel.TWEEN.stop();
						THIS_INSTANCE.Panel.TWEEN = null;
					}
					THIS_INSTANCE.Panel.TWEEN = new Tween(THIS_INSTANCE.Panel.PANELLISTSCROLLERTARGET, 'scrollLeft', Tween.regularEaseIn, THIS_INSTANCE.Panel.PANELLISTSCROLLERTARGET.scrollLeft, THIS_INSTANCE.Panel.PANELITEMLIST[itemIndex].offsetLeft-THIS_INSTANCE.Panel.PANELLISTSCROLLERTARGET.offsetLeft, 0.3, '');
					THIS_INSTANCE.Panel.TWEEN.start();
					objButtonList = THIS_INSTANCE.Panel.PANELBUTTONLISTTARGET.getElementsByTagName('a');
					for (var i = 0; i<objButtonList.length; i++) {
						if (objButtonList[i].itemIndex>=0) {
							objButtonList[i].className = '';
							if (objButtonList[i].itemIndex == itemIndex) {
								objButtonList[i].className = 'selected';
							}
						}
					}
				} else {
					throw new Error('Item not found');
				}
			} catch (e) {
				status = e.message;
			}
		}, Init:function (sTargetId) {
			var iPanelTotalWidth = 0;
			var iButtonTotalWidth = 0;
			THIS_INSTANCE.Panel.MAINTARGET = document.getElementById(sTargetId);
			try {
				if (THIS_INSTANCE.Panel.MAINTARGET == null) {
					throw new Error('MainTarget not found');
				} else {
					THIS_INSTANCE.Panel.ConsolidePanelList();
					if(THIS_INSTANCE.Panel.PANELITEMLIST.length > 1)
					{
					    for (var i = 0; i<THIS_INSTANCE.Panel.PANELITEMLIST.length; i++) {
						    iPanelTotalWidth += THIS_INSTANCE.Panel.PANELITEMLIST[i].offsetWidth;
						    THIS_INSTANCE.Button.Create(i);
					    }
					}
					
					for(var i = 0; i < THIS_INSTANCE.Panel.PANELBUTTONLISTTARGET.childNodes.length; i++)
					{
					    if((THIS_INSTANCE.Panel.PANELBUTTONLISTTARGET.childNodes[i].tagName != null) && (THIS_INSTANCE.Panel.PANELBUTTONLISTTARGET.childNodes[i].tagName.toLowerCase() == 'a'))
					    {
					        iButtonTotalWidth += THIS_INSTANCE.Panel.PANELBUTTONLISTTARGET.childNodes[i].offsetWidth;
					    }
					}
					
					THIS_INSTANCE.Panel.PANELBUTTONLISTTARGET.style.width = iButtonTotalWidth + 'px';
				}
				THIS_INSTANCE.Panel.PANELLISTTARGET.style.width = iPanelTotalWidth+'px';
				THIS_INSTANCE.Panel.PANELLISTSCROLLERTARGET.style.width = THIS_INSTANCE.Panel.MAINTARGET.offsetWidth+'px';
				//THIS_INSTANCE.Panel.PANELLISTSCROLLERTARGET.style.height = THIS_INSTANCE.Panel.MAINTARGET.offsetHeight+'px';
			} catch (e) {
				status = e.message;
			}
		}, ConsolidePanelList:function () {
			var objPanelList = THIS_INSTANCE.Panel.MAINTARGET.getElementsByTagName('div');
			try {
				if (objPanelList.length<=0) {
					throw new Error('No itens available in MainTarget');
				} else {
					THIS_INSTANCE.Panel.PANELITEMLIST = new Array();
					for (var i = 0; i<objPanelList.length; i++) {
						if (objPanelList[i].className == 'panellist') {
							THIS_INSTANCE.Panel.PANELLISTTARGET = objPanelList[i];
						} else if (objPanelList[i].className == 'panel') {
							THIS_INSTANCE.Panel.PANELITEMLIST.push(objPanelList[i]);
						} else if (objPanelList[i].className == 'panellistscroller') {
							THIS_INSTANCE.Panel.PANELLISTSCROLLERTARGET = objPanelList[i];
						} else if (objPanelList[i].className == 'panelbuttonlist') {
							THIS_INSTANCE.Panel.PANELBUTTONLISTTARGET = objPanelList[i];
						}
					}
				}
				if (THIS_INSTANCE.Panel.PANELLISTTARGET == null) {
					throw new Error('Panel List Target not found');
				} else if (THIS_INSTANCE.Panel.PANELLISTSCROLLERTARGET == null) {
					throw new Error('Panel List Scroller Target not found');
				} else if (THIS_INSTANCE.Panel.PANELBUTTONLISTTARGET == null) {
					throw new Error('Panel Button List Target not found');
				}
			} catch (e) {
				status = e.message;
			}
		}};
	}();
}

