$(window).ready(function() {
	
	function vIE(){return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;}
	vie = vIE();
	
	if ( vie == -1 ) {
		vie = 7;
	}
	
	current = 1;
	
	function toggleOffers() {
		
		var count = $('.jovenes > div').length;
		next = current+1;
		
		if ( next > count ) {
			next = 1;
		}
		
		$('.jovenes .j'+next).hide('1');
		$('.jovenes .j'+current).hide('1500', showNext);
		
		function showNext() {
			$('.jovenes .j'+next).show('1500');
		}
		
		current = next;
		
	};
	
	//var time = setInterval(toggleOffers, 9000);
	
	$('.stbuttontext').html('Compartelo');
	
	function lightbox(url) {
		
		winHeight = $(document).height();
		winWidth = $(window).width();
		$('#lb_black').css({
			height: winHeight,
			width: winWidth
		});
		
		$('#lb_close').css({top: '0'});
		setTimeout("$('#lb_close').css({display: 'block'}).animate({top: '-18px'}, 400)", 2000);
		
		if (url != undefined) {
			$('#lb_iframe').attr("src", url);
		}
		
		$('html,body').scrollTo(0, 400);
		$('#lb_loading').show();
		$('#lb_iframe').hide();
		
		$('#lb_black').css({
			opacity: '0',
			display: 'block'
		}).animate({
			opacity: '0.8'
		}, 1000);
		
		$('#lb_over').animate({
			top: '130px'
		}, 1000).animate({
			top: '100px'
		}, 200);
		
		$('#lb_iframe').load(function() {
			
			setTimeout("$('#lb_loading').hide('500')", 500);
			setTimeout("$('#lb_iframe').show('1000')", 1000);
			
		});
		
		if ( vie <= 6 ) {
			
			offset = $('#wrapper').offset();
			
			$('#lb_over').css({
				top: '100px',
				left: offset.left,
				height: '400px'
			});

		}
		
	}
	
	$('#buscador-form').target = "lb_iframe"; // Set form target to iframe
	$('#buscador-form').attr('target', 'lb_iframe');

	$('.buscador-box fieldset input.btn').click(function() {
		lightbox();
	});

	$('.area-clientes').click(function() {
		lightbox('http://multas.autoplus.es/clientesautoplus/login.asp');
		return false;
	});

	$('.registrar a').click(function() {
		lightbox('http://multas.autoplus.es/registroautoplus/registro_nuevo.asp');
		return false;
	});

	$('.accede a').click(function() {
		lightbox('http://multas.autoplus.es/registroautoplus/registro.asp');
		return false;
	});

	$('#lb_close').click(function(){

		$('#lb_black').animate({
			opacity: '0'
		}, 1000);

		setTimeout("$('#lb_black').css({display: 'none'});", 1001);

		$('#lb_over').animate({
			top: '-600px'
		}, 900);

		return false;

	});
	
});