﻿
/**
* 메뉴시스템 클래스
* 작성자 : 홍준수 ( huchi001@seedpost.co.kr )
*
* ex ) var topMenu = new menuSet ( $(".tab_exp" ) );
*	   topMenu.onClick = function ( num )
		{
			alert ( num );
		}
*/

/*
<ul class="tab_exp">
	<li><img src="images/expImages/tab_exp_1on.gif" alt="" /><div><img class="tab_exp_img" src="images/expImages/tab_exp_1off.gif" alt="" /></div></li>
	<li><img src="images/expImages/tab_exp_2on.gif" alt="" /><div><img class="tab_exp_img" src="images/expImages/tab_exp_2off.gif" alt="" /></div></li>
	<li><img src="images/expImages/tab_exp_3on.gif" alt="" /><div><img class="tab_exp_img" src="images/expImages/tab_exp_3off.gif" alt="" /></div></li>
	<li><img src="images/expImages/tab_exp_4on.gif" alt="" /><div><img class="tab_exp_img" src="images/expImages/tab_exp_4off.gif" alt="" /></div></li>
	<li><img src="images/expImages/tab_exp_5on.gif" alt="" /><div><img class="tab_exp_img" src="images/expImages/tab_exp_5off.gif" alt="" /></div></li>
	<li><img src="images/expImages/tab_exp_6on.gif" alt="" /><div><img class="tab_exp_img" src="images/expImages/tab_exp_6off.gif" alt="" /></div></li>
</ul>
*/

function menuSet ( container , active )
{
	this.container = container;
	this.interval;

	if ( active == undefined ) 
	{
		this.active = true;
	}
	else
	{
		this.active = active;
	}

	this.OVER = -1;
	this.menuMake();
}

menuSet.prototype.setOVER = function ( num )
{
	this.OVER = num;
	this.menuCheck( this.OVER );
}

menuSet.prototype.tempOVER = function ( num )
{
	this.menuCheck( num );
}

menuSet.prototype.tempOUT = function ( num )
{
	this.menuCheck( num );
}

menuSet.prototype.menuMake = function()
{
	var owner = this;

	this.container.find ( "li div").css ( { opacity:0 , cursor:"pointer" } );
	this.container.mouseover ( over ).mouseout ( out ).click ( click );

	function over ( e )
	{
		if ( $(e.target).attr ( "class" ) == owner.container.attr("class") ) return;
		var index = $(e.target).parent().parent().index();
		owner.menuCheck( index );
		if ( owner.onOver ) owner.onOver ( index );			
	}

	function out ( e )
	{
		if ( $(e.target).attr ( "class" ) == owner.container.attr("class") ) return;

		var index = $(e.target).parent().parent().index();
		owner.menuCheck( owner.OVER );
		if ( owner.onOut ) owner.onOut ( owner.OVER );
	}

	function click ( e )
	{
		if ( $(e.target).attr ( "class" ) == owner.container.attr("class") ) return;

		var index = $(e.target).parent().parent().index();
		if ( owner.active == true ) owner.OVER = index;
		owner.menuCheck( owner.OVER );
		owner.onClick ( index );
	}
}

menuSet.prototype.menuCheck = function ( num )
{
	this.container.find ( "li div" ).each ( function ( i )
	{
		var opa = ( i == num ) ? 1 : 0;
		$(this).stop().animate ( { opacity:opa } , 250 );
	} );
}












