﻿function addBookmark(title, url) {
    if (window.sidebar)
        window.sidebar.addPanel(title, url, "");
    else if (document.all)
        window.external.AddFavorite(url, title);
    else
        return true;
}

function changeLocation(url) {location.href = url;}

function linkConfirm(url,msg) {
    if (confirm(msg))
        document.location = url;
}

//== Display / Hide Layers Functions =======================
function displayMessage(divname, xcoor, ycoor) {
    //var sWidth = screen.width;
    document.getElementById(divname).style.display = 'inline';
    document.getElementById(divname).style.left = xcoor;
    document.getElementById(divname).style.top = ycoor;
    return true;
}

function displayMessageInline(divname) {
    document.getElementById(divname).style.display = 'inline';
    return true;
}

function displayMessageBlock(divname) {
    document.getElementById(divname).style.display = 'block';
    return true;
}

function toggleMessageBlock(divname) {
    if (document.getElementById(divname).style.display == 'none')
        document.getElementById(divname).style.display = 'block';
    else
        document.getElementById(divname).style.display = 'none';
    return true;
}

function hideMessage(divname) {
    document.getElementById(divname).style.display = 'none';
    return true;
}

function changePanelSign(divname) {
    if(document.getElementById(divname).innerHTML == '+')
        document.getElementById(divname).innerHTML = '-';
    else
        document.getElementById(divname).innerHTML = '+';
        
    return true;
}

//var cflag = 'true';
function checkCookies() {
    try {
        var boolres = 'true';
        var cname = "hpmcc";
        var tmpcookie = new Date();
        var value = (tmpcookie.getTime() + '');
        
        var daystoadd = 1;
        var cdate = new Date();
        cdate.setTime(cdate.getTime() + (daystoadd * 24 * 60 * 60 * 1000));
        var expires = "; expires="+cdate.toGMTString();

        document.cookie = cname + "=" + value + expires + "; path=/";

        if (document.cookie.indexOf(cname, 0) < 0) {
            boolres = 'false';  //== Cookies not accepted
            cflag = false;
            }
            
        SendRequest(boolres);

        //== Delete cookie
        value = '';
        cdate = new Date();
        daystoadd = -1;
        cdate.setTime(cdate.getTime() + (daystoadd * 24 * 60 * 60 * 1000));
        expires = "; expires=" + cdate.toGMTString();
        document.cookie = cname + "=" + value + expires + "; path=/";
    }
    catch (err) {
                //alert('Error: ' + err.description); 
                }
}

//== Ajax Cookie Test Functions ==
function SendRequest(flag) {
    //alert("Cookie check starting. - " + flag);
    HollywoodProductionMusic.WebServices.WebServiceLogin.SetCookiesEnabledFlag(flag, OnComplete, OnError, OnTimeOut);
    //alert("Cookie check started.");
}
function OnTimeOut(arg) {}
function OnError(arg) {} //alert("Cookie check error." + arg._message);

function SearchAutoComplete(str) {
    if (str.length < 3) {
        var ACTextDiv = document.all ? document.all["ajaxResultsBox"] : document.getElementById ? document.getElementById("ajaxResultsBox") : ""
        ACTextDiv.innerHTML = '';
        var ACAjaxDiv = document.all ? document.all["ajaxSearch"] : document.getElementById ? document.getElementById("ajaxSearch") : ""
        ACAjaxDiv.style.display = 'none';
        return;
    }
    else {
        var ACAjaxDiv = document.all ? document.all["ajaxSearch"] : document.getElementById ? document.getElementById("ajaxSearch") : ""
        ACAjaxDiv.style.display = 'block';
        HollywoodProductionMusic.WebServices.Search.AutoComplete(str, OnCompleteAC, OnErrorAC, OnTimeOutAC);
    }
}
function OnTimeOutAC(arg) {}
function OnErrorAC(arg) { } //alert("Cookie check error." + arg._message);
function OnCompleteAC(str) {
    try {
        var ACAjaxDiv = document.all ? document.all["ajaxSearch"] : document.getElementById ? document.getElementById("ajaxSearch") : ""
        var ACTextDiv = document.all ? document.all["ajaxResultsBox"] : document.getElementById ? document.getElementById("ajaxResultsBox") : ""
        ACAjaxDiv.style.display = 'none';
        
        if (str != '') {
            ACTextDiv.innerHTML = '<span style="float:right;padding-right:4px;padding-top:2px;"><a href="javascript:void(0);" onclick="(document.all ? document.all[\'ajaxResultsBox\'] : document.getElementById ? document.getElementById(\'ajaxResultsBox\') : \'\').style.display=\'none\';" rel="nofollow"><img src=\'images/close.gif\' width=\'12\' height=\'12\' border=\'0\' alt=\'close music search terms panel\'></a></span>' + str;
            ACTextDiv.style.display = 'block';           
        }
        else {
            ACTextDiv.style.display = 'none';
        }
    }
    catch (err) {}
}

function setDynFrame(divName, url, w, h) {
    setDynFrame(divName, url, w, h,'no');
}

function setDynFrame(divName, url, w, h, s) {
    var iframeTxt = '<div id="noticeClose" style="position:absolute;right:4px;top:4px;width:12px;height:12px;"><a href="javascript:void(0);" onclick="closeDiv(\'' + divName + '\')" class="GraySmall" rel="nofollow"><img src="images/close.gif" width="12" height="12" border="0" alt="close window"></a></div>' +
                    '<iframe src=\'' + url + '\' width=\'' + w + '\' height=\'' + h + '\' ' +
                    'FRAMEBORDER=\'0\' MARGINWIDTH=\'0\' MARGINHEIGHT=\'0\' scrolling=\''+s+'\' ' +
                    'style=\'background-color:#dddddd;\'></iframe>'
                    ;

    setInnerHtml(divName, iframeTxt);
}

function setDynPlr(dirDepth,divName, trackName, trackUrl, trackId, w, h, bg) {
    var furl = dirDepth + 'dspDynPly.aspx?tn=' + trackName + '&tu=' + trackUrl + '&tid=' + trackId + '&bg=' + bg;
    var iframeTxt = '<iframe src=\''+ furl + '\' width=\'' + w + '\' height=\'' + h + '\' ' +
                    'FRAMEBORDER=\'0\' MARGINWIDTH=\'0\' MARGINHEIGHT=\'0\' scrolling=\'no\' ' +
                    'style=\'background-color:#dddddd;\'></iframe>';

    setInnerHtml(divName, iframeTxt);
}

function setInnerHtml(e,str){
    if (!(e = GEById(e)) || !checkStr(e.innerHTML)) return null;
    var s = e.innerHTML;
    if (checkStr(str)) { e.innerHTML = str; e.style.display = 'block';}
    return s;
}

function closeDiv(e) {
    if (!(e = GEById(e)) || !checkStr(e.innerHTML)) return null;
    var s = e.innerHTML;
    e.innerHTML = '';
    e.style.display = 'none';
    return s;
}

function checkStr(s) {
    for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
    return true;
}

function GEById(e) {
    if(typeof(e)!='string') return e;
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
    return e;
}

//========= Tooltip Variables & Functions =========
var offsetfromcursorX = 12 //Customize x offset of tooltip
var offsetfromcursorY = 10 //Customize y offset of tooltip
var offsetdivfrompointerX = 10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY = 14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

var ie = document.all
var ns6 = document.getElementById && !document.all
var enabletip = false
if (ie || ns6)
    var tipobj = document.all ? document.all["dhtmltooltip"] : document.getElementById ? document.getElementById("dhtmltooltip") : ""

var pointerobj = document.all ? document.all["dhtmlpointer"] : document.getElementById ? document.getElementById("dhtmlpointer") : ""

function ietruebody() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor) {
    if (ns6 || ie) {
        if (typeof thewidth != "undefined") tipobj.style.width = thewidth + "px"
        if (typeof thecolor != "undefined" && thecolor != "") tipobj.style.backgroundColor = thecolor
        if (tipobj != null)
            tipobj.innerHTML = thetext
        enabletip = true
        return false
    }
}

function positiontip(e) {
    if (enabletip && tipobj != null) {
        var nondefaultpos = false
        var curX = (ns6) ? e.pageX : event.x + ietruebody().scrollLeft;
        var curY = (ns6) ? e.pageY : event.y + ietruebody().scrollTop;
        //Find out how close the mouse is to the corner of the window
        var winwidth = ie && !window.opera ? ietruebody().clientWidth : window.innerWidth - 20
        var winheight = ie && !window.opera ? ietruebody().clientHeight : window.innerHeight - 20

        var rightedge = ie && !window.opera ? winwidth - event.clientX - offsetfromcursorX : winwidth - e.clientX - offsetfromcursorX
        var bottomedge = ie && !window.opera ? winheight - event.clientY - offsetfromcursorY : winheight - e.clientY - offsetfromcursorY

        var leftedge = (offsetfromcursorX < 0) ? offsetfromcursorX * (-1) : -1000

        //if the horizontal distance isn't enough to accomodate the width of the context menu
        if (rightedge < tipobj.offsetWidth) {
            //move the horizontal position of the menu to the left by it's width
            tipobj.style.left = curX - tipobj.offsetWidth + "px"
            nondefaultpos = true
        }
        else if (curX < leftedge)
            tipobj.style.left = "5px"
        else {
            //position the horizontal position of the menu where the mouse is positioned
            tipobj.style.left = curX + offsetfromcursorX - offsetdivfrompointerX + "px"
            pointerobj.style.left = curX + offsetfromcursorX + "px"
        }

        //same concept with the vertical position
        if (bottomedge < tipobj.offsetHeight) {
            tipobj.style.top = curY - tipobj.offsetHeight - offsetfromcursorY + "px"
            nondefaultpos = true
        }
        else {
            tipobj.style.top = curY + offsetfromcursorY + offsetdivfrompointerY + "px"
            pointerobj.style.top = curY + offsetfromcursorY + "px"
        }
        tipobj.style.visibility = "visible"
        if (!nondefaultpos)
            pointerobj.style.visibility = "visible"
        else
            pointerobj.style.visibility = "hidden"
    }
}

function hideddrivetip() {
    if (ns6 || ie) {
        if (tipobj != null) {
            enabletip = false
            tipobj.style.visibility = "hidden"
            pointerobj.style.visibility = "hidden"
            tipobj.style.left = "-1000px"
            tipobj.style.backgroundColor = ''
            tipobj.style.width = ''
        }
    }
}

document.onmousemove = positiontip	

//** Tab Content script v2.0- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
function ddtabcontent(tabinterfaceid) {
    this.tabinterfaceid = tabinterfaceid //ID of Tab Menu main container
    this.tabs = document.getElementById(tabinterfaceid).getElementsByTagName("a") //Get all tab links within container
    this.enabletabpersistence = true
    this.hottabspositions = [] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container
    this.currentTabIndex = 0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array
    this.subcontentids = [] //Array to store ids of the sub contents ("rel" attr values)
    this.revcontentids = [] //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values)
    this.selectedClassTarget = "link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")
}
ddtabcontent.getCookie = function(Name) {
    var re = new RegExp(Name + "=[^;]+", "i"); //construct RE to search for target name/value pair
    if (document.cookie.match(re)) //if cookie found
        return document.cookie.match(re)[0].split("=")[1] //return its value
    return ""
}
ddtabcontent.setCookie = function(name, value) {
    document.cookie = name + "=" + value + ";path=/" //cookie value is domain wide (path=/)
}
ddtabcontent.prototype = {

    expandit: function(tabid_or_position) { //PUBLIC function to select a tab either by its ID or position(int) within its peers
        this.cancelautorun() //stop auto cycling of tabs (if running)
        var tabref = ""
        try {
            if (typeof tabid_or_position == "string" && document.getElementById(tabid_or_position).getAttribute("rel")) //if specified tab contains "rel" attr
                tabref = document.getElementById(tabid_or_position)
            else if (parseInt(tabid_or_position) != NaN && this.tabs[tabid_or_position].getAttribute("rel")) //if specified tab contains "rel" attr
                tabref = this.tabs[tabid_or_position]
        }
        catch (err) { alert("Invalid Tab ID or position entered!") }
        if (tabref != "") //if a valid tab is found based on function parameter
            this.expandtab(tabref) //expand this tab
    },

    cycleit: function(dir, autorun) { //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') )
        if (dir == "next") {
            var currentTabIndex = (this.currentTabIndex < this.hottabspositions.length - 1) ? this.currentTabIndex + 1 : 0
        }
        else if (dir == "prev") {
            var currentTabIndex = (this.currentTabIndex > 0) ? this.currentTabIndex - 1 : this.hottabspositions.length - 1
        }
        if (typeof autorun == "undefined") //if cycleit() is being called by user, versus autorun() function
            this.cancelautorun() //stop auto cycling of tabs (if running)
        this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])
    },

    setpersist: function(bool) { //PUBLIC function to toggle persistence feature
        this.enabletabpersistence = bool
    },

    setselectedClassTarget: function(objstr) { //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")
        this.selectedClassTarget = objstr || "link"
    },

    getselectedClassTarget: function(tabref) { //Returns target element to assign "selected" CSS class to
        return (this.selectedClassTarget == ("linkparent".toLowerCase())) ? tabref.parentNode : tabref
    },

    urlparamselect: function(tabinterfaceid) {
        var result = window.location.search.match(new RegExp(tabinterfaceid + "=(\\d+)", "i")) //check for "?tabinterfaceid=2" in URL
        return (result == null) ? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
    },

    expandtab: function(tabref) {
        var subcontentid = tabref.getAttribute("rel") //Get id of subcontent to expand
        //Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easily search through
        var associatedrevids = (tabref.getAttribute("rev")) ? "," + tabref.getAttribute("rev").replace(/\s+/, "") + "," : ""
        this.expandsubcontent(subcontentid)
        this.expandrevcontent(associatedrevids)
        for (var i = 0; i < this.tabs.length; i++) { //Loop through all tabs, and assign only the selected tab the CSS class "selected"
            this.getselectedClassTarget(this.tabs[i]).className = (this.tabs[i].getAttribute("rel") == subcontentid) ? "selected" : ""
        }
        if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers
            ddtabcontent.setCookie(this.tabinterfaceid, tabref.tabposition)
        this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array
    },

    expandsubcontent: function(subcontentid) {
        for (var i = 0; i < this.subcontentids.length; i++) {
            var subcontent = document.getElementById(this.subcontentids[i]) //cache current subcontent obj (in for loop)
            subcontent.style.display = (subcontent.id == subcontentid) ? "block" : "none" //"show" or hide sub content based on matching id attr value
        }
    },

    expandrevcontent: function(associatedrevids) {
        var allrevids = this.revcontentids
        for (var i = 0; i < allrevids.length; i++) { //Loop through rev attributes for all tabs in this tab interface
            //if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it
            document.getElementById(allrevids[i]).style.display = (associatedrevids.indexOf("," + allrevids[i] + ",") != -1) ? "block" : "none"
        }
    },

    setcurrenttabindex: function(tabposition) { //store current position of tab (within hottabspositions[] array)
        for (var i = 0; i < this.hottabspositions.length; i++) {
            if (tabposition == this.hottabspositions[i]) {
                this.currentTabIndex = i
                break
            }
        }
    },

    autorun: function() { //function to auto cycle through and select tabs based on a set interval
        this.cycleit('next', true)
    },

    cancelautorun: function() {
        if (typeof this.autoruntimer != "undefined")
            clearInterval(this.autoruntimer)
    },

    init: function(automodeperiod) {
        var persistedtab = ddtabcontent.getCookie(this.tabinterfaceid) //get position of persisted tab (applicable if persistence is enabled)
        var selectedtab = -1 //Currently selected tab index (-1 meaning none)
        var selectedtabfromurl = this.urlparamselect(this.tabinterfaceid) //returns null or index from: tabcontent.htm?tabinterfaceid=index
        this.automodeperiod = automodeperiod || 0
        for (var i = 0; i < this.tabs.length; i++) {
            this.tabs[i].tabposition = i //remember position of tab relative to its peers
            if (this.tabs[i].getAttribute("rel")) {
                var tabinstance = this
                this.hottabspositions[this.hottabspositions.length] = i //store position of "hot" tab ("rel" attr defined) relative to its peers
                this.subcontentids[this.subcontentids.length] = this.tabs[i].getAttribute("rel") //store id of sub content ("rel" attr value)
                this.tabs[i].onclick = function() {
                    tabinstance.expandtab(this)
                    tabinstance.cancelautorun() //stop auto cycling of tabs (if running)
                    return false
                }
                if (this.tabs[i].getAttribute("rev")) { //if "rev" attr defined, store each value within "rev" as an array element
                    this.revcontentids = this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))
                }
                if (selectedtabfromurl == i || this.enabletabpersistence && selectedtab == -1 && parseInt(persistedtab) == i || !this.enabletabpersistence && selectedtab == -1 && this.getselectedClassTarget(this.tabs[i]).className == "selected") {
                    selectedtab = i //Selected tab index, if found
                }
            }
        } //END for loop
        if (selectedtab != -1) //if a valid default selected tab index is found
            this.expandtab(this.tabs[selectedtab]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)
        else //if no valid default selected index found
            this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr
        if (parseInt(this.automodeperiod) > 500 && this.hottabspositions.length > 1) {
            this.autoruntimer = setInterval(function() { tabinstance.autorun() }, this.automodeperiod)
        }
    } //END int() function

} //END Prototype assignment


//** Animated Collapsible DIV v2.0- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
//1) ontoggle($, divobj, state) event that fires each time a DIV is expanded/collapsed, including when the page 1st loads
//2) Ability to expand a DIV via a URL parameter string, ie: index.htm?expanddiv=jason or index.htm?expanddiv=jason,kelly
//1) You can now insert rel="expand[divid] | collapse[divid] | toggle[divid]" inside arbitrary links to act as DIV togglers
//2) For image toggler links, you can insert the attributes "data-openimage" and "data-closedimage" to update its image based on the DIV state

var animatedcollapse = {
    divholders: {}, //structure: {div.id, div.attrs, div.$divref, div.$togglerimage}
    divgroups: {}, //structure: {groupname.count, groupname.lastactivedivid}
    lastactiveingroup: {}, //structure: {lastactivediv.id}
    preloadimages: [],

    show: function(divids) { //public method
        if (typeof divids == "object") {
            for (var i = 0; i < divids.length; i++)
                this.showhide(divids[i], "show")
        }
        else
            this.showhide(divids, "show")
    },

    hide: function(divids) { //public method
        if (typeof divids == "object") {
            for (var i = 0; i < divids.length; i++)
                this.showhide(divids[i], "hide")
        }
        else
            this.showhide(divids, "hide")
    },

    toggle: function(divid) { //public method
        if (typeof divid == "object")
            divid = divid[0]
        this.showhide(divid, "toggle")
    },

    addDiv: function(divid, attrstring) { //public function
        this.divholders[divid] = ({ id: divid, $divref: null, attrs: attrstring })
        this.divholders[divid].getAttr = function(name) { //assign getAttr() function to each divholder object
            var attr = new RegExp(name + "=([^,]+)", "i") //get name/value config pair (ie: width=400px,)
            return (attr.test(this.attrs) && parseInt(RegExp.$1) != 0) ? RegExp.$1 : null //return value portion (string), or 0 (false) if none found
        }
        this.currentid = divid //keep track of current div object being manipulated (in the event of chaining)
        return this
    },

    showhide: function(divid, action) {
        var $divref = this.divholders[divid].$divref //reference collapsible DIV
        if (this.divholders[divid] && $divref.length == 1) { //if DIV exists
            var targetgroup = this.divgroups[$divref.attr('groupname')] //find out which group DIV belongs to (if any)
            if ($divref.attr('groupname') && targetgroup.count > 1 && (action == "show" || action == "toggle" && $divref.css('display') == 'none')) { //If current DIV belongs to a group
                if (targetgroup.lastactivedivid && targetgroup.lastactivedivid != divid) //if last active DIV is set
                    this.slideengine(targetgroup.lastactivedivid, 'hide') //hide last active DIV within group first
                this.slideengine(divid, 'show')
                targetgroup.lastactivedivid = divid //remember last active DIV
            }
            else {
                this.slideengine(divid, action)
            }
        }
    },

    slideengine: function(divid, action) {
        var $divref = this.divholders[divid].$divref
        var $togglerimage = this.divholders[divid].$togglerimage
        if (this.divholders[divid] && $divref.length == 1) { //if this DIV exists
            var animateSetting = { height: action }
            if ($divref.attr('fade'))
                animateSetting.opacity = action
            $divref.animate(animateSetting, $divref.attr('speed') ? parseInt($divref.attr('speed')) : 500, function() {
                if ($togglerimage) {
                    $togglerimage.attr('src', ($divref.css('display') == "none") ? $togglerimage.data('srcs').closed : $togglerimage.data('srcs').open)
                }
                if (animatedcollapse.ontoggle) {
                    try {
                        animatedcollapse.ontoggle(jQuery, $divref.get(0), $divref.css('display'))
                    }
                    catch (e) {
                        alert("An error exists inside your \"ontoggle\" function:\n\n" + e + "\n\nAborting execution of function.")
                    }
                }
            })
            return false
        }
    },

    generatemap: function() {
        var map = {}
        for (var i = 0; i < arguments.length; i++) {
            if (arguments[i][1] != null) { //do not generate name/value pair if value is null
                map[arguments[i][0]] = arguments[i][1]
            }
        }
        return map
    },

    init: function() {
        var ac = this
        jQuery(document).ready(function($) {
            animatedcollapse.ontoggle = animatedcollapse.ontoggle || null
            var urlparamopenids = animatedcollapse.urlparamselect() //Get div ids that should be expanded based on the url (['div1','div2',etc])
            var persistopenids = ac.getCookie('acopendivids') //Get list of div ids that should be expanded due to persistence ('div1,div2,etc')
            var groupswithpersist = ac.getCookie('acgroupswithpersist') //Get list of group names that have 1 or more divs with "persist" attribute defined
            if (persistopenids != null) //if cookie isn't null (is null if first time page loads, and cookie hasnt been set yet)
                persistopenids = (persistopenids == 'nada') ? [] : persistopenids.split(',') //if no divs are persisted, set to empty array, else, array of div ids
            groupswithpersist = (groupswithpersist == null || groupswithpersist == 'nada') ? [] : groupswithpersist.split(',') //Get list of groups with divs that are persisted
            jQuery.each(ac.divholders, function() { //loop through each collapsible DIV object
                this.$divref = $('#' + this.id)
                if ((this.getAttr('persist') || jQuery.inArray(this.getAttr('group'), groupswithpersist) != -1) && persistopenids != null) { //if this div carries a user "persist" setting, or belong to a group with at least one div that does
                    var cssdisplay = (jQuery.inArray(this.id, persistopenids) != -1) ? 'block' : 'none'
                }
                else {
                    var cssdisplay = this.getAttr('hide') ? 'none' : null
                }
                if (urlparamopenids[0] == "all" || jQuery.inArray(this.id, urlparamopenids) != -1) { //if url parameter string contains the single array element "all", or this div's ID
                    cssdisplay = 'block' //set div to "block", overriding any other setting
                }
                else if (urlparamopenids[0] == "none") {
                    cssdisplay = 'none' //set div to "none", overriding any other setting
                }
                this.$divref.css(ac.generatemap(['height', this.getAttr('height')], ['display', cssdisplay]))
                this.$divref.attr(ac.generatemap(['groupname', this.getAttr('group')], ['fade', this.getAttr('fade')], ['speed', this.getAttr('speed')]))
                if (this.getAttr('group')) { //if this DIV has the "group" attr defined
                    var targetgroup = ac.divgroups[this.getAttr('group')] || (ac.divgroups[this.getAttr('group')] = {}) //Get settings for this group, or if it no settings exist yet, create blank object to store them in
                    targetgroup.count = (targetgroup.count || 0) + 1 //count # of DIVs within this group
                    if (jQuery.inArray(this.id, urlparamopenids) != -1) { //if url parameter string contains this div's ID
                        targetgroup.lastactivedivid = this.id //remember this DIV as the last "active" DIV (this DIV will be expanded). Overrides other settings
                        targetgroup.overridepersist = 1 //Indicate to override persisted div that would have been expanded
                    }
                    if (!targetgroup.lastactivedivid && this.$divref.css('display') != 'none' || cssdisplay == "block" && typeof targetgroup.overridepersist == "undefined") //if this DIV was open by default or should be open due to persistence								
                        targetgroup.lastactivedivid = this.id //remember this DIV as the last "active" DIV (this DIV will be expanded)
                    this.$divref.css({ display: 'none' }) //hide any DIV that's part of said group for now
                }
            }) //end divholders.each
            jQuery.each(ac.divgroups, function() { //loop through each group
                if (this.lastactivedivid && urlparamopenids[0] != "none") //show last "active" DIV within each group (one that should be expanded), unless url param="none"
                    ac.divholders[this.lastactivedivid].$divref.show()
            })
            if (animatedcollapse.ontoggle) {
                jQuery.each(ac.divholders, function() { //loop through each collapsible DIV object and fire ontoggle event
                    animatedcollapse.ontoggle(jQuery, this.$divref.get(0), this.$divref.css('display'))
                })
            }
            //Parse page for links containing rel attribute
            var $allcontrols = $('a[rel]').filter('[rel^="collapse["], [rel^="expand["], [rel^="toggle["]') //get all elements on page with rel="collapse[]", "expand[]" and "toggle[]"
            $allcontrols.each(function() { //loop though each control link
                this._divids = this.getAttribute('rel').replace(/(^\w+)|(\s+)/g, "").replace(/[\[\]']/g, "") //cache value 'div1,div2,etc' within identifier[div1,div2,etc]
                if (this.getElementsByTagName('img').length == 1 && ac.divholders[this._divids]) { //if control is an image link that toggles a single DIV (must be one to one to update status image)
                    animatedcollapse.preloadimage(this.getAttribute('data-openimage'), this.getAttribute('data-closedimage')) //preload control images (if defined)
                    $togglerimage = $(this).find('img').eq(0).data('srcs', { open: this.getAttribute('data-openimage'), closed: this.getAttribute('data-closedimage') }) //remember open and closed images' paths
                    ac.divholders[this._divids].$togglerimage = $(this).find('img').eq(0) //save reference to toggler image (to be updated inside slideengine()
                    ac.divholders[this._divids].$togglerimage.attr('src', (ac.divholders[this._divids].$divref.css('display') == "none") ? $togglerimage.data('srcs').closed : $togglerimage.data('srcs').open)
                }
                $(this).click(function() { //assign click behavior to each control link
                    var relattr = this.getAttribute('rel')
                    var divids = (this._divids == "") ? [] : this._divids.split(',') //convert 'div1,div2,etc' to array 
                    if (divids.length > 0) {
                        animatedcollapse[/expand/i.test(relattr) ? 'show' : /collapse/i.test(relattr) ? 'hide' : 'toggle'](divids) //call corresponding public function
                        return false
                    }
                }) //end control.click
            })// end control.each

            $(window).bind('unload', function() {
                ac.uninit()
            })
        }) //end doc.ready()
    },

    uninit: function() {
        var opendivids = '', groupswithpersist = ''
        jQuery.each(this.divholders, function() {
            if (this.$divref.css('display') != 'none') {
                opendivids += this.id + ',' //store ids of DIVs that are expanded when page unloads: 'div1,div2,etc'
            }
            if (this.getAttr('group') && this.getAttr('persist'))
                groupswithpersist += this.getAttr('group') + ',' //store groups with which at least one DIV has persistance enabled: 'group1,group2,etc'
        })
        opendivids = (opendivids == '') ? 'nada' : opendivids.replace(/,$/, '')
        groupswithpersist = (groupswithpersist == '') ? 'nada' : groupswithpersist.replace(/,$/, '')
        this.setCookie('acopendivids', opendivids)
        this.setCookie('acgroupswithpersist', groupswithpersist)
    },

    getCookie: function(Name) {
        var re = new RegExp(Name + "=[^;]*", "i"); //construct RE to search for target name/value pair
        if (document.cookie.match(re)) //if cookie found
            return document.cookie.match(re)[0].split("=")[1] //return its value
        return null
    },

    setCookie: function(name, value, days) {
        if (typeof days != "undefined") { //if set persistent cookie
            var expireDate = new Date()
            expireDate.setDate(expireDate.getDate() + days)
            document.cookie = name + "=" + value + "; path=/; expires=" + expireDate.toGMTString()
        }
        else //else if this is a session only cookie
            document.cookie = name + "=" + value + "; path=/"
    },

    urlparamselect: function() {
        window.location.search.match(/expanddiv=([\w\-_,]+)/i) //search for expanddiv=divid or divid1,divid2,etc
        return (RegExp.$1 != "") ? RegExp.$1.split(",") : []
    },

    preloadimage: function() {
        var preloadimages = this.preloadimages
        for (var i = 0; i < arguments.length; i++) {
            if (arguments[i] && arguments[i].length > 0) {
                preloadimages[preloadimages.length] = new Image()
                preloadimages[preloadimages.length - 1].src = arguments[i]
            }
        }
    }

}
//== End Animated Collapse ==

