function slideSwitch(){
	var $active = $('#slideshow div.active');
	if ( $active.length == 0 ) $active = $('#slideshow div:last');

	var $next =  $active.next().length ? $active.next()
		: $('#slideshow div:first');

	// uncomment the 3 lines below to pull the images in random order
	// var $sibs  = $active.siblings();
	// var rndNum = Math.floor(Math.random() * $sibs.length );
	// var $next  = $($sibs[rndNum]);

	$active.addClass('last-active');
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function(){
			$active.removeClass('active last-active');
		});
}

$(function(){
	setInterval('slideSwitch()',7000);
	$('#tabs').tabs();
    $('.fancybox').fancybox({
    	openEffect	: 'elastic',
    	closeEffect	: 'elastic',
    	helpers : {
    		title : {
    			type : 'over'
    		}
    	}
    });
	$('.various').fancybox({
		maxWidth	: 800,
		maxHeight	: 600,
		fitToView	: false,
		width		: '70%',
		height		: '70%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none'
	});
});

function finaliza(periods){
	if ($.countdown.periodsToSeconds(periods) < 3600){
		$(this).addClass('highlight');
	}
}

function serverTime(){
	var time = null;
	$.ajax({url: '/js/ajax.php?tipo=fecha',
		async: false, dataType: 'text',
		success: function(text){
			time = new Date(text);
		}, error: function(http, message, exc){
			time = new Date();
	}});
	return time;
}

function es_email(mail){
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if (mail.length > 7 && reg.test(mail) == true){
		$('#email').css('background-position','199px center');
		$('#enviar').attr('disabled',false);
	}else{
		$('#email').css('background-position','300px center');
		$('#enviar').attr('disabled',true);
	}
}

function compartir(promo){
	$('#vercompartir').dialog({
		draggable: false,
		resizable: false,
		modal: true,
		width: 450,
		height: 200
	});
}


function envio_compartir(promo){
	var email = $('#email').val();
	$.ajax({
	 type: 'GET',
	 url: '/js/ajax.php',
	 data: ({
	  tipo:'envio_compartir',
	  promo:promo,
	  email:email
	 }),
	 complete : function(){
	  $('#vercompartir').dialog('close');
	 }
	});	
}
