Oay, i've put it all together but im getting error that the boxNameArray and boxHeightArray are not defined, anyone know why?
function dropBox() {
function anchorReplace()
{
$("a[class=open]").each(function(i){
var anchorElement = $(this);
var newAnchorElement = $('<a href="#link' + i + '" class="' + anchorElement.attr('class') + '" name="#link' + i + '">' + anchorElement.text() + '</a>').insertBefore(anchorElement);
anchorElement.remove();
});
$("a[class=close]").each(function(i){
var anchorElement = $(this);
var newAnchorElement = $('<a href="#link2' + i + '" class="' + anchorElement.attr('class') + '" name="#link2' + i + '">' + anchorElement.text() + '</a>').insertBefore(anchorElement);
anchorElement.remove();
});
}
function giveDivName() //simply add name attribute to div element
{
$("div[class=dropDiv]").each(function(i){ //foreach div with class dropDiv
var divElement = $(this);
var newDivElement = $('<div class="dropDiv" name="div' + i + '">' + divElement.html() + '</div>').insertBefore(divElement);
divElement.remove();
});
}
function getOrigValues() //get the values before closing div
{
var boxHeightArray = []; //get original div height
var boxNameArray = []; //get div name
$("div[class=dropDiv]").each(function(i){
var height = $(this).height(true);
var name = $(this).attr("name");
boxHeightArray[i] = height;
boxNameArray[i] = name;
});
$("div[class=dropDiv]").css("height", "27px"); //close all dropDiv's
}
anchorReplace();
giveDivName();
getOrigValues();
$("#reportWrapper div").css("overflow", "hidden");
$("a[class=close]").bind("click", function(){
$(this).parents("div:eq(0)").animate({
height: '30px'
}, 1000);
});
$("a[class=open]").bind("click", function(){
var clicked = $(this);
$("a[class=open]").each(function(){
if( clicked.attr("name") !== $(this).attr("name") )
{
$(this).parents("div:eq(0)").animate({
height: '30px'
}, 1000);
}
else
{
var element = $(this);
function getNewHeight(element) // get the height for when clicked to open
{
var divName = element.parents("div:eq(0)").attr("name");
$.map( boxNameArray, function(i, val){
if( element.attr("name") == divName )
{
var key = i;
$.map(boxHeightArray, function(i, val)
{
if( key == i )
{
return newHeight = val;
}
});
}
});
}
getNewHeight(element);
clicked.parents("div:eq(0)").animate({
height: newHeight + 'px'
}, 1000);
}
});
});
}