/* ------------------------------------
*
*	Since : 2008-07-24
*	Editor : D_sasaki
*
-------------------------------------*/
//var uaFirefox = window.navigator.userAgent.indexOf("Firefox") > -1;

var ac_blurAction = function(){
	this.blur();
};

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
}

// Set SlideClass Class
var slideClass = function(obj){
	
	// parameter
	this.nowIndex = obj.nowIndex || 0;
	this.width = obj.width;
	this.maxPos = obj.maxPos;
	this.easing = obj.easing || "easeInOutQuart";
	this.speed = obj.speed || 800;
	this.rightArrow = obj.rightArrow;
	this.numberBigImgFunc = obj.numberBigImgFunc;
	
	// html element
	this.slideStage = obj.slideStage;
	this.box = obj.box;
	this.numberNavi = obj.numberNavi;
	this.numberNaviParent = obj.numberNaviParent;
	this.nextNavi = obj.nextNavi;
	this.prevNavi = obj.prevNavi;
	
	//default action	
	this.setWidth();
	this.setHeight();
	this.defaultArrow();
	
	// set event listener
	this.numberNavi.bind("click",this,this.tabAction);
	this.numberNavi.bind("focus",function(){
		this.blur();
	});
	if(this.prevNavi) {
		this.prevNavi.bind("click",this,this.prevAction);
		this.prevNavi.bind("focus",function(){
			this.blur();
		});
	};
	if(this.nextNavi) {
		this.nextNavi.bind("click",this,this.nextAction);
		this.nextNavi.bind("focus",function(){
			this.blur();
		});
	};
	/*
	if(this.numberBigImgFunc){
		this.mouseOverBigImg();
	};
	*/
	
	jQuery(document).bind("keydown",this,this.keyAction);
	
}

slideClass.prototype = {
	setHeight : function(){
		var height = this.box.height();
		this.slideStage.css("height",height)
	},
	setWidth : function(){
		var width = (this.maxPos + 1) * this.width + 100;
		this.box.css("width",width)
	},
	defaultArrow : function(){
		if(this.prevNavi) {
			this.prevNavi.addClass("on");
		};
		if(this.numberBigImgFunc){
			this.numberNaviParent
			.addClass("bigImg0");
		}else{
			this.numberNavi.eq(0).addClass("on");
		}
		
		if(!this.rightArrow && this.nextNavi) {
			this.nextNavi.addClass("on");
		}
	},
	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.numberBigImgFunc){
			this.changeBigImg(this.nowIndex)
		}else {
			this.changeClass(this.numberNavi.eq(this.nowIndex));
		}

	},
	toggleArrow : function(){
		if((this.nowIndex != this.maxPos) && (this.nowIndex != 0)){
			
			this.nextNavi.removeClass("on");
			this.prevNavi.removeClass("on");
			
		}else if(this.nowIndex == this.maxPos){
			if(this.maxPos != 0) {
				this.nextNavi.addClass("on");
				this.prevNavi.removeClass("on");
			}
			
		}else if(this.nowIndex == 0){
			
			this.prevNavi.addClass("on");
			this.nextNavi.removeClass("on");
			
		};
		
	},
	/*
	mouseOverBigImg : function(){
		
		var self = this;
		var nowClass;
		
		self.numberNavi.each(function(e){
			$(this).mouseover(function(){
				nowClass = self.numberNaviParent.attr("class")				   
				self.numberNaviParent
				.removeClass()
				.addClass(nowClass)	
				.addClass("bigImg" + e)										   
			})
			.mouseout(function(){
				
					$(this)	
					.removeClass()
					.addClass(nowClass)
				
					
			})
		})
		
		
	},*/	
	changeBigImg : function(index){
		this.numberNaviParent
		.removeClass()
		.addClass("bigImg" + index);	
		
	},
	changeClass : function(node){
		node
		.addClass("on");
		
		this.numberNavi
		.not(node)
		.removeClass("on");	
	},
	tabAction : function(e){
		var self = e.data;
		self.nowIndex = jQuery(self.numberNavi).index(this);
		self.slide(self.nowIndex);
		if(self.prevNavi && self.nextNavi) {
			self.toggleArrow();
		}
		
		return false;
	},
	prevAction : function(e){
		var self = e.data;
		if(self.nowIndex > 0){
			self.nowIndex--;
			self.slide(self.nowIndex);
			self.toggleArrow();
		};
		return false;
	},
	nextAction : function(e){
		var self = e.data;
		if(self.nowIndex < self.maxPos){
			self.nowIndex++;
			self.slide(self.nowIndex);	
			self.toggleArrow();
		};	
		return false;
	},
	keyAction : function(e){
		var self = e.data
		if(e.keyCode == 37){
			self.prevAction(e);
		}else if(e.keyCode == 39){
			self.nextAction(e);
		//}else if(e.keyCode >= 97 && e.keyCode <= 104){
			//var number = Number(e.keyCode - 97);
			//self.numberNavi.eq(number).click();	
		}else{
			return;	
		}
	}
};

(function($){
	$.extend({
		slideMenu : function(obj){
			
			// element and setting
			var obj = $.extend({
				trigger : $("#localNavi .toggle"),
				speed : 400,
				easing : "easeOutExpo"					
			}, obj || {});	

			// slide
			function slide(){				
				$(this)
				.toggleClass("on")
				.next("ul")
				.slideToggle(obj.speed,obj.easing);
				return false;
			};			
			
			// set event
			obj.trigger
			.bind("click",slide)
			.bind("focus",ac_blurAction);
			
			// default
			(function(){
				obj.trigger.each(function(){
					if(!$(this).hasClass("open")){
						$(this)
						.next("ul")
						.hide();
					}else{
						$(this)
						.addClass("on");
					}
				})
			})();
		},
		setProSpecIndex : function(item, group, target, width){
			var width = parseInt(width);
			for(var i = 1; i <= item; i += group){
				var val = i + "-" + (i + group - 1);
				var node = $('<li></li>').append('<a href="#">' + val + '</a>').css("width",width);
				target.append(node);
			};		
		},
		toTop : function(){
			$("#pageTop a").click(function(){
				$('html,body').animate({scrollTop: 0}, 350,"easeOutExpo");
				return false;
			});			
		},
		slidePromethod : function(node,onlyOverNode){
			
			if(!onlyOverNode){
				var onlyOverNode = $(".over");
				
				onlyOverNode.hover(function(){
					$(this).addClass("on");
				},
				function(){
					$(this).removeClass("on");
				});
			};
			
			var flag = false;
			node.mouseover(function(e){
				e.stopPropagation();				
				var target = $(this).next();
				
				$(this)
				.addClass("on")
				.next()
				.slideDown(300)
				.end()
				.parent()
				.parent()
				.find("ul")
				.not(target)
				.slideUp(300)
				.prev()
				.removeClass("on");
				
				flag = true;
						
			})
			.click(function(){
				return false;										
			})
			.mouseout(function(){
				flag = false;			
			});	
						
			node.next().mouseover(function(){
				flag = true;				   
			})
			.mouseout(function(){
				flag = false;			
			});	;
			
			window.setInterval(
				function(){
					if(!flag && node.hasClass("on")){
						node.each(function(){
							$(this)
							.removeClass("on")
							.next()
							.slideUp(300);
						})
					}					
				},
				800
			)
			
		},
		tabAction : function(obj){
			obj.target.not(":eq(0)").hide();
			obj.trigger.click(function(){
				var targetId = $(this).attr("href")
				$(targetId)
				.show()
				.siblings()
				.hide();
			
				if(obj.imgChange){
					
					var img = $(this).children("img");
					var imgs = obj.trigger.children("img")
					var orgSrc = img.attr("src");
					var onImgSrc = (orgSrc.indexOf("_on") > -1)? orgSrc : orgSrc.split(".gif")[0] + "_on.gif";
					
					img.attr("src",onImgSrc);
					imgs.not(img).each(function(){
						var src = $(this).attr("src");
						if(src.indexOf("_on") > -1){
							src = src.split("_on")[0] + ".gif";
						}
						$(this).attr("src",src)
					});

				}else{
					$(this)
					.addClass("on");
					
					obj.trigger
					.not(this)
					.removeClass("on");
				}
				return false;
			})
			.focus(ac_blurAction);			
		}
	})
})(jQuery);

jQuery(function($){
	$.toTop();
	
	$(".opCartBtn")
	.hover(
	function(){
		$(this).attr("src","/rental/images/ren_btn_004_on.gif");
	},
	function(){
		$(this).attr("src","/rental/images/ren_btn_004.gif");
	});
});





