$(function(){
// google map
	if(jQuery.fn.googlemap){
	  $('#gmap').googlemap({
		latitude: 35.753752,
		longitude: 139.361653,
		labels: true,
		controls: true,
		zoom: 16,
		markerpoints: ['35.753752,139.361653']
	  });
	}
//tipsy
    if(jQuery.fn.tipsy){
	  $('.minkara ul li a').tipsy({gravity: 's'});
	}
// cycle
	if(jQuery.fn.cycle){
		$('.recent-works .pic').cycle({
			fx: 'fade',
			timeout: 6000,
			speed: 800
		});
	}
// breadcrumb
	if(jQuery.fn.jBreadCrumb){
    	$(".breadcrumb").children().wrap('<li></li>').end().wrapInner('<ul></ul>')
		.jBreadCrumb({
			easing:'swing',
			minElementsToCollapse: 6
		});
	}
// search
	$ss = $('#searchsubmit').val() + ' ...';
	$('#search').css('background-position', '0 -164px');		  
    $('#s').val($ss).css('color', '#808080')
	  .focus(function() {  
		$('#search').css('background-position', '0 -197px')	
		if($(this).css('color', '#dddddd').val() == $ss)
		  $(this).val('');
	  })  
      .blur(function() {  
		$('#search').css('background-position', '0 -164px')		  
		if($(this).css('color', '#808080').val() == '')
		  $(this).val($ss);
	  });
// tab
    var $tab_id = 0;
	function createTab($content_target, $tab_target){
	  $content = $($content_target);	
	  if($content.size() > 0){
		$tab_container = $content
		    .wrap('<div class="tab-content"></div>')
			.parent().each(function(index){ $(this).attr('id', 'tab'+($tab_id+index)); })
			.wrapAll('<div class="tab-container clearfix"></div>')
			.parent();
		$tabs = $tab_container
		    .before('<ul class="tabs clearfix"></ul>')
			.prev();
		$tab = $($tab_target, $content);
		$tab.each(function(index){
			if(index == $tab.size() -1)				
				$tabs.append('<li class="last"><a href="#tab'+($tab_id+index)+'">'+$(this).html()+'</a></li>');
			else
				$tabs.append('<li><a href="#tab'+($tab_id+index)+'">'+$(this).html()+'</a></li>');
		});
		$tab_id += $content.size();
		$tab.remove();
		$('div.hr', $content).remove();
		$('.tab-content', $tab_container).hide();
		$('li:first', $tabs).addClass('active').show(); 
		$('.tab-content:first', $tab_container).show();
		$('li', $tabs).click(function() {
		  $this = $(this);
		  $this.siblings('li').removeClass("active"); 
		  $this.addClass("active");
		  $this.parent().next().find('.tab-content').hide();
		  var activeTab = $this.find('a').attr('href');
		  $activeTab = $(activeTab.slice(activeTab.indexOf('#')));
		  $activeTab.fadeIn();
		  return false;
		});
	  }
	}
	createTab('.hentry .tab', 'h2');
// colorbox
	if(jQuery.fn.colorbox){
		$('a[href$=.jpg], a[href$=.png]', '.contents').attr('rel', 'colorbox');
		$('a[rel=colorbox]').colorbox({previous:'前の画像', next:'次の画像', close:'閉じる'});
	}
// smooth scroll
	$('a[href*=#]').each(function(){
	    if($(this).parents('.tabs').size() == 0 && $(this).attr('href').indexOf('#comment-') == -1){
		  $(this).click(function() {
			if(location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
			&& location.hostname == this.hostname) {
				var $target = $(this.hash);  
				$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
				if ($target.length) {  
					var targetOffset = $target.offset().top - 20;
					$('html,body').animate({scrollTop: targetOffset}, 'fast');
					return false;  
				}
			}
			return false;
		  })
		}
	});
//  form
	if(jQuery.fn.validationEngine){
	  $('#contact-form').validationEngine({
		  success :  function(){
			var dataString 
				= 'company=' + $('#your-company').val()  
				+ '&name=' + $('#your-name').val()  
				+ '&email=' + $('#your-email').val()
				+ '&tel=' + $('#your-tel').val()  
				+ '&msg=' + $('#your-message').val();  

			$.ajax({
			  type: "POST",
  　　　　　　url: "http://www.artfactory-inc.com/cms/wp-content/themes/artfactory-inc.com/mail.php",
			  data: dataString,
			  success: function(reply){
				$.fn.colorbox({html:reply, open:true});
				return false;
			  },
			  error: function(XMLHttpRequest, textStatus, errorThrown){
				$.fn.colorbox({html:'<p>送信に失敗しました。お手数ですが、お電話（042）520-2408 にてお問い合わせください。</p>', open:true});
				return false;
			  }
			});
			return false;
		  },
		  promptPosition:'centerRight'
	  });
	}
});