/*
 * library.js 1.0
 * pre-require: jQuery v1.3.2
 * 2009/10/06
 */


/*--- RollOver ---*/

$(function initRollOverImages() {
	var image_cache = new Object();
	$("img.btn").each(function(i) {
		var imgsrc = this.src;
		var fileName = imgsrc.replace(/\\/g,'/').replace(/.*\//, '');
		if((fileName.indexOf("o.")) == -1 && (fileName.indexOf("s.")) == -1 ){
			var dot = this.src.lastIndexOf('.');
			var imgsrc_on = this.src.substr(0, dot) + 'o' + this.src.substr(dot, 4);
			image_cache[this.src] = new Image();
			image_cache[this.src].src = imgsrc_on;
			$(this).hover(
				function() { this.src = imgsrc_on; },
				function() { this.src = imgsrc; }
			);
		}
	});
});


/*--- OpenWindow ---*/

$(function windowOpen () {
	$("a.blank").click(function(){
		window.open($(this).attr("href"), 'new');
		return false;
		}
	);
});

$(function childPaint () {
	$("a.childPaint").click(function(){
		window.open($(this).attr("href"), 'popup', "width=690, height=810, location=no, menubar=no, status=yes, scrollbars=yes, resizable=yes, toolbar=no, left="+(window.screen.width-690)/2);
		return false;
		}
	);
});



/*--- globalnav ---*/
var naviConfig = [
    { rule:"/about/", selector:"#naviAbout" },
    { rule:"/tools/", selector:"#naviTools" },
    { rule:"/control/", selector:"#naviControl" },
    { rule:"/athlete/", selector:"#naviAthlete" },
    { rule:"/child/", selector:"#naviChild" }
];
(function(config){
    for(var i=0;i<config.length;i++){
        if( location.href.match(config[i].rule) ){
			var imgsrc = $(config[i].selector).attr("src");
			var dot = $(config[i].selector).attr("src").lastIndexOf('.');
			var imgsrc_stay = $(config[i].selector).attr("src").substr(0, dot) + 's' + $(config[i].selector).attr("src").substr(dot, 4);
			$(config[i].selector).attr("src", imgsrc_stay);
            $(config[i].selector).removeClass("btn");
            return;
        }
    }
})( naviConfig );



/*--- favorite ---*/
$(function(){
	var pageurl = encodeURIComponent(document.URL);
	// facebook
	var fburl = "http://www.facebook.com/plugins/like.php?href=" + pageurl + "&layout=button_count&show_faces=false&width=70&action=like&colorscheme=light&height=21";
	$(".fbBtn").each(function(){
		$(this).attr("src", fburl);		
	});
	// mixi
	var mixiurl = "http://plugins.mixi.jp/favorite.pl?href=" + pageurl + "&service_key=055e2d58ee3baea09d64d85a1ec76c2e7b5a56f0";
	$(".mixiBtn").each(function(){
		$(this).attr("src", mixiurl);		
	});
});


/*--- taidan ---*/
function vote_thanks() {
  wobj = window.open("", "vote","resizable=yes,status=no,toolbar=no,menubar=no,scrollbars=yes,width=615,height=350, left="+(window.screen.width-615)/2);
  frm = document.getElementsByName('vote_form');
  frm[0].submit();
  if(wobj && !wobj.closed){
  	wobj.focus();
  }
  return true;
}

$(function feedbackResult () {
	$(".feedbackResult a").click(function(){
		window.open($(this).attr("href"), 'popup', "width=615, height=580, location=no, menubar=no, status=yes, scrollbars=yes, resizable=yes, toolbar=no, left="+(window.screen.width-615)/2);
		return false;
		}
	);
});


$(function actResult () {
	$(".actResult a").click(function(){
		window.open($(this).attr("href"), 'popup', "width=650, height=650, location=no, menubar=no, status=yes, scrollbars=yes, resizable=yes, toolbar=no, left="+(window.screen.width-650)/2);
		return false;
		}
	);
});




/*--- sidenav ---*/
$(function(){
	$("dl.sideNavi li:last").attr("class", "last-child");		
});


