$(document).ready(function(){
	$('head').append('<link href="css/js.css" media="all" rel="stylesheet" type="text/css" />');
	function CLASSSWITCH(_classthis, _classremove, _classadd) { _classthis.removeClass(_classremove).addClass(_classadd); }				   
//step opacity
	$("ul.step a.step").css({opacity: 0.5});
	$("ul.step a#step").css({opacity: 1.0});
//grid click
	$("div.grid div.item").click(function(){ window.location=$(this).find("a").attr("href"); return false; });
	$("div.grid div.item").css({'cursor': 'pointer'});
	$("div.grid div.item img").css({'height': 55});
	$("div.grid div.item p").css({'display': 'block', 'height': 0, 'overflow': 'hidden'});
//grid hover
	$('div.grid div.item').hover(function() { 
		_gridimg = $(this).children('img');
		_gridp = $(this).children('p');
		_gridimg.stop(true, true).animate({'height': 100}, 'fast');
		_gridp.stop(true, true).animate({height: 42}, 'fast'); }, 
		function() { 
			_gridimg.animate({'height': 55}, 'fast');
			_gridp.animate({height: 0}, 'fast'); } )
//gallery
	$('div.gallery').wrap('<div class="gallery-wrap"></div>');
	$('div.gallery div.mid div').css({display: 'none', opacity: 'hide'});
	$('div.gallery li:first').addClass('show');
	_galleryfirst = $('div.gallery div.mid div:first');
	_galleryfirst
		.css({display: 'block', opacity: 'show', 'margin-top': (280 - _galleryfirst.height()) / 2})
		.addClass('show');
	$('div.gallery li img').each(function(index) { 
		_gallerymin = $(this);
		if (_gallerymin.height() > _gallerymin.width()) { 
			_gallerymin.css({'height': 41});
			_gallerymin.css({'margin-top': (41 - _gallerymin.width()) /2});}
		else { 
			_gallerymin.css({'width': 41});
			_gallerymin.css({'margin-top': (41 - _gallerymin.height()) /2}); } })
//gallery click
	$('div.gallery li').bind('click', function() {
		_gallerythis = $(this);
		_galleryindex = $('div.gallery li').index(this);
		_gallerynext = $('div.gallery div.mid div').eq(_galleryindex);
		_galleryprev = $('div.gallery div.mid div.show');
		if (_gallerynext.attr('class') != 'show') {
			_gallerynext
				.css({'margin-top': (280 - _gallerynext.height()) / 2})
				.addClass('show')
				.animate({opacity: 'show'}, 'slow');
			_galleryprev
				.animate({opacity: 'hide'}, 'slow')
				.removeClass('show');
			$('div.gallery li').removeClass('show');
			_gallerythis.addClass('show'); } })
//detail hover
	$("dl.detail dt span").css({cursor: 'pointer'});
//detail
	$('dl.detail dt').addClass('hide');
	$('dl.detail dd').addClass('hide');
//detail click
	$('dl.detail dt span').bind('click', function() {
		_detailspan = $(this);
		_detaildt = $(this).parent('dt');
		_detaildd = _detaildt.next('dd');
			
		if (_detaildd.attr('class') == 'hide') {
			_detaildd.css({'height': 'auto', 'display': 'block'});
			_detailheight = _detaildd.height();
			_detaildd.css({'height': '0'});
			CLASSSWITCH(_detailspan, 'hide', 'show');
			CLASSSWITCH(_detaildt, 'hide', 'show');
			_detaildd.animate({height: _detailheight}, 'fast');
			CLASSSWITCH(_detaildd, 'hide', 'show'); }
				
		else { _detaildd.animate({height: 0}, 'fast', function() { 
			CLASSSWITCH(_detailspan, 'show', 'hide');
			CLASSSWITCH(_detaildt, 'show', 'hide');	
			CLASSSWITCH(_detaildd, 'show', 'hide');
			_detaildd.css({'display': 'none'}); }) }})
//detail check
	$('dl.detail dd input.button-mid').bind('click', function() {
		_detaildt = $(this).parent('fieldset').parent('dd').prev('dt');
		_detaildd = $(this).parent('fieldset').parent('dd');
		_detailspan = $(this).parent('fieldset').parent('dd').prev('dt').children('span');
		$('fieldset input', _detaildt).attr('checked', 'checked');
		_detaildd.animate({height: 0}, 'fast', function() { 
			CLASSSWITCH(_detailspan, 'show', 'hide');
			CLASSSWITCH(_detaildt, 'show', 'hide');	
			CLASSSWITCH(_detaildd, 'show', 'hide');
			_detaildd.css({'display': 'none'}); }) })
//address init
	_addressdiv = $('div#address-div');
	_addressheight = _addressdiv.height();
	_addressdiv.css({'display': 'none', 'height': 0});
//address action
	$('input#address-check').bind('click', function() {
		if (_addressdiv.css('display') == 'block') { 
			$(this).attr('checked', false);
			_addressdiv.animate({'height': 0}, 'fast', function() { _addressdiv.css({'display': 'none'}) } ); }
		else { 
			$(this).attr('checked', true);
			_addressdiv.css({'display': 'block'}) .animate({'height': _addressheight}, 'fast'); } })
})
