// JavaScript Document

// IE ANCHOR BG CACHE

var version = navigator.appVersion;
version = version.substring(0,1);
var browser = navigator.appName;

if (browser =="Microsoft Internet Explorer"){
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch(e) {}
}

// FOCUS INPUT
var colorful = new ColorfulInput;
colorful.skip = ['submit'];
colorful.color['focus'] = '#F7F9F5';

window.onload = function() {
   colorful.set();
}

function ColorfulInput() {
   this.skip  = [];
   this.color = { 'blur': '', 'focus': '#F7F9F5' };

   this.set = function() {
      for (var i = 0; i < document.forms.length; i++) {
         for (var f = 0; f < document.forms[i].length; f++) {
            var elm = document.forms[i][f];
            if(!this._checkSkip(elm)) continue;

            this._setColor(elm, 'focus');
            this._setColor(elm, 'blur');
         }
      }
   }

   this._checkSkip = function(elm) {
      for(var i in this.skip) {
         if(elm.type == this.skip[i]) return false;
      }
      return true;
   }

   this._setColor = function(elm, type) { 
      var color = this.color[type];
      var event = function() { elm.style.backgroundColor = color; };

      if(elm.addEventListener) {
         elm.addEventListener(type, event, false);
      } else if(elm.attachEvent) {
         elm.attachEvent('on'+type, event);
      } else {
         elm['on'+type] = event;
      }
   }
}

// OPEN WINDOW
function openwin(url) {
 memo = window.open(url, 'memo','width=540,height=600,scrollbars=yes,resizable=yes');
 memo.focus();
}

//PRINT COUPON
function printCoupon(){
	if (navigator.appName == "Microsoft Internet Explorer") {
		if(window.ActiveXObject == null || document.body.insertAdjacentHTML == null) return;
			var sWebBrowserCode = '<object width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>'; 
			document.body.insertAdjacentHTML('beforeEnd', sWebBrowserCode); 
			var objWebBrowser = document.body.lastChild;
		if(objWebBrowser == null) return;
			objWebBrowser.ExecWB(7, 1);
			document.body.removeChild(objWebBrowser);
	} else {
		window.print();
	}
}



// ALPHA PNG IE

/*--------------------------------------------------------------------------*
 *  
 *  alphafilter JavaScript Library beta3
 *  
 *  MIT-style license. 
 *  
 *  2007 Kazuma Nishihata 
 *  http://www.webcreativepark.net
 *  
 *--------------------------------------------------------------------------*/

new function(){

	if(window.addEventListener){
		window.addEventListener('load',alphafilter,false);
	}else if(window.attachEvent){
		window.attachEvent('onload',alphafilter);
	}
	
	function alphafilter(){
		if (typeof document.body.style.maxHeight == "undefined") {//for old ie
			var elements = getElementsByClassName("alphafilter");
			for (var i=0; i<elements.length; i++) {
				var element = elements[i];
				if(element.nodeName=="IMG"){
					var newimg           = document.createElement("b");
					newimg.id            = element.id;
					newimg.className     = element.className;
					newimg.style.display = "block";
					newimg.style.width   = element.width;
					newimg.style.height  = element.height;
					newimg.style.float   = element.align;
					newimg.style.filter  = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+element.src+",sizingMethod='scale')";
					element.parentNode.replaceChild(newimg,element);
				}else{
					var anchors = element.getElementsByTagName("a");
					for (var j=0; j<anchors.length; j++) {
						var anchor = anchors[j];
						anchor.style.position="relative";
					}
					var  newimg = element.currentStyle.backgroundImage || element.style.backgroundImage;
					newimg.match(/^url[("']+(.*\.png)[)"']+$/i)
					var newimg = RegExp.$1;
					element.style.filter ="progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+newimg+",sizingMethod='image')";
					element.style.background = "none";
				}
			}
		}
	}
	
	function getElementsByClassName(className){
		var i, j, eltClass;
		var objAll = document.getElementsByTagName ? document.getElementsByTagName("*") : document.all;
		var objCN = new Array();
		for (i = 0; i < objAll.length; i++) {
			eltClass = objAll[i].className.split(/\s+/);
			for (j = 0; j < eltClass.length; j++) {
				if (eltClass[j] == className) {
					objCN.push(objAll[i]);
					break;
				}
			}
		}
		return objCN;
	}
}

/*
 * yuga.js 0.1.0
 *
 * Copyright (c) 2006 Kyosuke Nakamura (kyosuke.jp)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Since:     2006-10-30
 * Modified:  2006-11-15

*/

// YUGA JS

var yuga = {
	preloader: {
		loadedImages: [],
		load: function (url){
			var img = this.loadedImages;
			var l = img.length;
			img[l] = new Image();
			img[l].src = url;
			}
	},
	uri: {
		dirName: function(uri){
			var ary = uri.split('/');
			ary.pop();
			return ary.join('/');
		},
		path: function (uri){
			return uri.split('#')[0];
		},
		anchorName: function (uri){
			return uri.split('#')[1];
		},
		isSelfLink: function(href){
			return ((this.path(href) == this.path(location.href)) || (this.path(href) == this.dirName(location.href)+'/') || (this.path(href) == this.dirName(location.href)));
		}
	}
};


$(function(){
	//ROLLOVER IMAGE
	$('a img.roll_over').each(function(){
		this.originalSrc = this.src;
		this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, "_on$1");
		yuga.preloader.load(this.rolloverSrc);
	}).hover(function(){
		this.src = this.rolloverSrc;
	},function(){
		this.src = this.originalSrc;
	});

	//NOW PAGE IMAGE
	$('#contents a').each(function(){
		if (yuga.uri.isSelfLink(this.href) && !yuga.uri.anchorName(this.href)) {
			$(this).addClass('current');
			$(this).find('img').each(function(){
				$(this).unbind('mouseover');
				$(this).unbind('mouseout');
				this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_on$1");
				this.src = this.currentSrc;
			});
		}
	});

	//OTHER SITES BLANK WINDOW
	$('a[@href^="http://"]').not('[@href^="http://localhost/"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	}).addClass('externalLink');

	//EASING SCROLL PAGE ANCHOR
	$('a[@href^="#"]').click(function(){
		var href = yuga.uri.anchorName(this.href);
		$('#'+href).ScrollTo(800,'easeout');
		return false;
	});
});
