$(document).ready(function() {
	banners();
	setInterval('banners()', 16*1000);

	$("#top").click(function() {
		$('html').animate({scrollTop:0}, 'slow');
		return false;
	});

	$(".changeBackground").click(function() {
		changeBackground(1);
	});

	changeBackground(0);
});

function banners() {
	active1 = $('#bannersCentral div.active').length > 0 ? $('#bannersCentral div.active') : $('#bannersCentral div:first');
	next1 = ($('#bannersCentral .active').next().length > 0) ? $('#bannersCentral .active').next() : $('#bannersCentral div:first');
	active1.fadeOut(function(){
		active1.removeClass('active');
		next1.fadeIn().addClass('active');
	});

	active2 = $('#bannersHeader div.active').length > 0 ? $('#bannersHeader div.active') : $('#bannersHeader div:first');
	next2 = ($('#bannersHeader .active').next().length > 0) ? $('#bannersHeader .active').next() : $('#bannersHeader div:first');
	active2.fadeOut(function(){
		active2.removeClass('active');
		next2.fadeIn().addClass('active');
	});

	active3 = $('#bannersSecundario div.active').length > 0 ? $('#bannersSecundario div.active') : $('#bannersSecundario div:first');
	next3 = ($('#bannersSecundario .active').next().length > 0) ? $('#bannersSecundario .active').next() : $('#bannersSecundario div:first');
	active3.fadeOut(function(){
		active3.removeClass('active');
		next3.fadeIn().addClass('active');
	});

	active4 = $('#bannersDer1 div.active').length > 0 ? $('#bannersDer1 div.active') : $('#bannersDer1 div:first');
	next4 = ($('#bannersDer1 .active').next().length > 0) ? $('#bannersDer1 .active').next() : $('#bannersDer1 div:first');
	active4.fadeOut(function(){
		active4.removeClass('active');
		next4.fadeIn().addClass('active');
	});

	active5 = $('#bannersDer2 div.active').length > 0 ? $('#bannersDer2 div.active') : $('#bannersDer2 div:first');
	next5 = ($('#bannersDer2 .active').next().length > 0) ? $('#bannersDer2 .active').next() : $('#bannersDer2 div:first');
	active5.fadeOut(function(){
		active5.removeClass('active');
		next5.fadeIn().addClass('active');
	});
}

/*
Open Centered Popup Window Script-(c) DHTMLShock (www.dhtmlshock.com)
To add more shock to your site, visit www.DHTMLShock.com
*/

function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
	if(window.screen)if(isCenter)if(isCenter=="true"){
		var myLeft = (screen.width-myWidth)/2;
		var myTop = (screen.height-myHeight)/2;
		features+=(features!='')?',':'';
		features+=',left='+myLeft+',top='+myTop;
	}
	window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

function goTo(index, url) {
	OpenBrWindow(url, 'pu' + index, 'resizable=1,status=yes,menubar=yes,scrollbars=yes,toolbar=yes,titlebar=yes,location=yes','1010','650','true');
}

/*

si !session carga por hora
si click guarda sesion


body
{
background: #dfedb0 url('img/bg.jpg') repeat-x;

*/

function changeBackground(move) {
	$.ajax({
	  url: 'inc/changeBackground.php?move=' + move,
	  success: function(data) {
		$('body').css('background-image','url("'+data+'")');
	  }
	});
}
