var g_n_ArgusCrius = 0;

function ArgusCrius(sNameRef){
	g_n_ArgusCrius++;
	
	// Attributes
	this.NameRef = sNameRef;
	this.ComponentID = g_n_ArgusCrius;
	this.ContainerRef = 'argus_CriusContainer' + this.ComponentID;
	this.ContainerRowRef = 'argus_CriusContainerRow' + this.ComponentID;
	this.ContainerCellRef = 'argus_CriusContainerCell' + this.ComponentID + '_';
	this.ContainerWrapperRef = 'argus_CriusContainerWrapper' + this.ComponentID;
	this.SlideIntervalID = 0;
	
	// Properties
	this.AutoStart = true;
	this.BackgroundColor = 'transparent';
	this.CurrentSlide = 0;
	this.EndOfSequence = false;
	this.Font = 'Verdana, Arial';
	this.Height = 150;
	this.IsReadyToSwitch = false;
	this.TextDirection = 'ltr';
	this.TextAlign = 'left';
	this.SequenceIntervalID = 0;
	this.SlideDirection = 1; // Default - Up
	this.SlideEffectBrushSize = 0.25;
	this.SlideEffectDirection = 0; // Default - left-to-right
	this.SlideEffectDuration = 0.5;
	this.SlideEffectType = 'forward'; // forward, reverse, HIDE, PUSH, SPIN
	this.SlideHideEffect = 0; // Default - none;
	this.SlideEffect = 0; // Default - none; 1:Fade, 2:GradientWipe, 3:Pixelate, 4:Stretch
	this.SlideInterval = 3000;
	this.SlideMode = 1; // Default - SmoothSlide
	this.Slides = new Array();
	this.SlidesEnum = new Array();
	this.SlideSmoothness = 6;
	this.SlideSpeed = 5;
	this.VerticalAlign = 'top';
	this.Width = 200;
	
	this.GetPreviousSlide = f_argusCriusGetPreviousSlide;
	//this.GetEffectFilter = f_argusCriusGetEffectFilter;
	
	// Methods
	this.AdvanceSlides = f_argusCriusAdvanceSlides;
	this.ApplyHideEffect = f_argusCriusApplyHideEffect;
	this.ApplyShowEffect = f_argusCriusApplyShowEffect;
	this.SlideRoll = f_argusCriusSlideRoll;
	this.SlideSequence = f_argusCriusSlideSequence;
	this.SlideStep = f_argusCriusSlideStep;
	this.Start = f_argusCriusStart;
	this.StartSequence = f_argusCriusStartSequence;
	this.SwitchSlideCells = f_argusCriusSwitchSlideCells;
	
	// Events
	this.OnMouseOut = null;
	this.OnMouseOver = null;
	
}

function f_argusCriusSlideRoll(){
	this.SlideIntervalID = window.setInterval(this.NameRef + '.SlideStep();', this.SlideSpeed);
}

function f_argusCriusSlideStep(){
	var oWrapper = document.getElementById(this.ContainerWrapperRef);
	var nMoveBy = new Number(0);
	var nPreviousSlideHeight = new Number(0);
	var nPreviousSlideWidth = new Number(0);
	var nTickerTop = new Number(0);
	var nTickerSide = new Number(0);
	
	var oPreviousSlide = document.getElementById(this.ContainerCellRef + this.SlidesEnum[this.GetPreviousSlide()]);
	if(oPreviousSlide){
		nPreviousSlideHeight = parseInt(oPreviousSlide.offsetHeight);
		nPreviousSlideWidth = parseInt(oPreviousSlide.offsetWidth);
	}
	
	if(this.Slides.length > 1){
		switch(this.SlideDirection){
			case 1: // Default - up
				nTickerTop = parseInt(oWrapper.style.top);
				if(isNaN(nTickerTop)){
					nTickerTop = 0;
				}
				
				nMoveBy = Math.abs(nPreviousSlideHeight + nTickerTop) / this.SlideSmoothness;
				if(nMoveBy <= 2){
					nMoveBy = 1;
				}
				nTickerTop -= nMoveBy;
				
				if(nTickerTop + nPreviousSlideHeight == 0 || nTickerTop < (-1 - this.Height)){
					window.clearInterval(this.SlideIntervalID);
					this.SlideIntervalID = 0;
					oWrapper.style.top = '0px';
					this.SeuquenceIntervalID = window.setTimeout(this.NameRef + '.SlideSequence();', this.SlideInterval);
				}
				
				oWrapper.style.top = nTickerTop;
				break;
			
			case 2: // down
				break;
	
			case 3: // left
				nTickerSide = parseInt(oWrapper.style.left);
				if(isNaN(nTickerSide)){
					nTickerSide = 0;
				}
				
				nMoveBy = Math.abs(nPreviousSlideWidth + nTickerSide) / this.SlideSmoothness;
				if(nMoveBy <= 2){
					nMoveBy = 1;
				}						
				nTickerSide -= nMoveBy;
				
				if(nTickerSide + nPreviousSlideWidth == 0){
					window.clearInterval(this.SlideIntervalID);
					this.SlideIntervalID = 0;
					oWrapper.style.left = '0px';
					this.SeuquenceIntervalID = window.setTimeout(this.NameRef + '.SlideSequence();', this.SlideInterval);
				}
	
				oWrapper.style.left = nTickerSide;
				break;
	
			case 4: // right
				nTickerSide = parseInt(oWrapper.style.right);
				if(isNaN(nTickerSide)){
					nTickerSide = 0;
				}
				
				nMoveBy = Math.abs(nPreviousSlideWidth + nTickerSide) / this.SlideSmoothness;
				if(nMoveBy <= 2){
					nMoveBy = 1;
				}
				nTickerSide -= nMoveBy;
				//document.all['divTest'].innerHTML = (nPreviousSlideWidth + ' + ' + nTickerSide + ' / ' + this.SlideSmoothness + ' = ' + nMoveBy);
				if(nTickerSide + nPreviousSlideWidth == 0){
					window.clearInterval(this.SlideIntervalID);
					this.SlideIntervalID = 0;
					oWrapper.style.right = '0px';
					this.SeuquenceIntervalID = window.setTimeout(this.NameRef + '.SlideSequence();', this.SlideInterval);
				}
				
				oWrapper.style.right = nTickerSide;
				break;
			case 0: // none / filter
		}
		this.IsReadyToSwitch = true;
	}
}

function f_argusCriusApplyShowEffect(){
	var oContainer = document.all[this.ContainerRef];
	oContainer.filters[0].apply();
	oContainer.innerHTML = this.Slides[this.SlidesEnum[this.CurrentSlide]];
	oContainer.filters[0].play();
	this.SeuquenceIntervalID = window.setTimeout(this.NameRef + '.ApplyHideEffect();', this.SlideInterval);
}

function f_argusCriusApplyHideEffect(){
	this.AdvanceSlides();
	this.ApplyShowEffect();
}

function f_argusCriusGetPreviousSlide(){
	if(this.CurrentSlide == 0){
		return this.SlidesEnum.length - 1;
	}else{
		return this.CurrentSlide - 1;
	}
}

function f_argusCriusAdvanceSlides(){
	this.CurrentSlide++;
	if(this.CurrentSlide >= this.SlidesEnum.length){
		this.EndOfSequence = true;
		this.CurrentSlide = 0;
	}
}

function f_argusCriusSlideSequence(){
	this.SlideRoll();
	this.SwitchSlideCells();
	this.AdvanceSlides();
}

function f_argusCriusSwitchSlideCells(){
	var oWrapper = document.getElementById(this.ContainerWrapperRef);
	
	switch(this.SlideDirection){
		case 1: // up
		case 2: // down
			var oLastSlide = document.getElementById(this.ContainerCellRef + this.SlidesEnum[this.GetPreviousSlide()]);
			var oClonedSlide = oLastSlide.cloneNode(true);
			oWrapper.removeChild(oLastSlide);
			oWrapper.style.top = '0px';
			oWrapper.appendChild(oClonedSlide);
			break;

		case 3: // left
			if(this.IsReadyToSwitch){
				var oRow = document.getElementById(this.ContainerRowRef);
				var oFirstCell = oRow.cells[0];
				var oRemovedCell = oRow.removeChild(oFirstCell);
				oWrapper.style.left = '0px';
				var oAppendedCell = oRow.appendChild(oRemovedCell);
				this.IsReadyToSwitch = false;
			}
			break;
		case 4: // right
			if(this.IsReadyToSwitch){
				var oRow = document.getElementById(this.ContainerRowRef);
				var oFirstCell = oRow.cells[0];
				var oRemovedCell = oRow.removeChild(oFirstCell);
				oWrapper.style.right = '0px';
				var oAppendedCell = oRow.appendChild(oRemovedCell);
				this.IsReadyToSwitch = false;
			}
			break;
		
	}					
}

function f_argusCriusStartSequence(){
	this.SeuquenceIntervalID = window.setTimeout(this.NameRef + '.SlideSequence();', this.SlideInterval);
}

function f_argusCriusStart(){
	var nIndex = new Number(0);
	var nEnumIndex = new Number(0);
	var sContent = new String();
	var bValid = new Boolean(true); // by igor old value - false 
	var aAllowedDomains = new Array(
				'argus',
				'rest.co.il',
				'rest.co.il',
				'');
	
	for(I = 0; I < aAllowedDomains.length; I++){
		if(location.hostname == aAllowedDomains[I]){
			bValid = true;
			break;
		}
	}
	
	if(aAllowedDomains[0] == ''){
		bValid = true;
	}
	
	
	if(bValid == true){
		sContent = '' +
			'<span style="' +
			'	HEIGHT: ' + this.Height + 'px; ' +
			'	WIDTH: ' + this.Width + 'px; ' +
			'	BACKGROUND-COLOR: ' + this.BackgroundColor + '; ' +
			'	TEXT-ALIGN: ' + this.TextAlign + '; ' +
			'	OVERFLOW: hidden; ' +
			'	TOP: ' + this.Height + 'px;" id="' + this.ContainerRef + '">\n' +
			'	<div id="' + this.ContainerWrapperRef + '" style="PADDING: 2px; POSITION: relative;">\n';
			
		switch(this.SlideDirection){
			case 1: // up
				for(nIndex = 0; nIndex < this.Slides.length; nIndex++){
					if(this.Slides[nIndex]){
						sContent += '' +
							'		<div dir="' + this.TextDirection + '" id="' + this.ContainerCellRef + nIndex + '" style="HEIGHT: ' + this.Height + 'px; FONT-FAMILY: ' + this.Font + ';" align="' + this.TextAlign + '">' + this.Slides[nIndex] + '</div>\n';
						this.SlidesEnum[nEnumIndex] = nIndex;
						nEnumIndex++;
					}
				}
				break;
				
			case 3: // left
				sContent += '' +
					'		<table dir="ltr" cellpadding="0" cellspacing="0" height="' + this.Height + '" width="' + (this.Width * this.Slides.length) + '" style="POSITION: relative;"><tr id="' + this.ContainerRowRef + '">';
				
				for(nIndex = 0; nIndex < this.Slides.length; nIndex++){
					if(this.Slides[nIndex]){
						sContent += '' +
							'			<td id="' + this.ContainerCellRef + nIndex + '" height="' + this.Height + '" width="' + this.Width + '" style="FONT-FAMILY: ' + this.Font + ';" valign="' + this.VerticalAlign + '">' + this.Slides[nIndex] + '</td>';
						this.SlidesEnum[nEnumIndex] = nIndex;
						nEnumIndex++;
					}
				}
				
				sContent += '' +
					'		</tr></table>';
				break;

			case 4: // right
				sContent += '' +
					'		<table dir="rtl" cellpadding="0" cellspacing="0" height="' + this.Height + '" width="' + (this.Width * this.Slides.length) + '" style="RIGHT: ' + (this.Width * (this.Slides.length - 1)) + 'px; POSITION: relative;"><tr id="' + this.ContainerRowRef + '">';
				
				for(nIndex = 0; nIndex < this.Slides.length; nIndex++){
					if(this.Slides[nIndex]){
						sContent += '' +
							'			<td id="' + this.ContainerCellRef + nIndex + '" height="' + this.Height + '" width="' + this.Width + '" style="FONT-FAMILY: ' + this.Font + ';" valign="' + this.VerticalAlign + '">' + this.Slides[nIndex] + '</td>';
						this.SlidesEnum[nEnumIndex] = nIndex;
						nEnumIndex++;
					}
				}
				
				sContent += '' +
					'		</tr></table>';
				break;
			
			default: // filter-ready - populates wrapper with innerHTML of selected slide
				sContent = '' +
					'<span style="' +
					'	HEIGHT: ' + this.Height + 'px; ' +
					'	WIDTH: ' + this.Width + 'px; ' +
					'	BACKGROUND-COLOR: ' + this.BackgroundColor + '; ' +
					'	FONT-FAMILY: ' + this.Font + '; ' +
					'	TEXT-ALIGN: ' + this.TextAlign + '; ' +
					'	TOP: ' + this.Height + 'px;" id="' + this.ContainerRef + '">\n';
				break;
		}
		
		sContent += '' +
			'	</div>\n' + 
			'</span>';
		
		document.write(sContent);
	
		var oContainer = document.all[this.ContainerRef];
		var sType = new String('');
		switch(this.SlideEffect){
			case 1: // Fade
				oContainer.style.filter = 'progid:DXImageTransform.Microsoft.fade()';
				oContainer.filters[0].Duration = this.SlideEffectDuration;
				break;
			case 2: // GradientWipe
				switch(this.SlideEffectType){
					case 'reverse':
						sType = 'reverse';
						break;
					default:
						sType = 'forward';
						break;
				}
				oContainer.style.filter = 'progid:DXImageTransform.Microsoft.gradientWipe()';
				oContainer.filters[0].WipeStyle = this.SlideEffectDirection;
				oContainer.filters[0].Motion = sType;
				oContainer.filters[0].GradientSize = this.SlideEffectBrushSize;
				oContainer.filters[0].Duration = this.SlideEffectDuration;
				break;
			case 3: // Pixelate
				oContainer.style.filter = 'progid:DXImageTransform.Microsoft.pixelate()';
				oContainer.filters[0].Duration = this.SlideEffectDuration;
				oContainer.filters[0].MaxSquare = this.SlideEffectBrushSize;
			case 4: // Stretch
				switch(this.SlideEffectType){
					case 'HIDE':
						sType = 'HIDE';
						break;
					case 'SPIN':
						sType = 'SPIN';
						break;
					default:
						sType = 'PUSH';
						break;
				}
				oContainer.style.filter = 'progid:DXImageTransform.Microsoft.stretch()';
				oContainer.filters[0].Duration = this.SlideEffectDuration;
				oContainer.filters[0].StretchStyle = sType
		}
		
		if(this.AutoStart){
			if(this.SlideEffect == 0){
				this.StartSequence();
			}else{
				this.ApplyShowEffect();
			}
		}
	}else{
		sContent = '<div style="FONT-FAMILY: Arial; FONT-SIZE: 8pt">This product is <b>not</b> licensed to this domain. Please contact <a href="mailto:info@argusstudios.com">into@argusstudios.com</a> or visit <a href="http://argusstudios.com/" target="_blank">Argus Studios</a> for further details.</div>';
		document.write(sContent);
	}
}