   
/**
 * Namespaces
 */   
           
Nzn = {};
Nzn.SimpleImageGallery = {};

Nzn.SimpleImageGallery.thumbs = {};

//Objeto jquery responsavel por mostrar os thumbs 
//DEVE ESTAR OBRIGATORIAMENTE DENTRO DE UM ELEMENTO <a></a>
Nzn.SimpleImageGallery.shower = null;

Nzn.SimpleImageGallery.selected_index = 0;

Nzn.SimpleImageGallery.thumbs_a = null;

/**
 * Inicia a galeria, configurando coisas necessárias ao funcionamento
 * do esquema
 * @param shower_element object o objeto jquery da img 
 * responsavel por mostrar os thumbs
 */
Nzn.SimpleImageGallery.start_gallery = function(shower_element) {

    Nzn.SimpleImageGallery.shower = shower_element;

    var elements = $("div.thumbs ul li a");
    
    var next_b = $(".bt-next");
    var prev_b = $(".bt-prev");
    
    next_b.live("click", Nzn.SimpleImageGallery.next_image);
    prev_b.live("click", Nzn.SimpleImageGallery.prev_image);
    
    elements.live("click", function(event){
        event.preventDefault();
        Nzn.SimpleImageGallery.change_image(parseInt($(this).attr("data-array-index")));
    });
    
    var counter = 0;
    $.each(elements, function(element){
        $this = $(this);
        $this.attr("data-array-index", counter);
        counter++;
    });

    Nzn.SimpleImageGallery.thumbs_a = elements;
    Nzn.SimpleImageGallery.selected_index = 0;
}

/**
 * Muda para a proxima imagem
 */
Nzn.SimpleImageGallery.next_image = function() {
    if(Nzn.SimpleImageGallery.selected_index < (Nzn.SimpleImageGallery.thumbs_a.length - 1)){
        Nzn.SimpleImageGallery.change_image(Nzn.SimpleImageGallery.selected_index + 1);
    }
}

/**
 * Volta para a imagem anterior
 */
Nzn.SimpleImageGallery.prev_image = function() {
    if(Nzn.SimpleImageGallery.selected_index > 0){
        Nzn.SimpleImageGallery.change_image(Nzn.SimpleImageGallery.selected_index - 1);
    }
}

/**
 * Altera a imagem
 * @param img string A imagem que sera adicionada no thumb visivel
 */
Nzn.SimpleImageGallery.change_image = function(img_index) {
    var img = $(Nzn.SimpleImageGallery.thumbs_a[img_index]);
    
    var img_src = img.attr("href");
    var img_g = img.attr("rel");
    Nzn.SimpleImageGallery.shower.attr("src", img_src);
    
    $(".thumbs").find(".active").removeClass("active");
    img.addClass("active");
    var shower = Nzn.SimpleImageGallery.shower;
    shower.parent().attr("href", img_g);
    shower.attr("title", img.attr("title"));
    shower.attr("alt", img.attr("alt"));
    
    Nzn.SimpleImageGallery.selected_index = img_index;
}

//inicializa o trem
$(function(){
   // Nzn.SimpleImageGallery.start_gallery($("div.slideshow a img"));
			   Nzn.SimpleImageGallery.start_gallery($("#imgprincipal"));
			   
});
    
function sVotesTxt(){
	var volta = $('#detvotes').html();
	$('#detvoteshidden').html(volta);
	$('#detvotes').html('<span class="votes">clique para votar</span> | <a href="javascript:void(0);" onclick="$(\'#rate\').removeClass(\'active\');$(\'#detvotes\').html($(\'#detvoteshidden\').html())">cancelar</a>');
}








function compararprogs(){
	var result = $('#listaRelacionados li input:checked');
	var i=0;
	var total='';
	var separador='';
		for (i=0;i<result.length;i++){
			if(i==0){separador='';}else{separador=','}
				total = total+separador+result[i].value;
		}
		document.location.href='/comparar/default.asp?c='+total;
	return false;
}

function tipsonew() { //usado na pág dos programas para mostrar alternativas pro SO do user
	var veroutro='';
	var addUrl='/';
	if(uSO>1){addUrl='/'+uSOstr.toLowerCase()+'/'}
	if(pSOb.indexOf(',' + uSO)>-1){veroutro=', <a href="'+addUrl+url+'">veja a vers&atilde;o compat&iacute;vel</a>'}
	var msg='<div class=\"dwl-msg\">Esta vers&atilde;o do ' + prog + ' n&atilde;o &eacute; compat&iacute;vel com seu sistema operacional'+veroutro+'.</div>';
	$(msg).insertAfter('.tab-menu');
};


function getdadostempodown(tempo,vel){
	$('#temponet').html(tempo +' para baixar.');$('#velnet').html(vel);
		$(".time a").tipTip({
			activation:"click",
			keepAlive:"true",
			content: $(".time .ttip").html()
		});
}
$(document).ready(function() {
	$(function(){
	    $(".lang[title],.license[title]").tipTip();
		$(".beta").tipTip({
			activation:"click",
			keepAlive:"true",
			content:$(".beta",this).html()
		});
		$(".platform").tipTip({
			content:$(".platform",this).html()
		});
		$(".bits32").tipTip({
			content:$(".bits32",this).html()
		});
		$(".bits64").tipTip({
			content:$(".bits64",this).html()
		});
		$(".rate a[title],.aval[title],.rating[title]").tipTip({defaultPosition:"right"});
	})
	$(".chart-v[href],.chart-d[href]").each(function(){
	    $(this).tipTip({content: "<img src=\""+$(this).attr("href")+"\" />"});
	})
	
	$('.rate a').click(function() {
		if(autenticarCookiePergunta()){
			var nota = $('#valuerate').val();	
			var msg='';
			$.getJSON('/inc/asp/set-voto-programa.asp?c='+codprog+'&n='+nota+'&rdn='+Math.random(1000), function (resp) {
			switch (resp[0]) {
				case 'sucesso':
					msg='Obrigado pelo seu voto!'
				break;
				case 'ja-votou':
					msg='Voc&ecirc; j&aacute; votou nesse programa!'
				break;
				case 'erro':
					msg='Ocorreu um erro, tente novamente!'
				break;
				case 'acesso-externo':
					msg='erro.';
				break;
				default:
					msg='erro.'
				break;
			}
				$('#rate').removeClass('active');
				$('#detvotes').html('<span class="votes">'+msg+'</span>');
		   });
		}
	});


	function autenticarCookiePergunta() {
		if (getCookie("nzn")==null) {
			var janelaAbrir = 'http://www.baixaki.com.br/';
			if (document.location!=null) {
				janelaAbrir = document.location;
			}
			abrirJanela(janelaAbrir,1);
			return false;
		}
		return true;
	}

	function abrirJanela(url_go, usar_parent) {
		if (typeof(usar_parent)=='undefined') {
			usar_parent = 0;
		} else {
			usar_parent = 1;
		}
		tb_show('caixa-login','/usuarios/login.asp?go='+escape(url_go)+'&parent='+usar_parent+'&keepThis=true&TB_iframe=true&height=500&width=775');
	}


	//$('.#tempoDown').click(function() {
		//if(sistemaOp!='Web'){getTempoDownload();}else{$('#temponet').html('1s para acessar.');$('#velnet').html('');}
	//});
	
	//var tempo = tamanhoprog
	//$('#temponet').html(tempo +' para baixar.');$('#velnet').html(vel+' Megas');
	if(sistemaOp!='Web'){
		if ($("#teste-velocidade").html() == null) {$("body").append("<iframe id=\"teste-velocidade\" name=\"teste-velocidade\" style=\"display:none;\" />");}
		$('#teste-velocidade').attr('src','/imagens/teste-velocidade/calcn.asp?t='+tamanhoprog+'&rdn='+Math.random());
	}else{$('#temponet').html('1s para acessar.');$('#velnet').html('');}
	if((pSO!=uSO) && (pSOb.indexOf(',' + uSO)>-1)) { tipsonew(); };
	
	$(".thumbs").find("a").click(function(){
		$this = $(this);
		rel = $this.attr("rel");
		$("#nzn-gal-" + now).stop().hide();
		$("#nzn-gal-" + rel).stop().show();
		
		$("#nzn-thumb-"+ now).removeClass("active");
		$this.addClass("active");
		now = parseInt(rel);
	
	});
	
	$(".bt-prev").click(function(){
		if(now != first) {
			prv = nex = now - 1;
	
			$("#nzn-gal-" + now).stop().hide();
			$("#nzn-gal-" + prv).stop().show();
			
			$("#nzn-thumb-"+ now).removeClass("active");
			$("#nzn-thumb-"+ prv).addClass("active");
			
			now--;
		}
	});
	$(".bt-next").click(function(){
		if(now != last) {
			nex = now + 1;
	
			$("#nzn-gal-" + now).stop().hide();
			$("#nzn-gal-" + nex).stop().show();
			
			$("#nzn-thumb-"+ now).removeClass("active");
			$("#nzn-thumb-"+ nex).addClass("active");
			now++;
		}
	});

});

/**
	Validações Count Home 
**/
//
$(document).ready(function() {	
	var refPage = document.referrer;
	refPage=refPage.replace('www.','');
	var siteRef = '5';
	if(refPage=='http://baixaki.com.br/'){siteRef='1';}else if(refPage=='http://tecmundo.com.br/'){siteRef='4';}else{siteRef='5';}
	if(parseInt(siteRef) > 0){
		$.get('/usuarios/din/views-home.asp?ref='+siteRef+'&codItem='+codprog+'&rdn='+Math.random(),function(data) {});
	}
	$('#promoAika').click(function() {
  		dwnld('/omorp/2cipe/rb.moc.emagno.akia//:ptth',65795,1);
	});
	
	
});
if(document.location.protocol=='http:'){
 var Tynt=Tynt||[];Tynt.push('b5uHD-h_Wr4lBsadbi-bnq');Tynt.i={"ap":"Leia mais em: "};
 (function(){var s=document.createElement('script');s.async="async";s.type="text/javascript";s.src='http://tcr.tynt.com/ti.js';var h=document.getElementsByTagName('script')[0];h.parentNode.insertBefore(s,h);})();
};
////////Caregamento Widgets no onLoad //////
$(window).load(function(){jQuery.getScript('http://platform.twitter.com/widgets.js');$('.bt-facebook').html('<iframe src="//www.facebook.com/plugins/like.php?href='+urlRedesSociais+'&amp;send=false&amp;layout=button_count&amp;width=106&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font=arial&amp;height=21&amp;appId=192951650818648" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:106px; height:21px;" allowTransparency="true"></iframe>');
//TWITTER//
$('.bt-twitter').html('<a href="http://twitter.com/share?url='+urlRedesSociais+'" class="twitter-share-button" data-count="horizontal" data-via="BaixakiOficial" data-related="tec_mundo" rel="me" data-text="Baixando '+prog+' " " '+progVersao+' no Baixaki">Tweet</a>');
// YOUTUBE//
$('#ifrmYoutube').html('<iframe scrolling="no" src="http://www.youtube.com/subscribe_widget?p=baixaki" frameborder="0" style="border:none; overflow:hidden; width:300px; height:105px; background:#FFFFF; border:1px solid #CCCCCC" allowTransparency="true"></iframe>');window.___gcfg = {lang: 'pt-BR'};(function() {var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;po.src = 'https://apis.google.com/js/plusone.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);})();
$('.bt-google').html('<g:plusone size="medium"></g:plusone>');}); 