function resizeStockTitleWidth( width ){
	var obj = $("stockTitle");
	if ( obj != null ){
		obj.style.width = width + "px";
	}
}	
function goItemMain() {
	GoPage('/item/main.daum?code='+$('sCode').innerHTML)
}
function stockCss(val) {
	var colorCss = "cFt"
	if(parseFloat(val)>0) colorCss = "cUp";
	else if(parseFloat(val)<0) colorCss = "cDn";
	return colorCss;
}
function stockRate(val,isBold) {
	var sign = "";
	if(parseFloat(val)>0) sign="+";
	else if(parseFloat(val)<0) sign="-";
	var formatVal = FormatFloat(Math.abs(val),2);
	if(isBold) formatVal = "<b>"+formatVal +"</b>";
	return '<span class="'+stockCss(val)+' num">'+sign+formatVal+'%</span>';
}
//상단 슬라이드 li 만들기
function makeItem(name,rate) {
	if(name.length > 7) name = name.substring(0,7)+"..";
	return '<strong>'+name+'</strong><br />'+stockRate(rate,true)
}

function AddCompareSymbol(movieName, Symbol){
	getMovieName(movieName).addCompareSymbol(Symbol);
}
function DeleteCompareSymbol(movieName, Symbol){
	getMovieName(movieName).deleteCompareSymbol(Symbol);
}




/*************************************** 사진 슬라이드 ********************************************************/
var SlideShow = function(objId, options ){
	this.list = $(objId.list);
	this.btnPrevPage = $('prevPage'); this.btnPrevPage.oldCss = this.btnPrevPage.className;
	this.btnNextPage = $('nextPage'); this.btnNextPage.oldCss = this.btnNextPage.className;
	this.dummyCall = false;
	//this.btnPrevStep = $('prevStep'); this.btnPrevStep.oldCss = this.btnPrevStep.className;
	//this.btnNextStep = $('nextStep'); this.btnNextStep.oldCss = this.btnNextStep.className;
	
	// 기본옵션
	this.options = {
		stepWidth : 109, // width of step
		stepPerPage : 7, 
		defaultIndex :0,
		pageLoop : true
	}
	Object.extend( this.options, options );
	
	this.init(this.options.defaultIndex);
}

SlideShow.prototype = {
	init : function(idx) {		
		this.item = this.list.childNodes;
		if( this.item.length == 0 ) return false;
		for(var i=0,cnt=this.item.length;i<cnt;++i) AddEvent(this.item[i],"click",this.selectItem.bindEvent(this, i))
		if(idx) this.options.defaultIndex = idx;
		if( this.options.defaultIndex<0 ) {this.options.defaultIndex=0;} else if( this.options.defaultIndex>=this.item.length ){this.options.defaultIndex=this.item.length-1;}
		// 기본값
		this.timer = null;
		this.index = this.options.defaultIndex;
		this.totalPage = Math.ceil( this.item.length / this.options.stepPerPage );
		this.cursor = Math.floor( this.index / this.options.stepPerPage ) * this.options.stepPerPage;
		this.curX = 0;
		this.trgX = this.options.stepWidth*this.cursor*-1;
		this.list.style.width = this.item.length * this.options.stepWidth + "px";
		this.isInit = true;
		this.selectAction();
		this.isInit = false;
		this.dummyCall = true;
		this.setButton();
	},
	prevStep : function(){this.unselectAction();this.index--;this.selectAction();},
	nextStep : function(){this.unselectAction();this.index++;this.selectAction();},
	prevPage : function(){this.cursor -= this.options.stepPerPage;if( this.options.pageLoop == false && this.cursor<0){this.cursor=0;}this.checkCursor( this.cursor );/*this.setButton()*/},
	nextPage : function(){this.cursor += this.options.stepPerPage;if( this.options.pageLoop == false && this.cursor>=this.item.length){this.cursor=(this.totalPage-1)*this.options.stepPerPage;}this.checkCursor( this.cursor );/*this.setButton();*/},
	selectItem : function( event, num ){this.unselectAction();this.index = num;this.dummyCall = true;this.selectAction();	},
	unselectAction : function(){this.item[this.index].className = this.item[this.index].className.replace("on","");},
	selectAction : function(){
		this.checkCursor();
		this.item[this.index].className += " on";
		$('slideCur').innerHTML = this.index+1;
		getStockData(this.item[this.index].code, this.dummyCall);
		this.setButton();
	},
	checkCursor : function( cursor ){
		if( this.index >= this.item.length ) {
			this.index = 0;
			this.cursor = Math.floor( this.index / this.options.stepPerPage ) * this.options.stepPerPage;
		} else if( this.index < 0 ) {
			this.index = this.item.length-1;
			this.cursor = Math.floor( this.index / this.options.stepPerPage ) * this.options.stepPerPage;
		}
					
		if( cursor == undefined || cursor == null ){//기본
			this.cursor = Math.floor( this.index / this.options.stepPerPage ) * this.options.stepPerPage;
		} else {// 임의의 cursor 설정
			this.cursor = cursor;
			if( this.cursor < 0 ){
				this.cursor = Math.floor( (this.item.length-1) / this.options.stepPerPage ) * this.options.stepPerPage;
			} else if ( this.cursor >= this.item.length) {
				this.cursor = 0;
			}
		}
		if (this.isInit) {
			this.list.style.left = Math.round(this.options.stepWidth * this.cursor * -1)  + "px";
		}
		else {
			this.trgX = this.options.stepWidth * this.cursor * -1;
			this.curX = this.list.offsetLeft;
			var self = this;
			if (this.trgX != this.curX) {
				clearInterval(this.timer);
				this.timer = setInterval(this.enterFrame.bind(this), 10);
			}
		}
	},
	enterFrame : function(){
		if( this.trgX != this.list.offsetLeft ){
			this.curX += 0.3*(this.trgX  - this.curX );
			this.list.style.left = Math.round(this.curX)  + "px";
		} else {
			clearInterval( this.timer );
		}
	},
	setButton : function() {
		this.btnPrevPage.className = (this.totalPage == 1) ? this.btnPrevPage.oldCss+" off" : this.btnPrevPage.oldCss;
		this.btnNextPage.className = (this.totalPage == 1) ? this.btnNextPage.oldCss+" off" : this.btnNextPage.oldCss;
		//this.btnPrevPage.className = (Math.floor(this.cursor/this.options.stepPerPage) == 0) ? this.btnPrevPage.oldCss+" off" : this.btnPrevPage.oldCss;
		//this.btnNextPage.className = (Math.floor(this.cursor/this.options.stepPerPage) == this.totalPage-1) ?this.btnNextPage.oldCss+" off" : this.btnNextPage.oldCss;
		//this.btnPrevStep.className = (this.index == 0) ? this.btnPrevStep.oldCss : this.btnPrevStep.oldCss+" on";
		//this.btnNextStep.className = (this.index == this.item.length-1) ? this.btnNextStep.oldCss : this.btnNextStep.oldCss+" on";
	}
}
var AutoSlideOption = function( options ){
	this.options = {
		handle : null,
		mode : "stop",
		speed : [5000, 2500]
	}
	this.init(options);
}
AutoSlideOption.prototype = {
	init : function(options) {		
		Object.extend( this.options, options );
		this.timer = null;
		this.exec( this.options.mode );
	},
	exec : function( mode ){
		this.options.mode = mode;
		clearInterval( this.timer );
		switch( mode ){
			case "stop":break;
			case "slow":
				this.timer = setInterval( this.play.bind(this), this.options.speed[0] );
				break;
			case "fast":
				this.timer = setInterval( this.play.bind(this), this.options.speed[1] );
				break;
		}
	},
	play : function(){
		this.options.handle.dummyCall = false;
		this.options.handle.nextStep();
	}
}

function setSymbol(movieName, Symbol){
	getMovieName(movieName).setSymbol(Symbol);
}



var slideShow=null, autoSlide=null;


function showToolTip(type) {
	if((type=='prev' && slideShow.index-1<0) || (type=='next' && slideShow.index+1>=slideShow.item.length)) closeToolTip();
	var el = $('toolTip');
	if(type=='prev') {
		el.style.left = "17px";
		el.style.right = "auto";
	}
	else if(type=='next') {
		el.style.left = "auto";
		el.style.right = "17px";
	}
	var idx;
	if(type=='prev') {
		idx = (slideShow.index-1<0) ? slideShow.item.length-1 : slideShow.index-1;
	}
	else if(type=='next') {
		idx = (slideShow.index+1>=slideShow.item.length) ? 0 : slideShow.index+1;
	}
	el.innerHTML = '<b>'+slideShow.item[idx].name+'</b> <code class="num">('+slideShow.item[idx].code+')</code>';
	el.style.display = "block";
}

function closeToolTip() {$('toolTip').style.display = "none";}

