
var AtcImgRotator = {
	_timer : null,
	_items : [],
	_container : null,
	_index : 0,
	_imgs : [],
	intervalTime : 5000,
	init : function( objID, w, h, time ){
		this.intervalTime = time || this.intervalTime;
		this._container = document.getElementById( objID );
		this._container.style.display = "block";
		this._container.style.width = w + "px";
		this._container.style.height = h + "px";
		this._container.style.position = "relative";
		this._container.style.overflow  = "hidden";
		//this._container.style.border = "1px solid #fff";
		var linkStyle = "display: block; TEXT-DECORATION: none;";
		if( document.all ){
			linkStyle += "FILTER:";
			//linkStyle += "progid:DXImageTransform.Microsoft.Zigzag ( duration=0.5,gridSizeX=4,gridSizeY=40 ); width: 100%; height: 100%";
			linkStyle += "progid:DXImageTransform.Microsoft.Fade(duration=0.5,overlap=0)";
		}
		//
		var ulStyle = "margin:2;width:"+w+"px;position:absolute;z-index:999;right:5px;FILTER:Alpha(Opacity=30,FinishOpacity=90, Style=1);overflow: hidden;bottom:-1px;height:16px; border-right:1px solid #fff;";
		var liStyle = "margin:0;list-style-type: none; margin:0;padding:0; float:right;";
		var baseSpacStyle = "clear:both; display:block; width:16px; line-height:16px; font-size:12px; FONT-FAMILY:'Arial';opacity: 0.6;";
		baseSpacStyle += "border:1px solid #fff;border-right:0;border-bottom:0;";
		baseSpacStyle += "text-align:center; cursor:pointer; ";
		//
		var ulHTML = "";
		for(var i = this._items.length -1; i >= 0; i--){
			var spanStyle = "";
			if( i==this._index ){
				spanStyle = baseSpacStyle + "background:#1c5c9a;color:#fff;font-weight:bold;";
			} else {				
				spanStyle = baseSpacStyle + "background:#fff;color:#1c5c9a;";
			}
			ulHTML += "<li style=\""+liStyle+"\">";
			ulHTML += "<span onmouseover=\"AtcImgRotator.mouseOver(this);\" onmouseout=\"AtcImgRotator.mouseOut(this);\" style=\""+spanStyle+"\" onclick=\"AtcImgRotator.play("+i+");return false;\" herf=\"javascript:;\" title=\"" + this._items[i].title + "\">" + (i+1) + "</span>";
			ulHTML += "</li>";
		}
		//
		var html = "<a href=\""+this._items[this._index].link+"\" title=\""+this._items[this._index].title+"\" target=\"_blank\" style=\""+linkStyle+"\"></a><ul style=\""+ulStyle+"\">"+ulHTML+"</ul>";
		this._container.innerHTML = html;
		var link = this._container.getElementsByTagName("A")[0];	
		link.style.width =  w + "px";
		link.style.height = h + "px";
		link.style.background = 'url(' + this._items[0].img + ') no-repeat center center';
		//
		this._timer = setInterval( "AtcImgRotator.play()", this.intervalTime );
	},
	addItem : function( _title, _link, _imgURL ){
		this._items.push ( {title:_title, link:_link, img:_imgURL } );
		var img = new Image();
		img.src = _imgURL;
		this._imgs.push( img );
	},
	clearItem : function (){
		this._items.length = 0;
		this._index = 0;
		clearInterval(this._timer);
	},
	play : function( index ){
		if( index!=null ){
			this._index = index;
			clearInterval( this._timer );
			this._timer = setInterval( "AtcImgRotator.play()", this.intervalTime );
		} else {
			this._index = this._index<this._items.length-1 ? this._index+1 : 0;
		}
		var link = this._container.getElementsByTagName("A")[0];	
		if(link.filters){
			var ren = Math.floor(Math.random()*(link.filters.length));
			link.filters[ren].Apply();
			link.filters[ren].play();
		}
		link.href = this._items[this._index].link;
		link.title = this._items[this._index].title;
		link.style.background = 'url(' + this._items[this._index].img + ') no-repeat center center';
		//
		var liStyle = "margin:0;list-style-type: none; margin:0;padding:0; float:right;";
		var baseSpacStyle = "clear:both; display:block; width:16px;line-height:16px; font-size:12px; FONT-FAMILY:'Arial'; opacity: 0.6;";
		baseSpacStyle += "border:1px solid #fff;border-right:0;border-bottom:0;";
		baseSpacStyle += "text-align:center; cursor:pointer; ";
		var ulHTML = "";
		for(var i = this._items.length -1; i >= 0; i--){
			var spanStyle = "";
			if( i==this._index ){
				spanStyle = baseSpacStyle + "background:#1c5c9a;color:#fff;font-weight:bold;";
			} else {				
				spanStyle = baseSpacStyle + "background:#fff;color:#1c5c9a;";
			}
			ulHTML += "<li style=\""+liStyle+"\">";
			ulHTML += "<span onmouseover=\"AtcImgRotator.mouseOver(this);\" onmouseout=\"AtcImgRotator.mouseOut(this);\" style=\""+spanStyle+"\" onclick=\"AtcImgRotator.play("+i+");return false;\" herf=\"javascript:;\" title=\"" + this._items[i].title + "\">" + (i+1) + "</span>";
			ulHTML += "</li>";
		}
		this._container.getElementsByTagName("UL")[0].innerHTML = ulHTML;	
	},
	mouseOver : function(obj){
		var i = parseInt( obj.innerHTML );
		if( this._index!=i-1){
			obj.style.color = "#fe7a00";
		}
	},
	mouseOut : function(obj){
		var i = parseInt( obj.innerHTML );
		if( this._index!=i-1){
			obj.style.color = "#1c5c9a";
		}
	}
}

function showImageRotatorNew(Class, subClass)
{
	AtcImgRotator.clearItem();
	//alert(rotateImageCount[Class+"_"+subClass]);
	//alert("images/index/"+Class+"_"+subClass+"_"+1+".jpg");
	for(i=1;i<=rotateImageCount[Class+"_"+subClass];i++)
		AtcImgRotator.addItem(rotateImageDescription[Class+"_"+subClass]+"-"+i,rotateImageLink[Class+"_"+subClass][i],"images/index/"+Class+"_"+subClass+"_"+i+".jpg");

	AtcImgRotator.init( "divImgRotator", 555, 288 );
}

/**************************/

function changeSubClassImageGroup(Class)
{
  
	document.getElementById("Image21").src="images/index/Categories0"+Class+"_01_d.gif";
	for(i=2;i<=4;i++)
		document.getElementById("Image2"+i).src="images/index/Categories0"+Class+"_0"+i+".gif";
		
	currentSubClass = 1;
}

function highLightSubClassImage(subClass)
{
	//if(currentSubClass!=subClass)
	//	document.getElementById("Image2"+subClass).src="images/index/Categories0"+currentClass+"_0"+subClass+"_d.gif";
	whichSubImageWillBeChanged = subClass; 
	setTimeout("setCurrentSubClassImage('"+subClass+"')",500);
	//alert("OK");
}

function setCurrentSubClassImage(subClass)
{
 
	if(whichSubImageWillBeChanged==subClass)
	{
		document.getElementById("Image2"+currentSubClass).src="images/index/Categories0"+currentClass+"_0"+currentSubClass+".gif";
		document.getElementById("Image2"+subClass).src="images/index/Categories0"+currentClass+"_0"+subClass+"_d.gif";
		currentSubClass=subClass;
		showImageRotatorNew(currentClass, subClass)
	}
}

function subClassMouseOut(subClass)
 
{
	whichSubImageWillBeChanged=0;
	if(currentSubClass!=subClass)
		document.getElementById("Image2"+subClass).src="images/index/Categories0"+currentClass+"_0"+subClass+".gif";
}

