function fix_flash() {
    // loop through every embed tag on the site
    var embeds = document.getElementsByTagName('embed');
    for (i = 0; i < embeds.length; i++) {
        embed = embeds[i];
        var new_embed;
        // everything but Firefox & Konqueror
        if (embed.outerHTML) {
            var html = embed.outerHTML;
            // replace an existing wmode parameter
            if (html.match(/wmode\s*=\s*('|")[a-zA-Z]+('|")/i))
                new_embed = html.replace(/wmode\s*=\s*('|")window('|")/i, "wmode='transparent'");
            // add a new wmode parameter
            else
                new_embed = html.replace(/<embed\s/i, "<embed wmode='transparent' ");
            // replace the old embed object with the fixed version
            embed.insertAdjacentHTML('beforeBegin', new_embed);
            embed.parentNode.removeChild(embed);
        } else {
            // cloneNode is buggy in some versions of Safari & Opera, but works fine in FF
            new_embed = embed.cloneNode(true);
            if (!new_embed.getAttribute('wmode') || new_embed.getAttribute('wmode').toLowerCase() == 'window')
                new_embed.setAttribute('wmode', 'transparent');
            embed.parentNode.replaceChild(new_embed, embed);
        }
    }
    // loop through every object tag on the site
    var objects = document.getElementsByTagName('object');
    for (i = 0; i < objects.length; i++) {
        object = objects[i];
        var new_object;
        // object is an IE specific tag so we can use outerHTML here
        if (object.outerHTML) {
            var html = object.outerHTML;
            // replace an existing wmode parameter
            if (html.match(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")[a-zA-Z]+('|")\s*\/?\>/i))
                new_object = html.replace(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")window('|")\s*\/?\>/i, "<param name='wmode' value='transparent' />");
            // add a new wmode parameter
            else
                new_object = html.replace(/<\/object\>/i, "<param name='wmode' value='transparent' />\n</object>");
            // loop through each of the param tags
            var children = object.childNodes;
            for (j = 0; j < children.length; j++) {
                try {
                    if (children[j] != null) {
                        var theName = children[j].getAttribute('name');
                        if (theName != null && theName.match(/flashvars/i)) {
                            new_object = new_object.replace(/<param\s+name\s*=\s*('|")flashvars('|")\s+value\s*=\s*('|")[^'"]*('|")\s*\/?\>/i, "<param name='flashvars' value='" + children[j].getAttribute('value') + "' />");
                        }
                    }
                }
                catch (err) {
                }
            }
            // replace the old embed object with the fixed versiony
            object.insertAdjacentHTML('beforeBegin', new_object);
            object.parentNode.removeChild(object);
        }
    }
}

function flash6(nome, id, com, alt){
		document.write(
			'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+com+'" height="'+alt+'">'+
			'<param name="movie" value="'+nome+'" />'+
			'<param name="quality" value="high" />'+
			'<param name="wmode" value="transparent" />'+
			'<embed src="'+nome+'?" wmode="transparent" quality="high" width="'+com+'" height="'+alt+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
			'</object>'
		);
}

function abre(url, nome, largura, altura)
{
	// Para fazer com que a janela abra no centro da tela
	var width = screen.width ? (screen.width - largura)/2 : 0;
	var height = screen.height ? (screen.height - altura)/2 : 0;


	win = window.open(url,nome,"resizable,width="+largura+",height="+altura+",status=no,scrollbars,left="+width+",top="+height);
	if (parseInt(navigator.appVersion) >= 4)
	{
		win.window.focus();
	} 
}

function abreSem(url, nome, largura, altura)
{
	// Para fazer com que a janela abra no centro da tela
	var width = screen.width ? (screen.width - largura)/2 : 0;
	var height = screen.height ? (screen.height - altura)/2 : 0;


	win = window.open(url,nome,"width="+largura+",height="+altura+",left="+width+",top="+height);
	if (parseInt(navigator.appVersion) >= 4)
	{
		win.window.focus();
	} 
}

function CampoDespreencheIndicador(ValorInicial, Campo)
{
	var CampoDom = document.getElementById(Campo);
	
	if(ValorInicial == CampoDom.value) {
		CampoDom.value = '';
	}
	
	return true;
}

function CampoPreencheIndicador(ValorInicial, Campo)
{
	var CampoDom = document.getElementById(Campo);
	
	if(CampoDom.value == '' || CampoDom.value == ' ') {
		CampoDom.value = ValorInicial;
	}
	
	return true;
}
	
    ////////////////////////////////////////////////////////////////////////////
// Validação de e-mail by Alfred Reinold Baudisch, V. 1.0 (21/05/2001)    //
// E-mail: alfred@auriumsoft.com.br - http://www.auriumsoft.com.br        //
////////////////////////////////////////////////////////////////////////////
// Verifica se tem um e-mail digitado, com @, ponto no local correto, etc...
function checkEmail(o_email)
{
    var sim_nao = true
    // Verifica o @
    var arroba = o_email.indexOf("@");
    // Verifica o último ponto
    var ponto = o_email.lastIndexOf(".");
    // Verifica se há espaços
    var spaco = o_email.indexOf(" ");
    // 1ª: verifica se existe arroba no e-mail
    // 2ª: Arroba não deve ser o primeiro caractere
    // 3ª: Deve existir "."
    // 4ª: O ponto deve ser uma posição maior onde encontra-se o "@"
    // 5ª: O ponto não deve ser o último caractere
    // 6ª: Não deve existir espaço
    if ((o_email.indexOf("á")==-1) && (o_email.indexOf("à")==-1) && (o_email.indexOf("ã")==-1) && (o_email.indexOf("â")==-1) && (o_email.indexOf("é")==-1) && (o_email.indexOf("í")==-1) && (o_email.indexOf("ó")==-1) && (o_email.indexOf("õ")==-1) && (o_email.indexOf("ô")==-1) && (o_email.indexOf("ú")==-1) && (o_email.indexOf("ü")==-1) && (arroba != -1) && (arroba != 0) && (ponto != -1) && (ponto > arroba + 1) && (ponto < o_email.length - 1) && (spaco == -1) &&
    (o_email.indexOf("{")==-1) && (o_email.indexOf("}")==-1) && (o_email.indexOf("(")==-1) && (o_email.indexOf(")")==-1) && (o_email.indexOf("<")==-1) && (o_email.indexOf(">")==-1) && (o_email.indexOf("[")==-1) && (o_email.indexOf("]")==-1) && (o_email.indexOf("|")==-1) && (o_email.indexOf("\"")==-1) && (o_email.indexOf("/")==-1))
    {
        return true;
    }
    else
    {
        return false;	
    }

}

function ChangeURL(obj)
{
	location.href = obj.value;
}


var goto_top_type = -1;
var goto_top_itv = 0;
function goto_top_timer() {
	var y = goto_top_type == 1 ? document.documentElement.scrollTop : document.body.scrollTop;
	//alert(y);
	var moveby = 15; // set this to control scroll seed. minimum is fast
	y -= Math.ceil(y * moveby / 100);
	if (y < 0)
	y = 0;
	if (goto_top_type == 1)
	document.documentElement.scrollTop = y;
	else
	document.body.scrollTop = y;

	if (y == 0) {
		clearInterval(goto_top_itv);
		goto_top_itv = 0;
	}
}

function goto_top() {
	if (goto_top_itv == 0) {
		if (document.documentElement && document.documentElement.scrollTop)
		goto_top_type = 1;
		else if (document.body && document.body.scrollTop)
		goto_top_type = 2;
		else
		goto_top_type = 0;
		if (goto_top_type > 0)
		goto_top_itv = setInterval('goto_top_timer()', 25);
	}
}

// initialise plugins
jQuery(function(){
        // main navigation init
        jQuery('ul.sf-menu').superfish({
                animation:   {opacity:'show', height:'show'},
                onBeforeShow: function(){
                        $('embed, object, select').css({ 'visibility' : 'hidden' });
                },
                onHide: function(){
                        $('embed, object, select').css({ 'visibility' : 'visible' });
                }
        });
        // projects
        jQuery("#projects .desc .link").animate({opacity:"0"}, "fast");

        jQuery(".projects-wrapper:eq(0)").addClass('first-row');
        jQuery(".projects-wrapper:eq(1)").addClass('second-row').find('.project-img').css({ height: '0px' });
        jQuery(".projects-wrapper:eq(2)").addClass('third-row').find('.project-img').css({ height: '0px' });

        jQuery(".projects-wrapper").mouseenter(function() {
                jQuery(this).find('.project-img').stop().animate({ height: '138px'}, {easing:"easeOutCirc", duration: 700});
                jQuery(this).siblings('.projects-wrapper').find('.project-img').stop().animate({ height: '0px' });
        });


        jQuery(".first-row").find(".link").animate({opacity:"1"}, "fast");
        jQuery(".first-row").mouseenter(function() {
                jQuery(this).siblings('.second-row').stop().animate({ bottom: '73px' });
                jQuery(this).siblings('.second-row').find('.link').animate({opacity:"0"}, "fast");
                jQuery(this).siblings('.third-row').find('.link').animate({opacity:"0"}, "fast");
                jQuery(".first-row").find(".link").animate({opacity:"1"}, "fast");
        });

        jQuery(".third-row").mouseenter(function() {
                jQuery(this).siblings('.second-row').stop().animate({ bottom: '212px' });
                jQuery(this).siblings('.first-row').find('.link').animate({opacity:"0"}, "fast");
                jQuery(this).siblings('.second-row').find('.link').animate({opacity:"0"}, "fast");
                jQuery(".third-row").find(".link").animate({opacity:"1"}, "fast");
        });

        jQuery(".second-row").mouseenter(function() {
                jQuery(this).stop().animate({ bottom: '73px' });
                jQuery(this).siblings('.first-row').find('.link').animate({opacity:"0"}, "fast");
                jQuery(this).siblings('.third-row').find('.link').animate({opacity:"0"}, "fast");
                jQuery(".second-row").find(".link").animate({opacity:"1"}, "fast");
        });

});

$(document).ready(function(){
            $('#news').innerfade({
                    animationtype: 'slide',
                    speed: 750,
                    timeout: 2000,
                    type: 'random',
                    containerheight: '1em'
            });

            $('ul#portfolio').innerfade({
                    speed: 1000,
                    timeout: 5000,
                    type: 'sequence',
                    containerheight: '220px'
            });

            $('.fade').innerfade({
                    speed: 1000,
                    timeout: 6000,
                    type: 'random_start',
                    containerheight: '1.5em'
            });

            $('.adi').innerfade({
                    speed: 'slow',
                    timeout: 5000,
                    type: 'random',
                    containerheight: '150px'
            });

            fix_flash();
});
