// JavaScript Document
$(document).ready(function() {

    //Funcőes Básicas

    /* Target hack - para Strict */
    $('a.blank').click(function() {
        $(this).attr("target", "_blank");
    });

    $('a.self').click(function() {
        $(this).attr("target", "_self");
    });

    $('a.parent').click(function() {
        $(this).attr("target", "_parent");
    });

    /* Limpa o Input ao clicar */
    $('input:text').focus(function() {
        if ($(this).val() == $(this).attr("title")) {
            $(this).val("");
            if ($(this).hasClass("password")) {
                $(this).attr("type", "password");
            }
            $(this).bind("blur", function() {
                if ($(this).val() == '') {
                    if ($(this).hasClass("password")) {
                        $(this).attr("type", "text");
                    }
                    $(this).val($(this).attr("title"));
                }
            });
        }
    });

    // Ancoras
    $("#divAncoras a").click(function() {
        var e = $(this).attr("href");
        $(window).scrollTop($(e).offset().top + 30)
        return false;
    });

});

function getFlashMovieObject(movieName) {
	if (window.document[movieName]) {
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
		if (document.embeds && document.embeds[movieName]) return document.embeds[movieName]; 
	}
	else {
		return document.getElementById(movieName);
	}
}

function toggle(i) {
	if($(i).is(":hidden")) $(i).show();
	else $(i).hide();
}


/* 	LIGHTBOX */
function AbreLightBox(nomeArea)
{
	var nomeDiv = '#divLigthbox';
	$(nomeDiv).css("top",($(window).height() / 2) + $(window).scrollTop());
	$(nomeDiv).fadeIn('slow',function() {
		$(window).scroll(function() {
	   		$(nomeDiv).css("top",($(window).height() / 2) + $(window).scrollTop());
	   	});
	});
	$('.fundoLightbox').fadeIn('fast');
	$('.fundoLightbox').animate({opacity:0.3}, 200);
	
	var a = $("#divGeralSite").height();
	var b = $(".fundoLightbox").height();
	
	if(b < a)
	{
		$(".fundoLightbox").css("height", a);
	}else{
		$(".fundoLightbox").css("height", b);
	}
}

function FechaLightBox(nomeDiv)
{
	$(nomeDiv).fadeOut('slow');
	$('.fundoLightbox').fadeOut('fast');
	//var flash = getFlashMovieObject('galeria');
	//flash.FechaLightBox();
	
}

function XHConn()
{
    var xmlhttp, bComplete = false;
    try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
    catch (e) { try { xmlhttp = new XMLHttpRequest(); }
    catch (e) { xmlhttp = false; }}}
    if (!xmlhttp) return null;

    this.Abort = function()
    {
        xmlhttp.abort();
    }

    this.connect = function(sURL, sMethod, sVars, fnDone)
    {
        if (!xmlhttp) {
            return false
        };
        
        bComplete = false;
        
        sMethod = sMethod.toUpperCase();
        
        try {
            if (sMethod == "GET")
            {
                var URL = (sVars.length > 0 ? sURL+"?"+sVars : sURL);
                //alert(URL);
                xmlhttp.open(sMethod, URL, true);
                sVars = "";
            }
            else
            {
                xmlhttp.open(sMethod, sURL, true);
                xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
                xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            }
            xmlhttp.onreadystatechange = function(){
                if (xmlhttp.readyState == 4 && !bComplete)
                {
                    bComplete = true;
                    fnDone(xmlhttp);
                }
            };
            
            xmlhttp.send(sVars);
        }
        catch(z) { 
        alert("catch do metodo: " + z);
        return false;
        }
        return true;
    };
    return this;
}

function addEvent(obj, evType, fn, useCapture)
{
        if (obj.addEventListener){
            //alert("FF");
            obj.addEventListener(evType, fn, useCapture);
            return true;
        } 
        else if (obj.attachEvent){
            //alert("IE");
            var r = obj.attachEvent("on" + evType, fn);
            return r;
        } 
        else
        {
            alert("Handler could not be attached");
        }
    }

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

function tracker(name) {
    try {
        var pageTracker = _gat._getTracker("UA-10180128-1");
        pageTracker._trackPageview(name);
    } catch(err) {}
}
