var Dom_NN4		= false;
var Dom_NN6		= false;

//Mac or Win判定
var Dom_mac = false;
var Dom_win = false;

Dom_mac=navigator.userAgent.indexOf('Mac')!=-1;
if(!Dom_mac)
{
	Dom_win = true;
}

//NN or IE判定
var Dom_IE = false;
var Dom_NN = false;

Dom_IE= navigator.userAgent.indexOf('MSIE') != -1;
if(!Dom_IE)
{
	Dom_NN= navigator.userAgent.indexOf('Mozilla') != -1;
}

if(Dom_NN)
{
	//NN Version判定
	Dom_NN4= navigator.userAgent.indexOf('Mozilla/4') != -1;
	//Netscape6.2以上の場合Dom_NN6はtrue
	Dom_NN6= navigator.userAgent.indexOf('Netscape6') != -1;
	//NN4.x,6.x以外のNNはNN6として処理
	if(Dom_NN4 != true && Dom_NN6 != true)
	{
		Dom_NN6=true;
	}
}

function openWin(url) {
     window.open(url,"_blank","width=420,height=420,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,favorites=no,resizable=yes");
}

//2007/08/22 ykubota カード決済ヘルプページ
function WinOpen() { window.open("../../NewWin.htm","NewWindow","toolbar=no,location=no,directories=no,status=no,width=640,height=650")}

//2010/05/18 ykubota セキュリティコードとは
function WinOpen2() { window.open("../../card/card.html","NewWindow2","toolbar=no,location=no,directories=no,status=no,scrollbars=yes,width=730,height=650")}

//2011/10/04 ykubota 以下追加
function init() {
	setImageToggle();
	globalMenuDropdown();
	categoryMenuSlide();
	setRollover();
	imageReel();
	
	$('div#section_carousel ul').jcarousel({
		scroll: 1,
		auto: 6,
		vertical: true,
		animation: 800,
		wrap: 'circular'
	});
	
	$('select#select_price').change(function() {
		setSearchPrice('select_price', 'hdn_min_price', 'hdn_max_price');
	});
	
	$('select#select_price_main').change(function() {
		setSearchPrice('select_price_main', 'hdn_min_price_main', 'hdn_max_price_main');
	});

	$('ul#pickup_list li').hover(
		function() {
			$(this).addClass('selected');
			$('p.info', this).show();
		},
		function() {
			$(this).removeClass('selected');
			$('p.info', this).hide();
		}
	);
}

function setSearchPrice(select_name, min_name, max_name) {
	var price = [ { min: '', max: 30000 },
				  { min: '', max: 50000 },
				  { min: 50000, max: 100000 },
				  { min: 100000, max: 150000 },
				  { min: 150000, max: 200000 },
				  { min: 200000, max: 300000 },
				  { min: 300000, max: 500000 },
				  { min: 500000, max: ''} ];
	var index = $('select#' + select_name + ' option:selected').val() - 1;
	
	$('input#' + min_name).val(price[index].min);
	$('input#' + max_name).val(price[index].max);
}

function categoryMenuSlide() {

	var first_li = $('ul#smenu_list > li');
	
	first_li.hover(
		function () {
			$('ul', this).toggle('fast');
		 	if($(this).children('ul').length > 0) {
		 		$(this).children('a').addClass('open');
		 	}
		 	$(this).css('z-index', '9999');
		},
		function () {
			$('ul', this).toggle('fast');
			$(this).css('z-index', '1');
		 	if($(this).children('ul').length > 0) {
		 		$(this).children('a').removeClass('open');
		 	}
		}
	);

}

function setGlobalMenu() {

	var menu_imgs = $('div#gmenu ul li a img');
	
	var ii = 0;
	var menu_id = '';

	for(ii=0; ii<menu_imgs.length; ii++) {

		menu_id = $(menu_imgs[ii]).parent().parent().attr('id');
		
		if($('body.' + menu_id.replace('gmenu_', '')).length == 1) {
			imgOv($(menu_imgs[ii]));

		}else {

			$(menu_imgs[ii]).hover(
				function () {
				 	imgOv($(this));
				},
				function () {
					imgOut($(this));
				}
			);
		}
	}
}

/* gmenuのプルダウン */

function globalMenuDropdown(){
	$('div#gmenu > ul > li').hover(function(){
		if($.browser.msie && $.browser.version < 7) {
			$('form#frm_product_search select').css('visibility', 'hidden');
		}
		$('>ul:first:not(:animated)',this).slideDown();
	},
	function(){
		$('>ul:first',this).slideUp();
		if($.browser.msie && $.browser.version < 7) {
			$('form#frm_product_search select').css('visibility', 'visible');
		}
	})
}


function setSideMenu() {

	var menu_imgs = $('div#smenu ul li a img');
	
	var ii = 0;
	var menu_id = '';

	for(ii=0; ii<menu_imgs.length; ii++) {

		menu_id = $(menu_imgs[ii]).parent().parent().attr('id');
		
		if($('body.' + menu_id.replace('smenu_', '')).length == 1) {
			imgOv($(menu_imgs[ii]));

		}else {

			$(menu_imgs[ii]).hover(
				function () {
				 	imgOv($(this));
				},
				function () {
					imgOut($(this));
				}
			);
		}
	}
}


function setImageToggle() {
	$('img.' + 'ov').hover(
		function () {
		 	imgOv($(this));
		},
		function () {
			imgOut($(this));
		}
	);
}

function imgOv(img) {
	var src = img.attr('src');
	var file_type = src.substring(src.lastIndexOf('.'), src.length);
	var src_ov = src.replace(file_type, '_ov' + file_type);
	img.attr('src', src_ov);
}

function imgOut(img) {
	var src = img.attr('src');
	var file_type = src.substring(src.lastIndexOf('.'), src.length);
	var src_out = src.replace('_ov' + file_type, file_type);
	img.attr('src', src_out);
}


/* ov画像無しのロールオーバー */

function setRollover() {
	($('#container a img, #container input[type="image"]').not('.ov')).opOver(1.0,0.6,100,100);
}


function imageReel() {

	var fadeTime = 1000;
	var rotateTime = 9000;

	var images = $('div#panel p');
	var imageSum = images.length;

	if(imageSum < 1) {
		return;
	}

	$(images[0]).fadeIn(fadeTime);
	$('ul#panel_paging').show();
	$('ul#panel_paging li:first').addClass('active');

	rotate = function() {

		var previousTriggerID = $previous.attr('rel') - 1;
		var activeTriggerID = $active.attr('rel') - 1;
 
		$('ul#panel_paging li').removeClass('active');
		$active.addClass('active');
		
		$(images[previousTriggerID]).fadeOut(fadeTime);
		$(images[activeTriggerID]).fadeIn(fadeTime);
	}; 

	rotateSwitch = function(){
		
		play = setInterval(function(){
			$previous = $('ul#panel_paging li.active');
			$active = $previous.next();
			if ( $active.length === 0) {
				$active = $('ul#panel_paging li:first');
			}
			rotate();
		}, rotateTime);
	};

	rotateSwitch();

	$('div#panel a').hover(function() {
		clearInterval(play);
		}, function() { rotateSwitch(); }
	);

	$('ul#panel_paging li').click(function() {
		$previous = $('ul#panel_paging li.active');
		$active = $(this);
		clearInterval(play);
		rotate();
		rotateSwitch();
		return false;
	});
}

