/*
 * jQuery Atarimarket Customize Series vol.1
 * 
 *
 * Copyright (c) 2009 Atarimarket
 *
 * Date: 2009-08-08
 * 
 */

jQuery.fn.extend({
	//テキストボックス初期値設定
	//TextBox Initialize Setting
	iniValues: function(){
		var obj=$(this);
		obj.focus(function() {
			if($(this).val() == $(this).attr('defaultValue')){
				$(this).addClass('focus');
				$(this).attr('value','');
			}
		}).blur(function() {
			if($.trim($(this).val()) == '') {
				$(this).removeClass('focus');
				$(this).attr('value',$(this).attr('defaultValue'));
			}
		});
	},
	//サブカテゴリーアコーディオン
	subCategories: function(){
		var obj=$(this);
		$('li.menu',obj).each(function(){
			if($(this).is(':has(ul)')){
				var tar=$(this)
				tar.css({'background':'url(/common/images/subcategory_arrow.gif) no-repeat 0 0'});
				if($('ul',this)){
					var target=$('ul',this);
					target.slideUp();
					if(target.html()!=null){
						$('span',this).toggle(
							function(){
								tar.css({'background':'url(/common/images/subcategory_arrow_on.gif) no-repeat 0 0'});
								target.slideDown();
							},
							function(){
								tar.css({'background':'url(/common/images/subcategory_arrow.gif) no-repeat 0 0'});
								target.slideUp();
							}
						);
					}
				}
			}
		});
	},
	accordionOpen: function(target,status){
		var obj=$(this);
		$(target,obj).each(function(){
			
			$('.title',obj).css({cursor:'pointer'});
			$('.title',obj).hover(
				function(){
					$(this).addClass('hover');
				},
				function(){
					$(this).removeClass('hover');
				}
			);
			
			if(status=='hide'){
				$('.title',obj).addClass('active');
				$(target).hide();
			}
			
			if($(target).html()!=null){
				$('.title',obj).click(function(){
					$(this).toggleClass('active');
					$(target).slideToggle();
				});
			}
		});
	},
	//総合案内アコーディオン設定
	//PullDown Setting
	pullSets: function(){
		var obj=$(this);
		obj.hover(
			function(){
				$.data(obj,'break',true);
				$('a.parent',obj).addClass('hover');
				setTimeout(function() {
					if ($.data(obj,'break')){
						$('ul',obj).animate({height:'show'},1000, 'easeOutExpo');
					}
				}, 400);

			},
			function() {
				$.data(obj,'break',false);
				setTimeout(function() {			
					if (!$.data(obj,'break')){
						$('a.parent',obj).removeClass('hover');
						$('ul',obj).animate({height:'hide'},500, 'easeOutExpo');
					}
				}, 750);
			}
		);
	},
	//ピックアップ表示モジュール設定
	//PickUp Module Setting
	pickUp: function(){
		var obj=$(this);
		$('.contents div',obj).hide();
		$('.contents div:first',obj).show();
		$('.title li:first a',obj).addClass('active');
		$('.title li a',obj).click(function(){
			$('.title li a',obj).removeClass('active');
			$(this).addClass('active');
			var currentTab = $(this).attr('href');
			$('.contents div',obj).hide();
			$('.contents div'+currentTab,obj).show();
			return false;
		});
	},
	//PickUp Select Setting
	pickSelected: function(){
		var obj=$(this);
		$('li',obj).css({cursor:'pointer'});
		$('li',obj).click(function(){
			$(this).toggleClass('on');
			//return false;
			var url=$(this).attr('title');
			location.href = url;
		});
		$('li',obj).hover(
			function(){
				$(this).addClass('active');
			},
			function(){
				$(this).removeClass('active');
			}
		);
	},
	//PickUp Select Setting
	selectTab: function(){
		var obj=$(this);
		$('.contents div',obj).hide();
		$('.contents div:first',obj).show();
		$('.title li:first a',obj).addClass('active');
		$('.title li a',obj).click(function(){
			$('.title li a',obj).removeClass('active');
			$(this).addClass('active');
			var currentTab = $(this).attr('href');

			$('.contents div',obj).each(function(){
					$(this).stop();
					$(this).hide();
			});
			$(currentTab,obj).slideDown();
			return false;
		});
	},	
	//Item Hover Effect Setting
	itemHover: function(){
		var obj=$(this);
		obj.hover(
			function(){
				$('.item_obj',this).addClass('hover');
				$('.item_dtl a',this).addClass('hover');
			},
			function(){
				$('.item_obj',this).removeClass('hover');
				$('.item_dtl a',this).removeClass('hover');
			}
		);
	},
	//Image Change
	imageChange: function(){
		var obj=$(this);
		var img=$('li a img',obj);
		img.css({cursor:'pointer'});
		img.click(function(){
			var thumb=$(this).attr('src');
			var larger=$(this).parent().attr('href');
			var largest=$(this).parent().attr('rel');
			var image = new Image();
			image.larger;
			$('#thum_pic').load(function (){
					$('#thum_pic').fadeIn(500);
			});
			$('#zoom_pic').attr("href", largest);
			$('#thum_pic').fadeOut(500,function(){
				$('#thum_pic').attr('src', larger);
			});
			return false;
		});
	},
	
	//アントラーズ対応
	antlersYaesu: function(){
		$(this).click(function() {
			$("#antlers_overlay").setYaesu();
		});
	},
	
	setYaesu:function(){
		var arrPageSizes = getPageSize();
		$('#antlers_overlay').css({display: 'block'});
		$('#antlers_overlay').css({
				backgroundColor:	'#000',
				opacity:			0.7,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]
		}).show();
		
		var arrPageScroll = getPageScroll();
			// Calculate top and left offset for the jquery-lightbox div object and show it
		$('#antlers_inner').css({
			top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
			left:	arrPageScroll[0]
		}).fadeIn();
		
		$('#antlers_overlay').click(function() {
			closeLanding();									
		});
		$('#antlers_inner').click(function() {
			closeLanding();									
		});
		$('#yaesu_close').click(function() {
			closeLanding();									
		});
		
	
		$(window).resize(function() {
			// Get page sizes
			var arrPageSizes = getPageSize();
			// Style overlay and show it
			$('#antlers_overlay').css({
				width:	arrPageSizes[0],
				height:	arrPageSizes[1]
			});
			// Get page scroll
			var arrPageScroll = getPageScroll();
			// Calculate top and left offset for the jquery-lightbox div object and show it
			$('#antlers_inner').css({
				top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
				left:	arrPageScroll[0]
			});
		});
		
		function getPageSize(){
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		}
		function getPageScroll(){
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		}
		function closeLanding() {
			$('#antlers_overlay').hide();
			$('#antlers_inner').hide();
			// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
			$('embed, object, select').css({ 'visibility' : 'visible' });
		}
	},
	
	//オープニング
	clickMovie: function(){
		$(this).css({cursor: 'pointer'});
		$(this).click(function() {
			$("#overlay").setOpening();
		});
	},
	setOpening: function(){	
		var arrPageSizes = getPageSize();
		$('#overlay').css({display: 'block'});
		$('#overlay').css({
				backgroundColor:	'#fff',
				opacity:			0.9,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]
		}).show();
		var arrPageScroll = getPageScroll();
			// Calculate top and left offset for the jquery-lightbox div object and show it
		$('#landing_inner').css({
			top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
			left:	arrPageScroll[0]
		}).show();
		
		swfobject.embedSWF(landingfile, "landing_src", "820", "440", "8.0.0", expfile, l_flashvars, l_params);
		
		$('#overlay').click(function() {
			closeLanding();									
		});
	
		$(window).resize(function() {
			// Get page sizes
			var arrPageSizes = getPageSize();
			// Style overlay and show it
			$('#overlay').css({
				width:	arrPageSizes[0],
				height:	arrPageSizes[1]
			});
			// Get page scroll
			var arrPageScroll = getPageScroll();
			// Calculate top and left offset for the jquery-lightbox div object and show it
			$('#landing_inner').css({
				top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
				left:	arrPageScroll[0]
			});
		});
		
		function getPageSize(){
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		}
		function getPageScroll(){
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		}
		function closeLanding() {
			$('#overlay').hide();
			// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
			$('embed, object, select').css({ 'visibility' : 'visible' });
		}		
	},

	popupHelp: function(target){
		//初期設定
		var overlay="#popupHelp_OL";
		var inner  =target;
		
		if($(overlay).html()==null){
			$("body").prepend('<div id="popupHelp_OL"></div>');
		}
		
		$(overlay).css({
			position: 'absolute',
			top: 0,
			left: 0,
			zIndex : 20000,
			width: '100%'
		});
		$(inner).css({
			position: 'absolute',
			top: 0,
			left: 0,
			zIndex: 20001
		});
		$(overlay).hide();
		$(inner).hide();
		
		//クリッカブル設定
		$(this).css({cursor:"pointer"});
		$(this).hover(function(){
			$(this).addClass("hover");
		},
		function(){
			$(this).removeClass("hover");
		});
		
		$(this).click(function() {
			$(overlay).popupSets(inner);
		});
	},
	popupSets:function(inner){
		
		var ovl=$(this);
		var inn=$(inner);
		
		var arrPageSizes = getPageSize();
		ovl.css({display: 'block'});
		ovl.css({
				backgroundColor:	'#000',
				opacity:			0.5,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]
		}).show();
		
		var arrPageScroll = getPageScroll();
			// Calculate top and left offset for the jquery-lightbox div object and show it
		
		var inn_h=inn.height()/2;
		var inn_w=inn.width()/2;
		
		inn.css({
			top:	arrPageScroll[1] + (arrPageSizes[3] / 2)-inn_h,
			left:	arrPageScroll[0] + (arrPageSizes[2] / 2)-inn_w
		}).fadeIn();
			
		
		ovl.click(function() {
			//閉じる
			closeWindow();									
		});
		
		//閉じるボタンの設定
		$(".close",inn).css({cursor:"pointer"});
		$(".close",inn).click(function() {
			closeWindow();									
		});
		
		
		$(window).resize(function() {
			// Get page sizes
			var arrPageSizes = getPageSize();
			// Style overlay and show it
			ovl.css({
				width:	arrPageSizes[0],
				height:	arrPageSizes[1]
			});
			// Get page scroll
			var arrPageScroll = getPageScroll();
			// Calculate top and left offset for the jquery-lightbox div object and show it
			inn.css({
				top:	arrPageScroll[1] + (arrPageSizes[3] / 2)-inn_h,
				left:	arrPageScroll[0] + (arrPageSizes[2] / 2)-inn_w
			});
		});
		
		function getPageSize(){
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		}
		
		function getPageScroll(){
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		}
		
		function closeWindow() {
			ovl.hide();
			inn.hide();
			// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
			$('embed, object, select').css({ 'visibility' : 'visible' });
		}
		
	},

	popupReserve: function(target){
		//初期設定
		var overlay="#popupHelp_OL";
		var inner  =target;
		
		if($(overlay).html()==null){
			$("body").prepend('<div id="popupHelp_OL"></div>');
		}
		
		$(overlay).css({
			position: 'absolute',
			top: 0,
			left: 0,
			zIndex : 20000,
			width: '100%'
		});
		$(inner).css({
			position: 'absolute',
			top: 0,
			left: 0,
			zIndex: 20001
		});
		$(overlay).hide();
		$(inner).hide();
		
		$(overlay).popupSets(inner);
		
	},
	popupSets:function(inner){
		
		var ovl=$(this);
		var inn=$(inner);
		
		var arrPageSizes = getPageSize();
		ovl.css({display: 'block'});
		ovl.css({
				backgroundColor:	'#000',
				opacity:			0.5,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]
		}).show();
		
		var arrPageScroll = getPageScroll();
			// Calculate top and left offset for the jquery-lightbox div object and show it
		
		var inn_h=inn.height()/2;
		var inn_w=inn.width()/2;
		
		inn.css({
			top:	arrPageScroll[1] + (arrPageSizes[3] / 2)-inn_h,
			left:	arrPageScroll[0] + (arrPageSizes[2] / 2)-inn_w
		}).fadeIn();
			
		
		ovl.click(function() {
			//閉じる
			closeWindow();									
		});
		
		//閉じるボタンの設定
		$(".close",inn).css({cursor:"pointer"});
		$(".close",inn).click(function() {
			closeWindow();									
		});
		
		
		$(window).resize(function() {
			// Get page sizes
			var arrPageSizes = getPageSize();
			// Style overlay and show it
			ovl.css({
				width:	arrPageSizes[0],
				height:	arrPageSizes[1]
			});
			// Get page scroll
			var arrPageScroll = getPageScroll();
			// Calculate top and left offset for the jquery-lightbox div object and show it
			inn.css({
				top:	arrPageScroll[1] + (arrPageSizes[3] / 2)-inn_h,
				left:	arrPageScroll[0] + (arrPageSizes[2] / 2)-inn_w
			});
		});
		
		function getPageSize(){
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		}
		
		function getPageScroll(){
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		}
		
		function closeWindow() {
			ovl.hide();
			inn.hide();
			// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
			$('embed, object, select').css({ 'visibility' : 'visible' });
		}
		
	}



});
