var initK = '请输入产品或品牌名称';
function $(id){return document.getElementById(id)}
function ctab(aTab, onIndex, currenttabcls){
	this.aTab = aTab;
	this.currentTab = onIndex;
	this.currenttabcls = currenttabcls || null;
	this.init();
	this.show(onIndex);
}
ctab.prototype = {
	init: function(){
		
		var self = this;
		for(var i = 0; i < this.aTab.length; i++){
			$(this.aTab[i]).onmouseover = registerEvent(i);
		}
		function registerEvent(index){
			return function(){
				self.show(index);
			}
		}
		
	},
	show:function(index){
		$(this.aTab[this.currentTab]).className = 'commontaboff';
		$(this.aTab[index]).className = 'commontabon';
		$(this.aTab[this.currentTab]+'-content').className = 'tabcontent';
		$(this.aTab[index]+'-content').className = 'tabcontent currenttab';
		this.currentTab = index;
	}
};
function ccPlayer(aFrames, cFrame){
	this.aFrames = aFrames;
	this.currentFrame = cFrame;
	this.last = 0;
	this.init();
	//this.show(cFrame);
}
ccPlayer.prototype = {
	init: function(){
		var timer = null;
		var self = this;
		//create ctrl elements
		var ctrlElements = document.createElement('p');
		for(var i = 0; i < this.aFrames.length; i++){
			var ctrlItem = document.createElement('span');
			ctrlItem.innerHTML = i+1;
			ctrlItem.id = 'ctrlItem-'+i;
			ctrlItem.onclick = registerEvent(i);
			ctrlElements.appendChild(ctrlItem);
		}
		$('imgfocus-ctrl').appendChild(ctrlElements);
		function registerEvent(index){
			return function(){
				self.show(index);
			}
		}
		$('imgfocus-pic').onmouseover = function(){
			clearInterval(timer);
		}
		$('imgfocus-pic').onmouseout = function(){
			timer = setInterval(function(){
			self.autoPlay();
			}, 2000);
		}
		this.show(this.currentFrame);
		//自动播放
		timer = setInterval(function(){
			self.autoPlay();
			}, 2000);

	},
	autoPlay:function(){
		var i = this.currentFrame + 1;
		
		//this.currentFrame++;
		if(i == this.aFrames.length){
			i = 0;
		}
		this.show(i);
	},
	show:function(index){
		this.currentFrame = index;
		$('ctrlItem-'+this.last).style.background = '#a8276a';
		$('ctrlItem-'+this.last).style.color = '#fff';
		$('ctrlItem-'+this.last).style.textDecoration = 'none';
		$('ctrlItem-'+this.currentFrame).style.background = '#fff';
		$('ctrlItem-'+this.currentFrame).style.color = '#a8276a';
		$('ctrlItem-'+this.currentFrame).style.textDecoration = 'underline';
	
		$('imgfocus-url').href = this.aFrames[index].url;;
		$('imgfocus-pic-url').src = this.aFrames[index].img;;
		$('imgfocus-txt').innerHTML = this.aFrames[index].txt;
		this.last = index;
	}
};

