function abre_agenda(id_agenda){
    $.blockUI({
        message: $('#ag_text'),
        overlayCSS:  {
            backgroundColor: '#2e4649',
            opacity: 0.6
        }
    });
    $('#texto_ag').html($('#texto_agenda_'+id_agenda)[0].innerHTML);
}
function abre_video(linkvideo,id){
    $('#video_player').html(linkvideo);
    $('#video_player').slideDown('normal');
}




$(document).ready(function(){
    var pathname = window.location.pathname;
 
    if(pathname == "index_videos")       {
        $("a.a-videos").addClass("video-selected");
    };
    if(pathname == "index_br_artist")    {
        $("a.a-artistas").addClass("artista-selected");
    };
    if(pathname == "index_quem_somos")   {
        $("a.a-boranda").addClass("boranda-selected");
    };
    if(pathname == "index_fale_conosco") {
        $("a.a-contato").addClass("contato-selected");
    };
    if(pathname == "index_noticias")     {
        $("a.a-news").addClass("news-selected");
    };
    if(pathname == "index_loja_geral")   {
        $("a.a-loja").addClass("loja-selected");
    };
       
    $("#nav-aba li:first-child").addClass("act");
   
    $("#artistas-loja").hide();

    $("#artistas-loja").hover(function (){
        $("#artistas-loja").show();
    }, function(){
        $("#artistas-loja").hide();
    });

    $("a.menu-selecionar").hover(function () {
        $("#artistas-loja").show();
    }, function () {
        $("#artistas-loja").hide();
    });
    
    
    $('#friend-btn').click(function() { 
        $(".bgUi").css('display' , 'block');
        $(".UiContent").show("fast");
                   
    }); 
    
    $('p.some').click(function() { 
        $(".bgUi").css('display' , 'none');
        $(".UiContent").css('display' , 'none');
                   
    });

    $("#next-video").click(function() {
        var leftvalor = $('#art_boranda').css("left");
        var leftvalorinteiro = parseFloat(leftvalor);
        var mover = leftvalorinteiro - 520 + "px" ;

        $("#art_boranda").animate({
            left: mover
        }, '1000');
    });
   
    $("#prev-video").click(function() {
        var leftvalor = $('#art_boranda').css("left");
        var leftvalorinteiro = parseFloat(leftvalor);
        if(leftvalorinteiro < 0 ){
            var mover = leftvalorinteiro + 520 + "px" ;

            $("#art_boranda").animate({
                left: mover
            }, '1000');
        }
    });
 
    $("#bt_artistas").mouseover(function () {
        $("#menu_artistas_sub").css({
            display:"block"
        });
    });  
	
    $("#menu_artistas_sub").hover(
        function () {
            $("#menu_artistas_sub").css({
                display:"block"
            });
        },
        function () {
            $("#menu_artistas_sub").css({
                display:"none"
            });
        }
        );
    $("a.item_submenu_act span.right").mouseover(function () {
        $("#menu_artistas_sub").css({
            display:"none"
        });
    }); 
	
    $("#logar").toggle(
        function () {
            $("#formlogin").slideDown('slow');
            $(this).toggleClass('logar_act');
        },
        function () {
            $("#formlogin").slideUp('fast');
            $(this).toggleClass('logar_act');
        }
        );

    $("#esqueceu-senha").toggle(
        function(){
            $("#email").fadeOut('slow');
            $("#senha").fadeOut('slow');
            $(".bt_logins").fadeOut('slow');
            $("#email2").show(1000);
            $("#bt_logins").show(1000);
        },
        function() {

            $("#email").show();
            $("#senha").show();
            $(".bt_logins").show();
            $("#email2").hide();
            $("#bt_logins").hide();

        }
        );

	
    //pagina artista
    $(".videos_content ul li:last-child").css({
        border:"none",
        padding:"0",
        margin:"0"
    });
    $(".agenda ul li:last-child").css({
        border:"none",
        padding:"0",
        margin:"0"
    });
    $(".agenda_eventos ul li:last-child").css({
        border:"none",
        padding:"0",
        margin:"0"
    });
	 
	 
    $('.fechar').click(function() {
        $.unblockUI();
    });
    $('.blockOverlay').attr('title','Click to close').click($.unblockUI);

	
    $('#ag_01').click(function() {
        abre_agenda(document.getElementById('ag_div1').innerHTML);
		
    });
	
    // Video Script
    mudarvideo=function(xembeding, pos){
		
        $('#video_player').html("<object width='330' height='210'><param name='movie' value='"+xembeding+"'> </param><param name='allowFullScreen' value='true'></param> <param name='allowscriptaccess' value='always'> <param name='WMODE' value='transparent' /></param> <embed src='"+xembeding+"' width='330' height='210' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' movie='"+xembeding+"' wmode='transparent'></embed></object>");
		
		
        document.getElementById('video01').className = "a";
        document.getElementById('video02').className = "a";
        document.getElementById('video03').className = "a";
        document.getElementById('video0'+pos).className = "act";
    }
	
    $('#cyle_banner').cycle({
        fx: 'fade',
        delay:  1000,
        speed:  1000,
        timeout: 8000
    });
	
    $('.bt_disco').click(function() {
        $.blockUI({
            message: $('#pop_discos'),
            css: {
                top: '20%',
                width: '440px',
                height: 'auto',
                padding: '5px 10px 5px 10px'
				 
            }
        });
    });
	
    $('#close').click( function(){
        $.unblockUI();
        return false
    });
			
			
    $('#artist').cycle({
        fx: 'fade'
    });
	
	
    $('#cyle_art').cycle({
        fx: 'fade',
        delay:  1000,
        speed:  1000,
        timeout: 8000
    });
});

//alert_geral_grande
//
close_global_alert=function(){
    $('#alerta').fadeOut(550);
}

/* NEWSLETTER */
	
function newsletter(){
			
    if( $('#nome-news').val() == '' || $('#nome-news').val() == 'Seu nome' ){
        $('#nome-news').css({
            'border-color' : 'red',
            'border-style' : 'solid',
            'border-width' : '1px'
        });
        return false
    };
    if( $('#email-news').val() == '' || $('#email-news').val() == 'Seu email' ){
        $('#email-news').css({
            'border-color' : 'red',
            'border-style' : 'solid',
            'border-width' : '1px'
        });
        return false
    };
        
    var nemail = $('#email-news').val();
    var nnome = $('#nome-news').val();
        
    $('.newsf .email input').val(nemail);
    $('.newsf .nome input').val(nnome);
		
    var tam = $('.newsf').width();
        
    $.blockUI({
        message: $('#newsletter'),
        css: {
            width: tam,
            height:  'auto',
            top: '100px',
            border: 'none',
            cursor: 'default'
        }
    });
}
function fecharNews(){
    $.unblockUI();	
}
    
/*
	$(document).ready( function(){
		$('.enviarNews').click( function(){
		*/	
function enviarNews(){
		
    if( $('.newsf .nome input').val() == '' ){
        var mensagem = 'Type in your name';
        alert('Type in your name');
        $('.nerro').fadeOut(200).fadeIn(300).html(mensagem);
        $('.newsf .nome input').focus();
        return false
    };

    if( $('.newsf .email input').val() == '' ){
        var mensagem = 'Type in your email';
        alert('Type in your email');
        $('.nerro').fadeOut(200).fadeIn(300).html(mensagem);
        $('.newsf .email input').focus();
        return false
    };
    if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test( $('.newsf .email input').val() ))){
        var mensagem = "Invalid Email";
        alert('Invalid Email');
        $('.nerro').fadeOut(200).fadeIn(300).html(mensagem);
        $('.newsf .email input').focus();
        return false
    };
		
    $('.newsf').submit();
}
/*);
		
});*/



	
function discos_altera(parceiroid){
	
    $.blockUI({
        message: $('#'+parceiroid+''),
        css: {
            top: '25%',
            width: '420px',
            height: 'auto',
            padding: '5px 10px 5px 10px'
        }
    });
         
    $('.fechar').click(function() {
        $.unblockUI({
            });
    });
	
}
//Slide_js

var timeOut = null;
var left;
var t;
var inicial;
var final1 = 123456789;
var idCorre = 'navegacao_principal';
function stopScroll(){
    self.clearTimeout(timeOut);
}


function move(inicial, amt){
    left = Math.round(parseInt(document.getElementById('navegacao_principal').scrollLeft));
    inicial = Math.round(parseInt(inicial));
    amt = Math.round(parseInt(amt));
    //alert(left+"--"+amt);
    t = left + ((amt - left) * 0.3);
    t=Math.round(t);
    document.getElementById('navegacao_principal').scrollLeft = t;
    //alert(t);
    final1=Math.round(final1);
    if (final1 != t) {
        final1 = t;
        timeOut = self.setTimeout('move(' + inicial + ',' + amt + ')', 30);
    }
    else {
        stopScroll();
    }
}

function direita(amt){
    stopScroll();
    inicial = 0;
    amt = Math.round(parseInt(document.getElementById('navegacao_principal').scrollLeft-(-amt)));
    move(inicial, amt);
}


function esquerda(amt){
    stopScroll();
    inicial = 0;
    amt = Math.round(parseInt(document.getElementById('navegacao_principal').scrollLeft-amt));
    move(inicial, amt);
}


function moveport(amt){
    stopScroll();
    inicial = 0;
    amt = Math.round(parseInt(document.getElementById('navegacao_principal').scrollLeft + amt));
    move(inicial, amt);
}

function ArtistasFiltrar(artista2){

    $.post("filtroproduto.php",{
        artista: artista2
    },function(data){

        $('#navegacao_produto').html(data);

    });

}

function add(nome,foto,id,nomeartista) {

    var nome2 = nome;
    var foto2 = foto;
    var id2 = id;
    var nome4 = nomeartista;
	
    $.post("add.php",{
        nome: nome2,
        foto: foto2,
        id: id2,
        nomeartista: nome4
    },function(data){
        //   alert(data.name);
        if(!data.name){
            $('span.loading_effect').fadeOut(100);
			
            $('#cestinha').append("<li id='item_"+id2+"'><a href='javascript:;' title='Remover desta lista' class='remove_item' onclick=\"remove('"+id2+"',0);\"></a><a href=index_lojadetalhe_"+id2+" title="+nome2+"><img src='admin/uploads/artistas/discos_artista/"+foto+"' width='56' height='56' alt="+nome2+"></a></li>");
            valoratual = $('#numero_cesto').text();
            tamanhocesto++;
            if(tamanhocesto > 0){
                document.getElementById('fina_compra2').style.display='none';
                document.getElementById('fina_compra').style.display='block';
            }
			
            $('#botao_enviar_cesto').css('display','block');
            $('#cesta_produtos').slideDown();
            $('#msg_enviar_cesto').css('display','none');
            $('#msg_enviar_cesto2').css('display','none');
            $('#numero_cesto').text(parseFloat(valoratual)+1);
            $('#numero_cesto_2').text(parseFloat(valoratual)+1);
            //aviso
            $('span.msg_effect').fadeIn(700).fadeOut(700);
            $('span.msg_effect').text('Produto adicionado.');
            $('span.msg_effect').css('left','250px');
            $('span.msg_effect').css('color','#54a11b');
        }else{
            $('#jaaddprodutox').css('display', 'none');
            /*  document.getElementById('jaaddproduto').style.display='block';*/
            alert('Este produto já foi adicionado.\nAtualize a quantidade no seu carrinho.');
        }
    },"json");
}



function remove(item,flag){
    
    
    if(confirm("Te certeza que deseja excluir?")){
    
         $.post("remove.php",{id:item,flag:flag},function(data){
            
            tamanhocesto--;
            $('#item_'+item).fadeOut(100).remove();
            
            if(data != 0){
                location.href="index_carrinho";
            }
            
        });
    
     
    
    }
    
    
    //
}


function mostraCaixa(){

    switch(document.getElementById('dados').style.display){
        case 'block':
            document.getElementById('dados').style.display='none';
            break;

        case 'none':
            document.getElementById('dados').style.display='block';
            break;
    }
}

function alteraQtd(item,valor,preco){


    var  certo =  preco.replace(",", ".");

 
   
    precofull = valor*certo;
    var precotexto = precofull+"000";
    certofinal =  precotexto.replace(".", ",");
    finalo =  certofinal.indexOf(",");
    var agora = certofinal.substring(0,finalo+3);

    document.getElementById('precoTotal').innerHTML = agora;

}

function alteraQtdV2(item,iditem,preco2){


    listadiscospreco[item]=preco2.replace(",", ".");
    listadiscosquant[item]=document.getElementById('valo_'+iditem).value;
    
    if(listadiscosquant[item] == ''){
        
        listadiscosquant[item] = 1;
        
    }


    document.getElementById('item_quant_'+iditem).value=listadiscosquant[item];
    //alert(listadiscospreco[item]);
    //alert(listadiscosquant[item]);
    calcularTotal();

}

function calcularTotal(){

      
    var somador = 0;
    var quantTotal = 0;
    for(var i = 0; i<listadiscospreco.length;i++){
        var somador2 =  listadiscospreco[i]*listadiscosquant[i];
        quantTotal = quantTotal-(-listadiscosquant[i]);
        /* var somador3 = somador2+'';
   
        if(somador3.indexOf('.') == -1){
            somador2 = somador2+'.0';
        }*/

        somador = somador + somador2;

    }
    var agora;
    var somador_texto = somador+"";
    //alert(somador_texto);
    somador_texto =  somador_texto.replace(".", ",");
       
    var index_virgula =  somador_texto.indexOf(",");
    if(index_virgula == -1){
        agora = somador_texto+',00';
    } else{
        agora = somador_texto.substring(0,index_virgula+3);
       
        if((somador_texto.length - index_virgula) == 2){
            agora = agora+'0';
        }
       
    }


    document.getElementById('quant_total_prod').innerHTML = quantTotal;
    document.getElementById('quant_total_prod1').innerHTML = quantTotal;
    document.getElementById('precoTotal').innerHTML = agora;
}

function pedido(){
	
	var quantidade = 0;
	
	$('#carrinho-finalizar .first-li').each( function(){
		
		var numeros = $(this).find('input').val();
		quantidade = quantidade + Math.round($(this).find('input').val());
	
	});
	
	if(confirm("Deseja confirmar a compra de "+quantidade+" produto(s)?")){
	
    	$.post("inscrever.php", $("#formpedido").serialize(),
                
			function(data){
				//$(location).attr("href","pagina_inicial");
				$("#formpedido").submit();
				//location.href = "pagina_inicial";
	
			}
        );
	
		redireciona();
	
	}

}
var digitsOnly = /[; 0-9]/g;
$(document).ready(function(){

    $('.bloco_home .not_cont').eq(1).css({
        border : 'none',
        paddingBottom : 0
    });

    $('#nome').keyup(function(event){
        mudarcontador();
        restrictCharacters(this,digitsOnly);

    });
	
    /* noticias ultimo li */
	
    $('.last_no_border:last').css({
        'border-bottom' : 'none',
        'padding-bottom' : '0px'
    });

       
    $("#social-midias li").find('a').hover(function(){
        $("span" , this).css("display" , "block" );
    }, function(){
        $("span" , this).css( {
            "display":"none"
        });
    });
  


  
  
});

jQuery.fn.resetDefaultValue = function() {
    function _clearDefaultValue() {
        var _$ = $(this);
        if ( _$.val() == this.defaultValue ) {
            _$.val('');
        }
    };
    function _resetDefaultValue() {
        var _$ = $(this);
        if ( _$.val() == '' ) {
            _$.val(this.defaultValue);
        }
    };
    return this.click(_clearDefaultValue).focus(_clearDefaultValue).blur(_resetDefaultValue);
}
$(function() {
    $('input').resetDefaultValue(); // for all input elements

});

