﻿// Prevent IE6 Flickering
try { window.document.execCommand('BackgroundImageCache', false, true); } catch (e) { }
// First loop all the elements in the page that open a gallery
// Primeiro encontramos todos os elementos da página que vão abrir uma galeria
window.onload = function() {
    // For each element that has a class name of gallery

};
var ddGalleryObject = function() {
    var galleries = new Array();
    var elementsCreated = false;
    var currentGallery = -1;
    var currentIndex = -1;
    var progressIndicator = new Image();
    this.showThumbnails = true;
    this.backgroundColor = "#a28b4d";
    this.modalBackgroundColor = "#f0f1ec";
    this.modalBackgroundOpacity = 60;
    this.navigationCssStyle = "color:#fff; font-family:Arial, Verdana; font-size:12px;  text-decoration:none;font-weight:bold;";
    this.navigationSpliterCssStyle = "color:#ddd; font-family:Arial, Verdana; font-size:12px;  text-decoration:none;";
    this.nextText = "next &gt;&gt;";
    this.previousText = "&lt;&lt; prev";
    this.photoText = "picture";
    this.photoOfText = "of";
    this.slideshowCssStyle = "color:#fff; font-family:Arial, Verdana; font-size:11px; text-decoration:none;font-weight:bold;";
    this.closeButtonCssStyle = "color:#fff; font-family:Arial, Verdana; font-size:11px; text-decoration:none;font-weight:bold;";
    this.titleCssStyle = "color:#fff; font-family:Arial, Verdana; font-size:12px";
    this.currentSlideCssStyle = "color:#fff; font-family:Arial, Verdana; font-size:9px;";
    this.closeButtonText = "close [x]";
    this.resizeTimeout = null;
    this.slideShowInterval = null;
    this.slideShowFrameTime = 3000;
    this.addGallery = function(imageArray, galleryName) {
        var _gallery = new ddGallery();
        _gallery.galleryImages = imageArray;
        if (galleryName)
            _gallery.galleryName = galleryName;
        galleries.push(_gallery);
        // Preload the progress indicator
        // Fazer Preload do indicador de progresso para mostrar alguma coisa enquanto as imagens carregam
        // 
        // Before preloading it we need to know the image path
        // Mas antes temos que saber qual o caminho da imagem de preload
        var siteScripts = window.document.getElementsByTagName("script");
        for (i = 0; i < siteScripts.length; i++) { if (siteScripts[i].src.indexOf('ddGallery.js') > 0) { progressIndicator.src = siteScripts[i].src.substr(0, siteScripts[i].src.length - 12) + "gallery-loader.gif"; } }

    }
    this.showGallery = function(galleryName, startAtImageIndex) {
        if (!elementsCreated) {
            this.createGallery();
            elementsCreated = true;
        }
        var galleryBackground = document.getElementById("galleryBackground");
        var galleryInterface = document.getElementById("galleryInterfaceWrapper");
        galleryBackground.style.display = 'block';
        galleryInterface.style.display = 'block';
        currentIndex = (startAtImageIndex) ? (startAtImageIndex - 1) : -1;
        // Find the index of the gallery that we are showing

        for (i = 0; i < galleries.length; i++) { if (galleries[i].galleryName == galleryName) { currentGallery = i; } }
        this.showNextImage();
        // Create the thumbnails
        // Criar os thumbnails
        if (this.showThumbnails) { this.createThumbs(); }
    };
    this.hideGallery = function() {
        var galleryBackground = document.getElementById("galleryBackground");
        var galleryInterface = document.getElementById("galleryInterfaceWrapper");
        galleryBackground.style.display = 'none';
        galleryInterface.style.display = 'none';

        document.getElementById('div_banner').style.visibility = 'visible';
    };
    this.showNextImage = function() {
        currentIndex++;
        if (currentIndex >= galleries[currentGallery].galleryImages.length) { currentIndex = 0; }
        this.showImage();

    };
    this.showPreviousImage = function() {
        currentIndex--;
        if (currentIndex < 0) { currentIndex = 0; }
        this.showImage();

    };
    this.showImage = function(imageIndex) {
        if (!isNaN(imageIndex)) { currentIndex = imageIndex; };
        var btnNext = document.getElementById("btnNavigationRight");
        var btnPrevious = document.getElementById("btnNavigationLeft");
        var galleryImage = document.getElementById("galleryImageArea");
        var titleArea = document.getElementById("galleryTitleArea");
        var gInterface = document.getElementById("galleryInterfaceWrapper");
        var currentSlide = document.getElementById("currentSlide");
        titleArea.innerHTML = galleries[currentGallery].galleryImages[currentIndex][1];
        currentSlide.innerHTML = this.photoText + " " + (currentIndex + 1).toString() + " " + this.photoOfText + " " + galleries[currentGallery].galleryImages.length.toString();
        var image = new Image();
        image.src = galleries[currentGallery].galleryImages[currentIndex][0];
        if (image.width > 0) {
            galleryImage.style.backgroundImage = "url(" + galleries[currentGallery].galleryImages[currentIndex][0] + ")";
            var interfaceNewWidth = (image.width + 20 < 240) ? 240 : (image.width);
            var interfaceNewHeight = image.height + 20;
            daydreamGallery.adjustPosition([interfaceNewWidth, interfaceNewHeight]);
            //daydreamGallery.adjustPosition([1024, 668]);
        }
        else {
            galleryImage.style.backgroundImage = "url(" + progressIndicator.src + ")";
            daydreamGallery.adjustPosition([200, 100]);
            document.getElementById("galleryImageArea").style.width = '200px';
            document.getElementById("galleryImageArea").style.height = '100px';
            image.onload = function() {
                galleryImage.style.backgroundImage = "url(" + galleries[currentGallery].galleryImages[currentIndex][0] + ")";
                var interfaceNewWidth = (image.width + 10 < 240) ? 240 : (image.width);
                var interfaceNewHeight = image.height + 20;
                daydreamGallery.adjustPosition([interfaceNewWidth, interfaceNewHeight]);
                //daydreamGallery.adjustPosition([1024, 668]);
            };
        }
        btnPrevious.style.visibility = (currentIndex > 0) ? "visible" : "hidden";
        btnNext.style.visibility = (currentIndex < galleries[currentGallery].galleryImages.length - 1) ? "visible" : "hidden";
        document.getElementById("navigationSplitter").style.visibility = (currentIndex > 0 && currentIndex < galleries[currentGallery].galleryImages.length - 1) ? "visible" : "hidden";
    }
    this.adjustPosition = function(newImageSize) {
        var thumbsArea = document.getElementById("galleryThumbsArea");
        if (navigator.userAgent.indexOf("Firefox") != -1) {
            thumbsArea.style.visibility = "hidden";
        }
        if (this.resizeTimeout) { window.clearTimeout(this.resizeTimeout); }
        var galleryImage = document.getElementById("galleryImageArea");
        var gInterface = document.getElementById("galleryInterfaceWrapper");
        var currentWidth = galleryImage.offsetWidth;
        var currentHeight = galleryImage.offsetHeight;
        var widthFactor = (newImageSize[0] - currentWidth) / 1; // para definir o tempo que demora a abrir, aumentar ou diminuir aqui *
        if (widthFactor < 1 && widthFactor > 0) { widthFactor = 1; } if (widthFactor > -1 && widthFactor < 0) { widthFactor = -1; }
        var heightFactor = (newImageSize[1] - currentHeight) / 1; // * e aqui
        if (heightFactor < 1 && heightFactor > 0) { heightFactor = 1; } if (heightFactor > -1 && heightFactor < 0) { heightFactor = -1; }
        var newWidth = (widthFactor > 0 ? (currentWidth + widthFactor) > newImageSize[0] : (currentWidth + widthFactor) < newImageSize[0]) ? newImageSize[0] : parseInt(currentWidth + widthFactor);
        var newHeight = (heightFactor > 0 ? (currentHeight + heightFactor) > newImageSize[1] : (currentHeight + heightFactor) < newImageSize[1]) ? newImageSize[1] : parseInt(currentHeight + heightFactor);
        gInterface.style.width = newWidth.toString() + "px";
        //gInterface.style.width = "1024px";
        galleryImage.style.width = newWidth.toString() + "px";
        galleryImage.style.height = newHeight.toString() + "px";
        if (newWidth != newImageSize[0] || newHeight != newImageSize[1]) {
            this.resizeTimeout = window.setTimeout(function() {
                daydreamGallery.adjustPosition(newImageSize)
            }, 10);
        } else { thumbsArea.style.visibility = "visible"; }
        daydreamGallery.reposition();
    };
    this.slideShow = function() {
        var btnSlideShow = document.getElementById('btnSlideShow');
        if (!this.slideShowInterval) {
            this.slideShowInterval = window.setInterval(function() {
                daydreamGallery.showNextImage();
            }, this.slideShowFrameTime);
            btnSlideShow.innerHTML = "[ || ] slideshow";
        } else {
            this.slideShowInterval = window.clearInterval(this.slideShowInterval);
            btnSlideShow.innerHTML = "[ &gt; ] slideshow";
        }
    };
    this.reposition = function() {
        var galleryBackground = document.getElementById("galleryBackground");
        var gInterface = document.getElementById("galleryInterfaceWrapper");
        var ScrollTop = document.body.scrollTop;
        if (ScrollTop == 0) {
            ScrollTop = window.pageYOffset ? window.pageYOffset : ((document.body.parentElement) ? document.body.parentElement.scrollTop : 0);
        }
        galleryBackground.style.height = document.body.offsetHeight.toString() + "px";
        galleryBackground.style.width = document.body.offsetWidth.toString() + "px";
        gInterface.style.left = ((ddGetDocumentSize().width - gInterface.offsetWidth) / 2).toString() + "px";
        gInterface.style.top = (((ddGetDocumentSize().height - gInterface.offsetHeight) / 2) + ScrollTop).toString() + "px";
    }
    this.createThumbs = function() {
        var thumbsArea = document.getElementById("galleryThumbsArea");
        var thumbs = "";
        for (i = 0; i < galleries[currentGallery].galleryImages.length; i++) {
            thumbs += "<a href=\"#\" onmouseout=\"this.style.backgroundColor = 'transparent';\" onmouseover=\"this.style.backgroundColor = '#fff';\" onclick=\"daydreamGallery.showImage(" + i.toString() + ");\" style=\"display:block; float:left; padding:2px;\"><img alt=\"\" style=\"width:30px; height:24px; border:0px none;\" src=\"" + galleries[currentGallery].galleryImages[i][0] + "\" /></a>";
        }
        thumbsArea.innerHTML = thumbs + "<div style=\"clear:both; line-height:0px\"></div>";
    };
    this.createGallery = function() {
        document.getElementById('div_banner').style.visibility = 'hidden';
        // Create the elements that compose the gallery
        // Criar os vários elementos de HTML que compõem a galeria
        var background = document.createElement("div");
        background.setAttribute("id", "galleryBackground");
        background.style.display = "none";
        background.style.opacity = this.modalBackgroundOpacity * 0.01;
        background.style.filter = "alpha(opacity=" + this.modalBackgroundOpacity.toString() + ")";
        background.style.width = "100%";
        background.style.height = ddGetDocumentSize().height.toString() + "px";
        document.body.style.height = "100%";
        background.style.backgroundColor = this.modalBackgroundColor;
        background.style.position = "absolute";
        background.style.top = "0px";
        background.style.left = "0px";
        background.style.zIndex = 10000;
        document.body.appendChild(background);
        // Now that we have the background we can create the interface
        // Agora que temos o background podemos criar a interface
        var placeHolder = document.createElement("div");
        var galleryInterfaceWrapper = "<div id=\"galleryInterfaceWrapper\" style=\"display:none; padding:10px; background:" + this.backgroundColor + "; z-index:10001; width:240px; position:absolute\">";
        var interfaceCenter = "<div id=\"interfaceCenter\" style=\"margin:0px auto;\">";
        var headerString = "<div style=\"height:15px\"><a id=\"btnSlideShow\" style=\"display:block; float:left; " +
			this.slideshowCssStyle + "\" href=\"#\" onclick=\"daydreamGallery.slideShow();\">[ &gt; ] slideshow</a><a id=\"btnClose\" href=\"#\" onclick=\"daydreamGallery.hideGallery();\" style=\"display:block; float:right; " + this.closeButtonCssStyle + "\">" + this.closeButtonText + "</a></div>";
        var galleryImageArea = "<div id=\"galleryImageArea\" style=\"background-repeat:no-repeat; background-position:center center;\"></div>";
        var galleryNavigation = "<div id=\"galleryTitleArea\" style=\"padding-bottom:5px; " + this.titleCssStyle + "\"></div>";
        var thumbsArea = "<div id=\"galleryThumbsArea\" style=\"padding-bottom:10px\"></div>";
        var navigationArea = "<div><div id=\"currentSlide\" style=\"display:block; float:left;" + this.currentSlideCssStyle + "\"></div><a id=\"btnNavigationRight\" href=\"#\" onclick=\"daydreamGallery.showNextImage();\" style=\"visibility:hidden; float:right; " + this.navigationCssStyle + "\">" + this.nextText + "</a><span id=\"navigationSplitter\"style=\"visibility:hidden; float:right; " + this.navigationSpliterCssStyle + "\">&nbsp;&nbsp;|&nbsp;&nbsp;</span><a id=\"btnNavigationLeft\" href=\"#\" onclick=\"daydreamGallery.showPreviousImage();\" style=\"visibility:hidden; float:right; " + this.navigationCssStyle + "\">" + this.previousText + "</a><div style=\"clear:both; line-height:0px;\"></div></div>";
        placeHolder.innerHTML = galleryInterfaceWrapper + interfaceCenter +
			headerString + galleryImageArea + galleryNavigation + thumbsArea + navigationArea +
			"</div></div>";
        document.body.appendChild(placeHolder);
        window.onresize = function() { daydreamGallery.reposition(); }
        window.onscroll = function() { daydreamGallery.reposition(); }
    }
};
var lastGalleryId = 0;
var ddGallery = function() {
    this.galleryImages = new Array();
    lastGalleryId++;
    this.galleryName = "ddgallery_" + lastGalleryId.toString();
    this.galleryCurrentIndex = 0;
};
function ddGetScrollTop() { var ScrollTop = document.body.scrollTop; if (ScrollTop == 0) { ScrollTop = window.pageYOffset ? window.pageYOffset : ((document.body.parentElement) ? document.body.parentElement.scrollTop : 0); }; return ScrollTop; }
function ddGetDocumentSize() { var myWidth = 0, myHeight = 0; if (typeof (window.innerWidth) == 'number') { myWidth = window.innerWidth; myHeight = window.innerHeight; } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } return { width: myWidth, height: myHeight }; } var daydreamGallery = new ddGalleryObject();

/* END OF GALLERY */
function show_contact_form(id_div) {
    var divtoshow = document.getElementById(id_div);

    divtoshow.style.display = 'block';

}

function show_membership_form(id_div) {
    var divtoshow = document.getElementById(id_div);

    divtoshow.style.display = 'block';

}

function show_login_area(id_div) {
    var divtoshow = document.getElementById(id_div);

    divtoshow.style.display = 'block';

}

function show_masterplan(aux,idlingua) {

    document.getElementById('div_banner').style.visibility = 'hidden';

    if (document.getElementById('galleryBackground_1')) {
        var galleryBackground = document.getElementById("galleryBackground_1");
        var galleryInterface = document.getElementById("galleryInterfaceWrapper_1");
        var interfaceCenter = document.getElementById("interfaceCenter_1");
        var masterplanFlash = document.getElementById("masterplan_flash");
        var headerString = document.getElementById("headerString_1");

        galleryBackground.style.display = 'block';
        galleryInterface.style.display = 'block';

        var so = new SWFObject("flash/masterplan.swf", "masterplan_flash", "860", "660", "8", "#121212");
        so.addParam("wmode", "transparent");
        so.write("masterplan_flash");
    }
    else {

        var background = document.createElement("div");
        background.setAttribute("id", "galleryBackground_1");
        background.style.display = "block";
        background.style.opacity = 90 * 0.01; //80 * 0.01;
        background.style.filter = "alpha(opacity=" + '60' + ")";
        background.style.width = "100%";
        background.style.height = ddGetDocumentSize().height.toString() + "px";
        document.body.style.height = "100%";
        background.style.backgroundColor = '#f0f1ec';
        background.style.position = "absolute";
        background.style.top = "0px";
        background.style.left = "0px";
        background.style.zIndex = 10000;
        document.body.appendChild(background);

        var placeHolder = document.createElement("div");
        var galleryInterfaceWrapper1 = "<div id='galleryInterfaceWrapper_1' style='display:block; z-index:10002;position:absolute;top:0px;left:0px;height:100%;width:800px;background:transparent;' >";
        var interfaceCenter1 = "<div id='interfaceCenter_1' style='padding:0px 0px 0px 0px;margin:10px auto;height:100%;width:100%;position:relative;'>";
        var headerString1 = "<div id='headerString_1' style='float:left;text-align:right;height:15px;display:inline; width:800px;position:relative;z-index:10002;'><a id='btnClose' href='#nogo' onclick=\"hideMasterplan();\" style='color:#6f6f6f;font-weight:bold; font-family:Arial, Verdana; font-size:11px; text-decoration:none;'> </a></div>";
        var masterplan_flash1 = "<div id='masterplan_flash' style='position:relative;float:left;width:800px;height:100%; z-index:10002;'></div>";

        placeHolder.innerHTML = galleryInterfaceWrapper1 + interfaceCenter1 + headerString1 + masterplan_flash1 + "</div></div></div>";

        document.body.appendChild(placeHolder);
    }

    if (aux == 1) {
        var so = new SWFObject("flash/preloader.swf", "masterplan_flash", "860", "660", "8", "#121212");
        so.addParam("wmode", "transparent");
        so.addParam("flashvars", "swf=flash/" + idlingua + "/individual.swf");
        so.write("masterplan_flash");
    }
    else if (aux == 2) {
    var so = new SWFObject("flash/preloader.swf", "masterplan_flash", "860", "660", "8", "#121212");
    so.addParam("wmode", "transparent");
    so.addParam("flashvars", "swf=flash/" + idlingua + "/townhouses.swf");
        so.write("masterplan_flash");
    }
    else if (aux == 3) {
    var so = new SWFObject("flash/preloader.swf", "masterplan_flash", "860", "660", "8", "#121212");
        so.addParam("wmode", "transparent");
        so.addParam("flashvars", "swf=flash/" + idlingua + "/apartments.swf");
        so.write("masterplan_flash");
    }
    else if (aux == 4) {
    var so = new SWFObject("flash/" + idlingua + "/map.swf", "masterplan_flash", "950", "660", "8", "#121212");
        so.addParam("wmode", "transparent");
        so.write("masterplan_flash");

    }
    else {
        var so = new SWFObject("flash/" + idlingua + "/masterplan.swf", "masterplan_flash", "860", "660", "8", "#121212");
        so.addParam("wmode", "transparent");
        so.write("masterplan_flash");
    }
    reposition_1();

    window.onresize = function() { reposition_1(); }
}

hideMasterplan = function() {
    var galleryBackground = document.getElementById("galleryBackground_1");
    var galleryInterface = document.getElementById("galleryInterfaceWrapper_1");
    var interfaceCenter = document.getElementById("interfaceCenter_1");
    var masterplanFlash = document.getElementById("masterplan_flash");
    var headerString = document.getElementById("headerString_1");

    galleryBackground.style.display = 'none';
    galleryInterface.style.display = 'none';

    //document.getElementById('div_banner').style.display = 'block';
    document.getElementById('div_banner').style.visibility = 'visible';
};

reposition_1 = function() {
    var galleryBackground = document.getElementById("galleryBackground_1");
    var gInterface = document.getElementById("galleryInterfaceWrapper_1");
    var ScrollTop = document.body.scrollTop;
    if (ScrollTop == 0) {
        ScrollTop = window.pageYOffset ? window.pageYOffset : ((document.body.parentElement) ? document.body.parentElement.scrollTop : 0);
    }
    galleryBackground.style.height = document.body.offsetHeight.toString() + "px";
    galleryBackground.style.width = document.body.offsetWidth.toString() + "px";
    gInterface.style.left = ((ddGetDocumentSize().width - gInterface.offsetWidth) / 2).toString() + "px";
    gInterface.style.top = (((ddGetDocumentSize().height - gInterface.offsetHeight) / 2) + ScrollTop).toString() + "px";
}


/*Brochura Electronic*/
function show_brochura(idlingua) {
    //document.getElementById('div_banner').style.visibility = 'hidden';

    if (document.getElementById('galleryBackground_3')) {
        var galleryBackground = document.getElementById("galleryBackground_3");
        var galleryInterface = document.getElementById("galleryInterfaceWrapper_3");
        var interfaceCenter = document.getElementById("interfaceCenter_3");
        var brochuraFlash = document.getElementById("brochura_flash");
        var headerString = document.getElementById("headerString_3");

        galleryBackground.style.display = 'block';
        galleryInterface.style.display = 'block';

        //so.write("brochura_flash");
    }
    else {

        var background = document.createElement("div");
        background.setAttribute("id", "galleryBackground_3");
        background.style.display = "block";
        background.style.opacity = 80 * 0.01;
        background.style.filter = "alpha(opacity=" + '60' + ")";
        background.style.width = "100%";
        background.style.height = ddGetDocumentSize().height.toString() + "px";
        document.body.style.height = "100%";
        background.style.backgroundColor = '#f0f1ec';
        background.style.position = "absolute";
        background.style.top = "0px";
        background.style.left = "0px";
        background.style.zIndex = 10000;
        document.body.appendChild(background);

        var placeHolder = document.createElement("div");
        var galleryInterfaceWrapper3 = "<div id='galleryInterfaceWrapper_3' style='display:block; z-index:10003;position:absolute;top:0px;left:0px;height:100%;width:1024px;background:transparent;' >";
        var interfaceCenter3 = "<div id='interfaceCenter_3' style='padding:0px 0px 0px 0px;margin:10px auto;;width:100%;position:relative;'>";
        var headerString3 = "<div id='headerString_3' style='float:left;text-align:right;height:25px;display:inline; width:60px;position:relative; top:-615px; left:915px; z-index:10003;'><a id='btnClose' href='#nogo' onclick=\"hideBrochura();\" style='color:#6f6f6f;font-weight:bold; font-family:Arial, Verdana; font-size:11px; text-decoration:none;'><div class=\"div_btn_close\"></div></a></div>";
        var brochura_flash1 = "<div id='brochura_flash' style='position:relative;float:left;width:1024px; z-index:10003;'></div>";

        placeHolder.innerHTML = galleryInterfaceWrapper3 + interfaceCenter3 + brochura_flash1 + headerString3 + "</div></div></div>";

        document.body.appendChild(placeHolder);
    }

    var so = new SWFObject("flash/brochure/" + idlingua + "/main.swf", "brochura_flash", "1024", "650", "10", "#F0F1EB");
    
    so.addParam("wmode", "transparent");
    so.addParam("allowScriptAccess", "sameDomain");
    so.addParam("allowFullScreen", "true");
    so.addParam("movie", "flash/brochure/" + idlingua + "/main.swf");
    so.addParam("quality", "high");
    so.addParam("scale", "noscale");
    so.addParam("bgcolor", "#F0F1EB");    

    so.write("brochura_flash");
    reposition_3();

    window.onresize = function() { reposition_3(); }
    
    // window.onscroll = function() { reposition_1(); }
}

hideBrochura = function() {
    var galleryBackground = document.getElementById("galleryBackground_3");
    var galleryInterface = document.getElementById("galleryInterfaceWrapper_3");
    var interfaceCenter = document.getElementById("interfaceCenter_3");
    var brochuraFlash = document.getElementById("brochura_flash");
    var headerString = document.getElementById("headerString_3");

    galleryBackground.style.display = 'none';
    galleryInterface.style.display = 'none';

    document.body.style.overflow = "auto";
    //document.getElementById('div_banner').style.visibility = 'visible';
};


reposition_3 = function() {
    var galleryBackground = document.getElementById("galleryBackground_3");
    var gInterface = document.getElementById("galleryInterfaceWrapper_3");
    var ScrollTop = document.body.scrollTop;
    document.body.style.overflow = "auto";
    if (ScrollTop == 0) {
        ScrollTop = window.pageYOffset ? window.pageYOffset : ((document.body.parentElement) ? document.body.parentElement.scrollTop : 0);
    }
    galleryBackground.style.height = document.body.offsetHeight.toString() + "px";
    galleryBackground.style.width = document.body.offsetWidth.toString() + "px";
    gInterface.style.left = ((ddGetDocumentSize().width - gInterface.offsetWidth) / 2).toString() + "px";
    gInterface.style.top = (((ddGetDocumentSize().height - gInterface.offsetHeight) / 2) + ScrollTop).toString() + "px";
}

/* VIDEOS */
function show_video(video) {

    //document.getElementById('div_banner').style.visibility = 'hidden';
    //document.getElementById('div_banner').style.display = 'none';

    if (document.getElementById('galleryBackground_2')) {
        var galleryBackground = document.getElementById("galleryBackground_2");
        var galleryInterface = document.getElementById("galleryInterfaceWrapper_2");
        var interfaceCenter = document.getElementById("interfaceCenter_2");
        var masterplanFlash = document.getElementById("video_flash");
        var headerString = document.getElementById("headerString_2");

        galleryBackground.style.display = 'block';
        galleryInterface.style.display = 'block';
    }
    else {


        var background = document.createElement("div");
        background.setAttribute("id", "galleryBackground_2");
        background.style.display = "block";
        background.style.opacity = 80 * 0.01;
        background.style.filter = "alpha(opacity=" + '60' + ")";
        background.style.width = "100%";
        background.style.height = ddGetDocumentSize().height.toString() + "px";
        document.body.style.height = "100%";
        background.style.backgroundColor = '#f0f1ec';
        background.style.position = "absolute";
        background.style.top = "0px";
        background.style.left = "0px";
        background.style.zIndex = 10000;
        document.body.appendChild(background);

        var placeHolder = document.createElement("div");
        var galleryInterfaceWrapper2 = "<div id='galleryInterfaceWrapper_2' style='display:block; z-index:10002;position:absolute;top:0px;left:0px;height:100%;width:700px;background:transparent;' >";
        var interfaceCenter2 = "<div id='interfaceCenter_2' style='padding:0px 0px 0px 0px;margin:100px auto;height:100%;width:100%;position:relative;'>";
        var headerString2 = "";
        var video_flash2 = "<div style='position: absolute; right: -52px; top: -31px; z-index: 20001;'><img src='img/base/closebox.png' style='cursor: pointer; float: right;' onclick='javascript:hideVideo();'/></div><div id='video_flash' style='border:solid 10px white;position:relative;float:left;width:700px;height:412;margin:0px auto; z-index:10002;'></div>"
        placeHolder.innerHTML = galleryInterfaceWrapper2 + interfaceCenter2 + video_flash2 + headerString2 + "</div></div></div>";

        document.body.appendChild(placeHolder);
    }


    var so = new SWFObject("flash/player.swf", "video_flash", "700", "412", "8", "#121212");
    so.addParam("wmode", "transparent");
    so.addParam("allowfullscreen", "true");
    so.addVariable("stretching", "exactfit");
    so.addVariable("file", video);
    so.addVariable("autostart", "true");
    so.write("video_flash");



    reposition_2();

    window.onresize = function() { reposition_2(); }
    // window.onscroll = function() { reposition_1(); }
}

hideVideo = function() {
    var galleryBackground = document.getElementById("galleryBackground_2");
    var galleryInterface = document.getElementById("galleryInterfaceWrapper_2");
    var interfaceCenter = document.getElementById("interfaceCenter_2");
    var masterplanFlash = document.getElementById("masterplan_flash");
    var headerString = document.getElementById("headerString_2");

    galleryBackground.style.display = 'none';
    galleryInterface.style.display = 'none';

    var d = document.getElementById('video_flash')
    d.removeChild(d.firstChild);

    //document.getElementById('div_banner').style.display = 'block';
    //document.getElementById('div_banner').style.visibility = 'visible';
};

reposition_2 = function() {
    var galleryBackground = document.getElementById("galleryBackground_2");
    var gInterface = document.getElementById("galleryInterfaceWrapper_2");
    var ScrollTop = document.body.scrollTop;
    if (ScrollTop == 0) {
        ScrollTop = window.pageYOffset ? window.pageYOffset : ((document.body.parentElement) ? document.body.parentElement.scrollTop : 0);
    }
    galleryBackground.style.height = document.body.offsetHeight.toString() + "px";
    galleryBackground.style.width = document.body.offsetWidth.toString() + "px";
    gInterface.style.left = ((ddGetDocumentSize().width - gInterface.offsetWidth) / 2).toString() + "px";
    gInterface.style.top = (((ddGetDocumentSize().height - gInterface.offsetHeight) / 2) + ScrollTop).toString() + "px";
}

function toggleDiv(obj) { 
    $('#' + obj).animate({opacity: 'toggle'});
}


//VALIDATORS

function ValidateTextBox(source, args) {
    var controltovalidate = source.controltovalidate;
    var is_visible = $("#" + controltovalidate).is(':visible');
    if (is_visible) {
        var is_valid = ($("#" + controltovalidate).val().trim() != "" && $("#" + controltovalidate).val().trim() != 'Max. 1000 caracters');
        $("#" + controltovalidate).css("background-color", is_valid ? "white" : "#FFFFCC");
        args.IsValid = is_valid;
    }
    else {
        $("#" + controltovalidate).css("background-color", "white");
        args.IsValid = true;
    }
}

function ValidateEmailBox(source, args) {
    var emailPattern = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    var controltovalidate = source.controltovalidate;
    var is_visible = $("#" + controltovalidate).is(':visible');
    if (is_visible) {
        var is_valid = (
            $("#" + controltovalidate).val().trim() != ""
            && emailPattern.test($("#" + controltovalidate).val().trim())
        );

        $("#" + controltovalidate).css("background-color", is_valid ? "white" : "#FFFFCC");
        args.IsValid = is_valid;
    }
    else {
        $("#" + controltovalidate).css("background-color", "white");
        args.IsValid = true;
    }
}


function ValidateAnswerRadio(source, args) {
    args.IsValid = false;
    if ($("#ctl00_ContentPlaceHolderCenter_rblPergunta_38 input:radio:checked").length > 0) {
        args.IsValid = true;
        return true;
    }
    

    return false;
}
