if(!window.asBirds) window.asBirds = {};

(function(jQuery){
	
	jQuery.fn.tab = function(options){
		var targets = [];
		return this.each(function(){ 
			var s = this;
			
			s.opts = jQuery.extend({
				currentIndex : 0,
				classNames : {
					tab : 'tab',
					tabActive : 'tab_active',
					content : 'tab_content'
				}
			}, options);
			s.tabs = $(this).find('.' + s.opts.classNames.tab);
			s.tab_contents = $(this).find('.' + s.opts.classNames.content);
			
			var size = s.tabs.length;
			
			for(var i = 0; i < size; i++){
				var tabs = s.tabs;
				var tab = s.tabs.get(i);
				var tab_contents = s.tab_contents;
				var tab_content = s.tab_contents.get(i);
				var opts = s.opts;
				tab.index = i;
				$(s.tab_contents.get(i)).hide();
				$(tab).click(function(e){
					for(var j = 0; j < size; j++){
						$(tab_contents.get(j)).hide();
					}
					$(tabs.get(opts.currentIndex)).parent().removeClass(opts.classNames.tabActive);
					$(tab_contents.get(opts.currentIndex)).hide();
					opts.currentIndex = this.index;
					$(this).parent().addClass(opts.classNames.tabActive);
					$(tab_contents.get(opts.currentIndex)).show();
					//console.log($(tab_contents.get(opts.currentIndex)).height())
					$('#main').css('display', 'none')
					$('#main').css('display', 'block')
					return false;
				})
			}
			var index = 0;
			if(window.location.hash != ""){
				for(var i = 0; i < size; i++){
					var tab = s.tabs.get(i);
					if($(tab).attr('href') == window.location.hash){
						index = i;
						break;
					}
				}
			}
			if(i == size) i = 0;
			s.opts.currentIndex = index;
			$(s.tabs.get(s.opts.currentIndex)).parent().addClass(s.opts.classNames.tabActive);
			$(s.tab_contents.get(s.opts.currentIndex)).show();
			//$('#copyright').css('bottom', '0');
		});
	}
	
	
	asBirds.setNaviAnimation = function(){
		$("#menu .gl-nav").each(function(index, element) {
			if(!$(element).hasClass('selected')){
				var m_height = $(element).height();
				$(element).hover(
				 function(e){
					  $(element).animate({height:(m_height+75)+'px'},100);	 
				},
				 function(e){
					  $(element).animate({height:m_height+'px'},100);
				}
				)
			}
		});
		$(".m6").each(function(index, element) {
			if(!$(element).hasClass('selected')){
				var m_height =-106;
				$(element).hover(
				 function(e){
					  $(element).animate({top:(m_height+75)+'px'},100);	 
				},
				 function(e){
					  $(element).animate({top:m_height+'px'},100);
				}
				)
			}
		});
	}
	
	
	asBirds.initialize = function(){
		this.setNaviAnimation();
	}
	
	$(document).ready(function(e) {
		asBirds.initialize();
		
		$('#main').tab({
			classNames : {
				tab : 'tab',
				tabActive : 'tab_active',
				content : 'tab_content'
			}
		});
		
		$('#main').tab({
			currentIndex : 0,
			classNames : {
				tab : 'tab-history',
				tabActive : 'tab-history_active',
				content : 'tab-history_content'
			}
		});
	});
	
})(jQuery);
