$(document).ready(function() {
	$('body').click(function(){
		$('#producto_ampliado').hide();
	});
    $('a.fancyBox').fancybox();
    $('a#ofitpv').fancybox({
				'autoDimensions'		: false,
				'width'		    : 750,
				'height'		: 520,
                'type' : 'iframe'
    });
    $('a#callBack_header').fancybox({
                'titleShow' : false,
				'autoDimensions'		: false,
				'width'		    : 800,
				'height'		: 560,
				'padding'		: 0,
				'margin'		: 0,
                'type' : 'iframe'
    });
    $('a#callBack').fancybox({
                'titleShow' : false,
				'autoDimensions'		: false,
				'width'		    : 800,
				'height'		: 560,
				'padding'		: 0,
				'margin'		: 0,
                'type' : 'iframe'
    });
	$(".youtube_fancybox").click(function() {
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'		    : 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
					 'wmode'		: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});

		return false;
	});
    // alturas exactas para listados de columnas
    equalHeight($(".equalHeight_ul li"));
    equalHeight($(".equalHeight_div"));
});

function ajax_muebles(repaginate)
{
	idLinea = $('#idLinea').val();
	idFamilia = $('#idFamilia').val();
	idSubfamilia = $('#idSubfamilia').val();
	
	idSubfamilia2 = "";
	$('.js_idSubfamilia2').each(function(){
		if (this.checked) {
			idSubfamilia2 += "," + this.value;
		}
	});
	if (idSubfamilia2 == '') {
		idSubfamilia2 = $('#idSubfamilia2').val();
	}
	if (idSubfamilia2 == 'null' || idSubfamilia2 == undefined) {
		idSubfamilia2 = '';
	}

	frontal = "";
	$('.js_frontal').each(function(){
		if (this.checked) {
			frontal += "," + this.value;
		}
	});
	if (frontal == '') {
		frontal = $('#frontal').val();
	}
	if (frontal == 'null' || frontal == undefined) {
		frontal = '';
	}

	profundidad = "";
	$('.js_profundidad').each(function(){
		if (this.checked) {
			profundidad += "," + this.value;
		}
	});
	if (profundidad == '') {
		profundidad = $('#profundidad').val();
	}
	if (profundidad == 'null' || profundidad == undefined) {
		profundidad = '';
	}

	altura = "";
	$('.js_altura').each(function(){
		if (this.checked) {
			altura += "," + this.value;
		}
	});
	if (altura == '') {
		altura = $('#altura').val();
	}
	if (altura == 'null' || altura == undefined) {
		altura = '';
	}

	idTejido = "";
	$('.js_idTejido').each(function(){
		if (this.checked) {
			idTejido += "," + this.value;
		}
	});
	if (idTejido == '') {
		idTejido = $('#idTejido').val();
	}
	if (idTejido == 'null' || idTejido == undefined) {
		idTejido = '';
	}

	orden = $('#orden').val();
	regsPerPage = $('#regsPerPage').val();
	if (repaginate) {
		page = 1;
	} else {
		page = $('#page').val();
	}

	$('#catalogo-muebles-ajax').load('/catalogo-muebles-ajax.asp?idLinea=' + idLinea + '&idFamilia=' + idFamilia + '&idSubfamilia=' + idSubfamilia + '&idSubfamilia2=' + idSubfamilia2 + '&frontal=' + frontal + '&profundidad=' + profundidad + '&altura=' + altura + '&idTejido=' + idTejido + '&orden=' + orden + idTejido + '&regsPerPage=' + regsPerPage + '&page=' + page);
}

function activarPestanya(cual)
{
    $('#pestanyas li').removeClass('active');
    $('.seccion:not(#' + cual + ')').hide();
	if($('#' + cual).css('display') != 'block') {
		$('#pestanya_' + cual).addClass('active');
		$('#' + cual).slideDown('slow');
	} else {
		$('#' + cual).hide();
	}
}

function equalHeight(group) {
    var tallest = 0;
    group.each(function() {
        var thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

