var mbannerViewer = Class.create();

mbannerViewer.prototype = {
	initialize:function(options)
	{
		this.id = options.id;
		this.size = options.size;
		this.basic = options.basic;
		this.position = options.position;
		this.time = options.time;
		this.flag = '+';
		
		var obj;
		for(var i=0; i < this.size; i++) {
			obj = document.getElementById(this.id + i);
			if(i < this.basic) {
				obj.style.display="block";
			} else{
				obj.style.display="none";
			}
		}
		this.position = this.basic;

	},
	prev:function(isMsg)
	{
		if (isMsg == null) {
			isMsg = true;
		}	
		if(this.size == this.position) {
			if (isMsg) {
				alert('더 이상 이미지가 없습니다.');
			}
			this.flag = '+';
			return;
		}else if(this.size < this.basic) {
			if (isMsg) {
				alert('더 이상 이미지가 없습니다.');
			}	
			this.flag = '+';
			return;			
		}

		this.position ++;
		if(this.position==3) this.position ++;
		var obj;
		for(var i=0; i < this.size; i++) {
			obj = document.getElementById(this.id + i);

			if( this.position-i > this.basic) {
				obj.style.display="none";
			}
			else if( this.position <= i ) {
				obj.style.display="none";
			}else{
				obj.style.display="block";
			}

		}
	},
	
	next:function(isMsg)
	{
		if (isMsg == null) {
			isMsg = true;
		}
		if(this.position - this.basic == 0) {
			if (isMsg) {
				alert('더 이상 이미지가 없습니다.');
			}
			this.flag = '-';
			return;
		}

		if(this.position==4) this.position --;
		this.position--;
		
		var obj;
		for(var i=0; i < this.size; i++) {
			obj = document.getElementById(this.id + i);
			if(this.position-i > this.basic) {
				obj.style.display="none";
			}else if(this.position<i+1) {
				obj.style.display="none";
			}else{
				obj.style.display="block";
			}
		}
	},
	start:function()
	{
		setTimeout(this.start.bind(this), this.time);
		if(this.flag == '+')
		{
			this.next(false);
		}
		else
		{
			this.prev(false);
		}
	}
}

var photoViewer = Class.create();

photoViewer.prototype = {
	initialize:function(options)
	{
		this.id = options.id;
		this.size = options.size;
		this.basic = options.basic;
		this.position = options.position;
		this.time = options.time;
		this.flag = '+';
		
		var obj;
		for(var i=0; i < this.size; i++) {
			obj = document.getElementById(this.id + i);
			if(i < this.basic) {
				obj.style.display="block";
			} else{
				obj.style.display="none";
			}
		}
		this.position = this.basic;

	},
	prev:function(isMsg)
	{
		if (isMsg == null) {
			isMsg = true;
		}	
		if(this.size == this.position) {
			if (isMsg) {
				alert('더 이상 이미지가 없습니다.');
			}
			this.flag = '+';
			return;
		}else if(this.size < this.basic) {
			if (isMsg) {
				alert('더 이상 이미지가 없습니다.');
			}	
			this.flag = '+';
			return;			
		}

		this.position ++;

		var obj;
		for(var i=0; i < this.size; i++) {
			obj = document.getElementById(this.id + i);

			if( this.position-i > this.basic) {
				obj.style.display="none";
			}
			else if( this.position <= i ) {
				obj.style.display="none";
			}else{
				obj.style.display="block";
			}

		}
	},
	
	next:function(isMsg)
	{
		if (isMsg == null) {
			isMsg = true;
		}
		if(this.position - this.basic == 0) {
			if (isMsg) {
				alert('더 이상 이미지가 없습니다.');
			}
			this.flag = '-';
			return;
		}

		this.position--;
		var obj;
		for(var i=0; i < this.size; i++) {
			obj = document.getElementById(this.id + i);
			if(this.position-i > this.basic) {
				obj.style.display="none";
			}else if(this.position<i+1) {
				obj.style.display="none";
			}else{
				obj.style.display="block";
			}
		}
	},
	start:function()
	{
		setTimeout(this.start.bind(this), this.time);
		if(this.flag == '+')
		{
			this.next(false);
		}
		else
		{
			this.prev(false);
		}
	}
}


function resizeImage(obj, thumbWidth, thumbHeight)
{
	var Size = GetImageSize(obj);
	var thumbRatio = thumbWidth / thumbHeight;
	var imageWidth = Size.Width;
	var imageHeight = Size.Height;
	var imageRatio = imageWidth / imageHeight;

	if(thumbRatio < imageRatio)
	{
		thumbHeight = parseInt(thumbWidth / imageRatio);
		if(thumbHeight > imageHeight)//원본 이미지가 썸네일 사이즈보다 작을경우 원본 크기를 적용
		{
			thumbWidth = imageWidth;
			thumbHeight = imageHeight;
		}
	}
	else
	{
		thumbWidth = parseInt(thumbHeight * imageRatio);
		if(thumbWidth > imageWidth)//원본 이미지가 썸네일 사이즈보다 작을경우 원본 크기를 적용
		{
			thumbWidth = imageWidth;
			thumbHeight = imageHeight;
		}
	}

	obj.style.width =  (thumbWidth+'px');
	obj.style.height =  (thumbHeight+'px');
}


function GetImageSize(obj)
{
	with(tempImage = document.body.appendChild(document.createElement('img')))
	{
		src = obj.src;
		var Width = offsetWidth;
		var Height = offsetHeight;
	}

	document.body.removeChild(tempImage);

	return { Width : Width, Height : Height };
}