$(document).ready(function() {	
	/*
	Tooltip
	*/
	var currentlyShowing = false;
	$(".highlight").hover(
		function() {
			if(currentlyShowing == false) {
				currentlyShowing = true;
				//alert($(this).text());
				thistmpid = $(this).attr("id");
				//alert(thistmpid);
				//e.preventDefault();
				toolTipShow(thistmpid, currentlyShowing);
			}
		},
		function() {
			$("#" + thistmpid + " div").hide();
			$("#" + thistmpid + " span").hide();
			currentlyShowing = false;
		}
	);
	
	//Little menu
	$('li.littlemenu').hover(
		function(){ 
			$('ul', this).css('display', 'block'); 
			$(this).addClass('hover');			
		},
		function(){ 
			$('ul', this).css('display', 'none'); 
			$(this).removeClass('hover');
		}
	);
	
	//External links (show confirmation prompt)
	$('a.externallink').click(function(){
		var extURL = $(this).attr('href');
		//alert(extURL);
		var answer = confirm("You are now leaving the INREIT site");
		if(answer){
			window.location = extURL;
		}
		return false;
	});
	
});

function externalLink(){
	
}

function rPosition(elementID, mouseX, mouseY) {
  /*
  var offset = $('#'+elementID).offset();
  var x = mouseX - offset.left;
  var y = mouseY - offset.top;
  */
  var x = mouseX;
  var y = mouseY;
  
  return {'x': x, 'y': y};
}
var mouseX = 0;
var mouseY = 0;
$().mousemove( function(e) {
   mouseX = e.pageX; 
   mouseY = e.pageY;
 });
function toolTipShow(elementid, tmpShow) {
	//$("#" + elementid).attr("title", data);
	//alert($("#" + elementid).attr("title"));
	//$("#" + elementid).title = "AGTESTING";
	var thistext = "";
	thistext = $("#" + elementid).text();
	//alert(thistext);
	var pos = $("#copy_col").offset();  
  	var width = $("#copy_col").width();

	$("#" + elementid).simpletip({
		content: "<img src='images/loading.gif' alt='Loading' />",
		//fixed: false,
		position: [0, 0],
		onBeforeShow: function(){
			// Note this refers to the API in the callback function
			if(tmpShow) {
				this.load('ajax_tooltip.php?tooltip=' + escape(thistext) + "&x=" + (mouseX - pos.left) + "&y=" + (mouseY - pos.top));
			}
		}
	});
}
function settab(thistab) {
	//alert(document.MM_sr[0].oSrc);
	//alert(x.oSrc);
	var thiselement = "";
	var thisimage = "";
	for(i = 1; i <= 4; i++) {
		var thisitem = "tab_content_" + i;
		var thisicon = "tab_off_" + i;
		if(i == thistab) {
			thiselement = document.getElementById(thisitem);
			thiselement.style.display = "block";
			thisimage = document.getElementById(thisicon);
			thisimage.src = "images/tab_on_" + i + ".gif";
			document.MM_sr[0].oSrc = "images/tab_on_" + i + ".gif";
			
		}
		else {
			thiselement = document.getElementById(thisitem);
			thiselement.style.display = "none";
			thisimage = document.getElementById(thisicon);
			thisimage.src = "images/tab_off_" + i + ".gif";
			//document.MM_sr[0].oSrc = "images/tab_off_" + i + ".gif";
			
		}
	}
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function viewpageid(thispage, thisid, thiswidth, thisheight) {
	var thiswindow;
	thiswindow = window.open(thispage + '?id=' + thisid, 'viewpage', 'width=' + thiswidth + ',height=' + thisheight + ',scrollbars,resizable');
	thiswindow.focus();
}
function viewpage(thispage, thiswidth, thisheight) {
	var thiswindow;
	thiswindow = window.open(thispage, 'viewpage2', 'width=' + thiswidth + ',height=' + thisheight + ',scrollbars,resizable');
	thiswindow.focus();
}
function viewimage(thisimg, thiswidth, thisheight) {
	var thiswindow;
	thiswindow = window.open('viewimage.php?id=' + thisimg, 'viewphoto', 'width=' + thiswidth + ',height=' + thisheight + ',scrollbars,resizable');
	//alert('viewimage.php?id=' + thisimg);
	thiswindow.focus();
}
function viewphotogallery(thisimg, thiswidth, thisheight) {
	var thiswindow;
	thiswindow = window.open('viewphotogallery.php?id=' + thisimg, 'viewphotogallery', 'width=' + thiswidth + ',height=' + thisheight + ',scrollbars,resizable');
	//alert('viewimage.php?id=' + thisimg);
	thiswindow.focus();
}
function closethiswindow() {
	window.close();
	window.opener.focus();
}
function inittb(pagestr)
{
tb_show('Loaded onload', pagestr, null);
}
