$(document).ready(function() {
    /*hack png*/
    $(".png").ifixpng();

    /*botao imprimir*/
    $("#btnImprimir").click(function() {
        $(".print").printArea();
        return false;
    });

    /*flashs*/
    $('#flashHome').flash({ src: '/swf/flashHome.swf', width: 623, height: 453, wmode: 'window' }, {version: '8'} );
    $('#flashComunicacao').flash({ src: '/swf/comunicacao.swf', width: 353, height: 361, wmode: 'transparent' });
    $('#flashConectividade').flash({ src: '/swf/conectividade.swf', width: 353, height: 361, wmode: 'transparent' });
    $('#flashEntretenimento').flash({ src: '/swf/entretenimento.swf', width: 353, height: 361, wmode: 'transparent' });
    $('#flashTecnologia').flash({ src: '/swf/tecnologia.swf', width: 353, height: 361, wmode: 'transparent' });

    /*players youtube*/
	$("#playerPosts").flash({ width: "462", height: "281", bgcolor: "#FFFFFF", wmode: "transparent" }, { version: 9 }, function(htmlOptions){
		htmlOptions.src = 'http://www.youtube.com/v/' + $(this).attr('rel') + '&autoplay=0';
		$(this).html($.fn.flash.transform(htmlOptions));
	});

    /*botoes navegacao compartilhe*/
    $("#share a").each(function() {
        $url = document.location;
        $msg = $(".printTitle").text();
        $href = $(this).attr("href").replace(/(#URL#)/gi, $url).replace(/(#MSG#)/gi, encodeURI($msg));
        $(this).attr("href", $href);
    });

    /*chamada plugin zoom*/
    $(".fontsize").each(function() {
        fontResizer('11px', '12px', '13px');
    });

    /*select gizmodo*/
    $("#optionsGizmodo option").click(function() {
        window.location = $(this).val();
    });

    /*select aprenda*/
    $("#optionsAprenda option").click(function() {
        window.location = $(this).val();
    });
	
	/**/
	 if ( $("h3").hasClass("postGizmodo") ){
	 	$("#boxVerdeAprenda").hide();
		$("#boxVermelhoGizmodo").slideDown();		
	 }
	 else{
	 	$("#boxVermelhoGizmodo").hide();
	 	$("#boxVerdeAprenda").slideDown();
	 }

    /*tickbox gizmodo*/
    $("a.indiqueGizmodo").click(function() {
        $urlIndique = $("a.indiqueGizmodo").attr("rel");
        $template = $("a.indiqueGizmodo").attr("rev");
        tb_show('', '../tb/indiqueGizmodo.aspx?urlIndique=' + $urlIndique + '&template=' + $template + '&keepThis=true&TB_iframe=true&width=630&height=291&modal=true', false);
        return false;
    });

    /*tickbox aprenda*/
    $("a.indiqueAprenda").click(function() {
        $urlIndique = $("a.indiqueAprenda").attr("rel");
        $template = $("a.indiqueAprenda").attr("rev");
        tb_show('', '../tb/indiqueAprenda.aspx?urlIndique=' + $urlIndique + '&template=' + $template + '&keepThis=true&TB_iframe=true&width=630&height=291&modal=true', false);
        return false;
    });

    /*valida form de Indique por Email*/
    $("#formIndiqueAmigo").validate({ errorContainer: $('.msgTenteNovamente'),
        submitHandler: function() { /*mostra mensagem de sucesso*/
            $.ajax({
                data: $("#formIndiqueAmigo").serialize(),
                dataType: "json",
                url: '/Site/Save.ashx?urlIndique=' + getUrlVars()["urlIndique"] + '&template=' + getUrlVars()["template"],
                type: "post",
                success: function(json) {
                    if (json.msg == "OK") {
                        $(".msgSucces").fadeIn();
						$("input[name='Indique.NomeAmigo1'], input[name='Indique.EmailAmigo1'], input[name='Indique.NomeAmigo2'], input[name='Indique.EmailAmigo2']").attr("value","");
                    } else {
                        $(".msgTenteNovamente").fadeIn();
                    }
                }
            });
        }
    });
    function getUrlVars() {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    }
	
	/*GA*/
	$(".ga").click(function(){
		pageTracker._trackPageview($(this).attr("rel"));
	});
	
	/*image repleace titulos*/
	
	/*
	 $("p.rec").flash({ src: '/swf/jfr.swf', wmode: 'transparent', flashvars: {css: ['* { color: #c50a20; }'].join(' ')} }, { version: 8 },
			function(htmlOptions) {
				htmlOptions.flashvars.txt = this.innerHTML;
				this.innerHTML = '<span>'+this.innerHTML+'</span>';
				var $alt = $(this.firstChild);
				htmlOptions.height = $alt.height();
				htmlOptions.width = $alt.width();
				$alt.addClass('alt');
				$(this)
					.addClass('flash-replaced')
					.prepend($.fn.flash.transform(htmlOptions));
			});*/
	
});

/* FONT SIZER VERSION 1.0
 Developed by fluidByte (http://www.fluidbyte.net) */

function imprimir()
{
	$(".print").printArea();
}
 
function fontResizer(smallFont,medFont,largeFont)
{
function clearSelected() { $(".smallFont").removeClass("curFont"); $(".medFont").removeClass("curFont"); $(".largeFont").removeClass("curFont"); }
function saveState(curSize) { var date = new Date(); date.setTime(date.getTime()+(7*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); document.cookie = "fontSizer"+"="+curSize+expires+"; path=/"; }

$(".smallFont").click(function(){ $('.fontsize').css('font-size', smallFont); clearSelected(); $(".smallFont").addClass("curFont"); saveState(smallFont); });

$(".medFont").click(function(){ $('.fontsize').css('font-size', medFont); clearSelected(); $(".medFont").addClass("curFont"); saveState(medFont); });

$(".largeFont").click(function(){ $('.fontsize').css('font-size', largeFont); clearSelected(); $(".largeFont").addClass("curFont"); saveState(largeFont); });

function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "="); if (c_start!=-1) { c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) c_end=document.cookie.length; return unescape(document.cookie.substring(c_start,c_end)); } } return ""; }

var savedSize = getCookie('fontSizer');

if (savedSize!="") { $('.fontsize').css('font-size', savedSize); switch (savedSize) { case smallFont: $(".smallFont").addClass("curFont"); break; case medFont: $(".medFont").addClass("curFont"); break; case largeFont: $(".largeFont").addClass("curFont"); break; default: $(".medFont").addClass("curFont"); } }
else { $('.fontsize').css('font-size', medFont); $(".medFont").addClass("curFont"); }
}