$(document).ready(function(){
    // agregar al maletin
    $('#ctl00_ContentPlaceHolder1_hlAgregarMaletin').click(function(){
        $.get(this.href, function(data){
            // defined in global.js
            loadMaletin();
            $('#ctl00_ContentPlaceHolder1_divAgregarAmigo').hide('slow');
            });
        return false;
    });
    
    // lightbox
    // $('#miniaturas a').lightBox({imageLoading:$base+'App_themes/elinmobiliario2/images/lightbox-ico-loading.gif',
    //     imageBtnClose:$base+'App_themes/elinmobiliario2/images/lightbox-btn-close.gif',
    //     imageBtnPrev :$base+'App_themes/elinmobiliario2/images/lightbox-btn-prev.gif',
    //     imageBtnNext :$base+'App_themes/elinmobiliario2/images/lightbox-btn-next.gif',
    //     imageBlank :$base+'App_themes/elinmobiliario2/images/lightbox-blank.gif'
    // });
     
      
     // evento tabs
//     $('.tabs').bind('tabsshow', function(event, ui) {
//        var doPost=true;
//        var tab;
//        
//        switch(ui.index){
//            case 0:
//                tab='Ficha';
//                break;
//            case 1:
//                tab='Plantas';
//                break;
//            case 2:
//                tab='Ubicacion';
//                break;
//            case 3:
//                tab='Multimedia';
//                break;
//            default:
//                doPost=false;
//                break;
//        }
//        // cod, tab, id
//        if(doPost){
//            $.post($base+'AjaxMetodos/AjaxMetodosFicha.aspx',{cod:$codProyecto, id:$idProyecto, tab:tab});
//        }
//    });

     // seleccion de tab
//     var tab=getParameterByName('ver');
//     if(tab==''){
//        $('#botons').tabs('select', 0);
//     }
//     if(tab=='plantas'){
//        $('#botons').tabs('select', 1);
//        // verificar planta específica
//        var planta=getParameterByName('planta');
//        if(planta!=''){
//            $('#ctl00_ContentPlaceHolder1_ddlPlanta').val(planta).change();
//        }
//     }
//     if(tab=='mapa'){
//        $('#botons').tabs('select', 2);
//     }
//     if(tab=='multimedia'){
//        $('#botons').tabs('select', 3);
//     }
     
//     $('#GB_window img').click(function(){window.location.reload();});
     
     // botones
//     $('#ctl00_ContentPlaceHolder1_cotiza, #otrasplantas').click(function(){
//        $('#botons').tabs('select',1);
//        return false;
//        });
        
     // acordeon
     if($('#ctl00_ContentPlaceHolder1_idVideos_dt').length && $('#ctl00_ContentPlaceHolder1_id360_dt').length) {
         $("dd:not(:first)").hide();
		    $("dt a").click(function(){
			    $("dd:visible").slideUp("slow");
			    $(this).parent().next().slideDown("slow");

			    return false;
		    });
		}
	
	//imprimir
	$('#imprimir').click(function(){ ResizeCenterPopup(700,450); });
		
	// adición de evento hide para greybox
	jQuery.aop.before({target: jQuery.fn, method: "hide"},
                                function(){
                                        this.trigger("hide");
                                });
});



function cotiza(){
    ctl00_ContentPlaceHolder1_popUpCotizacion.Show();
}

function enviaAmigo(){
    PopUpEnviarAmigo.Show();
}

/*Marca o Desmarca VivirEn*/
function MarcaDesmarcar(strIdSubCategoria, strIdComunas, strLogo, strLogoDesactivado)
{
    var valor = document.getElementById("ctl00_ContentPlaceHolder1_txtHidden2").value;
    if (valor.indexOf(','+strIdSubCategoria+"&")!=-1)
    {
        var dato = document.getElementById("ctl00_ContentPlaceHolder1_txtHidden2").value.replace(','+strIdSubCategoria+"&",'');            
        document.getElementById("ctl00_ContentPlaceHolder1_txtHidden2").value = dato;
        parent.frames['FrameMapas'].SacarPuntos(strIdSubCategoria);
        document.getElementById("btn" + strIdSubCategoria).style.backgroundImage = "url(../Upload/VivirEn/SubCategoria/" + strLogoDesactivado + ")";
    }
    else
    {
        document.getElementById("ctl00_ContentPlaceHolder1_txtHidden2").value = valor + "," + strIdSubCategoria + "&";
        parent.frames['FrameMapas'].CargarPuntos("../XmlDinamic/XmlMapaVivirEn.aspx?idComunas=" + strIdComunas + "&idSubCategoria="+ strIdSubCategoria +"&", strIdSubCategoria);
        document.getElementById("btn" + strIdSubCategoria).style.backgroundImage = "url(../Upload/VivirEn/SubCategoria/" + strLogo + ")";
    }
} 
/*Fin Ficha Acerca del barrio */

/*Ficha Multimedia*/
function CargarVideos(nombreArchivo,tipoVideo,TipoArchivo,idVideo)
{
    document.getElementById("FrameMultimedia").src='PreCargaMultimediaV3.aspx?file='+ nombreArchivo + '&amp;type='+ tipoVideo + '&amp;version='+ TipoArchivo + '&amp;idVideo=' + idVideo;
}
/*Fin Ficha Multimedia*/


function _reload(){window.location.reload();}
//function ResizeCenterPopup(width, height){
//    // calcular left, top de acuerdo a medidas
//    var left=$(window).width()/2-width/2;
//    var top=$(window).scrollTop()+$(window).height()/2-height/2;
//    
//    if(left<=50)
//        left=50;
//    if(top<=50)
//        top=50;
//    // animar
//    $('#GB_window').animate({width:width, height:height, top:top, left:left},500, function(){
//        $('#GB_frame').css('height', height-20).css('overflow','none');
//    });

//}

function verPlanta(idPlanta){
    $('#botons').tabs('select', 1);
    $('#ctl00_ContentPlaceHolder1_ddlPlanta').val(idPlanta).change();
}

function linkListarComunas(idcomuna)
{   
    CallbackListar.PerformCallback(idcomuna);
}
function endCallback(s, e)
{
    location.href = 'Listar.aspx?idComuna=0,' + s.cpComuna
}
