﻿// TODO: Work out where this file lives, and how to ensure it gets referenced 
// (presumably by PubliSiteTemplateBaseClass)

function showhide(id)
{
	if (document.getElementById)
	{
		obj = document.getElementById(id);
	
		if (obj.style.display != "block")
			obj.style.display = "block";
		else 
			obj.style.display = "none";
	}
}

// These functions control the display of the TinyMCE rich text edit control

function getOffSet(myEditor) {
  // Fetch the editor window
  if(document.getElementById) {
    currentEditor = document.getElementById(myEditor).style;
  } else if(document.all) {
      currentEditor = eval('document.all.'+myEditor+'.style');
  }
  currentEditor.display = "block";
  moveEditor(myEditor);
}

function moveEditor(myEditor) {
  if(currentEditor) {

    if (document.documentElement && document.documentElement.scrollTop) {
      var y_offset = document.documentElement.scrollTop;
    } else if (document.body) {
      var y_offset = document.body.scrollTop;
    } else if (window.pageYOffset) {
      var y_offset = window.pageYOffset;
    } else {
      var y_offset = 0;
    }

    if(y_offset > 0) {
      var y_pos = y_offset + 5;
    } else {
      var y_pos = 5;
    }
     currentEditor.top = y_pos;
  }
}

function closeEditor() {
  if(currentEditor) {
    currentEditor.display = "none";
  }
}

$(document).ready(function() {

    $("#pageSettings").click(function() {
        $(this).toggleClass("active");
    });

    $('.editIcon').hover(
		function() {
            var tip = $(this).attr('alt');
            // For IE hide the title
            $(this).attr('title', '');

		    $('body').append('<div class="editIconToolTip"><div class="editIconToolTipBot"><p>' + tip + '</p></div></div>');

		    $('.editIcon').mousemove(function(e) {
		        var x = e.pageX - this.offsetLeft;
		        var y = e.pageY - this.offsetTop;
		        var xOffset = -15;
		        var yOffset = -50;
		        var tooltipWidth = 180;
		        var winWidth = $(window).width();

		        if (x + tooltipWidth > winWidth) {
		            xOffset = -160;
		            $('.editIconToolTip').css('background-position', 'bottom right');
		        }

		        $('.editIconToolTip').css('top', e.pageY + yOffset).css('left', e.pageX + xOffset);

		    });
		    $('.editIconToolTip').fadeIn(500);
		},
	    function() {
		    $('.editIconToolTip').fadeOut(200).remove();
		    $(this).attr('title', $('.editIconToolTipBot').html());
	    }
	);
});  
