var base_url = $('base').attr('href');


var teste = null;

$(document).ready(function(){

      $('.bt_comercial, .bt_ver_depoimento').click(function(){
            video = $(this).attr('href');
            $('#comercial:visible').hide();
            $('#depoimento:visible').hide();
            $(video).css("display","block");
            //clearTimeout(teste);

            troca_fundos_ivete();

            return false;
        })
            
        $('.bt_comercial').click();
	
	$('.nome_news').focusin(function(){
		$(this).addClass('txt_active');							   
	});
	$('.nome_news').focusout(function(){
		$(this).removeClass('txt_active');							   
	});
	$('.email_news').focusin(function(){
		$(this).addClass('txt_active');							   
	});
	$('.email_news').focusout(function(){
		$(this).removeClass('txt_active');							   
	});	
	
	$(".lista_box_home .box_centro").click(function(){
		location.href = $("base").attr("href") + "moda_de_novela";
	})	
	watermark.init();
	validacao_contato();
	boxHover();
	$('.sub_mn').hide();
	open_submenu();
	exception();
	foto();
	select_fake('.select_padrao');
	page = new Page("a[rel=page]");
    page.start();
	jQuery('a[rel*=facebox]').facebox() 
	facebox();

    jQuery('#mycarousel').jcarousel({
        vertical: false,
		horizontal: true,
        scroll: 1
    });
	
	var i = 0;
    jQuery("#mycarousel").find("li").each(function(){
        if(i <= 4){
            jQuery('.jcarousel-prev').hide();
			jQuery('.jcarousel-next').hide();
        }
        i++;
    });
				   
});



 function troca_video(){

                 //teste = setTimeout(function(){
                    var fundos_camila = new Array("home1.jpg","home2.jpg","home3.jpg");
                    indice = Math.round((Math.random()*(fundos_camila.length-1) ));
                    $("body").attr("style","background:#000 url(uploads/fundos/" + fundos_camila[indice] + ") center 0 no-repeat");
                    $('#video_2, #colecao_2').show();
                    $('#video_1, #colecao_1').hide();
					$('.bt_veja_mais span').html('Grendha Ivete Sangalo Jóia Cigana');
					$('.bt_veja_mais').click(function(){
						troca_fundos_ivete();
					});
                    /*setTimeout(function(){
                        troca_fundos_ivete();
                     },35000)*/
                // },35000)
                
            }

function troca_fundos_ivete(){
         var fundos_ivete = new Array("bg_ivete_2_01.jpg","bg_ivete_2_02.jpg","bg_ivete_2_03.jpg");
         indice = Math.round((Math.random()*(fundos_ivete.length-1) ));
         $("body").attr("style","background:#000 url(uploads/fundos/" + fundos_ivete[indice] + ") center 0 no-repeat");
         $('#video_1, #colecao_1').show();
         $('#video_2, #colecao_2').hide();
		 $('.bt_veja_mais span').html('Grendha Beleza Natural com Camila Pitanga');

		 		$('.bt_veja_mais').click(function(){
					troca_video();
				});
				 /*teste = setTimeout(function(){
                        troca_video();
                     },35000);*/
}

//Funções para o FaceBox
function abrir(strMensagem)
{
    $(document).ready(function(){
         $("#facebox").removeClass('modal_video');
         $("#facebox").addClass('modal_zoon');
         jQuery.facebox(strMensagem);
    })
}

function busca_cidades(estado_id)
{
	var wait = 'Carregando Cidades';

    $("#cidade").parent('li').find('.select-replacement').html(wait);

	vet_dados = "estado_id="+estado_id;

    base_url  = $('base').attr('href')+"cadastro/busca_cidades";
    $.ajax({
        type: "POST",
        url: base_url,
        data: vet_dados,
        success: function(msg) {
			$("#cidade").parent('li').find('.select-replacement').html('Selecione uma cidade');
        	$("#cidade").html(msg);
        }
   });
   
}

function exception(){
    var cont = 1;
	
    jQuery(".lista_modelo").find("li").each(function(){
        if(cont % 6 == 0){
            jQuery(this).addClass("last");
        }
        cont++;
    });
	
	jQuery(".lista_posts ul li:last-child").addClass('last');


	jQuery(".lista_posts ul li p").each(function(){
		var str = jQuery(".lista_posts ul li h2").text() + jQuery(this).text();
    	//alert(str);
        if(str.length >= 150){
            str = str.substring(0,150)+"...";
        }
		
        //jQuery(this).text(str);
	});
}

	

function boxHover(){
	$('.text_moda').hover(
	
	function(){
		$('.bg_top, .bg_content, .bg_bottom').addClass('hover');
	},
	
	function(){
		$('.bg_top, .bg_content, .bg_bottom').removeClass('hover');
	}

	);	
	
}

function open_submenu(){
	$(".with_submenu").hover(function(){
		$(this).next('.sub_mn').fadeIn();
	});
	$(".item_menu").hover(function(){
		$('.sub_mn').fadeOut();
	});
	$(".sub_mn").mouseout(function(){
		$(this).mouseleave(function(){
			$(this).fadeOut();
		});
	});
	
}

function validacao_contato(){
	$(".bt_enviar_contato").click(function(){
		var status_valida=0;							  
		if($('#nome_contato').val() == ''){
			$('#nome_contato').addClass('alerta_form');
			status_valida=1;
		}
		else{
			$('#nome_contato').removeClass('alerta_form');
		}
		if($('#email_contato').val() == ''){
			$('#email_contato').addClass('alerta_form');
			status_valida=1;
		}
		else{
			$('#email_contato').removeClass('alerta_form');
		}
		if($('#mensagem').val() == ''){
			$('#mensagem').addClass('alerta_form');
			$('#mensagem').addClass('alerta_msg');
			status_valida=1;
		}
		else{
			$('#mensagem').removeClass('alerta_form');
			$('#mensagem').removeClass('alerta_msg');
		}
		if(status_valida==1){
			$('.mensagem_erro').fadeIn();
			return false;
		}
	});
	
	$('.bt_indicar').click(function(){
		var status_valida=0;
		if($('#nome').val() == 'seu nome'){
			$('#nome').addClass('error');
			status_valida=1;
		}
		else{
			$('#nome').removeClass('error');
		}
		
		if($('#e-mail').val() == 'seu e-mail'){
			$('#e-mail').addClass('error');
			status_valida=1;
		}
		else{
			$('#e-mail').removeClass('error');
		}
		
		if($('#nome_amiga').val() == 'nome da amiga'){
			$('#nome_amiga').addClass('error');
			status_valida=1;
		}
		else{
			$('#nome_amiga').removeClass('error');
		}
		
		if($('#email_amiga').val() == 'e-mail da amiga'){
			$('#email_amiga').addClass('error');
			status_valida=1;
		}
		else{
			$('#email_amiga').removeClass('error');
		}
		
			
			
		if(status_valida == 1){
			return false;}
	});
	
	$('#bt_news').click(function(){
		var status_valida=0;
		if($('.nome_news').val() == 'nome'){
			$('.nome_news').addClass('error');
			$('.alerta').show();
			status_valida=1;
		}
		else{
			$('.nome_news').removeClass('error');
			$('.alerta').hide();
		}
		
		if($('.email_news').val() == 'email'){
			$('.email_news').addClass('error');
			$('.alerta').show();
			status_valida=1;
		}
		else{
			$('.email_news').removeClass('error');
			$('.alerta').hide();
		}
		
		if(status_valida == 1){
			return false;}
	});
}


function Page(start){
    jQuerypage = this;
    //start = "a[rel=pages]";
    var url;
    position = new Object();
	
    //start
    jQuerypage.start = function(){
        jQuery("<div />",{
            id: 'page'
        }).appendTo('body');
        jQuery("<div />",{
            id: 'loader'
        }).appendTo('body');
        jQuery("#page").append("<a title=\"Fechar\" class=\"fechar\" /><div id=\"page-content\" />")
        //istancia
        jQuery(start).each(function(){
            jQuery(this).click(function(e){
                //verifica a posiçao
                lastUrl = url;
			
                url = jQuery(this).attr('href');
			
                if(url != lastUrl){
                    jQuery("#page").fadeOut("slow");
                }
			
			
                position.x = e.pageX;
                position.y = e.pageY;
                position.aux =  parseInt(jQuery("#page").css('padding-top')) + parseInt(jQuery("#page").css('padding-bottom'));
                position.top  = jQuery(this).offset().top;
                position.left = jQuery(this).offset().left;
			
                position.elTop  = jQuery(this).offset().top - (jQuery(this).height() + 5);
                position.elLeft = position.x - 15;
			
                if(jQuery(this).hasClass("relative")){
				
                    position.top  = (jQuery(".content").height() - (jQuery(this).height() + 270)) / 2;
                    position.left = jQuery(".content").offset().left + 213;
                }
			
                //carrega
                jQuerypage.load();
                return false;
            });
        });
    }
	
    jQuerypage.load = function(){
        jQuery("#loader").css({
            left: position.elLeft,
            top: position.elTop
        });
		
        jQuery.ajax({
            url: url,
            beforeSend: function(){
                jQuery("#loader").fadeIn();
            },
            complete: function(a,b){
                jQuery("#loader").fadeOut();
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                jQuery("#page-content").empty();
                jQuery("#page-content").append("<span class=\"page-error\">Ops! ocorreu um erro ao acessar a página " + url + "</span>");
                jQuery("#page").css({
                    left: position.left,
                    top: position.top
                });
                jQuery("#page").fadeIn("slow");
                jQuerypage.close();
            },
            success: function(data) {
                jQuery("#page-content").html(data);
                jQuerypage.close();
                jQuery("#page").css({
                    left: position.left,
                    top: position.top
                });
                jQuery("#page").fadeIn("slow");
                watermark.init();
                $(".validate").each(function(){
                    $(this).validate();
                })
                //validate();

				$(".pagination a").each(function(){
					$(this).click(function(){
						$("#dados").load($(this).attr("href"));
						return false;	
					})
				});
            }
        });
		
    }
	
    jQuerypage.close = function(){
        jQuery(".fechar").unbind();
        jQuery(".fechar").click(function(){
            jQuery("#page").fadeOut();
            return false;
        });
    }
	
}

function foto(){
	jQuery('.foto_click').click(function(){
		var url = jQuery(this).attr('href');
                var codigo = jQuery(this).attr('title');
                var id_cor = jQuery(this).attr('id');
                var url_indique = 'modal_indique.php?id_cor=' + id_cor;
                var url_ok = url.replace("70x53", "355x277");
                var url = url.replace("70x53", "200x156");
		jQuery(".carrega_foto").attr('src',url,'hrf',url);
                jQuery(".zoom_foto").attr('src',url_ok,'hrf',url_ok);
                jQuery("#link_indique").attr('href',url_indique,'hrf',url_indique);
                $('#cod_prod').html(codigo);
		return false;
	})
	jQuery('.foto_click:eq(0)').click();
}

function facebox(){
	$(".bt_zoon").click(function(){
			$("#facebox").removeClass('modal_video');
			$("#facebox").addClass('modal_zoon');
			var zoon = $('#foto_grande').html()
			jQuery.facebox(zoon);
		});
	
	
	$(".abre_video").click(
		function(){
			$("#facebox").addClass('modal_video');
			$("#facebox").removeClass('modal_zoon');
			var video = $('#zoon_video').html()
                        //var video = '#zoon_video';
                        //alert(video);
			jQuery.facebox(video);
		});
	
	$(".bt_zoon_universo").click(function(){
		$("#facebox").removeClass('modal_video');
		$("#facebox").addClass('modal_zoon');
		var zoon = $('#foto_grande').html()
		jQuery.facebox(zoon);
	});
}

function select_fake(start){
		$('.select_padrao').each(function(){
				var el  = $(this).find('option:first-child').html();
				var color = $('.'+$(this).attr('class')).css('color');
				var w = $(this).width() - 15;
				$(this).addClass('select-hide');
				$(this).before('<div class="borda-left"></div><div class="select-fake" style="width:'+w+'px;color:'+color+'">'+el+'</div><div class="clear"></div>');
	
			$(this).change(function(){
									
						var str = $(this).children('option:selected').text();

						$(this).parent('li').find('.select-fake').html(str);
				});
		});
	}
	
	

	

