$(document).ready(function() {	
	activeItem = $('nav').attr('name');
	divBG();
	Menutree();
	activeMenu();
	randBG(".$numero.");
	alternateBG();
})
function hideSubnav(){
	$('#mNav .subnav').hide();
}
function divBG() {
	if($('body').hasClass('singleBg')) {
		$('body').css('background', 'url(../img/bg/'+activeItem+'/bg0.jpg) no-repeat center center')
	} else {		
		$('body').append('<div class="bg" id="bg1"></div><div class="bg" id="bg2"></div>')
	}
}
function Menutree(){
	$('a.subin').click(function(){
		hideSubnav();
		Desloc();
		$(this).siblings('.subnav').fadeIn('slow');
		return false;
	})
}
function Desloc(){
	var msection = $('#sMain');
	$(msection).animate({ left: '395px'}, 1000, function() {
    // Animation complete.
  });
}
function activeMenu(){
	$('#'+activeItem).addClass('active')
}


function randBG(numBg){
	var numRand=Math.floor(Math.random()*numBg)
	$('.container').css('background','url(../img/bg/'+activeItem+'/bg'+numRand+'.jpg)')
}

function randBG(){
	var thehost = window.location.host;
	$('#bg1').css('backgroundImage','url(http://'+thehost+'/img/bg/'+activeItem+'/bg1.jpg)');
	$('#bg2').css('backgroundImage','url(http://'+thehost+'/img/bg/'+activeItem+'/bg0.jpg)');
}

function alternateBG() {
	var elem = $('#bg2');

window.setInterval( function(){
	if(elem.css('display')=='none'){
		elem.fadeIn('slow');
	}else{
		elem.fadeOut('slow');
	};
}, 3000 );

}



