var loadDataDestacadoPromo = function(thisID, data){
	jQuery("#imgCont_"+thisID).attr({
						          	alt: data.alt,
						          	src: data.foto,
									width: data.w,
									height: data.h
	});
}

var loadDataDestacado = function(thisID, data){
	jQuery("#destac_"+thisID+" #h_a_"+thisID).html(data.titulo);
		jQuery("#destac_"+thisID+" #h_a_"+thisID).attr({
    	href: data.url,
    	target:data.target
    });

	jQuery("#destac_"+thisID+" #p_a_"+thisID).html(data.descripcion);
    jQuery("#destac_"+thisID+" #p_a_"+thisID).attr({
    	href: data.url,
    	target:data.target
    });

	jQuery("#destac_"+thisID+" #a_"+thisID).attr({
    	href: data.url,
    	target:data.target
    });

	jQuery("#imgCont_"+thisID).attr({
						          	alt: data.alt,
						          	src: data.foto,
									width: data.w,
									height: data.h
	});
}

function bannerDestacado1(){
		var thisID = '01';
		if ( typeof ( jQuery('#destac_01').attr('class') ) != "undefined" ){
			var idMio = jQuery('#destac_01').attr('class').substring(2);
			jQuery.getJSON("ajax.php?id="+idMio+"&side=0&tipo=0", function(data){
									jQuery('#destac_'+thisID).removeClass();
									jQuery('#destac_'+thisID).addClass('b_'+data.id);
									jQuery("#destac_"+thisID).fadeTo("normal", 0, function(){
										jQuery("#imgCont_"+thisID).attr({
								          	src: data.foto,
											onload : loadDataDestacado(thisID, data)
								     	});
								}).fadeTo("normal", 1);
				});
		}
	}

function bannerDestacado2(){
		var thisID = '02';
		if ( typeof ( jQuery('#destac_02').attr('class') ) != "undefined" ){
			var idMio = jQuery('#destac_02').attr('class').substring(2);
			jQuery.getJSON("ajax.php?id="+idMio+"&side=1&tipo=0", function(data){
									jQuery('#destac_'+thisID).removeClass();
									jQuery('#destac_'+thisID).addClass('b_'+data.id);
									jQuery("#destac_"+thisID).fadeTo("normal", 0, function(){
											jQuery("#imgCont_"+thisID).attr({
									          	src: data.foto,
												onload : loadDataDestacado(thisID, data)
									     	});
								}).fadeTo("normal", 1);
			});
		}
	}

function bannerDestacado3(){
		var thisID = '01';
		if ( typeof ( jQuery('#destac_01').attr('class') ) != "undefined" ){
			var idMio = jQuery('#destac_01').attr('class').substring(2);
			jQuery.getJSON("ajax.php?id="+idMio+"&side=0&tipo=3", function(data){
									jQuery("#destac_"+thisID).fadeTo("normal", 0, function(){
										jQuery("#imgCont_"+thisID).attr({
								          	src: data.foto,
											onload : loadDataDestacadoPromo(thisID, data)
								     	});
								}).fadeTo("normal", 1);
				});
		}
}

function validateEnviarAmigo(){
	var bool1 = validateTextfield('miNombre');	
	var bool2 = validateEmail('miEmail');
	var bool3 = validateTextfield('nombreAmigo');
	var bool4 = validateEmail('emailAmigo');
	var bool5 = validateTextarea('comentariosAmigo');
	var bool = bool1 && bool2 && bool3 && bool4 && bool5;
	if (!bool){
		setDisplay("popup_error_msg", "");
	}
	return bool;
}

jQuery(document).ready(function() {
	jQuery(function() {

		jQuery(".lightboxEmpresaImgsPrincipal").lightbox();

		jQuery(".lightBoxImagenesNoticias").lightbox();

		jQuery(".lightboxEmpresaImgsSecundarias").lightbox();

		jQuery(".lightboxPromociones").lightbox();

		jQuery("#carousel").jCarouselLite({
			 btnNext: ".btnNext",
 		     btnPrev: ".btnPrev",
 		     scroll: 1,
 		     visible: 1
		});
		
		jQuery("#video_tab_icon").click(function(){
			jQuery("#video_tab").parent().addClass('active');
			jQuery("#image_tab").parent().removeClass('active');
			jQuery("#promo_carousel").hide();
			jQuery("#promo_visita_virtual").show();
			return false;			
		});
		
		jQuery("#video_tab").click(function(){
			jQuery("#video_tab").parent().addClass('active');
			jQuery("#image_tab").parent().removeClass('active');
			jQuery("#promo_carousel").hide();
			jQuery("#promo_visita_virtual").show();
			return false;			
		});
		
		jQuery("#image_tab").click(function(){
			jQuery("#image_tab").parent('li').addClass('active');
			jQuery("#video_tab").parent('li').removeClass('active');
			jQuery("#promo_visita_virtual").hide();
			jQuery("#promo_carousel").show();
			return false;			
		});
		
		jQuery(".vid_win_switcher").click(function(){
			if (jQuery(this).hasClass('vid_win_switcher_collapse')){
				jQuery(this).removeClass('vid_win_switcher_collapse');
				jQuery("#div_vista_cont").removeClass("visita_virtual_bigger");
			}
			else{
				jQuery(this).addClass('vid_win_switcher_collapse');
				jQuery("#div_vista_cont").addClass("visita_virtual_bigger");
			}
		});		
		
		jQuery("#send_to_friend").click(function(){
			var idPromo = jQuery("#idPromo").val();
			var idCat = jQuery("#idCat").val();			
			var urlPromo = sTPurl_domain+jQuery(this).attr('href');
			var txt = '<div class="body"><p id="popup_sin_error_msg" style="">Envía información de esta promoción a un amigo.</p>';
			txt += '<div class="form"><form name="f_enviarAmigo" id="f_enviarAmigo" method="post" action="">';
			txt += '<div id="popup_error_msg" class="error_msg" style="display:none">Los campos sombreados son requeridos para el env&iacute;o.</div><table>';
			txt += '<tr id="tr_miNombre" class="f_textfield"><th>Mi Nombre</th><td><input id="miNombre" name="miNombre" type="text" value="" /></td></tr>';
			txt += '<tr id="tr_miEmail" class="f_textfield"><th>Mi Email</th><td><input id="miEmail" name="miEmail" type="text" value="" /></td></tr>';
			txt += '<tr id="tr_nombreAmigo" class="f_textfield"><th>Nombre destinatario</th><td><input id="nombreAmigo" name="nombreAmigo" type="text" value="" /></td></tr>';
			txt += '<tr id="tr_emailAmigo" class="f_textfield"><th>Email destinatario</th><td><input id="emailAmigo" name="emailAmigo" type="text" value="" /></td></tr>';
			txt += '<tr id="tr_comentariosAmigo" class="f_textarea"><th>Comentarios</th><td><textarea id="comentariosAmigo" name="comentariosAmigo" cols="" rows=""></textarea></td></tr>';
			txt += '<tr class="f_hint"><th></th><td>Escribe un comentario para tu amigo.</td></tr>';
			txt += '<tr class="f_hint"><th></th><td>Al enviar estos datos declaro que acepto la <a href="'+sTPurl+'lopd.php" target="_top">Política de Privacidad</a>.</td></tr>';
			txt += '</table>';
			txt += '</form>';
			txt += '</div></div>';

			function mycallbackform(v, m){
				if (v) {
					jQuery.getJSON(sTPurl + "ajax_inmo.php", {
						action: 'sendToFriend',												
						miNombre: m.find("#miNombre").val(),
						miEmail: m.find('#miEmail').val(),
						nombreAmigo: m.find('#nombreAmigo').val(),
						emailAmigo: m.find('#emailAmigo').val(),
						comentariosAmigo: m.find('#comentariosAmigo').val(),
						idCat: idCat,
						idPromo: idPromo,
						url: urlPromo
					},
					function(json){
						jQuery.prompt('Gracias - su mensaje ha sido enviado!',{
				      			buttons: { Aceptar: true }
							});
					}
					);
					
				}
			}

			jQuery.prompt(txt, {
				callback: mycallbackform,
				buttons: {
					Cancelar: false,
					Enviar: 'trueValidateEnviarAmigo'
				}
			});
			/*
			jQuery.prompt('En desarrollo...', {
				buttons: {
					Aceptar: false					
				}
			});*/
			return false;
		});

	});
});