/**
 * tooltip
 */
(function($){  
	$.fn.tinyTips = function (supCont) {
		var tipName = 'lightTip';
		var tipFrame = '<div class="' + tipName + '"><div class="bottom">&nbsp;</div><div class="content"></div></div>';
		var animSpeed = 300;
		var tinyTip;
		var tText;
		$(this).hover(function() {
			$(this).append(tipFrame);
			var divTip = 'div.'+tipName;
			tinyTip = $(divTip);
			tinyTip.hide();
			if (supCont === 'title') {
				var tipCont = $(this).attr('title');
			} else if (supCont === 'rel') {
				var tipCont = $($(this).attr('rel')).html();
			} else if (supCont !== 'title') {
				var tipCont = supCont;
			}
			$(divTip + ' .content').html(tipCont);
			tText = $(this).attr('title');
			$(this).attr('title', '');

			var pos = $(this).offset();
			var nPos = pos;
			nPos.top = $(this).height();
/*@cc_on
//nPos.top = pos.top + $(this).height();
@*/
			nPos.left = Math.floor(nPos.left + $(this).width() - tinyTip.width() / 2 - $('#topNavi').offset().left);
			tinyTip.css('position', 'absolute').css('z-index', '10010');
			tinyTip.css(nPos).fadeIn(animSpeed);
		}, function() {
			$(this).attr('title', tText);
			tinyTip.fadeOut(animSpeed, function() {
				$(this).remove();
			});
		});
	}
})(jQuery);

/**
 * ready, load
 */
$(function(){

	$('#topNavi li[rel]').tinyTips('rel');

	$("#sidebarCompany").each(function(){
		var o = $(this).parent();
		var offset = o.offset();
		var topPadding = 80;
        $(window).scroll(function() {
            if ($(window).scrollTop() > offset.top) {
                o.stop().animate({
                    marginTop: $(window).scrollTop() - offset.top + topPadding
                });
            } else {
                o.stop().animate({
                    marginTop: 0
                });
            };
        });
	});

	$("#sidebarInformation").each(function(){
		var o = $(this).parent();
		var offset = o.offset();
		var topPadding = 80;
        $(window).scroll(function() {
            if ($(window).scrollTop() > offset.top) {
                o.stop().animate({
                    marginTop: $(window).scrollTop() - offset.top + topPadding
                });
            } else {
                o.stop().animate({
                    marginTop: 0
                });
            };
        });
	});

	//$("div[data-target-blank]").each(function(){$("a", this).each(function(){$(this).attr("target", "_blank")})});

	//nav
	for (var url = location.pathname; url.length > 1; url = url.slice(0, -1)) {
		var x = $('#topNavi li a[href="' + url + '"]').each(function(){
			if ($(this).attr('href').indexOf(url) == 0) {
				$(this).parent().addClass('active');
				return false;
			}
		});
		if (x.length) {
			break;
		}
	}

	$("#inquiry-form").on("submit", function(){
		$.ajax({
			url: this.action,
			type: this.method,
			data: $(this).serialize(),
			dataType: "json",
			success: function(data){alert("メッセージを送信しました。");},
			error: function(){alert("メッセージを送信できませんでした。");}
		});
		return false;
	});

	$('.carousel').height(400)
	$('.carousel').carousel();
	
/*
	//どんなときに接客する？
	$('body').click(function(){
		$('#conce').css({bottom:0, right:"15px"}).fadeIn();
	});
*/
});



/**
 * 
 */
if (document.location.href.indexOf("/staffpage/") != -1) {
	var _b = document.location.href.substring(0, document.location.href.indexOf("/staffpage/"))
	document.write(unescape("%3Cscript src='" + _b + "/js/tiny_mce/tiny_mce.js' type='text/javascript'%3E%3C/script%3E"));
	document.write(unescape("%3Cscript src='" + _b + "/js/tiny_mce_init.js' type='text/javascript'%3E%3C/script%3E"));
}



/**
 * questionBoshuForm
 */
function qbfe(o)
{
	if (o.form.comment.value) {
		var a = $.ajaxSettings.xhr();
		a.open("POST", o.form.action, true)
		a.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
		a.onreadystatechange = function() {
			if (a.readyState == 4) {
				if (a.status == 200) {
					if (a.responseText == "0") {
						o.form.comment.value = ""
						o.form.getElementsByTagName("div")[0].innerHTML = "書き込みありがとうございます。送信いたしました。"
						return
					}
				}
				o.form.getElementsByTagName("div")[0].innerHTML = "エラーが発生しました。"
			}
		}
		a.send("comment=" + encodeURI(o.form.comment.value))
	} else {
		o.form.getElementsByTagName("div")[0].innerHTML = "コメントを入力してください。"
	}
}
function qbcl()
{
	document.getElementById("questionBoshuForm").getElementsByTagName("div")[0].innerHTML = "&#160;"
	document.getElementById("questionBoshuForm").comment.value = ""
	tb_remove()
}



/**
 * ga.js
 */
if (document.location.hostname.indexOf("softel.co.jp") != -1) {
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-2765006-1']);
	_gaq.push(['_trackPageview']);
	(function() {
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();
}

