/*--- toolbar ---*/
function initToolbar(){
	var _speed = 500;
	var _hold = $('div.toolbar-wrapper:eq(0)');
	if(_hold.length){
		var _list = _hold.find('div.slide-hold').parent();
		_list.each(function(){
			var _el = $(this);
			var _btn = _el.children('a');
			var _box = _el.children('div.slide-hold');
			
			if(_btn.length && _box.length){
				_box.hide();
				var sub_box = _box.children();
				sub_box.css({ position:'relative'});
				_btn.mouseenter(function(){
					if(_box.is(':hidden')){
						_box.show();
						if($.browser.msie) sub_box.css({bottom: -(sub_box.outerHeight()+10)});
						else sub_box.css({bottom: -(sub_box.outerHeight()+10), opacity: 0});
					}
					_el.addClass('hover');
					if($.browser.msie) sub_box.stop().animate({bottom:0}, _speed);
					else sub_box.stop().animate({bottom:0, opacity: 1}, _speed);
				});
				_el.mouseleave(function(){
					if($.browser.msie){
						sub_box.stop().animate({bottom:-(sub_box.outerHeight()+10)}, _speed, function(){
							_box.hide();
							_el.removeClass('hover');
						});
					}
					else{
						sub_box.stop().animate({bottom:-(sub_box.outerHeight()+10), opacity: 0}, _speed, function(){
							_box.hide();
							_el.removeClass('hover');
						});
					}
				});
				_box.find('a.btn-close').click(function(){
					_el.trigger('mouseleave');
					return false;
				});
			}			
		});
		
		var _box1 = _hold.children('ul.toolbar');
		var _box2 = _hold.children('div.maximize-wrapper');
		var t_h1 = _box1.height();
		var t_h2 = _box2.height();
		
		// Added the if condition around the original to make sure that the collapsed toolbar is visible
		if  (MEYReadCookie("MeyToolBarVisible") != "no")
		{
			_box2.hide();
		}
		_hold.find('#minimize > a').click(function(){
			// Here's the code that creates a cookie which tells us whether the toolbar is visible or not.
			MEYCreateCookie("MeyToolBarVisible","no",999);
			$(this).parent().trigger('click');
			if($.browser.msie){
				if(_box2.is(':hidden')){
					_box2.show();
					t_h2 = _box2.height();
					_box2.height(0);
				}
				_box1.stop().animate({height:0}, _speed, function(){
					$(this).css({display:'none', height:'auto'});
				});
				_box2.stop().animate({height:t_h2}, _speed, function(){
					$(this).height('auto');
				});
			}
			else{
				if(_box2.is(':hidden')){
					_box2.show();
					t_h2 = _box2.height();
					_box2.css({height:0, opacity: 0});
				}
				_box1.stop().animate({height:0, opacity:0}, _speed, function(){
					$(this).css({display:'none', height:'auto'});
				});
				_box2.stop().animate({height:t_h2, opacity:1}, _speed, function(){
					$(this).height('auto');
				});
			}
			return false;
		});
		_hold.find('#maximize a').click(function(){
			// Here's the code that creates a cookie which tells us whether the toolbar is visible or not.
			MEYCreateCookie("MeyToolBarVisible","yes",999);
			$(this).parent().trigger('click');
			if($.browser.msie){
				if(_box1.is(':hidden')){
					_box1.show();
					t_h1 = _box1.height();
					_box1.height(0);
				}
				_box2.stop().animate({height:0}, _speed, function(){
					$(this).css({display:'none', height:'auto'});
				});
				_box1.stop().animate({height:t_h1}, _speed, function(){
					$(this).height('auto');
				});
			}
			else{
				if(_box1.is(':hidden')){
					_box1.show();
					t_h1 = _box1.height();
					_box1.css({height:0, opacity: 0});
				}
				_box2.stop().animate({height:0, opacity:0}, _speed, function(){
					$(this).css({display:'none', height:'auto'});
				});
				_box1.stop().animate({height:t_h1, opacity:1}, _speed, function(){
					$(this).height('auto');
				});
			}
			return false;
		});
		
		// Adding code here to support auto showing of notifications in case of new items:
		var _noteButton = $("#notificationButton");
		if (_noteButton.length)
		{
			_noteButton.trigger('mouseenter');
		}
	}
}
$(document).ready(function(){
	initToolbar();
	
	// Rob's added bits
			
			//$("<div id='pop_detwrap'></div>").appendTo("div.menu");
			var host = window.location.host;
			var prot = window.location.protocol;
			var url = prot + "//" + host;
			$("#pop_detwrap").load(url + "/wp-content/plugins/meytoolbar/dets.html", function() {			
				
				var item = $("div.menu ul li a");
				
				item.mouseover(function() {
								
					var _item = "div#" + $(this).attr("class");
					var _last = $("div#pop_detwrap").children().hasClass("pophover");	
									
					$("div#pop_detwrap").width("190px");

					if(_last === true) {
					
						$(".pophover").stop().animate({left:-195}, 500, function() {
						$(_item).stop().animate({left:0}, 500).addClass("pophover");
						});
						
		
					} else {
					
						$(_item).stop().animate({"left":"-195px"}, 500).addClass("pophover");
						
						
					}
				
					$("div.menu").mouseleave(function() {
					
						$(".pophover").stop().animate({left:-195}, 500, function() {
						$("div#pop_detwrap").width("0px");
						});
						
					});
								
				});
			
			});

	// end of Rob Stuff
});

function MEYCreateCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function MEYReadCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function MEYEraseCookie(name) {
	createCookie(name,"",-1);
}