var yMouse = null;

$(document).ready(function(){

    $().mousemove(function(e){
        yMouse = e.pageY;
    });
    
    var isOpen = readCookie("open");
    if (isOpen == "true") {
        $('#accordion').accordion({
            autoheight: false,
            header: ".opener",
            active: 0,
            selectedClass: 'active',
            alwaysOpen: false
        });
    }
    else {
        $('#accordion').accordion({
            autoheight: false,
            header: ".opener",
            active: '.selected',
            selectedClass: 'active',
            alwaysOpen: false
        });
    }
    
    var _height = [];
    var _drops = $('div.drop');
    _drops.each(function(i, div){
        _height[i] = $(div).height();
        $(div).css({
            display: 'none',
            'visibility': 'visible',
            height: _height[i]
        });
    });
    
    $('.nav-holder').css({
        'position': 'absolute',
        'bottom': '0px',
        'left': '0px'
    });
    
    $('#main-nav li:has(div)').hover(function(){
        var _index = _drops.index($(this).children('div'));
        var _this = this;
        $(this).children('div.drop').css({
            'display': 'block',
            height: 0,
            overflow: 'hidden'
        });
        
        this.timer = setTimeout(function(){
            $(_this).children('div.drop').animate({
                height: _height[_index]
            }, {
                queue: false,
                duration: 800,
                easing: 'easeOutQuint',
                complete: function(){
                    $(this).css('overflow', 'visible');
                }
            });
            $(this).addClass("hover");
        }, 200);
    }, function(){
        if (this.timer) 
            clearTimeout(this.timer);
        var _this = this;
        
        $(this).children('div.drop').stop().css('overflow', 'hidden').animate({
            height: 0
        }, {
            queue: false,
            duration: 200,
            complete: function(){
                $(this).css({
                    'display': 'none',
                    overflow: 'hidden'
                });
            }
        });
        $(this).removeClass("hover");
    });
    $('#main-nav li').hover(function(){
        $(this).addClass("hover");
    }, function(){
        $(this).removeClass("hover");
    });
    
	
    var homes = getElementsByClassName("popup", "a", document.getElementById("accordion"));
    for (i = 0; i < homes.length; i++) {
        if (window.location == homes[i].href) {
            if (navigator.appName == "Microsoft Internet Explorer") {
				homes[i].style.setAttribute("cssText", "background:#b8c0b3;");
			}
			else {
				homes[i].setAttribute("style", "background:#b8c0b3;");
			}
        }
    }
	
	/*
    var homes = getElementsByClassName("home-item", "li", document.getElementById("accordion"));
    for (i = 0; i < homes.length; i++) {
        if (window.location == homes[i].getElementsByTagName("a")[0].href) {
            if (navigator.appName == "Microsoft Internet Explorer") {
				homes[i].style.setAttribute("cssText", "background:#b8c0b3;");
			}
			else {
				homes[i].setAttribute("style", "background:#b8c0b3;");
			}
        }
    }*/
    
});

function readCookie(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 getElementsByClassName(className, tag, elm){
    var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
    var tag = tag || "*";
    var elm = elm || document;
    var elements = (tag == "*" && elm.all) ? elm.all : elm.getElementsByTagName(tag);
    var returnElements = [];
    var current;
    var length = elements.length;
    for (var i = 0; i < length; i++) {
        current = elements[i];
        if (testClass.test(current.className)) {
            returnElements.push(current);
        }
    }
    return returnElements;
}


/*
function neighborhoodsMouseOver(){
    $('.neighborhoods').trigger('mouseenter');
}

function neighborhoodsMouseOut(){
    $('.neighborhoods').trigger('mouseleave');
}



function lifestyleMouseOver(){
    $('.lifestyles').trigger('mouseenter');

}

function lifestyleMouseOut(){
    $('.lifestyles').trigger('mouseleave');
}



function locationMouseOver(){
    $('.where').trigger('mouseenter');

}

function locationMouseOut(){
    $('.where').trigger('mouseleave');
}
*/


