var addEvent = function (obj, type, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(type, fn, false);
	}
	else if (obj.attachEvent) {
		obj["e" + type + fn] = fn;
		obj[type + fn] = function () {
			obj["e" + type + fn](window.event);
		};
		obj.attachEvent("on" + type, obj[type + fn]);
	}
};

var positionFinder = function (obj, xy) {
	var xy = xy || [0, 0];

	xy[0] += obj.offsetLeft;
	xy[1] += obj.offsetTop;

	if (obj.offsetParent) {
		positionFinder(obj.offsetParent, xy);
	}

	return xy;
};

var resLinkDivRemoverTimerBegin = function () {
	window.timer = setTimeout(function () {document.body.removeChild(document.getElementById("reslinkdiv"))}, 500);
};

var resLinkDivRemoverTimerClear = function () {
	if (typeof window.timer !== "undefined") {
		clearTimeout(window.timer);
	}
};

var resLinkOver = function () {
	if (document.getElementById("reslinkdiv") !== null) {
		document.body.removeChild(document.getElementById("reslinkdiv"))
	}
	
	var xy = positionFinder(document.getElementById("a-dates"), [183, -10]);

	var resLinkDiv = document.body.appendChild(document.createElement("div"));
	resLinkDiv.id = "reslinkdiv";
	resLinkDiv.style.position = "absolute";
	resLinkDiv.style.left = xy[0].toString() + "px";
	resLinkDiv.style.top = xy[1].toString() + "px";

	var links = [["https://www.reservations-page.com/c00000/h00053/be.ashx", "New Reservation"], ["https://www.reservations-page.com/c00000/h00053/be.ashx?pg=changereservation", "Modify Reservation"], ["https://www.reservations-page.com/c00000/h00053/be.ashx?pg=cancelreservation", "Cancel Reservation"]];

	var ul = resLinkDiv.appendChild(document.createElement("ul"));
	
	for (var i = 0; i < links.length; i++) {
		var li = ul.appendChild(document.createElement("li"));
		var a = li.appendChild(document.createElement("a"));
		a.href = links[i][0];
		a.appendChild(document.createTextNode(links[i][1]));
	}

	document.getElementById("a-dates").onmousemove = resLinkDivRemoverTimerClear;
	document.getElementById("a-dates").onmouseout = resLinkDivRemoverTimerBegin;

	resLinkDiv.onmousemove = resLinkDivRemoverTimerClear;
	resLinkDiv.onmouseout = resLinkDivRemoverTimerBegin;
};

// addEvent(window, "load", function () {document.getElementById("a-dates").onmouseover = resLinkOver});

(function($){
	$.fn.displayMenu = function(){
		var $subMenu = this.find('ul:eq(0)');
		
		this.mouseover(function(){
			$(this).find('ul:eq(0)').css({left : '340px'});
			
		});
		
		this.mouseout(function(){
			$(this).find('ul:eq(0)').css({left : '-4000px'});
		});
		
		// return jQuery object for chaining
		/*return this.each(function(){	 	
		});*/
	}	
})(jQuery);

/*$(function() {
$("a#menu-call").mouseover( function() {
    $("ul#menu").animate({height:"show",opacity:"show"},"slow"); return false;
  });
$("ul#menu").hover( function() {},
  function() { $("ul#menu").animate({opacity:1.0},1125).slideUp(375); return false;
  });
$("a.mlnk").hover(
  function() { $(this).css({ backgroundColor:"#ececec", border:"1px solid #1042de"  }) },
  function() { $(this).css({ border:"none",backgroundColor:"#ffffff"  }) }
  );
})
*/


(function($){
	$.fn.subMenu = function(){	
	
		var $menu = this.find('ul').length > 0 ? this.find('ul:eq(0)') : null;
			
		var $a = $('li:has(ul) > a');
		var timer = 0;
		
		var $myA = $a;			 
		$myA.mouseover(function(index){
			$(this).parents('ul').find('ul').css({ display : 'none'});
			var me = this;				
			clearInterval(timer);
			
			this.$submenu = $(this).parents('li').find('ul:first');
			//this.$submenu.animate({height:'show', opacity:'show'},'slow');
			this.$submenu.css({display: 'block'});				
			this.$submenu.mouseover(function(){
				me.over = true;							 
				clearInterval(timer); 
			});
			
			this.$submenu.mouseout(function(){
				me.over = false;					
				clearInterval(timer); 
				timer = setTimeout (function(){clearMenu(me)}, 500);
			});
			
		});
		
		$myA.mouseout(function(){							  
			var	me = this;
			
			if (typeof me.over == 'undefined' || me.over == false){					
				timer = setTimeout (function(){clearMenu(me)}, 500);
			};
		});
		
			
		function clearMenu(obj){
			obj.$submenu.css({display: 'none'});
		}		
	}
	
})(jQuery);

$(function(){
	$('div.Navigation ul:eq(0)').subMenu();
	
	$('li#petcanstay a').click( function(){
		window.open(this, 'petcanstay', 'scrollbars = 1, location = 1, status=1, height = 700, width =600, resizable =1');									 
		return false;
	});
});


