/* =========================================================================================

   arquivo: 	nav.images.js
   criado por: 	Autor desconhecido (supoe-se que tenha sido Rafael - rafaellive@gmail.com)
   criado em:	??/??/????
   descricao:	Conjunto de funcoes das caixas laranja sobre as fotos dos usuarios do orkut

   ========================================================================================= */

var Users = {};
    
Users.menu = new Array();

function ImageNavLinksUserId(image)
{
	var link;
	if ((typeof(image.parentNode.href) != 'undefined'))
	{
		link = image.parentNode.href;
	}else
	{
		link = image.href;
	}

	if(link.toLowerCase().indexOf('uid=') != -1)
	{
	    return link.substring(link.toLowerCase().indexOf('uid=') + 4);
    }
    else
    {
        var _uid = link.substring(link.toLowerCase().indexOf('uid%3d') + 6);
        if(_uid.indexOf('&') != -1)
	        return _uid.substring(0, _uid.indexOf('&'));
	    else
	        return _uid;
    }
}

function ImageNavLinksHtml(id)
{   try{
	return '<table style="width: 120; height: 130" cellpadding="0" cellspacing="0">'
           + '<tr><td style="width:10px"></td>'
           + '<td align="right" style="width:120px"><img id="setaTop" src="http://static.powerscrap.com/images/mouseOver_arrow_icon.gif"></td>'
           + '<td style="width:10px"></td></tr>'
           + '<tr><td valign="top"><img id="setaLeft" src="http://static.powerscrap.com/images/mouseOver_arrow_icon3.gif"></td>'
           + '<td><table cellpadding="0" cellspacing="0" style="width: 110px; height: 120px; background: #FFBF12; ">'
		   + '<tr><td class="enviarRecado" onmouseover="this.style.backgroundColor=\'#ffd973\';" onmouseout="this.style.backgroundColor=\'\';" onclick="showRecadosSimples(\''+ id +'\')">'+lblPostscrap+'</td></tr>'
		   + '<tr><td class="verPerfil" onmouseover="this.style.backgroundColor=\'#ffd973\';" onmouseout="this.style.backgroundColor=\'\';" onclick="window.top.goUrl(\'nav/powerkut/Profile.aspx?uid='+ id +'\')">'+lblProfile+'</td></tr>'
		   + '<tr><td class="verRecados" onmouseover="this.style.backgroundColor=\'#ffd973\';" onmouseout="this.style.backgroundColor=\'\';" onclick="window.top.goUrl(\'nav/powerkut/Scrapbook.aspx?uid='+ id +'\')">'+lblScrapbook+'</td></tr>'
		   + '<tr><td class="verFotos" onmouseover="this.style.backgroundColor=\'#ffd973\';" onmouseout="this.style.backgroundColor=\'\';" onclick="window.top.goUrl(\'nav/powerkut/AlbumList.aspx?uid='+ id +'\')">'+lblAlbum+'</td></tr>'
		   + '<tr><td class="verVideos" onmouseover="this.style.backgroundColor=\'#ffd973\';" onmouseout="this.style.backgroundColor=\'\';" onclick="window.top.goUrl(\'nav/powerkut/FavoriteVideos.aspx?uid='+ id +'\')">'+lblVideos+'</td></tr>'
   		  // + '<tr><td class="enviarKiss" onmouseover="this.style.backgroundColor=\'#ffd973\';" onmouseout="this.style.backgroundColor=\'\';" onclick="window.top.goUrl(\'power/machinekiss.aspx?keepSite=ORKUT\')">'+lblMachineKiss+'</td></tr>'
	       + '</table></td>'
           + '<td valign="bottom"><img id="setaRight" src="http://static.powerscrap.com/images/mouseOver_arrow_icon1.gif"></td>'
           + '</tr><tr><td></td>'
           + '<td align="left"><img id="setaBottom" src="http://static.powerscrap.com/images/mouseOver_arrow_icon2.gif"></td>'
           + '<td></td></tr></table>';
	}catch(e){return '';}
}

function ImageNavLinksLayer()
{
	var div = document.getElementById('ImageNavLinksLayer');
	if(!div)
	{
		div = document.createElement('div');
		document.body.appendChild(div);
		div.id = 'ImageNavLinksLayer';
		div.className = 'mouseOver';
		//div.style.width = '140px';
		div.style.position = 'absolute';
		div.style.zIndex = 1001;
		div.onmousemove = function(e){if(!e) e = event; e.cancelBubble = true;};
	}
	div.style.display = '';
	
	return div;
}

function ImageNavLinks(image)
{
    var fixedTop  = 30;
    var fixedLeft = 30;
    
    var userId = ImageNavLinksUserId(image);
	var layer = ImageNavLinksLayer();
	var html = ImageNavLinksHtml(userId);
	layer.innerHTML = html;
	
	var openerPos = getElementPosition(image);	
    var menuSize = getElementPosition(layer);
    var screenSize = getScreenSize();
    var parentScrolling = getParentScrolling(image);
    
    var posLeft = openerPos.left;
    var posTop = openerPos.top;
    
    var setaTop = document.getElementById('setaTop');
    var setaLeft = document.getElementById('setaLeft');
    var setaRight = document.getElementById('setaRight');
    var setaBottom = document.getElementById('setaBottom');
    
    setaTop.style.display = 'none';
    setaLeft.style.display = 'none';
    setaRight.style.display = 'none';
    setaBottom.style.display = 'none';
    
    var setaAlignedOnTop = false;
    var setaAlignedOnLeft = true;

    //Defines the vertical position of the DHTML layer
    if ((posTop - parentScrolling.top + menuSize.height - fixedTop) > screenSize.height){
        if (openerPos.height < 35) fixedTop = 40;        
        posTop = posTop - menuSize.height + fixedTop;
        setaAlignedOnTop = true;
    }
    else{
        if (openerPos.height < 35) fixedTop = 15;
        posTop = posTop + openerPos.height - fixedTop;
    }

    //if the DHTML layer overlaps the footer's div
    if((posTop+(menuSize.height)) > document.getElementById('foottxtID').offsetTop){
        setaAlignedOnTop = true;
        posTop -= menuSize.height;
    }

    //Defines the horizontal position of the DHTML layer
    //if not ie, must verify if exists a media player object and its position
    var isOverMPObject = false;
    if (navigator.plugins && navigator.plugins.length){
        var MediaPlayer = document.getElementById('MediaPlayer');            
        if (MediaPlayer != null){ 
            var posMediaPlayer = getElementPosition(MediaPlayer);
            var maxMediaPlayerTop = posMediaPlayer.top + posMediaPlayer.height;
            var maxMenuTop = posTop + menuSize.height;
            
            if (posTop < maxMediaPlayerTop && maxMenuTop > posMediaPlayer.top)
                isOverMPObject = true;
        }
    }

    if (((posLeft - parentScrolling.left - menuSize.width + fixedLeft) < 0) || (isOverMPObject)){
        if (openerPos.width < 35) fixedLeft = 15;
        posLeft = posLeft + openerPos.width - fixedLeft;
        setaAlignedOnLeft = false;
    }
    else{        
        if (openerPos.width < 35) fixedLeft = 22;
        posLeft = posLeft - menuSize.width + fixedLeft;
    }   

    //Defines the position of the arrow 
    if(setaAlignedOnTop){
        if (setaAlignedOnLeft)
            setaRight.style.display = 'block';
        else
            setaBottom.style.display = 'block';
    }
    else{
        if (setaAlignedOnLeft)
            setaTop.style.display = 'block';
        else
            setaLeft.style.display = 'block';
    }
    
    layer.style.left = posLeft + 'px';
    layer.style.top = posTop + 'px';
}

function ImageNavLinksMouseOut(e)
{
	var div = document.getElementById('ImageNavLinksLayer');
	if(!div) return;
	div.style.display = 'none';	
}
function configImages()
{
    if(!isIE){
		try{
			var alist = document.getElementsByTagName('img');
			for(var i in alist){
				try{
					var bAddMouseOver = true;
					if ((alist[i].id.indexOf("imgFriendImage_FriendPickerControl") != -1) || (alist[i].id.indexOf("hide.gif") != -1) || (alist[i].id.indexOf("show.gif") != -1))
					{
						bAddMouseOver = false;
					}
				
					if(((alist[i].src.indexOf("small") != -1) || (alist[i].src.indexOf("i_nophoto64") != -1)) && bAddMouseOver ){
							alist[i].onmouseover = function(){var o = this; setTimeout(function(){ImageNavLinks(o);}, 0)};
							alist[i].onmousemove = function(e){if(!e) e = event; e.cancelBubble = true;};
					}
					
				}catch(ex){}
			}
			addEvent(document.body, 'mousemove', ImageNavLinksMouseOut)
			return;
		}catch(e){return;}
    }
    
    
	var alist = document.getElementsByTagName('a');
	var controlLowBand = true;
	for(var i in alist){
		try{
		    if((alist[i].href.indexOf('Profile.aspx') != -1) && (typeof(alist[i].firstChild.src) != 'undefined')){
		        if(alist[i].firstChild.src.indexOf('medium') == -1 && alist[i].firstChild.src.indexOf('p_profile.gif') == -1 && alist[i].firstChild.src.indexOf('b.gif') == -1){
			        alist[i].firstChild.onmouseover = function(){var o = this; setTimeout(function(){ImageNavLinks(o);}, 0)};
					alist[i].firstChild.onmousemove = function(e){if(!e) e = event; e.cancelBubble = true;};
					controlLowBand = false;
				}
			}else
			{
				if (controlLowBand)
				{				
					if((alist[i].href.indexOf('Profile.aspx') != -1) && (typeof(alist[i].firstChild.src) == 'undefined')){					
						if (alist[i].childNodes!=null && alist[i].childNodes.length  >= 2 && alist[i].childNodes[1].className =='relbutton')
						{

							 alist[i].childNodes[1].onmouseover = function(){var o = this; setTimeout(function(){ImageNavLinks(o);}, 0)};
							 alist[i].childNodes[1].onmousemove = function(e){if(!e) e = event; e.cancelBubble = true;};
						}else
						{
							if (alist[i].childNodes.length  == 1)
							{
								if (alist[i].innerHTML!='perfil' &&alist[i].innerHTML!='Perfil' && alist[i].innerHTML!='Profil' && alist[i].innerHTML!='profile'&& alist[i].innerHTML!='Profile' )
								{
									alist[i].onmouseover = function(){var o = this; setTimeout(function(){ImageNavLinks(o);}, 0)};
									alist[i].onmousemove = function(e){if(!e) e = event; e.cancelBubble = true;};
								}
							}
						}
					}
				}
			}
		}catch(ex){}
	}
	addEvent(document.body, 'mousemove', ImageNavLinksMouseOut)
}

//Verifica se a página tem scroll e se o mesmo foi utilizado
function getParentScrolling(object){
    var objectParent = object;
    var scrollingTop = 0, scrollingLeft = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrollingTop = window.pageYOffset;
        scrollingLeft = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrollingTop = document.body.scrollTop;
        scrollingLeft = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrollingTop = document.documentElement.scrollTop;
        scrollingLeft = document.documentElement.scrollLeft;
    }
    
    return {left:scrollingLeft, top:scrollingTop }
}

//Obtém a posição absoluta de um objeto na tela
function getElementPosition(offsetTrail){
    var offsetLeft = 0;
    var offsetTop = 0;
    var offsetWidth = offsetTrail.offsetWidth;
    var offsetHeight = offsetTrail.offsetHeight;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;    
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop, width:offsetWidth, height:offsetHeight};
}

//Obtém o tamanho da tela
function getScreenSize()
{
    var offsetHeight = 0;
    var offsetWidth = 0;
    if( typeof( window.innerHeight ) == 'number' ) {
        //Non-IE
        offsetHeight = window.innerHeight;
        offsetWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientHeight ) {
        //IE 6+ in 'standards compliant mode'
        offsetHeight = document.documentElement.clientHeight;
        offsetWidth = document.documentElement.clientWidth;
    } else if( document.body && document.body.clientHeight ) {
        //IE 4 compatible
        offsetHeight = document.body.clientHeight;
        offsetWidth = document.body.clientWidth;
    }
    
    return {width:offsetWidth, height:offsetHeight};
}