﻿// JavaScript Document
$(document).ready(function(){
if (window.PIE) {
        $('body.howto #content .before_flow li,body.howto #content .after_flow li,body.howto #content .after_flow li b').each(function() {
           PIE.attach(this);
        });
}
});


$(document).ready(function(){


//$("#srch_sec").css("visibility","visible")


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

$(window).bind('load', function() {
$(".radi").each(function(){
$(this).css({
			   "background":"url("+$(this).attr('src')+") center no-repeat",
			   "width":$(this).width(),
			   "height":$(this).height()
			   })
.attr("src","/images/spacer.gif")

})
})

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

//$("#footer .ptop").hover(
//  function () {
//    $(this).css("top","-23px");
//  },
//  function () {
//    $(this).css("top","-23px");
//  }
//);


var tg =$("body.check")
tg.find(".right dt,.right dd").wrapInner("<table><tr><td></td></tr></table>");
tg.find(".right dt,.right dd").find("td")
.css({"vertical-align":"middle"})
.height(tg.find(".right dt").find("td").closest("dt").height()-2)
.closest("table").css({"margin":"0 auto"})


var tg =$("body.children_h .child_cure_box,body.recep .child_cure_box")
tg.find("table tr:odd").addClass("odd")


$("#nav a img,body.pro_aid dl.chart img,#addnav li img").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"));
});

//var bc = $("body").attr("class")
//if(bc.match("acc")){
//$("#addnav li img:eq(1)").attr("src",$("#addnav li img:eq(1)").attr("src").replace("_n","_r"));
//}


//hearingaids　tab
//var tg =$("body.hearingaids, body.check")
var tg =$("body.hearingaids, body.check, body.faq")
faq_tgl()
if(location.hash=="#t02"){
tg.find(".tabbox:first").hide()
$('html,body').scrollTop(50)
} else {
tg.find(".tabbox:last").hide()
}

tg.find(".tab").each(function(i){
$(this).find("li").each(function(i){
$(this).click(function(){
$(".tabbox").hide()
$(".tabbox:eq("+i+")").show()
});
});
});
tg.find(".tabbox").find("a.dtl").click(function(){
$(".tabbox").toggle()
});


$("head").append("<link>");
css = $("head").children(":last");
css.attr({
    rel: "stylesheet",
    type: "text/css",
    href: "/css/font_s.css"
});
if(!$.cookie('fnt')){
$.cookie('fnt',"s",{path:'/'})
}

var size = $.cookie('fnt');
$("link[rel=stylesheet]:last").attr("href","/css/font_"+size+".css")

$("#size_chng").find("dd."+size+"").find("img").attr("src",$(this).find("dd."+size+"").find("img").attr("src").replace("_n","_r"));


$("#size_chng").find("dd").click(function(){
var c = $(this).attr("class")
$("link[rel=stylesheet]:last").attr("href","/css/font_"+c+".css")
$.cookie('fnt', c,{path:'/'})

$("#size_chng").find("dd").each(function(){
$(this).find("img").attr("src",$(this).find("img").attr("src").replace("_r","_n"));
})
$(this).find("img").attr("src",$(this).find("img").attr("src").replace("_n","_r"));
})

$(".before_flow ul li").tile(3);
$("body.cros #content .colo_cros li").tile();


if($("body").attr("class").match("products")){
posi_set();
$('#pro_color_box .zoom').zoomy({zoomText: 'クリックで拡大',glare:false,zoomSize:250});
if ($.browser.msie && $.browser.version < 8)
{
$('#pro_color_box .zoom').click(function(){
$('#pro_color_box .color ul li').toggle();
})				  
}
}

///wink
$("#pro_lineup_box .func dl img,#pro_anc li img,.wink").hover(function(){
$(this).css("opacity", "0.5");
$(this).fadeTo("slow", 1.0);
});
///wink



crrent();			   
//$(".fixHeight").fixHeight();

});/////////readyEND


function posi_set() {
	$('#pro_color_box ul').each(function () {
    by = $(this).offset().top;
    bx = $(this).offset().left;

    var pos = new Array();
    $(this).find('li').each(function (i) {
        y = $(this).offset().top;
        x = $(this).offset().left;
        wid = $(this).width()
        pos[i] = new Array(y - by, x - bx, wid)
    });
    $(this).find('li').each(function (i) {
        $(this).css({
            margin: "0",
            float: "none",
            position: "absolute",
			"z-index":"50",
            top: pos[i][0],
            left: pos[i][1],
            width: pos[i][2]
        })
    })
	})
} //positon set




//FAQトルグ
function faq_tgl(){
var faq_id = $("body.faq");
faq_id
.find(".wraptable").each(function(){
	$(this).css("height",$(this).height()+"px");})
.show().hide().end() 
.find(".opentbl").click(function () {
$(this).next().slideToggle("fast");
})
.toggle(function () {
$(this).find(".dtlopen").attr('src',"/faq/images/btn_faq_c_n.gif");
},
function () {
$(this).find(".dtlopen").attr('src',"/faq/images/btn_faq_a_n.gif");
}
)
.hover(function () {
$(this).css("cursor", "pointer");
},
function () {
$(this).css("cursor", "nomal");
}
);
}



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
}



/*
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
 *
 */
(function($) {
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;
    }
};
})(jQuery);

///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
**/
(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);


/*
 * fixHeight - jQuery Plugin
 * http://www.starryworks.co.jp/blog/tips/javascript/fixheightjs.html
 *
 * Author Koji Kimura @ STARRYWORKS inc.
 * http://www.starryworks.co.jp/
 * 
 * Licensed under the MIT License
 *
 */


(function($){
	
	var isInitialized = false;
	var parents = [];
	var textHeight = 0;
	var $fontSizeDiv;
	
	$.fn.fixHeight = function() {
		this.each(function(){
			var childrenGroups = getChildren( this );
			
			$.each( childrenGroups, function(){
				
				var $children = $(this);
				if ( !$children.filter(":visible").length ) return;
				
				var row = [];
				var top = 0;
				$children.each(function(){
					if ( top != $(this).position().top ) {
						$(row).sameHeight();
						row = [];
						top = $(this).position().top;
					}
					row.push(this);
				});
				if ( row.length ) $(row).sameHeight();
			});
			
			
		});
		init();
		return this;
	}
	
	$.checkFixHeight = function( i_force ) {
		if ( $fontSizeDiv.height() == textHeight && i_force !== true ) return;
		textHeight = $fontSizeDiv.height();
		$(parents).fixHeight();
	}
	
	$.fn.sameHeight = function() {
		var maxHeight = 0;
		this.css("height","auto");
		this.each(function(){
			if ( $(this).height() > maxHeight ) maxHeight = $(this).height();
		});
		return this.height(maxHeight);
	}
	
	function getChildren( i_parent ) {
		var $parent = $( i_parent );
		
		if ( $parent.data("fixHeightChildrenGroups") ) return $parent.data("fixHeightChildrenGroups");
		var childrenGroups = [];
		
		var $children = $parent.find(".fixHeightChild");
		if ( $children.length ) childrenGroups.push( $children );
		
		var $groupedChildren = $parent.find("*[class*='fixHeightChild']:not(.fixHeightChild)");
		if ( $groupedChildren.length ) {
			var classNames = {};
			$groupedChildren.each(function(){
				var a = $(this).attr("class").split(" ");
				var i;
				var l = a.length;
				var c;
				for ( i=0; i<l; i++ ) {
					c = a[i].match(/fixHeightChild[a-z0-9_-]+/i);
					if ( !c ) continue;
					c = c.toString();
					if ( c ) classNames[c] = c;
				}
			});
			for ( var c in classNames ) childrenGroups.push( $parent.find("."+c) );
		}
		
		if ( !childrenGroups.length ) {
			$children = $parent.children();
			if ( $children.length ) childrenGroups.push( $children );
		}
		
		$parent.data("fixHeightChildrenGroups", childrenGroups );
		parents.push( $parent );
		
		return childrenGroups;
	}
	
	
	function init() {
		if ( isInitialized ) return;
		isInitialized = true;
		$fontSizeDiv = $(document).append('<div style="position:absolute;left:-9999px;top:-9999px;">s</div>');
		setInterval($.checkFixHeight,1000);
		$(window).resize($.checkFixHeight);
		$.checkFixHeight();
		$(window).load( function(){ $.checkFixHeight(true); } );
	}
	
})(jQuery);



$(function(){
///news accordion
	$('.com_news .box dl').css({"display":"none"});
	$('.com_news .box dl:first').css({"display":"block"});
	
	$('.com_news .box h4').click(function() {
		$(this).next().slideToggle();
		return false;
	});
	
	if(location.hash.match("d11")){
	$(".box").find(".y2011").next().css({"display":"block"});
	};
});
////end news accordion


$(window).load(function(){
///acc url	
	$("#pro_acc_box").find("table").find("img").each(function(){
	var accSrc = $(this).attr('src').replace(".jpg","").replace("/products/images/acc_ico","");	
	$(this).wrap("<a href=''></a>");
	//$(this).before( accSrc );
	
	if( accSrc.match("00")){
		$(this).parent().attr( 'href', '/products/accessories/index.html#KeyPilot2' );
		} else
	if( accSrc.match("01")){
		$(this).parent().attr( 'href', '/products/accessories/index.html#PilotOne' );
		} else
	if( accSrc.match("02")){
		$(this).parent().attr( 'href', '/products/accessories/index.html#MyPilot' );
		} else
	if( accSrc.match("03")){
		$(this).parent().attr( 'href', '/products/accessories/interface.html' );
		} else
	if( accSrc.match("04")){
		$(this).parent().attr( 'href', '/products/accessories/cros.html' );
		} else
	if( accSrc.match("05")){
		$(this).parent().attr( 'href', '/products/fm/' );
		} else
	if( accSrc.match("06")){
		$(this).parent().attr( 'href', '/products/accessories/interface.html#ComPilot' );
		} else
	if( accSrc.match("07")){
		$(this).parent().attr( 'href', '/products/accessories/interface.html#Mycom' );
		}
	});
	
});
////end acc url





//jQuery(document).ready(function(){
//	$(".fixHeight").fixHeight();
//});


// fixHeight - jQuery Plugin end







