$(function(){
	$('.main_menu').children('ul').children('li').each(function(){
		$(this).mouseover(function(){
			$(this).children('.main_menu_bg').addClass('main_menu_bg_over');
			$(this).children('.main_menu_bg').children('.main_menu_text').addClass('main_menu_text_over');
			$(this).children('.main_menu_bg').children('.main_menu_icon').addClass('main_menu_icon_over');
			if ($(this).children('.main_menu_bg').children('.sub_menu').text()) {
				//$(this).children('.main_menu_bg').children('.sub_menu').animate({ 'width' : '200px' }, 1000);
				main_menu_anim_open(this);
			}

		}).mouseout(function(){
			$(this).children('.main_menu_bg').removeClass('main_menu_bg_over');
			$(this).children('.main_menu_bg').children('.main_menu_text').removeClass('main_menu_text_over');
			$(this).children('.main_menu_bg').children('.main_menu_icon').removeClass('main_menu_icon_over');
			if ($(this).children('.main_menu_bg').children('.sub_menu').text()) {
				//$(this).children('.main_menu_bg').children('.sub_menu').animate({ 'width' : '200px' }, 1000);
				main_menu_anim_close(this);
			}
		});
	});
	$('#div_demo_link').css({'background-color':'#000000','opacity':.70});

	$('.main_bar').each(function(){
		$(this).css('opacity',.75);
		$(this).mouseover(function(){
			$(this).css('opacity',.9);
		}).mouseout(function(){
			$(this).css('opacity',.75);
		
		});
	});
	$('#main_bar_close').click(function(){
		$(this).parent().fadeOut(100);
	});

});

function main_menu_anim_open(o) {
	$('.main_menu').children('ul').children('li').each(function(){
		if (this == o) {
			$(this).stopTime().everyTime(100,function(){
				anim(this,446,0.75,'width');
				anim($(this).children('.main_menu_bg').children('.main_menu_text'),32,0.75,'left');
				anim($(this).children('.main_menu_bg').children('.sub_menu'),380,0.75,'width');
			});
		} else {
			$(this).stopTime().everyTime(100,function(){
				anim(this,106,0.75,'width');
				$(this).children('.main_menu_bg').children('.main_menu_text').css('left',"50%");
				anim($(this).children('.main_menu_bg').children('.sub_menu'),0,0.8,'width');

			});
		}
	});
}
function main_menu_anim_close(o) {
	$('.main_menu').children('ul').children('li').each(function(){
		$(this).stopTime().everyTime(100,function(){
			if ($(this).hasClass('main_menu_home')) {
				anim(this,165,0.75,'width');
			} else {
				anim(this,163,0.75,'width');
			}
			$(this).children('.main_menu_bg').children('.main_menu_text').css('left',"50%");
			anim($(this).children('.main_menu_bg').children('.sub_menu'),0,0.8,'width');

		});
	});
}

function anim(obj,set,k,axis) {
	var now = parseInt($(obj).css(axis));
	var val = now + Math.round(( set - now ) * k);
	$(obj).css(axis,val+"px");
	if (Math.abs(val-set) < 1) { $(obj).stopTime().css(axis,set+"px"); }
}

