// JavaScript Document

$(function(){
		   
if($("body").attr("class").match("blog")){

if(!location.href.match("192")){

$("#main a").each(function(){
						   
						   
$(this).attr("href",$(this).attr("href").replace("http://192.168.0.71:8851","http://www.ascot-systems.jp"))					   
						   });

}

}
						   
if ($.browser.msie )
{
$("a").focus(function(){
$(this).blur();
});
$("img").attr("title","");
}


hvr();
crrent();
accordion();
addclassodd();
inc();
blogmoretoggle();
toggle();

///wink
$(".all_mg li a,.wink").hover(function(){
$(this).css("opacity", "0.5");
$(this).fadeTo("slow", 1.0);
});
///wink

$("#pgtop").click (function(){
							$("html, body").scrollTop(0);
							});

$("body.conf,body.cond").find("#hline").append('<img src="/images/free_bc.gif" class="free_bc blk">')




});////ready end

$(window).bind('load', function() {
tileSet()
});


//hover func
function hvr(){

var bstg = $("#navi li a img,#snavi li a img,.hvr img,.btns img,#bnn_area img,#pgtop img,#contact_box a img,#bann img");
bstg.hover(
  function () {
    $(this).attr("src",$(this).attr("src").replace("_n.","_r."));
  },
  function () {
    $(this).attr("src",$(this).attr("src").replace("_r.","_n."));
  }
)
.each(function(){
$("<img>").attr("src",$(this).attr("src").replace("_n.","_r."));
});

}

//current func
function crrent(){
var href = location.href.split(/[#?]/)[0];
var href = href.replace(/[/]$/,'/index.html');
//var href = href.replace(/.*\//,'');

$("a").each(function() {
var myhref = this.href;
var myhref = myhref.replace(/[/]$/,'/index.html');
//var myhref = myhref.replace(/.*\//,'');

if (href==myhref){
$(this).addClass("current");
}
});//each
}

//tileSet func
function tileSet(){
$(" .wn_box,body.ser .whalf .set").tile();
}

//footer element include func
function inc(){


var kit = $("html.webkit")
var nokit = $("html:not(.webkit)")

kit.find("#footer #news_inner").load("/ #news_input .flt");
kit.find("#free dd:eq(0) a").load("/condition/ .entry:eq(0)",modi);
kit.find("#free dd:eq(1) a").load("/confused/ .entry:eq(0)",modi);

nokit.find("#footer #news_inner").load("/app/cha_set.php?sub=/ #news_input .flt");
nokit.find("#free dd:eq(0) a").load("/app/cha_set.php?sub=/condition/ .entry:eq(0)",modi);
nokit.find("#free dd:eq(1) a").load("/app/cha_set.php?sub=/confused/ .entry:eq(0)",modi);

function modi(){
$(this).find("p:not(:first),.dot,.entry-footer,br").remove()
tileSet()
}

}

//accodion func
function accordion() {

    var bstg = $(".w_panel")
    bstg.each(function () {

        $(this).prepend("<div class='blind'></div>");
        $(this).find(".blind").css({
            "position": "absolute",
            "z-index": "50",
            "background": "#FFF",
            "opacity": "0",
            "display": "none",
            "height": $(this).height(),
            "width": $(this).width()
        })

        $(this).find(".panel").click(function () {
            $(this).next().slideToggle(200)
            $(this).toggleClass("panel_cr");
        });
        $(this).find(".panel").toggle(

        function () {
            $(".panel:not('.panel_cr')").animate({"opacity":"0.1"}).prev().show();

            if ($.browser.msie && $.browser.version < 8) {
                $(".panel:not('.panel_cr') h4").animate({"opacity":"0.1"});
            }
        }, function () {
            $(".panel:not('.panel_cr')").css("opacity", "1").prev().hide();
            if ($.browser.msie && $.browser.version < 8) {
                $(".panel:not('.panel_cr') h4").css("opacity", "1")
            }
        });
    });

}

//addClassOdd finc
function addclassodd(){

var ectg = $(".blocks")	
var bstg = $(".half")


ectg.each(function(i) {
$(this).find(".half:odd").addClass("odd").after("<div class='clear'></div>")
})

}


//blog more toggle
function blogmoretoggle() {
    var hit_id = $("body.blog");
    var c = $("body").attr("class");
    hit_id.find("#morepane li:lt(12)").hide();
    if ($.cookie(c)) {
        hit_id.find("#morepane").show();
        hit_id.find("#open_pane").find("span").text('閉じる').parent().addClass("open");
        hit_id.find("#open_pane").toggle(function () {
            $(this).find("span").text('もっと見る').parent().removeClass("open");
        }, function () {
            $(this).find("span").text('閉じる').parent().addClass("open");
        });
    } else {
        hit_id.find("#morepane").hide();
        hit_id.find("#open_pane").toggle(function () {
            $(this).find("span").text('閉じる').parent().addClass("open");
        }, function () {
            $(this).find("span").text('もっと見る').parent().removeClass("open");
        });
    }
    hit_id.find("#open_pane").click(function () {
        if ($.cookie(c)) {
            $.cookie(c, '', {
                expires: -1,
                path: '/'
            });
        } else {
            $.cookie(c, 1, {
                expires: 7,
                path: '/'
            }); //cookieをセットする  
        }
        $(this).next().slideToggle("fast");
    });
}


//
function toggle (){
	
var bstg = $("body.hit").find(".box");

bstg.each(function(){
				   $(this).find(".more").click(function () {
											$(this).next().slideToggle("fast");		 
														 });
				   bstg.find(".more").toggle(function () {
            $(this).find("span").text('閉じる').parent().addClass("open");
        }, function () {
            $(this).find("span").text('詳しくは').parent().removeClass("open");
        });
				   })
}

/*
CSS Browser Selector v0.3.1
Rafael Lima (http://rafael.adm.br)
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' '+s+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
//* CSS Browser Selector  END



/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */


jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

///Cookie pluginEND

/**
 * Flatten height same as the highest element for each row.
 *
 * Copyright (c) 2011 Hayato Takenaka
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * @author: Hayato Takenaka (http://urin.take-uma.net)
 * @version: 0.0.2
 $('.sample1').tile();
 $().tile(columns);
**/
(function($) {
	$.fn.tile = function(columns) {
		var tiles, max, c, h, last = this.length - 1, s;
		if(!columns) columns = this.length;
		this.each(function() {
			s = this.style;
			if(s.removeProperty) s.removeProperty("height");
			if(s.removeAttribute) s.removeAttribute("height");
		});
		return this.each(function(i) {
			c = i % columns;
			if(c == 0) tiles = [];
			tiles[c] = $(this);
			h = tiles[c].height();
			if(c == 0 || h > max) max = h;
			if(i == last || c == columns - 1)
				$.each(tiles, function() { this.height(max); });
		});
	};
})(jQuery);

/*
	カーニングペアの定義
	単位はem。 -0.5(em) でボックス0.5個分詰まる。
	"*く" と定義した場合、"あく"、"いく"、"うく"、というように、全ての"○く"の組み合わせにカーニングが設定される。
	"あく" と定義をした場合、 "あく"という文字のペアのみにカーニングが設定される。
	ワイルドカードペアと直接指定のペアが衝突する場合、直接指定のペアが優先される。
*/
var p = {};

//前後の文字をワイルドカード指定した汎用のカーニングペア
p["*う"] = -0.03;
p["う*"] = -0.02;
p["*く"] = -0.075;
p["く*"] = -0.075;
p["*し"] = -0.075;
p["し*"] = -0.075;
p["*ぁ"] = -0.05;
p["ぁ*"] = -0.075;
p["*ぃ"] = -0.05;
p["ぃ*"] = -0.075;
p["*ぅ"] = -0.05;
p["ぅ*"] = -0.075;
p["*ぇ"] = -0.05;
p["ぇ*"] = -0.075;
p["*ぉ"] = -0.05;
p["ぉ*"] = -0.075;
p["*っ"] = -0.075;
p["っ*"] = -0.075;
p["*ゃ"] = -0.05;
p["ゃ*"] = -0.075;
p["*ゅ"] = -0.05;
p["ゅ*"] = -0.075;
p["*ょ"] = -0.075;
p["ょ*"] = -0.075;
p["*ト"] = -0.075;
p["ト*"] = -0.075;
p["*ド"] = -0.075;
p["ド*"] = -0.075;
p["*リ"] = -0.075;
p["リ*"] = -0.075;
p["*ッ"] = -0.05;
p["ッ*"] = -0.075;
p["ャ*"] = -0.05;
p["*ャ"] = -0.05;
p["ュ*"] = -0.05;
p["*ュ"] = -0.05;
p["ョ*"] = -0.08;
p["*ョ"] = -0.08;
p["*「"] = -0.25;
p["」*"] = -0.25;
p["*（"] = -0.25;
p["）*"] = -0.25;
p["、*"] = -0.25;
p["。*"] = -0.25;
p["・*"] = -0.25;
p["*・"] = -0.25;
p["*："] = -0.25;
p["：*"] = -0.25;



//1文字は行頭専用のカーニングペア
p["「"] = -0.5;
p["『"] = -0.5;
p["（"] = -0.5;
p["【"] = -0.5;
p["“"] = -0.5;


/*
 * @class FLAutoKerning
 * @version 0.0.3 (2011/02/28)
 * 
 * テキストに文字詰めを適用するUtilityクラス。
 * インスタンス化せずに、スタティック関数として使用する。
 *
 * @author Takayuki Fukatsu, artandmobile.com, fladdict.net
 * @requires jQuery
 */
var FLAutoKerning = {};


/*
 * ディフォルトのカーニング情報を格納した定数。
 * ユーザーが任意のカーニング情報を適用しない場合は、この情報を基準にカーニングが設定される。
 */
FLAutoKerning.DEFAULT_KERNING_INFO = p;


/*
 * 渡された jQuery オブジェクト内のテキストに、字詰めを適用する。
 * 字詰めはスタイルシートのletter-spacingによって実現される。
 * 第2引数を指定することで、ユーザー独自のカーニング情報を適用することも可能。
 * 
 * @param {jQuery} elements テキストを内包したhtml要素の jQuery オブジェクト。
 * @param {Array} kerningInfo カーニングペア情報を格納した配列。省略した場合は、FLAutoKerning.DEFAULT_KERNING_INFO が適用される。
 */
FLAutoKerning.process = function( elements, kerningInfo )
{
	if(kerningInfo==undefined)
		kerningInfo = FLAutoKerning.DEFAULT_KERNING_INFO;
	
	elements.each(
		function(index, element){
			var html = $(element).html();
			var newHtml = "";
			var n = html.length;
			for(var i=0; i<n; i++)
			{
				var char = html.substr(i,1);
				var char2 = char;
				var nextChar = html.substr(i+1,1);
				var space = 0;
				
				if(kerningInfo[char+nextChar]){
					//明示的なカーニングペアの処理
					space = kerningInfo[char+nextChar];
				}else{
					//汎用カーニングペアの処理
					if(kerningInfo[char+"*"] )
						space += kerningInfo[char+"*"];
					if(kerningInfo["*"+nextChar] )
						space += kerningInfo["*"+nextChar];
				}
				if(space!=0)
					char2 = "<span style='letter-spacing:" + space + "em'>" + char + "</span>";
					
				//行頭約物の処理
				if(i == 0 && kerningInfo[char])
					char2 =  "<span style='margin-left:" + kerningInfo[char] + "em'/>" + char2;
					
				newHtml += char2;
			}
			$(element).html(newHtml);
		});
}

//tenpの変数を削除
delete p;



