// -------------------------------- //
//				variables
// -------------------------------- //
var imgArrayOff = [];
var imgArrayOn = [];


// -------------------------------- //
//				constructor
// -------------------------------- //
$(window).load(function() {
	tab.init();
});

$(document).ready(function(){
	tab.change();
	tab.showList();
});


// -------------------------------- //
//				functions
// -------------------------------- //


var tab = {
	
	// settings //	
	init: function() {
		
		var liNum = $('#tabNav li').length;
		
		// create array
		$('#tabNav li').each(function(i){
			var obj = this;
			var el = obj.childNodes;
			
			imgArrayOff.push([el[0].firstChild.getAttribute('src'),obj]);
			imgArrayOn.push(el[0].firstChild.getAttribute('src').replace('_n','_a'));
		});
		
		// create ID
		$('#tabNav li').each(function(i){			
			$(this).attr('id','tab_' + (i+1));
		});
		
		$('#tabCnt blockquote').each(function(i){
			$(this).attr('id','box_' + (i+1));
		});
		
		for(var i=1; i<liNum+1; i++) {
			
			if(i == 1){
				
				$('#tab_'+ i).click();

			}
			
		}

	},
	
	// change //
	change: function() {	
	
		$('#tabNav li').click(function(){
			
			var myTab = this;
			var myChild = this.childNodes;
			var liNum = $('#tabNav li').length;
			var index = this.id.substr(4);
								
				for(var i=1; i<liNum+1; i++) {
					
					if(i != index) {
						var obj = imgArrayOff[i-1][1].childNodes;
						
						obj[0].firstChild.setAttribute('src',imgArrayOff[i-1][0]);
						$('#tab_'+ i).removeClass('activeTab');
						$('#box_'+ i).removeClass('on');
						$('#box_'+ i).animate({opacity: 0}, 300);
						
					}
					
				}
				
				myChild[0].firstChild.setAttribute('src',imgArrayOn[index-1]);
				$('#tab_'+ index).addClass('activeTab');
				$('#box_'+ index).addClass('on');
				$('#box_'+ index).animate({opacity: 1}, 800);
				
				return false;

		});
	},
	
	// change //
	showList: function() {	
	
		$('#tabNav li span a').click(function(){
			
			var myTarget = this;
			var myLink = myTarget.getAttribute('href');
			
			if(myLink != '#' || ''){
				location.href = myLink;
			}
			
			return false;
			
		});
	}
			
}
