// JavaScript Document
$(document).ready(function() {
	var cantidad 	= 3;
	var pagina		= 1;
	var img 		= $('.slide img').length;	
	
	$('.slide').width((img * 130));
	
	$('.btn_left a').click(function() {
		if (cantidad > 3) {
			cantidad--;
		
			$('.slide').css({position: 'relative'}).animate({left: '+=130px'}, 1000);
			
			$(this).blur();
		}		
		return false;
		
	});	
	$('.btn_right a').click(function() {		
		if (cantidad < img) {
			cantidad++;			
			$('.slide').css({position: 'relative'}).animate({left: '-=130px'}, 1000);
			
			$(this).blur();
		}
		
		return false;
	});
	$('.slide a').click(function() {
		
		var x = $(this).attr('href');		
		var id = x.split('=');
		
		$.post('comerciales/detalles.php', {com:id[2]}, function(comercial) {		
															 
			eval('comercial='+comercial);
			$('.m_titulo').text(comercial.nombre);
			$('.m_desc').text(comercial.descripcion);				
			
			$('.content').load(x, function() {
				$('.content a').click(function() {
					
					var este = $(this);					
					blackout();
					
					$('body').append('<div id="eventosFlyerIMG"><img src="imagenes/loading.gif" class="loading" /><img src="'+este.attr('href')+'" style="display: none;" class="flyer" /></div>');
					
					var wh = windowSize();
					var iz = {width: (wh.width - 24) / 2, height: (wh.height - 24) / 2};
					
					$('#eventosFlyerIMG .loading').css({
						zIndex: 101,
						position: 'absolute',
						top: iz.height+'px',
						left: iz.width+'px'						
					});
					
					$('#eventosFlyerIMG .flyer').load(function() {
						var wh = windowSize();
						var iz = {width: (wh.width - $(this).width()) / 2, height: (wh.height -  $(this).height()) / 2};
						
						//alert(iz.width + ' - ' + iz.height);
						$('#eventosFlyerIMG .loading').remove();
						
						$(this).css({
							position: 'absolute',
							top: iz.height+'px',
							left: iz.width+'px',
							zIndex: 101
						}).fadeIn('slow');
					});
					
					$('#eventosFlyerIMG img, #blackout').click(function() {
						clearBlackout();
						$('#eventosFlyerIMG').remove();
									
					});
					
					return false;
				});									 
			});
				
		});
		
		return false;					   
		
	});
	$('.content a').click(function() {
					
		var este = $(this);					
		blackout();
				
		$('body').append('<div id="eventosFlyerIMG"><img src="imagenes/loading.gif" class="loading" /><img src="'+este.attr('href')+'" style="display: none;" class="flyer" /></div>');
					
		var wh = windowSize();
		var iz = {width: (wh.width - 24) / 2, height: (wh.height - 24) / 2};
		
		$('#eventosFlyerIMG .loading').css({
			position: 'absolute',
			top: iz.height+'px',
			left: iz.width+'px'
		});
					
		$('#eventosFlyerIMG .flyer').load(function() {
			var wh = windowSize();
			var iz = {width: (wh.width - $(this).width()) / 2, height: (wh.height -  $(this).height()) / 2};
						
			//alert(iz.width + ' - ' + iz.height);
			$('#eventosFlyerIMG .loading').remove();
						
			$(this).css({
				position: 'absolute',
				top: iz.height+'px',
				left: iz.width+'px',
				zIndex: 101
				}).fadeIn('slow');
			});
					
		$('#eventosFlyerIMG img, #blackout').click(function() {
			clearBlackout();
			$('#eventosFlyerIMG').remove();
						
		});
			
		return false;
	});				
	
});
