/*---------------------------------------------------------------
-----------------------------------------------------------------
msn-prius javascript
-----------------------------------------------------------------

.ブラウザチェック
.イベント割り当て関数
.スクロールイベント
.minmax.js: make IE5+/Win support CSS min/max-width/height

-----------------------------------------------------------------
---------------------------------------------------------------*/

/*=================================================================
//
// .ブラウザチェック
//
=================================================================*/
function BrowserCheck(){
		var b = navigator.appName;
		if (b == "Netscape") this.b = "NN";
		else if (b == "Microsoft Internet Explorer") this.b = "IE";
		else this.b = b;
		this.version = navigator.appVersion;
		this.vSub = navigator.vendorSub;
		this.userAgent = navigator.userAgent;
		this.appVersion = navigator.appVersion;
		this.v = parseInt(this.version);
		this.vs = parseFloat(this.vSub);
		
		this.NN = (this.b == "NN");
		this.NN3 = (this.b == "NN" && this.v == 3);
		this.NN4 = (this.b == "NN" && this.v == 4);
		this.NN6x = (this.b == "NN" && this.v == 5 && this.vs >= 6.01);
		this.NN6 = (this.b == "NN" && this.v == 5);
		this.NN7 = (this.b == "NN" && this.v == 5 && this.vs >= 7);
		
		this.IE = (this.b == "IE");
		this.IE3 = (this.userAgent.indexOf('MSIE 3')>0);
		this.IE45 = (this.userAgent.indexOf('MSIE 4.5')>0);
		this.IE401 = (this.userAgent.indexOf('MSIE 4.01')>0);
		this.IE4 = (this.userAgent.indexOf('MSIE 4')>0);
		this.IE51 = (this.userAgent.indexOf('MSIE 5.1')>0);
		this.IE512 = (this.userAgent.indexOf('MSIE 5.12')>0);
		this.IE514 = (this.userAgent.indexOf('MSIE 5.14')>0);
		this.IE52 = (this.userAgent.indexOf('MSIE 5.2')>0);
		this.IE5 = (this.userAgent.indexOf('MSIE 5')>0);
		this.IE6 = (this.userAgent.indexOf('MSIE 6')>0);
		this.IE7 = (this.userAgent.indexOf('MSIE 7')>0);
		this.IE8 = (this.userAgent.indexOf('MSIE 8')>0);
		
		this.GEK = (this.userAgent.indexOf("Gecko") != -1);
		this.SAF = (this.userAgent.indexOf("Safari",0) != -1);
		this.FF = (this.userAgent.indexOf("Firefox") != -1);
		this.GC = (this.userAgent.indexOf("Chrome") != -1);
		this.CAB = (this.userAgent.indexOf("iCab",0) != -1);
		this.OPE = (this.userAgent.indexOf("Opera",0) != -1);
		
		this.Win = (this.userAgent.indexOf('Win',0) != -1);
		this.Mac = (this.userAgent.indexOf('Mac',0) != -1);
		this.MacOSX = (this.userAgent.indexOf('Mac OS X',0) != -1);
		if(this.IE512 || this.IE52){
			this.MacOSX=true;
		}
		else if(this.IE514){
			if (navigator.plugins) {
				for (i=0; i < navigator.plugins.length; i++ ) {
					if (navigator.plugins[i].name.indexOf('QuickTime') >= 0 && navigator.plugins[i].filename.indexOf('.plugin')!=-1){
						this.MacOSX=true;
					}
				}
			}
		}
		this.Unix = (this.appVersion.indexOf('X11',0) != -1);
}

var checkB = new BrowserCheck();
//window.alert(checkB.IE52);

/*=================================================================
//
// .イベント割り当て関数
//
=================================================================*/
function addEvent(elm, evType, func, useCapture) {
	if(elm.addEventListener){
		elm.addEventListener(evType, func, useCapture);
		return true;
	} else if(elm.attachEvent){
		var r = elm.attachEvent('on' + evType, func);
		return r;
	} else {
		elm['on' + evType] = func;
	}
}

/*=================================================================
//
// .Open Window
//
=================================================================*/
function externalLinks() {
	if(!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for(var i=0; i<anchors.length; i++){
		var anchorlink = anchors[i];
		if(anchorlink.getAttribute("href") && anchorlink.getAttribute("rel") == "external"){
			anchorlink.target = "_blank";
		}
	}
}

addEvent(window, 'load', externalLinks, false);


/*
 * IE PNG Fix v1.4
 *
 * Copyright (c) 2006 Takashi Aida http://www.isella.com/aod2/
 *
 */

// IE5.5+ PNG Alpha Fix v1.0RC4
// (c) 2004-2005 Angus Turnbull http://www.twinhelix.com

// This is licensed under the CC-GNU LGPL, version 2.1 or later.
// For details, see: http://creativecommons.org/licenses/LGPL/2.1/

if (typeof IEPNGFIX == 'undefined') {
//--============================================================================

var IEPNGFIX = {
	blank:  'http://www.isella.com/aod2/images/blank.gif',
	filter: 'DXImageTransform.Microsoft.AlphaImageLoader',

	fixit: function (elem, src, method) {
		if (elem.filters[this.filter]) {
			var filter = elem.filters[this.filter];
			filter.enabled = true;
			filter.src = src;
			filter.sizingMethod = method;
		}
		else {
			elem.style.filter = 'progid:' + this.filter +
				'(src="' + src + '",sizingMethod="' + method + '")';
		}
	},

	fixwidth: function(elem) {
		if (elem.currentStyle.width == 'auto' &&
			elem.currentStyle.height == 'auto') {
			elem.style.width = elem.offsetWidth + 'px';
		}
	},

	fixchild: function(elem, recursive) {
		if (!/MSIE (5\.5|6\.|7\.)/.test(navigator.userAgent)) return;

		for (var i = 0, n = elem.childNodes.length; i < n; i++) {
			var childNode = elem.childNodes[i];
			if (childNode.style) {
				if (childNode.style.position) {
					childNode.style.position = childNode.style.position;
				}
				else {
					childNode.style.position = 'relative';
				}
			}
			if (recursive && childNode.hasChildNodes()) {
				this.fixchild(childNode, recursive);
			}
		}
	},

	fix: function(elem) {
		if (!/MSIE (5\.5|6\.|7\.)/.test(navigator.userAgent)) return;

		var bgImg =
			elem.currentStyle.backgroundImage || elem.style.backgroundImage;

		if (elem.tagName == 'IMG') {
			if ((/\.png$/i).test(elem.src)) {
				this.fixwidth(elem);
				this.fixit(elem, elem.src, 'scale');
				elem.src = this.blank;
				elem.runtimeStyle.behavior = 'none';
			}
		}
		else if (bgImg && bgImg != 'none') {
			if (bgImg.match(/^url[("']+(.*\.png)[)"']+$/i)) {
				var s = RegExp.$1;
				this.fixwidth(elem);
				elem.style.backgroundImage = 'none';
				this.fixit(elem, s, 'scale'); // crop | image | scale

				if (elem.tagName == 'A' && elem.style) {
					if (!elem.style.cursor) {
						elem.style.cursor = 'pointer';
					}
				}

				this.fixchild(elem);
				elem.runtimeStyle.behavior = 'none';
			}
		}
	},

	hover: function(elem, hvImg) {
		var bgImg = elem.style.backgroundImage;

		if (!bgImg && elem.currentStyle) bgImg = elem.currentStyle.backgroundImage;

		if (elem.tagName == 'IMG' && hvImg) {
			var image = elem.src;
			elem.onmouseover = function() {
				elem.src = hvImg;
				IEPNGFIX.fix(elem);
			};
			elem.onmouseout = function() {
				elem.src = image;
				IEPNGFIX.fix(elem);
			};
		}
		else if (bgImg && bgImg != 'none' && hvImg) {
			elem.onmouseover = function() {
				elem.style.backgroundImage = 'url(' + hvImg + ')';
				IEPNGFIX.fix(elem);
			};
			elem.onmouseout = function() {
				elem.style.backgroundImage = bgImg;
				IEPNGFIX.fix(elem);
			};
		}

		IEPNGFIX.fix(elem);
	}
};

//--============================================================================
} // end if (typeof IEPNGFIX == 'undefined')
