// All Products drop down

var HIDE_LEFT_ATTRIB = 'nu_orig_left';
var HIDE_TOP_ATTRIB = 'nu_orig_top';
var HIDE_POSITION_ATTRIB = 'nu_orig_position';
var HIDE_HEIGHT_ATTRIB = 'nu_orig_height';
var GROUP_ATTRIB = 'nu_orig_group';
var HIDE_POSITION_TOP = '-300000em';


function toggle_the_div(div,fast,with_fade,customFunction)
{
    div.each( function() {
        var item = $(this);
        if (HIDE_POSITION_TOP==item.css('top'))
            show_the_div(item,fast,with_fade,customFunction);
        else
            hide_the_div(item,fast,with_fade,customFunction);
    });
}

function hide_the_div(div,fast,with_fade,customFunction)
{
    div.each( function() {
        var item = $(this);
        if (HIDE_POSITION_TOP == item.css('top'))
            return;
        
        item.attr( HIDE_TOP_ATTRIB, item.css('top') );
		item.attr( HIDE_LEFT_ATTRIB, item.css('left') );
        item.attr( HIDE_POSITION_ATTRIB, item.css('position') );
        if (item.height()!='100%')
            item.attr( HIDE_HEIGHT_ATTRIB, item.height() );
        if (fast) {
            item.css('height','0px').css('position','absolute').css('top',HIDE_POSITION_TOP).css('left',0);
        }
        else {
            var settings = null;
            if (with_fade)
                settings = {height:'0px',opacity:0.0};
            else
                settings = {height:'0px'};
            // Now it's been stored we can animate and hide the div
            item.animate( settings, 'normal', function() {
                $(item).css('position','absolute').css('top',HIDE_POSITION_TOP).css('left',0);
				if (customFunction != undefined) customFunction();
            });
        }
    } );
}

function show_the_div(div,fast,with_fade,customFunction)
{
     $(div).each( function() {
		var item = $(this);

		if (item.attr(HIDE_TOP_ATTRIB) == item.css('top'))
            return;

        if (undefined == item.attr(HIDE_TOP_ATTRIB))
            return;
		if (undefined == item.attr(HIDE_LEFT_ATTRIB))
            return;
        if (with_fade)
            item.css('opacity',0.0);
        item.css('top', item.attr(HIDE_TOP_ATTRIB) );
		item.css('left', item.attr(HIDE_LEFT_ATTRIB) );
        item.css('position', item.attr(HIDE_POSITION_ATTRIB) );

        if (undefined == item.attr(HIDE_HEIGHT_ATTRIB))
            var new_height = '';
        else
            var new_height = item.attr(HIDE_HEIGHT_ATTRIB);

		if (fast) {
            item.css('height','').css('opacity',1.0);
			if (customFunction != undefined) {
				customFunction();
			}
        }
        else {
			if (with_fade) {
				item.animate( {opacity:1.0,height:new_height}, 'slow', function() { $(this).height(''); if (customFunction != undefined) {customFunction(); } });
			}
			else {
				item.css('opacity',1.0).animate( {height:new_height}, function() { $(this).height(''); if (customFunction != undefined) {customFunction(); } });
			}
		}
    } );
}


