﻿d = document;

// addLoadEvent
function addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, false);
		return true;
	}
	else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	}
	else {
		return false;
	}
}


// rollover
function onMouse() {
	if (!document.getElementById) return;
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName("img");

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == "r") {
			var src = aImages[i].getAttribute("src");
			var ftype = src.substring(src.lastIndexOf("."), src.length);
			var hsrc = src.replace(ftype, "_on"+ftype);
			aImages[i].setAttribute("hsrc", hsrc);
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute("src");
				this.setAttribute("src", this.getAttribute("hsrc"));
			}	
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute("src").replace("_on"+ftype, ftype);
				this.setAttribute("src", sTempSrc);
			}
		}
	}
}

// Focus Text Area
function txtFocus(){
	if(!d.getElementById) return false;
	if(!d.copy) return false;
	
	// onFocus Event
	var text_area = d.copy.elements;
	for(var i=0; i < text_area.length; i++) {
		text_area[i].onfocus = function (){
			this.select();
		}
	}
}


// Default Value
function txtDefaultValue(){
	var input = d.getElementsByTagName("input");
	var textarea = d.getElementsByTagName("textarea");

	//input
	for(var i=0; i<input.length; i++){
		if((!input[i].getAttribute("type") == "text")||(!input[i].getAttribute("type") == "password")) return false;
		if(input[i].className != ""){ //classの有無
			var inputCn = String(input[i].className).split(" ");
			for(var n=0; n<inputCn.length; n++){
				if(inputCn[n] == "df"){ //class名の取得
					if(input[i].value==input[i].defaultValue){
						input[i].style.color = "#888888"; //入力前のフォントカラー
					}
					input[i].onfocus = function (){
							if(this.value==this.defaultValue){
								this.value = "";
								this.style.color = "#444444"; //入力中のフォントカラー
							}
					}
					input[i].onblur = function (){
							if(this.value==""){
								this.value = this.defaultValue;
								this.style.color = "#888888"; //入力前のフォントカラー
							}else if(!this.value==""){
								this.style.color = "#444444"; //入力後のフォントカラー
							}
					}
				}
			}
		}
	}

	//textarea
	for(var i=0; i<textarea.length; i++){
		if(textarea[i].className != ""){ //classの有無
			var txtareaCn = String(textarea[i].className).split(" ");
			for(var n=0; n<txtareaCn.length; n++){
				if(txtareaCn[n] == "df"){ //class名の取得
					if(textarea[i].value==textarea[i].defaultValue){
						textarea[i].style.color = "#888888"; //入力前のフォントカラー
					}
					textarea[i].onfocus = function (){
							if(this.value==this.defaultValue){
								this.value = "";
								this.style.color = "#444444"; //入力中のフォントカラー
							}
					}
					textarea[i].onblur = function (){
							if(this.value==""){
								this.value = this.defaultValue;
								this.style.color = "#888888"; //入力前のフォントカラー
							}else if(!this.value==""){
								this.style.color = "#444444"; //入力後のフォントカラー
							}
					}
				}
			}
		}
	}
}



// onload Event
addEvent(window, 'load', onMouse);
addEvent(window, 'load', txtFocus);
addEvent(window, 'load', txtDefaultValue);



// JQuery
// トップ　みんなのアルバム　ロールオーバー
$(document).ready(function(){
	if($("#topAlbum li div").length>0){
		$("#topAlbum li div").hover(function (){
			$(this).css({borderColor:"#ff8500"});
		}, function (){
			$(this).css({borderColor:"#cccccc"});
		});
	}
});

// ペットと出会う　人気の犬種ピックアップ　ロールオーバー
$(document).ready(function(){
	if($("#breedPetList01 dd.ph img").length>0){
		$("#breedPetList01 dd.ph img").hover(function (){
			$(this).css({borderColor:"#a7d606"});
		}, function (){
			$(this).css({borderColor:"#696969"});
		});
	}
});

