$(function(){
/*
		$('a._hover').hover(
			function(){
				$(this).fadeTo(100, 0.7);
			},
			function(){
				$(this).fadeTo(500, 1.0);
			}
		);
		
		$('a._hover2').hover(
			function(){
				$(this).children("img").fadeTo(100, 0.7);
			},
			function(){
				$(this).children("img").fadeTo(500, 1.0);
			}
			);
		$('ul.item_list li').hover(
			function(){
				$(this).addClass("hover");
				var cs_thumbs = $(this).children("div.cs_thumbs");
				var cs_thumbs_height = $(this).height();

				$(this).children("div.cs_thumbs").show();
				$(this).children("div.cs_thumbs").height(cs_thumbs_height + 6);
				$(this).css("z-index","2");
				$(this).next().css("z-index","1");
			},
			function(){
				$(this).removeClass("hover");
					$(this).children("div.cs_thumbs").hide();
			}
		);
		
		var mainSrc =	$('#mainPhoto').attr("src");
		$('div.photo_thumbs_block a').hover(
			function(){
				var thisSrc =	$(this).attr("name");
				$('#mainPhoto').attr("src",thisSrc);
			},
			function(){
				var thisSrc =	$(this).attr("name");
				$('#mainPhoto').attr("src",mainSrc);
			}
		);
		
		$('div.item_color_variation_block div a').hover(
			function(){
				var thisSrc =	$(this).attr("name");
				$('#mainPhoto').attr("src",thisSrc);
			},
			function(){
				var thisSrc =	$(this).attr("name");
				$('#mainPhoto').attr("src",mainSrc);
			}
		);
		
		// $('a._zoom1').lightBox();
		// $('a._zoom2').lightBox();
	*/
		
	$('ul.categoryListNavi li.categoryListNaviPrev a').hover(
		function () {
			$(this).attr('title', $(this).find('img').attr('src') );
			$(this).find('img').attr('src', $(this).attr('name'));
		},
		function () {
			$(this).find('img').attr('src', $(this).attr('title'));
		}
	);
	$('ul.categoryListNavi li.categoryListNaviNext a').hover(
		function () {
			$(this).attr('title', $(this).find('img').attr('src') );
			$(this).find('img').attr('src', $(this).attr('name'));
		},
		function () {
			$(this).find('img').attr('src', $(this).attr('title'));
		}
	);
	
	var cib_max_height = 0;
	$('.collectionIndexMajorityRow div.collectionIndexBlock').each(
		function () {
			if ( cib_max_height == 0 || cib_max_height < $(this).height() ) {
				cib_max_height = $(this).height();
			}
		}
	);
	$('.collectionIndexMajorityRow div.collectionIndexBlock').each(
		function () {
			if ( $(this).height() < cib_max_height ) {
				//var diff = cib_max_height - $(this).height();
				$(this).height(cib_max_height);
				$(this).find('.collectionIndexBlockMore').css('position', 'absolute').css('bottom', '8px').css('right', '15px');
			}
		}
	);
	$('.collectionIndexMajorityRow div.collectionIndexBlock a.collectionIndexBlockAnchor').each(
		function () {
			$(this).height(cib_max_height + 20);
		}
	);
	
	var cib_min_max_height = 0;
	$('.collectionIndexMinorityRow div.collectionIndexBlock').each(
		function () {
			if ( cib_min_max_height == 0 || cib_min_max_height < $(this).height() ) {
				cib_min_max_height = $(this).height();
			}
		}
	);
	$('.collectionIndexMinorityRow div.collectionIndexBlock a.collectionIndexBlockAnchor').each(
		function () {
			$(this).height(cib_min_max_height + 20);
		}
	);
});

$(function() {
  $('.tabs').tabs();
});



$(document).ready(function() {
	zoom();
	modal();
});

$(function() {
	flatHeight();
	valignCenter();
	hover();
	preview();
	itemListMore();
});

function flatHeight() {
	$('._flatHeight').find('._flatItem').each(function() {
		$(this).css('display', 'block');
	});
    $('._flatHeight').each(function() {
    	$(this).find('._flatItem').flatHeights();
    });
}

function valignCenter() {
	$('._valignCenter').center({
		horizontal: false
	});
}

function zoom() {
	$('a._zoom').fancybox({
		'titleShow': false
	});
	$('a._zoom1').fancybox({
		'titleShow': false
	});
	$('a._zoom2').fancybox({
		'titleShow': false
	});
	$('a._iframe').fancybox({
		'titleShow': false,
		'type': 'iframe'
	});
}

function hover() {
	$('a._hover').hover(
		function(){
			$(this).children("img").fadeTo(100, 0.7);
		},
		function(){
			$(this).children("img").fadeTo(500, 1.0);
		}
	);
	$('a._hover2').hover(
		function(){
			$(this).children("img").fadeTo(100, 0.7);
		},
		function(){
			$(this).children("img").fadeTo(500, 1.0);
		}
	);
}

function preview() {
	var mainSrc = $('#mainPhoto').attr('src');
	$('a._preview').hover(
		function() {
			var thisSrc = $(this).attr('name');
			if ( !thisSrc ) {
				var img = $(this).children('img:first');
				if ( img ) {
					thisSrc = $(img).attr('src');
				}
			}
			$('#mainPhoto').attr('src', thisSrc);
		},
		function() {
			$('#mainPhoto').attr('src', mainSrc);
		}
	);
}


function itemListMore() {
	$('._listItem').each(function() {
		$(this).hover(
		function(){
			$(this).addClass("hover");
			$(this).children(".cs_thumbs").show();
			$(this).css("z-index","2");
			$(this).next().css("z-index","1");
		},
		function(){
			$(this).removeClass("hover");
			$(this).children(".cs_thumbs").hide();
		});
	});
}

function modal() {
	$('._inlinePopup').each(function() {
		var params = { 'modal': true, 'titleShow': false };
		$(this).fancybox(params);
	});
	$('._inlinePopupClose').click(function(){
		$.fancybox.close();
	});
}

function change_limit(obj, path){
//  var curr_url = location.href;
  var protocol = location.protocol;
  var host = location.host;
  var index = obj.selectedIndex;
  var value = obj.options[index].value;
//  if (curr_url.match(/\/limit\/[0-9]+/)) {
//    var url = curr_url.replace(/\/limit\/[0-9]+/, '/limit/'+value);
//  } else {
//    var url = curr_url+'/limit/'+value;
//  }
  location.href = protocol+"//"+host+path+'/limit/'+value;
}





function change_sort(obj, path){
  var protocol = location.protocol;
  var host = location.host;
  var index = obj.selectedIndex;
  var value = obj.options[index].value;
  location.href = protocol+"//"+host+path+'/sort/'+value;
}


function change_stock_available(obj, path){
  var protocol = location.protocol;
  var host = location.host;
  var index = obj.selectedIndex;
  var value = obj.options[index].value;
  if(value == 0){
    location.href = protocol+"//"+host+path;
  }else{
    location.href = protocol+"//"+host+path+'/stock_available/'+value;
  }
  
}





