﻿
var posx = 0, posy =0;
var highlightedText ="";
var ua=navigator.userAgent;
var brw=ua.indexOf("MSIE");
var myContext ="";
var myNavMenu = document.getElementById("navMenu");

var NavContext = {
    //some final vars:
    //alert("zzzz");
    TYPE_MENU: 0,       // menu item
    TYPE_TEXT: 1,       // inline text (non-mutable hard coded)
    TYPE_TEXT_EXT: 2,   // external text (retrived via rpc call)
    TYPE_SEPERATOR:3,   // separator line
    TYPE_ATTRIBUTES:4,  // menu attributes.
    TYPE_ONLINE_AJAX:5,
    TYPE_MESSAGE_AJAX:6,
    TYPE_NOTIFICATIONS_AJAX:7,
    TYPE_ACTIONS_AJAX:8,
    // set the event to trigger the menus: RIGHT,LEFT (right/left click) or mouse MOVE 
    menuTriggerEvent: "LEFT",
    
    // object to hold temp mouse position
    mousePos: {x:0, y:0},

    // offset for menu from mouse pointer
    rightOffset: 5,

    // type of html tags that can have context menus. You can edit this to 
    // allow more tags into the party.
    allowedContexts: ["a","div","span","body","input","td"],

    // object to hold a collection of menus indexed by name
    menuCollection: new Object(),

    // the currently visible context menu DIV element
    contextMenu: null,
    
    // some state machine: is the menu showing (LEFT), and should killing it be aborted (MOVE)
    isShowing: false,
    abortKill: false,
    
    // image cache
    images: new Object(),
    
    // var to hold external requests
    req: null,
    
    // initialize NavContext object 
    initialize: function () {
        this.attachContextEvents();   
    },

    // adds a menu to the menuCollection
    addMenu: function (n, m) {
        this.menuCollection[n] = m;
    },

    // return a menu from the menu collection
    getMenu: function (n) {
            return this.menuCollection[n];
    },

    // loop all context allowed tags in the document and attach menu events to 
    // those that contain the menu attribute
    
    attachContextEvents: function () {
        var tagContext, thisTag;
        for (var t=0; t<this.allowedContexts.length; t++) {
            tags = document.getElementsByTagName(this.allowedContexts[t]);

            for (e=0; e<tags.length; e++) {
                thisTag = tags[e];
                
                //CONTEXT OLUP OLMAMASI BURADA TANIMLI//
         
                tagContext = thisTag.getAttribute("context");
                if (tagContext!=null && tagContext != "undefined") {
                	this.bindEvent('mousemove', tags[e], function(e) { return NavContext.locateMousePos(e); });
					if (this.menuTriggerEvent=="RIGHT") {
                    	tags[e].oncontextmenu = function() { return NavContext.render(this);   }; 
                    } else if (this.menuTriggerEvent=="LEFT") {
						//this.bindEvent('click', tags[e],  function() {  return NavContext.render(this, tagContext);  });
                        tags[e].onclick = function(e) {
                                                        myContext=this.id;
                                                        NavContext.killBubble(e);
                                                        return NavContext.render(this)
                                                       };
                    } else if (this.menuTriggerEvent=="MOVE") {
                        if (!document.all) {
                            this.bindEvent('mouseover', tags[e], function(e) { NavContext.locateMousePos(e); return NavContext.render(this); });
	    					this.bindEvent('mouseout',  tags[e], function(e) { setTimeout("NavContext.killMenu()", 500); });
                        } else {
                            tags[e].onmouseover =  function(e) { NavContext.locateMousePos(e); return NavContext.render(this); };
                            tags[e].onmouseout = function(e) { setTimeout("NavContext.killMenu()", 500); };
                        }
                    }
                }
            }
        }
    },
    
    killBubble: function(e) {
        if (!e) var e = window.event;
        e.cancelBubble = true;
        if (e.stopPropagation) e.stopPropagation();
    },
    
    // binds an event handler to an object
    bindEvent: function (evt, obj, act, bubble) {
   
        if (!bubble) bubble = false;
        if (obj.addEventListener) {
            obj.addEventListener(evt, act, bubble);
        } else if (obj.attachEvent) {

        //obj.attachEvent('on'+evt, act);
        
        ///YENI EKLENENLER BASLIYOR///
        switch (evt)
        {
        case "mousemove":
        obj.attachEvent('on'+evt, act);
        break;
        case "click":
        obj.attachEvent('on'+evt, act);
        break;
        default:
        obj.attachEvent('on'+evt, addEventToObjforIE);
        break;  
        }       
            
        }
        
        function addEventToObjforIE()
        {
        
        switch(evt)
        {
        case "mouseout":
        obj.className="rcMenuItem";
        break;
        case "mouseover":
        obj.className="rcMenuItemHover";
        //obj.className="rcMenuItem";
        break;
        }
        
        ///YENI EKLENENLER BITIYOR///
        
        }

    },
    
 
    /*
     renders a given menu and attaches it to the caller object.
     The caller is responsible to contain a few extra attributes
     that will help construct the links for this menu (i.e., provide the Context)
    */
    render: function (caller, name) {
        var url, title;
        // if name was not specified, grab it from the caller
        // v0.2 - changed to getAttribute (used direct nodeValue access before my mistake). pointed out by JDG.
        var name = name || caller.getAttribute("context");

        // get the requested menu
        var thisMenu = this.getMenu(name);
         
        // extracts this menus attributes list and items
        var attributes = thisMenu["attributes"].split(',');   
        var items = thisMenu.items;
        
        // constructs a map from the callers attributes
        var objMap = this.buildAttributeMap(attributes, caller);

        // start building the menu itself, but first remove menu if visible
        this.killMenu();
        this.buildMenu(caller);
        
        // create a table to build the menu items in
        tbl = document.createElement("TABLE");
        tbl.id = "rcNavContextTable";
        tbl.cellPadding ="1";
        tbl.cellSpacing ="1";
        // loop the menu items and render each according to its type
        for (var m=0; m<items.length; m++) {
            switch (items[m]["type"]) {
                case this.TYPE_MENU:
                    // add the menu item
                    if (this.isDisplayed(items[m], objMap)) {
                    
                    ///YENI EKLENENLER BASLIYOR///
                                       	            
		            //if (m==0) 
		            //{
		            //items[m]["text"] = "<table class='smalltextbold'><tr><td align='right' width='150px'><img src=arrow.png height=8px width=10px></td><td><a href='/SeeOnLineNow.jsp' target='_self'>See All</a></td></tr></table>" ;
		            //}
		            
		         		         		            
                    ///YENI EKLENENLER BITTI///
                                      
                    this.addMenuItem(items[m], objMap, tbl);
                    }
                    break;

                case this.TYPE_TEXT:
                    // add fixed text
                    text = this.transform(items[m]["text"], objMap);
                    cell = this.addTableCell(tbl, "rcMenuItemText", text);
                    break;

               case this.TYPE_TEXT_EXT:
                    cell = this.addTableCell(tbl, "rcMenuItemTextExt");
                    url = this.transform(items[m]["url"], objMap);
                    this.request(url, function() { if (NavContext.req.readyState == 4 && NavContext.req.status == 200) { cell.innerHTML = NavContext.req.responseText } });
                    break;

                case this.TYPE_SEPERATOR:
                    cell = this.addTableCell(tbl);
                    cell.appendChild(this.getSeparator());
                    break;
                    
                case this.TYPE_ONLINE_AJAX:
                    cell = this.addTableCell(tbl, "rcMenuItemText");
                    url = this.transform(items[m]["url"], objMap);
                    //image = this.transform(items[m]["image"], objMap);
                    //align = this.transform(items[m]["align"], objMap);
                    
                    //cell.style.cursor = document.all?'hand':'pointer';
                    //this.bindEvent('mouseover', cell, function(e) { this.className="rcMenuItemHover";});
                    //this.bindEvent('mouseout',  cell, function(e) { this.className="rcMenuItem";     });
                    
                    this.request(url, function()
                    {
                        if (NavContext.req.readyState == 4 && NavContext.req.status == 200)
                        {
                       //this.addMenuItem(items[m], objMap, tbl);
                       
                       
                       //XML'i karsilayip ayristiran bölüm basliyor//
                       var myperson;
                       var mypersonfriends;
                       var mypersongold;
                       var mypersonuid;
                       var mypersonpic;
                       var mypersonstatus;
                       var mypersoncount;
                       var mypersonHTML;
                       var mypersonHTMLforFF;
                                              
                       var xmldata = NavContext.req.responseXML.documentElement;

                                              
                       mypersoncount=xmldata.getElementsByTagName('person').length;
                       
                       for (var i=0;i<mypersoncount;i++)
                       {
                       
                       if (brw<0) //FF
                       {
                       myperson = xmldata.getElementsByTagName('person')[i].childNodes[0].nodeValue;
	                   mypersonfriends = xmldata.getElementsByTagName('friends')[i].childNodes[0].nodeValue;
	                   mypersongold = xmldata.getElementsByTagName('gold')[i].childNodes[0].nodeValue;
                       mypersonuid = xmldata.getElementsByTagName('uid')[i].childNodes[0].nodeValue;
                       mypersonpic = xmldata.getElementsByTagName('pic')[i].childNodes[0].nodeValue;
                       mypersonstatus = xmldata.getElementsByTagName('status')[i].childNodes[0].nodeValue;
                       }
                       else//IE
                       {
                       myperson = xmldata.childNodes(i).childNodes(0).text;
	                   mypersonfriends = xmldata.childNodes(i).childNodes(1).text;
	                   mypersongold = xmldata.childNodes(i).childNodes(2).text;
	                   mypersonuid = xmldata.childNodes(i).childNodes(3).text;
	                   mypersonpic = xmldata.childNodes(i).childNodes(4).text;
	                   mypersonstatus = xmldata.childNodes(i).childNodes(5).text;
                       }
                       
                       if (mypersongold == "gold")
                       {mypersongold =  "<img src='http://images2.yonja.com/images/star.gif' alt='Gold üye' width='11' height='11'>&nbsp;<img src='http://images2.yonja.com/images/tr/on.gif' alt='&#350;u anda Online!' width='21' height='9'>";}
                       else
                       {mypersongold ="&nbsp;<img src='http://images2.yonja.com/images/tr/on.gif' alt='&#350;u anda Online!' width='21' height='9'>"}
                       //XML'i karsilayip ayristiran bölüm bitiyor//
                       
                       //alert(myperson);// = xmldata.getElementsByTagName('person')[i].childNodes[0].nodeValue;
	                   //alert(mypersonfriends);// = xmldata.getElementsByTagName('friends')[i].childNodes[0].nodeValue;
	                   //alert(mypersongold);// = xmldata.getElementsByTagName('gold')[i].childNodes[0].nodeValue;
                                                               
                       if (i==0)
                       {
                       mypersonHTML = "<div align='left'><table onclick=\"goUserPage('profile.jsp?u=" + mypersonuid + "')\" onmouseover='this.className=\"tblON\";' onmouseout='this.className=\"tblOFF\";' border='0' cellpadding='0' cellspacing='3' width='200' bgcolor='#efebe7'><tr><td width='30' height='30' rowspan='2' align='center'><div STYLE='height:30px; width:30px;overflow: hidden;border: 1px solid #D5E0E6'><IMG onContextMenu='return false' src='" + mypersonpic + "' width='100%' height='100%' border='0'></div></td><td height='15' width='130' align='left' class='smalltext'>&nbsp;<b>" + myperson + "</b></td><td height='15' width='40' align='center'>" + mypersongold + "</td></tr><tr><td height='15' width='130' align='left' class='smalltext'><i>&nbsp;&nbsp;" + mypersonstatus + "</i></td><td height='15' width='40' align='center' class='smalltext'>" + mypersonfriends + "</td></tr></table>";
	                   }
                       else
                       {
                       mypersonHTML = mypersonHTML + "<table border='0' cellpadding='0' cellspacing='0' width='200' height='1'><tr><td bgcolor='#cccccc'><img height='1' src='http://images2.yonja.com/images/s.gif'></td></tr></table>" + "<table onclick=\"goUserPage('profile.jsp?u=" + mypersonuid + "')\" onmouseover='this.className=\"tblON\";' onmouseout='this.className=\"tblOFF\";' border='0' cellpadding='0' cellspacing='3' width='200' bgcolor='#efebe7'><tr><td width='30' height='30' rowspan='2' align='center'><div STYLE='height:30px; width:30px;overflow: hidden;border: 1px solid #D5E0E6'><IMG onContextMenu='return false'  src='" + mypersonpic + "' width='100%' height='100%' border='0'></div></td><td height='15' width='130' align='left' class='smalltext'>&nbsp;<b>" + myperson + "</b></td><td height='15' width='40' align='center'>" + mypersongold + "</td></tr><tr><td height='15' width='130' align='left' class='smalltext'><i>&nbsp;&nbsp;" + mypersonstatus + "</i></td><td height='15' width='40' align='center' class='smalltext'>" + mypersonfriends + "</td></tr></table>";
                       }
                                                                                  
                       }
                       
                       mypersonHTML = mypersonHTML + "<table border='0' cellpadding='0' cellspacing='0' width='200' height='1'><tr><td bgcolor='#cccccc'><img height='1' src='http://images2.yonja.com/images/s.gif'></td></tr></table></div>"
                   
                       if (brw<0) //FF
                       {
                       cell.innerHTML = mypersonHTML;
                       }
                       else //IE
                       {
                       cell.innerHTML = mypersonHTML;
                       }
                       
                    

                       } 
                    });
                    break;
                   
                   case this.TYPE_MESSAGE_AJAX:
                    cell = this.addTableCell(tbl, "rcMenuItemText");
                    url = this.transform(items[m]["url"], objMap);
                    //image = this.transform(items[m]["image"], objMap);
                    //align = this.transform(items[m]["align"], objMap);
                    
                    //cell.style.cursor = document.all?'hand':'pointer';
                    //this.bindEvent('mouseover', cell, function(e) { this.className="rcMenuItemHover";});
                    //this.bindEvent('mouseout',  cell, function(e) { this.className="rcMenuItem";     });
                    
                    this.request(url, function()
                    {
                        if (NavContext.req.readyState == 4 && NavContext.req.status == 200)
                        {
                       //this.addMenuItem(items[m], objMap, tbl);
                       
                       
                       //XML'i karsilayip ayristiran bölüm basliyor//
                       var mymessageperson;
                       var mymessageid;
                       var mymessagecontent;
                       var mymessagepic;
                       var mymessagedate;
                       var mymessagecount;
                       var mymessageHTML;
                       var mymessageHTMLforFF;
                                              
                       var xmldata = NavContext.req.responseXML.documentElement;

                                              
                       mymessagecount=xmldata.getElementsByTagName('person').length;
                       
                       for (var i=0;i<mymessagecount;i++)
                       {
                       
                       if (brw<0) //FF
                       {
                       mymessageperson = xmldata.getElementsByTagName('person')[i].childNodes[0].nodeValue;
                       mymessageid = xmldata.getElementsByTagName('id')[i].childNodes[0].nodeValue;
                       mymessagecontent = xmldata.getElementsByTagName('content')[i].childNodes[0].nodeValue.substr(0,60).replace(",",", ");
                       mymessagepic = xmldata.getElementsByTagName('pic')[i].childNodes[0].nodeValue;
                       mymessagedate = xmldata.getElementsByTagName('date')[i].childNodes[0].nodeValue;
                       }
                       else//IE
                       {
                       mymessageperson = xmldata.childNodes(i).childNodes(0).text;
	                   mymessageid = xmldata.childNodes(i).childNodes(1).text;
	                   mymessagecontent = xmldata.childNodes(i).childNodes(2).text.substr(0,60).replace(",",", ");
	                   mymessagepic = xmldata.childNodes(i).childNodes(3).text;
	                   mymessagedate = xmldata.childNodes(i).childNodes(4).text;
                       }
                       
                      //XML'i karsilayip ayristiran bölüm bitiyor//
                       
                       //alert(mymessage);// = xmldata.getElementsByTagName('person')[i].childNodes[0].nodeValue;
	                   //alert(mymessagefriends);// = xmldata.getElementsByTagName('friends')[i].childNodes[0].nodeValue;
	                   //alert(mymessagegold);// = xmldata.getElementsByTagName('gold')[i].childNodes[0].nodeValue;
                                                               
                       if (i==0)
                       {
                       mymessageHTML = "<div align='left'><table onclick=\"goUserPage('Messages.jsp?dsp=" + mymessageid + "&l=0')\" onmouseover='this.className=\"tblON\";' onmouseout='this.className=\"tblOFF\";' border='0' cellpadding='0' cellspacing='0' width='200' bgcolor='#efebe7'><tr><td width='35' height='30' rowspan='2' align='center'><div STYLE='height:30px; width:30px;overflow: hidden;border: 1px solid #D5E0E6'><IMG onContextMenu='return false'  src='" + mymessagepic + "' width='100%' height='100%' border='0'></div></td><td height='15' width='115' align='left' class='smalltext'>&nbsp;<b>" + mymessageperson + "</b></td><td height='15' width='50' align='center' class='smalltext'>" + mymessagedate + "</td></tr><tr><td height='15' width='161' align='left' colspan='2' class='smalltext' style='border-top:0px solid #CCCCCC; padding-left:4px;'>&nbsp;<i>" + mymessagecontent + "...</i></td></tr></table>";
	                   }
                       else
                       {
                       mymessageHTML = mymessageHTML + "<table border='0' cellpadding='0' cellspacing='0' width='200' height='1'><tr><td bgcolor='#cccccc'><img height='1' src='http://images2.yonja.com/images/s.gif'></td></tr></table>" + "<table onclick=\"goUserPage('Messages.jsp?dsp=" + mymessageid + "&l=0')\" onmouseover='this.className=\"tblON\";' onmouseout='this.className=\"tblOFF\";' border='0' cellpadding='0' cellspacing='0' width='200'  bgcolor='#efebe7'><tr><td width='35' height='30' rowspan='2' align='center'><div STYLE='height:30px; width:30px;overflow: hidden;border: 1px solid #D5E0E6'><IMG onContextMenu='return false'  src='" + mymessagepic + "' width='100%' height='100%' border='0'></div></td><td height='15' width='115' align='left' class='smalltext'>&nbsp;<b>" + mymessageperson + "</b></td><td height='15' width='50' align='center' class='smalltext'>" + mymessagedate + "</td></tr><tr><td height='15' width='161' align='left' colspan='2' class='smalltext' style='border-top:0px solid #CCCCCC; padding-left:4px;'>&nbsp;<i>" + mymessagecontent + "...</i></td></tr></table>";
                       }
                                                                                  
                       }
                       
                       mymessageHTML = mymessageHTML + "<table border='0' cellpadding='0' cellspacing='0' width='200' height='1'><tr><td bgcolor='#cccccc'><img height='1' src='http://images2.yonja.com/images/s.gif'></td></tr></table></div>"
                   
                       if (brw<0) //FF
                       {
                       cell.innerHTML = mymessageHTML;
                       }
                       else //IE
                       {
                       cell.innerHTML = mymessageHTML;
                       }
                       
                    

                       } 
                    });
                    break;
                    
                   case this.TYPE_NOTIFICATIONS_AJAX:
                    cell = this.addTableCell(tbl, "rcMenuItemText");
                    url = this.transform(items[m]["url"], objMap);
                    //image = this.transform(items[m]["image"], objMap);
                    //align = this.transform(items[m]["align"], objMap);
                    
                    //cell.style.cursor = document.all?'hand':'pointer';
                    //this.bindEvent('mouseover', cell, function(e) { this.className="rcMenuItemHover";});
                    //this.bindEvent('mouseout',  cell, function(e) { this.className="rcMenuItem";     });
                    
                    this.request(url, function()
                    {
                        if (NavContext.req.readyState == 4 && NavContext.req.status == 200)
                        {
                       //this.addMenuItem(items[m], objMap, tbl);
                       
                       
                       //XML'i karsilayip ayristiran bölüm basliyor//
                       var mynotificationcontent;
                       var mynotificationpic;
                       var mynotificationdate;
                       var mynotificationcount;
                       var mynotificationHTML;
                       var mynotificationHTMLforFF;
                                              
                       var xmldata = NavContext.req.responseXML.documentElement;

                                              
                       mynotificationcount=xmldata.getElementsByTagName('content').length;
                       
                       for (var i=0;i<mynotificationcount;i++)
                       {
                       
                       if (brw<0) //FF
                       {
                       mynotificationcontent = xmldata.getElementsByTagName('content')[i].childNodes[0].nodeValue;
                       mynotificationpic = xmldata.getElementsByTagName('pic')[i].childNodes[0].nodeValue;
                       mynotificationdate = xmldata.getElementsByTagName('date')[i].childNodes[0].nodeValue;
                       }
                       else//IE
                       {
                       mynotificationcontent = xmldata.childNodes(i).childNodes(0).text;
	                   mynotificationpic = xmldata.childNodes(i).childNodes(1).text;
	                   mynotificationdate = xmldata.childNodes(i).childNodes(2).text;
                       }
                       
                      //XML'i karsilayip ayristiran bölüm bitiyor//
                       
                       //alert(mynotification);// = xmldata.getElementsByTagName('person')[i].childNodes[0].nodeValue;
	                   //alert(mynotificationfriends);// = xmldata.getElementsByTagName('friends')[i].childNodes[0].nodeValue;
	                   //alert(mynotificationgold);// = xmldata.getElementsByTagName('gold')[i].childNodes[0].nodeValue;
                                                               
                       if (i==0)
                       {
                       mynotificationHTML = "<div align='left'><table width='200' border='0' cellspacing='0' cellpadding='0' class='mediumtext' bgcolor='#efebe7' style='table-layout: fixed'><tr><td align='center'><img src='http://images2.yonja.com/images/" + mynotificationpic + "' width='16' height='16'></td><td style='overflow: hidden' width='140'>" + mynotificationcontent + "</td><td class='mediumtext' width='36' valign='top' align='right'><font style='font-size: 9px; font-weight:700'>" + mynotificationdate + "&nbsp;</font></td></tr></table>";
	                   }
                       else
                       {
                       mynotificationHTML = mynotificationHTML + "<table border='0' cellpadding='0' cellspacing='0' width='200' height='1'><tr><td bgcolor='#cccccc'><img height='1' src='http://images2.yonja.com/images/s.gif'></td></tr></table>" + "<table width='200' border='0' cellspacing='0' cellpadding='0' class='mediumtext' bgcolor='#efebe7' style='table-layout: fixed'><tr><td align='center'><img src='http://images2.yonja.com/images/" + mynotificationpic + "' width='16' height='16'></td><td style='overflow: hidden' width='140'>" + mynotificationcontent + "</td><td class='mediumtext' width='36' valign='top' align='right'><font style='font-size: 9px; font-weight:700'>" + mynotificationdate + "&nbsp;</font></td></tr></table>";
                       }
                                                                                  
                       }
                       
                       mynotificationHTML = mynotificationHTML + "<table border='0' cellpadding='0' cellspacing='0' width='200' height='1'><tr><td bgcolor='#cccccc'><img height='1' src='http://images2.yonja.com/images/s.gif'></td></tr></table></div>"
                   
                       if (brw<0) //FF
                       {
                       cell.innerHTML = mynotificationHTML;
                       }
                       else //IE
                       {
                       cell.innerHTML = mynotificationHTML;
                       }
                       
                    

                       } 
                    });
                    break;
                    
                    case this.TYPE_ACTIONS_AJAX:
                    cell = this.addTableCell(tbl, "rcMenuItemText");
                    url = this.transform(items[m]["url"], objMap);
                    //image = this.transform(items[m]["image"], objMap);
                    //align = this.transform(items[m]["align"], objMap);
                    
                    //cell.style.cursor = document.all?'hand':'pointer';
                    //this.bindEvent('mouseover', cell, function(e) { this.className="rcMenuItemHover";});
                    //this.bindEvent('mouseout',  cell, function(e) { this.className="rcMenuItem";     });
                    
                    this.request(url, function()
                    {
                        if (NavContext.req.readyState == 4 && NavContext.req.status == 200)
                        {
                       //this.addMenuItem(items[m], objMap, tbl);
                       
                       
                       //XML'i karsilayip ayristiran bölüm basliyor//
                       var myactionid;
                       var myactiontext;
                       var myactionpic;
                       var myactionleft;
                       var myactioncount;
                       var myactionHTML;
                       var myactionHTMLforFF;
                                              
                       var xmldata = NavContext.req.responseXML.documentElement;

                                              
                       myactioncount=xmldata.getElementsByTagName('actionid').length;
                       
                       for (var i=0;i<myactioncount;i++)
                       {
                       
                       if (brw<0) //FF
                       {
                       myactionid = xmldata.getElementsByTagName('actionid')[i].childNodes[0].nodeValue;
                       myactiontext = xmldata.getElementsByTagName('text')[i].childNodes[0].nodeValue;
                       myactionpic = xmldata.getElementsByTagName('pic')[i].childNodes[0].nodeValue;
                       myactionleft = xmldata.getElementsByTagName('left')[i].childNodes[0].nodeValue;
                       }
                       else//IE
                       {
                       myactionid = xmldata.childNodes(i).childNodes(0).text
	                   myactiontext = xmldata.childNodes(i).childNodes(1).text
	                   myactionpic = xmldata.childNodes(i).childNodes(2).text;
	                   myactionleft = xmldata.childNodes(i).childNodes(3).text;
	                   }
                       
                      //XML'i karsilayip ayristiran bölüm bitiyor//
                       
                       //alert(myaction);// = xmldata.getElementsByTagName('person')[i].childNodes[0].nodeValue;
	                   //alert(myactionfriends);// = xmldata.getElementsByTagName('friends')[i].childNodes[0].nodeValue;
	                   //alert(myactiongold);// = xmldata.getElementsByTagName('gold')[i].childNodes[0].nodeValue;
                                                               
                       if (i==0)
                       {
                       myactionHTML = "<div align='left'><table onclick=\"goActionPage('" + myactionid + "')\" onmouseover='this.className=\"tblON\";' onmouseout='this.className=\"tblOFF\";' width='200' border='0' cellspacing='0' cellpadding='0' class='mediumtext' bgcolor='#efebe7' style='table-layout: fixed'><tr><td align='center' height='25'><img border='0' src='" + myactionpic + "' width='16' height='16'></td><td style='overflow: hidden' width='140'>&nbsp;" + myactiontext + "</td><td class='mediumtext' width='36' align='center'><font style='font-size: 9px; font-weight:700'>" + myactionleft + "</font></td></tr></table>";
	                   }
                       else
                       {
                       myactionHTML = myactionHTML + "<table border='0' cellpadding='0' cellspacing='0' width='200' height='1'><tr><td bgcolor='#cccccc'><img height='1' src='http://images2.yonja.com/images/s.gif'></td></tr></table>" + "<table onclick=\"goActionPage('" + myactionid + "')\" onmouseover='this.className=\"tblON\";' onmouseout='this.className=\"tblOFF\";' width='200' border='0' cellspacing='0' cellpadding='0' class='mediumtext' bgcolor='#efebe7' style='table-layout: fixed'><tr><td align='center' height='25'><img border='0' src='" + myactionpic + "' width='16' height='16'></td><td style='overflow: hidden' width='140'>&nbsp;" + myactiontext + "</td><td class='mediumtext' width='36' align='center'><font style='font-size: 9px; font-weight:700'>" + myactionleft + "</font></td></tr></table>";
                       }
                                                                                  
                       }
                       
                       myactionHTML = myactionHTML + "</div>"
                   
                       if (brw<0) //FF
                       {
                       cell.innerHTML = myactionHTML;
                       }
                       else //IE
                       {
                       cell.innerHTML = myactionHTML;
                       }
                       
                    

                       } 
                    });
                    break;
                                             
                default:
                    // no default behaviour
                    break;
            }
            
        }
        // append the menu item table to the menu itself
        this.contextMenu.appendChild(tbl);

        // make sure we're not overflowed to the edge of the screen.
        this.repositionMenu();
        
        if (this.menuTriggerEvent=="MOVE") {
            this.bindEvent('mouseout',  this.contextMenu, function(e) { NavContext.abortKill = false; setTimeout("NavContext.killMenu()",500); });
			this.bindEvent('mouseover', this.contextMenu, function(e) { NavContext.abortKill = true;  });
        } else if (this.menuTriggerEvent=="LEFT" || this.menuTriggerEvent=="RIGHT") {
        	this.bindEvent('click', document.body, function(e) { setTimeout("NavContext.killMenu();", 300); }, false);
        } 
        this.isShowing = true;
        
        return false;
    },

    isDisplayed : function(item, objMap) {
        var reqVar, reqVal;
        var shown = true; // by default all items are shown, unless they require something 
        // lets make sure this item does not require any condition to be true in order to display
        if (item["requires"] != null && item["requires"] != "undefined") {
            // yep, this one has a requirement...
            reqVar = item["requires"][0];
            reqVal = item["requires"][1];
            if (objMap[reqVar] != null && objMap[reqVar] != "undefined") {
                // if the condition is not met, do not show this item.
                if (objMap[reqVar] != reqVal) {
                    shown = false;    
                }
            } else {
                // if the condition is not defined do not show the item
                shown = false;
            }
        }
        return shown;
    },
    
    // check if the menu goes outside the window boundries and adjust its 
    // location if so
    repositionMenu: function() {
        var mPos = this.findPosition(this.contextMenu);
        var mDim = this.getDimensions(this.contextMenu);
        var winHeight = window.innerHeight || document.body.clientHeight;   
        var winWidth = window.innerWidth || document.body.clientWidth;
        if (mPos.y + mDim.height > winHeight-30 ) {
            this.position(this.contextMenu, mPos.x, mPos.y - mDim.height);
            mPos = this.findPosition(this.contextMenu);
        } 
        if (mPos.x + mDim.width > winWidth - 30 ) {
            this.position(this.contextMenu, mPos.x-mDim.width, mPos.y);
        } 
    },
    
    // returns an HR sepearator which uses the rcMenuSeparator style
    getSeparator: function () {
        var sep = document.createElement("HR");
        sep.size=1;
        sep.className = "rcMenuSeparator";
        return sep;
    },
    
    // adds a table cell to the provided table and returns it.
    // attached a class if provided and initializes the cell with some content 
    // where applicable
    addTableCell: function (table, className, content) {
        row = table.insertRow(-1);
        cell = row.insertCell(0);
        if (className) { 
            cell.className = className;
            if (content) {
            cell.innerHTML = content;
            }
        }
        return cell;
    },

    // adds a menu item to the provided table. transforms all data as defined 
    // in the objMap argument
    addMenuItem: function (item, objMap, tbl) {
        var title = this.transform(item["text"], objMap);
        var url, frame, img, imgAlign, itemSrc, tmp, itemAction; 
        var cell = this.addTableCell(tbl, "rcMenuItem", title); 
        cell.style.cursor = document.all?'hand':'pointer';
        this.bindEvent('mouseover', cell, function(e) { this.className="rcMenuItemHover";});
        this.bindEvent('mouseout',  cell, function(e) { this.className="rcMenuItem";     });
        
        // deal with image if applicable
        if (item["image"]!=null && item["image"]!="undefined") {
        	// get image alignment or default to absmiddle
        	imgAlign = (item["align"]!=null && item["align"]!="undefined") ? item["align"] : "absmiddle";
        	// load the image from the cache, or from disk (and then cache it)
        	if (this.images[item["image"]] != null && this.images[item["image"]] != "undefined") {
        		img = this.images[item["image"]];
        	} else {
        		img = this.loadImage(item["image"]);
        	}
        	// set image alignment
        	img.align=imgAlign;
        	// insert the image as first child of the cell
        	cell.insertBefore(this.images[item["image"]], cell.childNodes[0]);
        }
        
        if (item["url"]!=null && item["url"] != "undefined") {
            url   = this.transform(item["url"],  objMap);
            frame = false;
            if (item["frame"] != null && item["frame"] != "undefined") {
                frame = item["frame"];
            }
            cell.onclick = function () { NavContext.redirect(url, frame); }
        } else {
            // we first need to find out if the event handler contains a potential 
            // tag. if so, we grab its source, transform it and re-evaluate it. 
            // if this fails, the value reverts back to its original function
            itemAction = item["onclick"]; 
            try {

	    itemSrc = item["onclick"].toString();
	    if (itemSrc.indexOf('[')>-1) {
                itemSrc = this.transform(itemSrc, objMap);
                if (document.all) { // IE's eval won't return a parsed function.. we need to tell it to set it and then eval
                    eval('itemAction = ' + itemSrc);
                } else { // firefox allows this. 
                    itemAction = eval(itemSrc);
                }
            }
         
            } catch (e) {
               // nothing...
            }

            // set the cell onclick event handler.
            cell.onclick=itemAction;
        }

    },

    // transforms a string based on the provided map
    transform: function (str, map) {
        var tStr, tmp;
        tStr = str;
        for (p in map) {
            tmp = "[" + p + "]";
            tStr = tStr.replace(tmp, map[p]);
        }
        return tStr;
    },

    // returns the menu's attributes collection that will be used to construct 
    // the transformation map
    getMenuAttributeArray: function (menu) {
        for (var i=0; i<menu.length; i++) {
            if (menu[i].type == this.TYPE_ATTRIBUTES) {
                return menu[i]["attributes"].split(',');
            }
        }
        return new Array(0);
    },

    // construct the transformation map for a given object based on the tags in 
    // attribs
    buildAttributeMap: function (attribs, obj) {
        var thisAttr, thisValue;
        var attrMap = new Object();

        for (var a=0; a<attribs.length; a++) {
            thisAttr = attribs[a];
            thisValue = obj.getAttribute(attribs[a]);
            if (typeof thisValue != "undefined") {
                attrMap[thisAttr] = thisValue;
            }
        }
        return attrMap;
    },

    // find the position of an element on the screen and returns an array of [x,y]
    findPosition: function (obj) {
        var lft = 0;
        var top = 0;
        if (obj.offsetParent) {
            lft = obj.offsetLeft
            top = obj.offsetTop
            while (obj = obj.offsetParent) {
                lft += obj.offsetLeft
                top += obj.offsetTop
            }
        }
        return {x:lft,y:top};
    },

    // Returns the dimensions of an element on screen. Lifted from the wonderful 
    // prototype framework
    getDimensions: function(obj) {
        //var display = obj.getStyle('display');
        //if (display != 'none' && display != null) // Safari bug
        //  return {width: element.offsetWidth, height: element.offsetHeight};

        // All *Width and *Height properties give 0 on elements with display none,
        // so enable the element temporarily
        var objStyle = obj.style;
        var originalVisibility = objStyle.visibility;
        var originalPosition = objStyle.position;
        var originalDisplay = objStyle.display;
        objStyle.visibility = 'hidden';
        objStyle.position = 'absolute';
        objStyle.display = 'block';
        var originalWidth = obj.clientWidth;
        var originalHeight = obj.clientHeight;
        objStyle.display = originalDisplay;
        objStyle.position = originalPosition;
        objStyle.visibility = originalVisibility;
        return {width: originalWidth, height: originalHeight};
    },


    // positions object at x,y coordinates
    // v0.2 - added px to the position coordinate (provided by JDG)
    position: function (obj, x, y) {

///YENI EKLENENLER BASLIYOR///

switch(myContext)
{
case 'tmc_link1':
  obj.style.left = (document.body.clientWidth / 2) - 349 + 'px';
  obj.style.top = 292 + 'px';
  break;    
case 'tmc_link2':
  obj.style.left = (document.body.clientWidth / 2) - 171 + 'px';
  obj.style.top = 292 + 'px';
  break;
case 'tmc_link3':
  obj.style.left = (document.body.clientWidth / 2) + 19 + 'px';
  obj.style.top = 292 + 'px';
  break;
case 'tmc_link4':
  obj.style.left = (document.body.clientWidth / 2) + 160 + 'px';
  obj.style.top = 292 + 'px';
  break; 
default:
}


/*
var rightedge = document.body.clientWidth-posx;
var bottomedge = document.body.clientHeight-posy;

if (rightedge < obj.offsetWidth)
obj.style.left = (posx - obj.offsetWidth) + 'px';
else
obj.style.left = posx + 'px';
if (bottomedge < obj.offsetHeight)
obj.style.top = (posy - obj.offsetHeight) + 'px';
else
obj.style.top = posy + 'px';*/
///YENI EKLENENLER BITTI///
    
    
    //alert((document.all) ? document.selection.createRange().text : document.getSelection());
    
      //  obj.style.left = x + 'px';
      //  obj.style.top  = y + 'px';
    },

    // builds a menu for parent object
    buildMenu: function (parent) {
        var pos, dim, tbl;
        //document.onmousemove  = NavContext.getMousePos;
        this.contextMenu = document.createElement("DIV");
        this.contextMenu.id = "rcNavContext";
        this.contextMenu.className = 'rcMenuContainer';

        // get the position and dimensions of the parent
        pos = this.findPosition(parent);
        dim = this.getDimensions(parent);

        // position the container to the bottom right of the element.
        this.position (this.contextMenu, this.mousePos.x + this.rightOffset, pos.y+dim.height);

        // set some event handlers
        // if the menu is triggered by a right click, disable the right click on the menu itself
        if (this.menuTriggerEvent == "RIGHT") {
	        this.contextMenu.oncontextmenu = function () { return false; };
	    }
  		
        // add the container to the body of the document
        //document.body.appendChild(this.contextMenu);
        myNavMenu.appendChild(this.contextMenu);
         
    },


    // kills the currently visible context menu
    killMenu: function () {
        if (!this.abortKill && this.isShowing) {
        try {
            rc = this.contextMenu;
            //document.body.removeChild(rc);
            myNavMenu.removeChild(rc);
        } catch (e) {
            // already removed?
        }
        this.contextMenu = null;
        this.isShowing = false;
        this.abortKill = false;
        }
    },

    // locate the mouse cursor position 
    locateMousePos: function(e) {
        //var posx = 0, posy =0;
        if(e==null) e=window.event;
        if(e.pageX || e.pageY) {
            posx=e.pageX; posy=e.pageY;
        } else if (e.clientX || e.clientY) {
            if(document.documentElement.scrollTop){
                posx=e.clientX+document.documentElement.scrollLeft;
                posy=e.clientY+document.documentElement.scrollTop;
            } else {
                posx=e.clientX+document.body.scrollLeft;
                posy=e.clientY+document.body.scrollTop;
            }
        }
        
        this.mousePos = {x:posx , y:posy};

    },
    
    // redirects the browser to given url
    // if frame!=false, it will open in provided frame (or new win if _blank)
    redirect: function (u, frame) {
        if (!frame) {
            document.location = u;  
        } else {
            if (frame=="_blank") {
                w = window.open(u, 'w');
            } else {
                window.frames[frame].document.location = u;
            }
        }
    },
    
    // performs a request - ajax style
    request: function (url, callBack) {
        if (window.XMLHttpRequest) { // native XMLHttpRequest
            this.req = new XMLHttpRequest();
            this.req.onreadystatechange =  callBack; 
            this.req.open("GET", url, true);
            this.req.send(null);
         } else if (window.ActiveXObject) { // The M$ 'standard'
            this.req = new ActiveXObject("Microsoft.XMLHTTP");
            if (this.req) { 
                this.req.onreadystatechange =   callBack;
                this.req.open("GET", url, true);
                this.req.send();
             }
         }
    },
    
    loadImage: function (url) {
    	var img = new Image();
    	img.src = url; 
    	img.className = "rcImage";
    	this.images[url] = img;
    	return img;
    }

}
