/**
 *  _____ _____ _____ _____ _____ _____ _____ 
 * | __  |  _  |     |     |     |     |   | |
 * |    -|     |   --|   --|  |  |  |  | | | |  ∧＿_∧
 * |__|__|__|__|_____|_____|_____|_____|_|___| <´･ェ･`>
 *                                            
 * raccoon.js
 * @author Tenderfeel
 * @ver 1.0
 * @HOME http://tenderfeel.xsrv.jp/
 * 
 * @Need:mootools 1.2
 *
 * ---MIT License--------------------------------------------
 * Copyright (c) 2008 Tenderfeel all rights reserved.
 * ----------------------------------------------------------
 */


var DOMAIN = "";

window.addEvent('domready', function(){
									
	new wtnRollover({area:"#main"});
	//new wtnLinkIcons({excludeStr:["file:///D:/WebSite/tono/","http://web-zero.jp"],iconDir:"images/filetype/",QuickBox:true,open:"blank"});
	
	if(Browser.Engine.trident && Browser.Engine.version < 5){
		setSize();
	}
	
	/* go to top */
	new GotoTop();
	

	/* アナログIE */
	new mooAnalogIE({element:"teaser"});
	
	/* Google Analytics*/
	
	/*----start::
	
	//Tracker
	var container = $("container");
	var gtracker = new Element("script",{src:DOMAIN+'js/gtracker.js',"type":"text/javascript"});
	gtracker.inject(container,"after");
	
	//Analytics
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	var ga = new Element("script",{src:gaJsHost + "google-analytics.com/ga.js","type":"text/javascript"});
	ga.inject(container,"after");
	
	::end------*/
});

if(Browser.Engine.trident && Browser.Engine.version < 5){
	window.addEvent("resize",function(){
		setSize();
	});
}

function setSize(){
	var size = $(document).getSize();
	$("teaser").setStyle("width",size.x);
}
/** QuickBox Plugin */
var QuickBox_js = new Asset.javascript(DOMAIN+'js/QuickBox.js');
var QuickBox_CSS = new Asset.css(DOMAIN+"css/quickbox.css",{ "media":"screen"});



/** 
 * 
 * Google Ajax API 
 * 
 */
 
var gAPIkey = 'ABQIAAAAwrzVu2iAWtCM12EpP4ZXHBQHU6XcrFApqbdamdjM5_BLA7149BQrMYCbjHjT0BDL0CY-nSgMTukMYQ';
var gs,gm,gf;

/** Gmap */
var gmConfig = {
	"pageName":"shop.html",//表示するページ
	"gmLat":35.4238625055001,  //GLat
	"gmLng":137.0052409172058, //GLng
	"gmDivID":"gmap",    //地図を表示する要素のID
	"gmScope":18,        //拡大率
	"markerAdd":true,  //マーカーの表示
	"SMap_Controler":false, //小さいコントローラ
	"LMap_Controler":true, //大きいコントローラ
	"Type3_Controler":true, //地図タイプ切り替え（３種）
	"Type2_Controler":false, //地図タイプ切り替え（2種）
	"Scale_Controler":true, //スケール
	"OV_Controler":true, //右下の縮小地図
	"WheelZoom":false, //ホイールでのズーム操作
	"DClickZoom":true //ダブルクリックでのズーム操作
}


/** 情報ウィンドウのHTML */
var gmIWhtml = "<em>湯の花アイランド</em><br />岐阜県可児市土田大脇4800-1";


if(location.href.indexOf(gmConfig.pageName)!==-1){
	new Asset.javascript(DOMAIN+'js/gmap.js');var gm=true;
}

new Asset.javascript('http://www.google.com/jsapi?callback=googleAPIloadings&key='+gAPIkey);

function googleAPIloadings(){
	if(gm){google.load("maps", "2",{"callback" : mapsLoaded,"language" : "ja"});}
}


/**
 * AnalogIE
 * @ver 1.0
 * IE6以下の場合にアナログと表示する
 */
var mooAnalogIE = new Class({
	
	Implements: [Options],

	options: {
		html:'<img src="images/analog.png" width="57" height="13" alt="アナログ" />',
		text:"まだアナログ環境をご利用ですか？今すぐデジタル環境へアップグレード",
		element:"header"
	},
	initialize: function(options) {
		this.setOptions(options);
		this.html = this.options.html;
		this.text = this.options.text;
		this.element =  $(this.options.element);
		if(this.element) this.start();
		else return false;
	},
	start:function(){
		if(Browser.Engine.trident && Browser.Engine.version < 5){
			var self = this;
			new Element("a",{
				"href":"http://www.microsoft.com/japan/windows/products/winfamily/ie/function/default.mspx",
				"title":"Internet Explorer8のダウンロードサイトへ",
				"target":"_blank",
				"id":"analogIE",
				events:{
					"mouseover":function(){
						this.addClass("mover");
						this.set("html",self.text);
					},
					"mouseout":function(){
						this.removeClass("mout");
						this.set("html",self.html);
					}
				},
				html:this.html
			}).inject(this.element);
		}
	}
});

/**
 * GotoTop
 * @ver 1.0
 * ページのトップに戻るボタン
 */
var GotoTop = new Class({
	
	Implements: [Options],

	options: {
		id:'gototop',
		width:100
	},
	initialize: function(options) {
		this.setOptions(options);
		this.width = this.options.width;
		this.gototop =  $(this.options.id);
		new SmoothScroll({duration:500});
		if(this.gototop) this.start();
		else return false;
	},
	start:function(){
		var self=this;
		self.gototop.set('opacity','0').setStyle('display','block');
		window.addEvent('scroll',function(e) {
			if(Browser.Engine.trident4) {
				self.gototop.setStyles({
					'position': 'absolute',
					'bottom': window.getPosition().y + 10,
					'width': this.width
				});
			}
			self.gototop.fade((window.getScroll().y > 300) ? 'in' : 'out');
		});
	}
});

/**
 * wtnRollover
 * @ver 1.0
 * リンク下にある画像をロールオーバーor透過処理させる
 */

var wtnRollover = new Class({
	
	Implements: [Options],

	options: {
		current:true,
		area:"body",
		over:"_on",
		off:"_off"
	},
	initialize: function(options) {
		this.setOptions(options);
		this.overTxt = this.options.over;
		this.offTxt = this.options.off;
		this.imgs =  $$(this.options.area + " a img");
		if(this.imgs) this.Roll();
		return true;
	},
	Roll:function(){
		var self = this;
		self.imgs.each(function(img,index){
			var current;
			if($type(img)=="element"&& !img.hasClass("rollskip")){
				if(self.options.current==true){
					current = self.Current(img);
				}
				img.addEvents({
					"mouseover":function(){
						if(img.src.indexOf(self.offTxt) === -1)
							img.set("tween",{duration: 200}).tween("opacity",[1,0.5]);
						else
							img.src = img.src.replace(self.offTxt,self.overTxt);
						},
					 "mouseleave":function(){
					 	if(img.src.indexOf(self.overTxt) === -1||current==true)
							img.fade(1);
						else
							img.src = img.src.replace(self.overTxt,self.offTxt);
					 }
				});
			}
		});
		return;
	},
	Current:function(img){
		var URL = this.FilePass(document.location.href);
		var Href =  this.FilePass(img.getParent().href);
		if(Href === URL && Href){
			img.src = img.src.replace(this.offTxt,this.overTxt);
			return true;
		}
	},
	FilePass:function(str){
		var FilePass = str.substring(str.lastIndexOf("/")+1,str.length);
		return FilePass;
	}
});

/**
 * wtnLinkIcons
 * @ver 1.3
 * 
 * 別窓を開くアイコンとhrefの拡張子に応じたアイコンや属性を追加
 */

var wtnLinkIcons = new Class({					
	Implements: [Options],		
	options: {
		//search area
		areaID:"",
		//External Link OPTIONS
		ExternalLink:true,
		linkTitle:"リンクを新しいウインドウで開く",
		addExtIconClass:"exiAdd", //AddExternalIcon
		open:"blank",
		excludeStr:[],
		//Filetype Icon OPTIONS
		FiletypeIcon:true,
		ImagetypeIcon:false,//PNG JPG GIF
		media:["pdf","doc","zip","xls","mov","mp3","psd","swf","txt","wmv",".ai","exe","ppt","mpg","flv"],
		iconType:"gif",
		iconDir:"images/filetype/",
		iconW:16,
		iconH:16,
		//USE QuickBox OPTIONS
		QuickBox:false
		
	},
	initialize: function(options) {
		this.setOptions(options);
		this.exStr = this.options.excludeStr;
		this.addExI = this.options.addExtIconClass;
		this.media = this.options.media;
		this.iconD = this.options.iconDir;
		this.iconT = this.options.iconType;
		this.iconW = this.options.iconW;
		this.iconH = this.options.iconH;
		this.linkT = this.options.linkTitle;
		this.imgR = this.options.imgRel;
		this.FtI = this.options.FiletypeIcon;
		this.QuickBox = this.options.QuickBox;
		this.External = this.options.ExternalLink;
		this.gallery = false;
		this.gNum = 0;
		if(this.options.areaID =="")
			this.area = $(document.body);
		else
			this.area = $(this.options.areaID);
			
		this.area.getElements('a[href]').each(this.addIcon,this);
		return true;
	},
	
	addExternal:function(a){
		if(!this.External) return;
		if(this.options.open == "js"){
			var ANC = new Element("a",{"href":"#","title":this.linkT,"class":"newWin",events:{"click":function(){window.open(a.href);return false;}}});
		}else{
			var ANC = new Element("a",{"href":a.href,"title":this.linkT,"target":"_blank", "class":"newWin"});
		}
		ANC.set("html",'<img src="'+this.iconD +'external.'+this.iconT+'" width="'+this.iconW+'" height="'+this.iconH+'" alt="" />')
		ANC.inject(a,"after");
	},
	
	addArgs:function(qb,a){
		if(qb==1){//USE QuickBox
			var rel = a.getProperty("rel");
			var gal = ""; rel = (rel!=null)? " "+rel:"";
			//if((a.hasClass("start")&&!this.gallery)||this.gallery){ gal ="[img"+this.gNum+"]"; this.gallery = true; }
			//if(a.hasClass("end")){ gal ="[img"+this.gNum+"]"; this.gNum++; this.gallery = null; }
			a.setProperty("rel","quickbox"+gal+rel);
		}else{
			if(!this.External) return;
			if(this.options.open == "js"){a.addEvent("click",function(){window.open(this.href);return false;});}
			else{a.setProperty("target","_blank");}
		}
	},
	
	createIcon:function(tn,alt){
		return new Element("img",{
			"class":"icon",
			"src":this.iconD+tn+"."+this.iconT,
			"width":this.iconW,
			"height":this.iconH,
			"alt":alt
		});
	},
	
	addIcon:function(item,index){
		var self = this;
		var h = item.href;
		var t = h.replace(h.slice(0, -3), "").toLowerCase();
		var txt = item.get("text");
		var pct = item.getChildren("img");
		var icoskip = exiskip = expAdd = exiAdd = false;
		var prop = item.getProperties("target","onclick","Class");
		if(this.options.ImagetypeIcon==true){this.media.extend(["jpg","gif","png"]);}
		//Skip
		if(item.hasClass("icoSkip")||item.hasClass("jbiwnjtorzbrnezsjqya")){icoskip = true;}
		if(item.hasClass("exiSkip")||prop.target||(prop.onclick&&prop.onclick.indexOf("window.open")!==-1)||item.hasClass("jbiwnjtorzbrnezsjqya")){exiskip = true;}
		//Add
		if(item.hasClass("expAdd")){expAdd = true;}
		if(item.hasClass(this.addExI)){exiAdd =true;}
		//excludeString Check
		var exclude = this.exStr.some(function(str){ if(h.indexOf(str) !== -1) return true; })+$chk(h.match(/\.gif$|\.png$|\.jpg$|\.doc$|\.psd$|\.zip$|\.xls$|\.ai$|\.exe$|^mailto:|window\.print\(\)/));
		//Images Link
		if(t=="jpg"||t=="gif"||t=="png"){
			if(this.QuickBox===true){
				icoskip = true; self.addArgs(1,item);
			//Pict only & QuickBox OFF
			}else if (txt=="" && this.QuickBox===false){
				icoskip = true;self.addArgs(0,item);
			}else if(this.QuickBox===false){//
				self.addExternal(item);
			}
		}else if(!exiskip){
			//Add External
			if(!exiskip&&expAdd||expAdd){
				self.addArgs(2,item);
			}else{
				if(t=="txt"||t=="pdf"||t=="swf"||t=="mpg"||t=="mp3"||(h!="" && !exclude &&pct.length==0)||exiAdd){
					self.addExternal(item);
				}else if((txt!= ""&&pct.length!=0&& h!=""&& !exclude)||(txt==""&& pct.length!=0 &&h!=""&& !exclude)){
					self.addArgs(2,item);
				}
			}
		}
		//Add Filetype Icon
		if(!icoskip && this.FtI == true){
			if(prop.Class&&prop.Class.indexOf("icoAdd")!==-1){
				var n = prop.Class.slice(7);
				self.createIcon(n.toLowerCase(),n.toUpperCase() + " File").inject(item,"before");
			}
			//AddIconType Array Check
			if (this.media.contains(t)) {
				if(t.slice(0, 1)=="."){t=t.replace(".", "");}//2length Name
				self.createIcon(t,t.toUpperCase() + " File").inject(item,"before");
			}else if(item.protocol=="mailto:"){
				self.createIcon("email","Mail").inject(item,"before");
			}else if(item.protocol==="https:"){
				self.createIcon("https","SSL Page").inject(item,"before");
			}else if(h=="javascript:window.print()"){
				self.createIcon("print","Print").inject(item,"before");
			}
		}
	}
});
