

/* ------------------------------------
*
*Since: 2008-03-28
*Editor: BBmedia Inc. D_sasaki
*
-------------------------------------*/

var slideClass = function(obj){
	
	// parameter
	this.nowIndex = obj.nowIndex || 0;
	this.width = obj.width || 427;
	this.maxPos = obj.maxPos || 4;
	this.easing = obj.easing || "easeOutExpo";
	this.speed = obj.speed || 700;
	
	// add function
	this.naviImgRep = obj.naviImgRep || false;
	this.repImgClass = obj.repImgClass || "set";
	
	// html element
	this.slideStage = obj.slideStage;
	this.box = obj.box;
	this.parentBox = obj.parentBox;
	this.numberNavi = obj.numberNavi;
	this.nextNavi = obj.nextNavi;
	this.prevNavi = obj.prevNavi;
	
	//default action
	this.setHeight();
	
	// set event listener
	this.numberNavi.bind("click",this,this.tabAction);
	this.numberNavi.bind("focus",function(){
		this.blur();
	});
	this.prevNavi.bind("click",this,this.prevAction);
	this.prevNavi.bind("focus",function(){
		this.blur();
	});
	this.nextNavi.bind("click",this,this.nextAction);
	this.nextNavi.bind("focus",function(){
		this.blur();
	});
	
	$(document).bind("keydown",this,this.keyAction);	
	
}

slideClass.prototype = {
	setHeight : function(){
		var height = this.box.height() + 20;
		this.slideStage.css("height",height)
	},
	slide : function(pos){
		if(this.box.filter(":animated").size()){
			this.box.stop();
		};		
		
		var targetPos = -(pos * this.width);
		this.box.animate(
			 {left : targetPos},
			 this.speed,
			 this.easing
		)
		if(this.naviImgRep){
			this.changeNaviImg(this.nowIndex);
		}else{
			this.changeClass(this.numberNavi.eq(this.nowIndex));
		}
	},
	changeClass : function(node){
		node
		.addClass("on");
		
		this.numberNavi
		.not(node)
		.removeClass("on");	
	},
	changeNaviImg : function(index){
		this.parentBox
		.removeClass()
		.addClass(this.repImgClass + (index + 1))
	},
	tabAction : function(e){
		var self = e.data;
		self.nowIndex = $(self.numberNavi).index(this);
		self.slide(self.nowIndex);
		return false;
	},
	prevAction : function(e){
		var self = e.data;
		if(self.nowIndex > 0){
			self.nowIndex--;
			self.slide(self.nowIndex);		
		};
		return false;
	},
	nextAction : function(e){
		var self = e.data;
		if(self.nowIndex < self.maxPos){
			self.nowIndex++;
			self.slide(self.nowIndex);		
		};	
		return false;
	},
	keyAction : function(e){
		var self = e.data
		if(e.keyCode == 37){
			self.prevNavi.click();
		}else if(e.keyCode == 39){
			self.nextNavi.click();
		}else if(e.keyCode >= 97 && e.keyCode <= 104){
			var number = Number(e.keyCode - 97);
			self.numberNavi.eq(number).click();	
		}else{
			return;	
		}
	}
};

(function($){
	$.extend({
		fadeInFunc : function(node){
			node.fadeIn(3500);			
		}	 	 
	})	  
}(jQuery));

function observe(target, type, listener) {
    if (target.addEventListener) target.addEventListener(type, listener, false);
    else target.attachEvent('on' + type, function() { listener.call(target, window.event); });
};


function autoPOP()
{
	var x = document.getElementsByTagName('a');
	for (var i=0;i<x.length;i++)
	{
		if (x[i].getAttribute('className') == 'popup' || x[i].getAttribute('class') == 'popup')
		{
			x[i].onclick = function () {
			return winOpen(this.href)
			}
			x[i].title += '別窓で開きます';
		}
	}
};

function winOpen(url) {
	window.open(
		url,
		'popup',
		'width=800,height=700,scrollbars=1,resizable=1'
	);

	return false;
};

