/* 
 * jsEffects JavaScriptUtils module
 * 
 * Provides visual effects and usability-related improvements.
 * 
 */
 
jQuery.fn.jsEffects_dropDown = function() {
	return this.parent()
		.each( function () {
			var innerItem = $(this).children(".dropDown:first");
			$(this).data("assoc", innerItem.get(0));
			innerItem.css({ "position": "absolute", "margin": "0" }).appendTo(hoverLayerElementsContainer);
		})
		.mouseover( function () {
			var item = $(this).data("assoc");
			if (item) $(item).makeHover($(this), 'bottom');
		})
		.addHoverAbility();
}


var memoryRolltop_proc = function () {
	elem = $(this);
	rolltopId = "memoryRolltop-" + elem.attr('id');
	elemParent = elem.parents('div.uses-jsEffects:first');
	var newCookie = elem.hasClass('show') ? "hide" : "show";
	var oldCookie = elem.hasClass('show') ? "show" : "hide";
	elem.removeClass(oldCookie).addClass(newCookie);
	elemParent.find("." + rolltopId).each(function () {
		$(this).removeClass(oldCookie).addClass(newCookie);
	});
	$.cookie(rolltopId, newCookie); // Store to cookies
}
jQuery.fn.jsEffects_memoryRolltop = function() {
	var eventItemId = this.attr('id');
	$(this).click(memoryRolltop_proc).keypress(memoryRolltop_proc).addHoverAbility().css('cursor', 'pointer');
	var newClass = this.hasClass('show') ? "show" : "hide";
	this.parents('div.uses-jsEffects:first').find(".memoryRolltop-" + eventItemId).each( function () {
		$(this).addClass(newClass);
	});
	return this;
}

jQuery.fn.makeFloatingPanelBottom = function () {
	var a = this;
	a.css("position", "absolute");
	if (jQuery.browser.msie && (jQuery.browser.version == '6.0')) {
		jQuery(window).scroll(function(){
			a.css("top", jQuery(window).scrollTop() + jQuery(window).height() - a.outerHeight());
		});
		a.css("top", jQuery(window).scrollTop() + jQuery(window).height() - a.outerHeight());	
		jQuery(function(){
			a.css("top", jQuery(window).scrollTop() + jQuery(window).height() - a.outerHeight());	
		});
	} else {
		a.css("bottom", 0).css("position", "fixed");
	}
}	



function getMemoryRolltopStatus(id) {
	var ret = $.cookie('memoryRolltop-' + id);
	if (ret == null) ret = 'show';
	return ret;
}


$(function() {

	var jsEffectsElements = $('div.uses-jsEffects');
	if (jsEffectsElements.length) {


		/* 
		 * memoryRollTop
		 */
		// Attach to elements
		jsEffectsElements.find('.memoryRolltop').jsEffects_memoryRolltop();

		/*
		 * Dropdowns
		 */
		jsEffectsElements.find(".dropDown").jsEffects_dropDown();
			
	}		
});	



