/*  TAD JavaScript , version 0.1.0
 *  (c) 2008 Pioneer Design Corporation.
 *
 *  TAD Menu 
 *
/*--------------------------------------------------------------------------*/
var TAD = {
	
	Version	:	"0.1.0",
	Copyright	:	"Pioneer Design Corporation.",
	Author	:	"Pioneer Design Corporation. Web Group S.N",

	feedTimer          : new Array(),
	feedInId           : -1,
	feedOutId          : -1,
	feedOutId_wk       : -1,
	feedObj            : new Array(),
	timeout_id         : null,
	interval_id        : -1,
	interval_out_id    : -1,
	Anchor			   : null,
	wait			   : null,
	
	// Initialization
		init : function () { 
			
			// set div id.
				var ids = new Array(
					"hn_products_menu",
					"hn_prounits_menu"
				);

			// var menu <a>
				// Anchor name & rollover position
				this.Anchor = new Array(
					new Array("hn_products_a",'0 0','0 -76px'),
					new Array("hn_prounits_a",'-377px 0','-377px -76px')
				);

			for ( i=0; i<ids.length; i++ ){

				// Set Object
					var div  = document.getElementById(ids[i]);

				// Set alpha
					var opacity = 0;
					div.style.filter = 'alpha(opacity=' + opacity + ')';  // use Internet Explorer
					var non_ie_opacity = 0;
					div.style.mozOpacity = non_ie_opacity;	// use FireFox
					div.style.opacity = non_ie_opacity;		// use Safari
					div.style.zIndex = i;

				// Release Object
					this.feedObj[i] = div;
					this.feedObj[i]["alpha"] = 0;
					this.feedObj[i]["speed"] = 5;
					this.feedObj[i]["time"] = 40;
					this.feedObj[i]["interval_id"] = -1;
					this.feedObj[i]["feedinEnd"] = false;
					this.feedObj[i]["mode"] = "";
					this.feedObj[i].style.display = "none";

			}

			setBG();

		},

	// main
		enterFrame	:	function(){
			var non_count=0;			
			for ( var i=0; i<this.feedObj.length; i++ ){
				
				if ( this.feedObj[i]["mode"] == "feedin" ) {
					$(this.Anchor[i][0]).style.backgroundPosition = this.Anchor[i][2]; 
					TAD.run_feedin(i);
				} else if ( this.feedObj[i]["mode"] == "feedout" ) {
					$(this.Anchor[i][0]).style.backgroundPosition = this.Anchor[i][1]; 
					TAD.run_feedout(i);
				} else {
					non_count++;
				}
			}

			if ( non_count >= this.feedObj.length ) {
				clearInterval(this.interval_id);
				this.interval_id = -1;
			}

		},


	// FeedIn
		start_feedin  : function(no) {

			this.feedObj[no].style.display = "block";
			this.getHighDepth(no);
			this.feedObj[no]["mode"] = "feedin";

			if ( this.interval_id == -1 ) {
				this.interval_id = setInterval("TAD.enterFrame()",this.feedObj[no]["time"]);
			}

		},
	
		run_feedin : function (i) {

//			if ( this.feedInId >= 0 ) {
			if ( this.feedObj[i]["mode"] == "feedin" ) {

//				var i = this.feedInId;

				if( this.feedObj[i] ) {

					var opacity = this.feedObj[i]["alpha"];
					this.feedObj[i].style.filter = 'alpha(opacity=' + opacity + ')';  // Internet Explorer用
					var non_ie_opacity = 0;
					if (opacity != 0 ){
						non_ie_opacity = opacity / 100;
					}
					this.feedObj[i].style.mozOpacity = non_ie_opacity;              // FireFox用
					this.feedObj[i].style.opacity = non_ie_opacity;                 // Safari用

					if( this.feedObj[i]["alpha"] < 100 ) {
						this.feedObj[i]["alpha"] += parseInt(this.feedObj[i]["speed"]);
					} else if ( this.feedObj[i]["alpha"] >= 100) {

						this.feedObj[i]["alpha"] = 100;
						this.feedObj[i]["feedinEnd"] = true;
						this.feedObj[i]["mode"]  ="";

						if ( this.feedOutId == -1 ) {
//							clearInterval(this.feedObj[i]["interval_id"]);
//							this.feedObj[i]["interval_id"] = -1;
						}
					}

				} else {
					return;
				}

			} 

		},

	// FeedOut
		start_feedout  : function(no) {

			this.feedObj[no].style.display = "block";
			this.feedObj[no]["mode"] = "feedout";

			if ( this.interval_id == -1 ) {
				this.interval_id = setInterval("TAD.enterFrame()",this.feedObj[no]["time"]);
			}

		},

		run_feedout : function (i) {

//			if ( this.feedOutId >= 0 ) {
			if ( this.feedObj[i]["mode"] == "feedout" ) {

//				var i = this.feedOutId;

				if( this.feedObj[i] ) {
					var opacity = this.feedObj[i]["alpha"];
					this.feedObj[i].style.filter = 'alpha(opacity=' + opacity + ')';  // Internet Explorer用
					var non_ie_opacity = 0;
					if (opacity != 0 ){
						non_ie_opacity = opacity / 100;
					}
					this.feedObj[i].style.mozOpacity = non_ie_opacity;              // FireFox用
					this.feedObj[i].style.opacity = non_ie_opacity;                 // Safari用

					if( this.feedObj[i]["alpha"] > 0 ) {
						this.feedObj[i]["alpha"] -= parseInt(this.feedObj[i]["speed"]);
					} else if ( this.feedObj[i]["alpha"] <= 0) {

						this.feedObj[i]["mode"]  ="";
					}
				} else {
					return;
				}

			}

		},

	// getHighDepth()
		getHighDepth : function(elm) {

			var depth = "";
			var idx="";

			for( var i=0; i<this.feedObj.length; i++ ) {

				var wk = this.feedObj[elm].style.zIndex;
				var wk2 = this.feedObj[i].style.zIndex;

				if ( wk < wk2 ) {
					var z = this.feedObj[elm].style.zIndex;
					this.feedObj[elm].style.zIndex = wk2;
					this.feedObj[i].style.zIndex = z;
				}
			}

		}

}


function setBG() {


	var home_img = new Array(
		"url(./img/home_img2.jpg)",
		"url(./img/home_img3.jpg)",
		"url(./img/home_img4.jpg)",
		"url(./img/home_img5.jpg)"
	);

	var home_contents_img = new Array(
		"url(./img/home_contents_img2.jpg)",
		"url(./img/home_contents_img3.jpg)",
		"url(./img/home_contents_img4.jpg)",
		"url(./img/home_contents_img5.jpg)"
	);

	rnd = Math.floor(Math.random() * home_img.length);
	
	$("home_img_inner").style.backgroundImage = home_img[rnd];
	$("home_contents").style.backgroundImage = home_contents_img[rnd];

}


