var od = {w: 0, cw: [], bp: '', margin: {left: ''}}
var ch;
var cl

$(document).ready(function()
{
	$('a[rel="external"]').click(function(i){
		window.open(this.href);
		return false;
	});
	
	var tabBtm;
	var tabTemp = null;
	var tgBtm = 0;
	$('#bottom .header h4').click(function()
	{
		tabTemp = tabBtm;

		tabBtm = $(this).parents('.tab').index();


		if(tgBtm == 1 && tabTemp == tabBtm)
		{
			tgBtm = 0;

			$('#bottom').animate({'height': '0px', 'margin-top': '-30px'}, {duration: 400, complete: function()
				{
					$('#superbarman, #btm-menu').removeClass('active');
				}
			});
		}
		else
		{
			tgBtm = 1;

			$('#bottom').animate({'height': '160px', 'margin-top': '-190px'}, 400);


			if(tabBtm == 0)
			{
				$('#superbarman').addClass('active');
				$('#btm-menu').removeClass('active');
			}

			if(tabBtm == 1)
			{
				$('#btm-menu').addClass('active');
				$('#superbarman').removeClass('active');
			}
		}
	});
	
	ch = $('#btm-menu .wrapper').children()
	cl = ch.length;
	od.w = $('#btm-menu .wrapper').width()
	//od.bp = $('#btm-menu .wrapper').css('background-position')
	od.margin.left = $('#btm-menu .wrapper').css('margin-left')
	
	for(i=0;i<cl;i++)
	{
		od.cw.push($(ch[i]).width())
	}
	onResize()
});

$(window).resize(onResize)

function onResize(){

	var gap = 50
	var w = $(this).width()-gap
	var wp = (w)/cl-30
	
	if(w > 1000)
	{
		$('#btm-menu .wrapper').width(w)
		//$('#bottom .w1').css('margin-left', gap+50)
		//$('#btm-menu .wrapper').css('background-position', wp+'px 0px')
		for(i=0;i<cl;i++)
		{
			if(i==cl-1)
				$(ch[i]).width(wp-80)
			else
				$(ch[i]).width(wp+20)
		}
	}
	else
	{
		$('#btm-menu .wrapper').width(od.w)
		//$('#bottom .w1').css('margin-left', od.margin.left)
		//$('#btm-menu .wrapper').css('background-position', od.bp)
		for(i=0;i<cl;i++)
		{
			$(ch[i]).width(od.cw[i])
		}
	}
	
	
}
