function Message ()
{
    this.doc = null;
    this.anchor = null;

    this.url = null;


    this.init = function () {

        var doc = document.createElement('div');
        $(doc).addClass('lock');
        $(document.body).prepend(doc);
        this.doc = doc;

        var anc = document.createElement('A');

        $(anc).html('Publicar no twitter').attr('href','javascript:;');


        this.anc = anc;
        $(doc).append(anc);

        $(anc).click(function () {
           window.open(Msg.url, '_blank');
           Msg.hide();
        });

        $(window).resize(function () {Msg.setSize();});

        this.setSize();
    }

    this.setSize = function () {

        $(this.doc).width(document.body.clientWidth);
        $(this.doc).height(document.body.clientHeight);
        var top = (document.body.clientHeight/2)-20;
        $(this.anc).css('marginTop', top+'px');

    }

    this.show = function ()
    {
        $(this.doc).show().fadeTo('fast', 0.9);
    }

    this.hide = function () {
        $(this.doc).hide();
    }

}

var Msg = new Message();

$().ready(function () {Msg.init();})

function getSwf(id) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[id];
    }
    else {
        return document[id];
    }
}  

function shareFacebook (url)
{
    var pageUrl = 'http://www.facebook.com/share.php?u='+encodeURIComponent(url);
    var a = window.open(pageUrl,'facebook', 'toolbar=no,width=700,height=400');
}

function shareTwitter (title,url)
{    
        var msg = title+' '+url+' #fabriciopecanha';
        var u = 'http://twitter.com/?status='+encodeURIComponent(msg);
        window.open(u,'_blank');
}


function shorten (url, callBack)
{
    $.get(Zend().currentPath() + '/shorten', {
        url: url
    }, callBack);
}


var Maps = function () {

	
    this.open = function (id,c, nome, local,data,lial)
    {
        /*	$.get(Zend().currentPath()+'/image/size/id/'+id,{},
		
		function (r)
		{		*/	
        var init = c.split(',');
        //var sizes = r.split(',');
			
        //var iw = parseInt(sizes[0]);
        //var ih = parseInt(sizes[1]);
        //
        var container = document.createElement('div');
        $(container).css('position','absolute');
        $(container).css('width', '100%');
        $(container).css('height', '100%');
        $(container).css('backgroundColor', '#000000');
			
        //$('#flashcontent').css('display', 'none');
			
        $(document.body).append(container);
			
        var bar = document.createElement('div');
        $(bar).attr('id','barmaps');
			
        var logo = document.createElement('div');
        $(logo).attr('id','logo-small');
			
        var text = document.createElement('div')
        $(text).attr('id','txt');
        $(text).html(nome+' @ '+local+' <br>'+data);
			
        var close = document.createElement('div');
        $(close).attr('id','closebt');
			
			
        $(bar).append(logo);
        $(bar).append(text);
        $(bar).append(close);
			
			
        var mapa = document.createElement('div');
        $(mapa).attr('id','maptg');
        $(mapa).css('height',$(window).height());
			
        $(container).append(mapa);
        $(container).append(bar);
			
			
        $(close).click (
            function ()
            {
                $(container).remove();
            //$('#flashcontent').css('display', 'block');
            }
            );
			
        if (GBrowserIsCompatible())
        {
            var map = new GMap2(mapa);
				
            var point = new GLatLng(parseFloat(init[0]), parseFloat(init[1]));
            //alert(parseFloat(init[0]));
				 
            map.setCenter(point, parseInt(init[2]));
				 
            var st='';
				 
				 
				 
            var icon = new GIcon();
            icon.iconSize = new GSize(42, 36);
            icon.iconAnchor = new GPoint((42/2), 36);
            icon.infoWindowAnchor = new GPoint((42/2), 0);
            //icon.image = Zend().getUri()+"/image/marker/id/"+id+"/lial/"+lial;
				 
				 
            if(lial == 'no')
            {
                icon.image = 'http://fabriciopecanha.com/markers/marker_fp.png';
                //icon.image = 'http://localhost/fp/public/imgs/site/marker_fp.png';
                st = 'logos-fp';
            }
            else
            {
                icon.image = 'http://fabriciopecanha.com/markers/marker_lial.png';
                st = 'logos-lial';
            }
				 
            var locked = map.getCenter();
			 	 
            var marker = new GMarker(locked, {
                icon:icon,
                trackMarkers: true
            });
				 
				 
            map.addOverlay(marker);
				 
            var bottomLeft = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(10,10));
				 
            map.addControl(new GSmallMapControl(), bottomLeft);
				 
            map.enableScrollWheelZoom();

				 
            GEvent.addListener(marker, "click", function() {
                marker.openInfoWindowHtml("<div id='"+st+"'></div> <h2><b>"+nome+"</b></h2><br><b>"+data+"</b> - "+local);
            });

        }
        $(bar).fadeTo('fast',0.8);
		
		
		
    //});
    };
}
var mapa = new Maps();

$().ready(function() {
   var params = {
        quality: "high",
        scale: "noscale",
        allowscriptaccess: "always",
        bgcolor: "#000000",
        wmode: 'opaque'
    };
    var flashvars = {
        siteXML: "xml/site.xml"
    };
    var attributes = {
        id: "flashcontent",
        name: "flashcontent"
    };
	
    //alert(FlashDetect.installed);
	
    if(FlashDetect.installed)
    {
        swfobject.embedSWF(Zend().baseUrl() + "/swf/main.swf", "flashcontent", "100%", "100%", "10.0.0", Zend().baseUrl() + "/swf/expressInstall.swf", flashvars, params, attributes);
        swffit.fit("flashcontent",'1000','550');
    }
	
});
function Tritoq_Download(id, file)
{
    var url	  = Zend().baseUrl() + '/' + Zend().module() + '/xml/download';
	
    if(file && id) {
        var TFrame;
        if($('#Tritoq_Frame_Download').length <= 0) {
            TFrame = $(document.createElement('iframe'));
            TFrame.attr('name','TritoqFrameDownload');
            TFrame.attr('id',  'Tritoq_Frame_Download');
            TFrame.attr('style','height:0px; width:0px; border:0; display:none;');
        } else {
            TFrame = $('#Tritoq_Frame_Download');
        }
		
        // Formulário
        var TFile		= $(document.createElement('input'));
        TFile.attr('type', 'hidden').attr('name', 'Tritoq_File').attr('value' ,file);
						
        var TIdFile		= $(document.createElement('input'));
        TIdFile.attr('type', 'hidden').attr('name', 'Tritoq_IdFile').attr('value' ,id);

        var TSection	= $(document.createElement('input'));
        TSection.attr('type', 'hidden').attr('name', 'Tritoq_Section').attr('value' , Zend().action());
		
        var TForm;
        if($('#Tritoq_Form_Download').length <= 0) {
            TForm = $(document.createElement('form'));
            TForm.attr('action', url).attr('method', 'POST').attr('target', 'TritoqFrameDownload').attr('id', 'Tritoq_Form_Download');
        } else {
            $('#Tritoq_Form_Download input').remove();
            TForm = $('#Tritoq_Form_Download');
        }
		
        // Apends
        $(TForm).append(TFile);
        $(TForm).append(TIdFile);
        $(TForm).append(TSection);
        $('body').append(TFrame);
        $('body').append(TForm);
		
        // Submit Form
        $(TForm).submit();
    }
}

