var mBanner = {

	oGallery : null,
	numSlides : 0,
	maxHeight : 0,
	oLayer : null,
	fIndex : 0,
	oNavigation : null,
	fTransition : null,
	fInterval : 5000,
	fSlideshow : 0,
	fPaused : false,

	create : function (oDiv) {

		var oPrev, oNext;
		this.oLayer = document.createElement("div");
		this.oLayer.style.position = 'relative';
		this.oLayer.style.top = '0px';
		this.oLayer.style.zIndex = 1;
		this.oLayer.style.left = '0px';
		this.oNavigation = document.createElement("div");
		this.oNavigation.className = 'sliderBox';
		this.oNavigation = this.oNavigation.appendChild(document.createElement("table"));
		this.oNavigation.className = 'slideNumber';
		this.oNavigation = this.oNavigation.appendChild(document.createElement("tbody"));
		this.oNavigation = this.oNavigation.appendChild(document.createElement("tr"));
		oPrev = this.oNavigation.appendChild(document.createElement("td"));
		oPrev.className = 'startend';
		oPrev	 = oPrev.appendChild(document.createElement("a"));
		oPrev.href = '#';
		oPrev.innerHTML = '&larr;';
		oPrev.onclick = function (e) {return mBanner.prev();}
		this.oGallery = new Array();
		while (oDiv.childNodes.length) {			
			var o = oDiv.childNodes[0];
			if (o.tagName && o.tagName.toLowerCase() == 'div') {
				this.oGallery.push(this.createSlide(o));
				this.oLayer.appendChild(oDiv.removeChild(o));
				this.numSlides++;
			} else {
				oDiv.removeChild(o);
			}
		} if (this.numSlides) {
			this.oLayer.style.height = this.maxHeight+'px';
			oDiv.appendChild(this.oLayer);
			if (this.numSlides > 1) {				
				oPrev = this.oNavigation.appendChild(document.createElement("td"));
				oPrev.className = 'startend';
				oPrev	 = oPrev.appendChild(document.createElement("a"));
				oPrev.href = '#';
				oPrev.innerHTML = '&rarr;';
				oPrev.onclick = function (e) {return mBanner.next();}
				oDiv.appendChild(this.oNavigation.parentNode.parentNode.parentNode);
				this.play();
			}
		} 

	},

	prev : function () {

		this.stop();
		var cur = this.fIndex;
		this.fIndex--;
		if (this.fIndex < 0) this.fIndex = this.numSlides - 1;
		this.show(this.fIndex,cur);
		return false;

	},

	next : function () {

		this.stop();
		var cur = this.fIndex;
		this.fIndex++;
		if (this.fIndex == this.numSlides) this.fIndex = 0;
		this.show(this.fIndex,cur);
		return false;

	},

	createSlide : function (oElem) {

		var oRef = this;
		var oIndex = this.numSlides;
		oElem.style.display = 'block';		
		if (this.maxHeight < oElem.offsetHeight) this.maxHeight = oElem.offsetHeight;
		oElem.onmouseover = function (e) {oRef.fPaused = true;}
		oElem.onmouseout = function (e) {oRef.fPaused = false;}
		oElem.style.position = 'absolute';
		oElem.style.zIndex = 1;
		oElem.style.top = '0px';
		oElem.style.width = '325px';
		oElem.style.left = (this.numSlides*325) + 'px';
		var navElem = this.oNavigation.appendChild(document.createElement("td"));
		if (!this.numSlides) navElem.className = 'active';
		navElem = navElem.appendChild(document.createElement("a"));
		navElem.href = '#';
		navElem.appendChild(document.createTextNode(this.numSlides+1));
		navElem.onclick = function (e) {return oRef.select(oIndex);}
		return oElem;

	},

	select : function (oId) {

		this.stop();
		this.show(oId,this.fIndex);
		return false;

	},

	play : function () {		
		
		if (this.numSlides > 1) {
			if (!this.fSlideshow) { 
				this.fSlideshow = setInterval("mBanner.play()",this.fInterval);
			} else {
				if (this.fPaused) return;
				var cur = this.fIndex;
				this.fIndex++;
				if (this.fIndex == this.numSlides) this.fIndex = 0;
				this.show(this.fIndex,cur);
			}			
		}

	},

	stop : function () {

		if (this.fSlideshow) {
			clearInterval(this.fSlideshow);			
			this.fSlideshow = 0;
		}

	},

	show : function (oId,oCurrent) {

		this.fTransition = {total: 20,current: 0,fps : 30,src: oCurrent,dst: oId};
		this.oNavigation.childNodes[oCurrent+1].className = '';
		setTimeout("mBanner.transition()",this.fTransition.fps);
		this.fIndex = oId;

	},

	transition : function () {

		if (this.fTransition.current < this.fTransition.total) {
			if (this.fTransition.src < this.fTransition.dst) {
				var dst = (this.fTransition.dst - this.fTransition.src) * 325;
				var pos = (Math.round(this.cubicInOut(this.fTransition.current,0,dst,this.fTransition.total)) + this.fTransition.src * 325) * -1;
			} else {
				var dst = (this.fTransition.src - this.fTransition.dst) * 325;
				var pos = (this.fTransition.src * 325 - Math.round(this.cubicInOut(this.fTransition.current,0,dst,this.fTransition.total))) * -1;
			} this.oLayer.style.left = pos+'px';
			this.fTransition.current++;
			setTimeout("mBanner.transition()",this.fTransition.fps);
		} else {
			this.oLayer.style.left = (this.fIndex * 325 * -1) + 'px';
			this.oNavigation.childNodes[this.fIndex+1].className = 'active';
		}

	},

	cubicInOut : function (t, b, c, d) {
		
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;

	}

}

function OpenWindow(url, w, h) {
	
	var vh = window.open("", "", 'menubar=no,directories=no,location=no,resizable=no,target=viv,scrollbars=no,width='+w +',height='+h);
	vh.document.body.style.padding = 0;
	vh.document.body.style.margin = 0;
	var a = vh.document.body.appendChild(vh.document.createElement("img"));
	a.src = document.location.protocol+'//'+document.location.hostname+url;
	a.style.padding = 0;
	a.style.margin = 0;

}

function toggleLayer (oId) {

	var o;
	if (o = document.getElementById(oId)) {
		o.style.display = o.style.display == 'none' ? 'block' : 'none';
	}

}

function removeItem (oId) {
	
	var frm = document.forms['orderForm'];
	frm['cmd'].value = 'remove';
	frm['pid'].value = oId;
	frm.submit();

}

function posPrint (oStr) {

	if (oStr.length) {
		var a = oStr.split('-');
		for (var i = 0; i < a.length; i++) {
			if (b = document.getElementById(a[i])) {
				b.style.display = 'block';
			}
		} 
	} window.print();
	return false;

}

function showPopup (oState) {

	var active_popup = document.getElementById('invoiceForm');
	if (oState) {
		active_popup.style.display = 'block';
		active_popup.style.visibility = 'visible';
	} else {
		active_popup.style.display = 'none';
		active_popup.style.visibility = 'hidden';
	}

}

window.onload = function () {
	
	if ((o = document.getElementById("mainBBlock"))) mBanner.create(o);

}