﻿var _myDropDowns = new Array();

function _hoveritup(o) {
    //return;
    for (var n = 0; n < _myDropDowns.length; n++) {
        var myID = _myDropDowns[n].ioj;
        if (jqQDDN(o).attr('id') == myID) {
            jqQDDN(_myDropDowns[n].wrappingLI).trigger('mouseover');
        }
    }
}
function _hoveritout(o) {
    //return;
    for (var n = 0; n < _myDropDowns.length; n++) {
        var myID = _myDropDowns[n].ioj;
        if (jqQDDN(o).attr('id') == myID) {
            jqQDDN(_myDropDowns[n].wrappingLI).trigger('mouseout');
        }
    }
}

function _hoverCount(o) {
    var countr = 0;
    for (var n = 0; n < _myDropDowns.length; n++) {
        if (_myDropDowns[n].IsHiding) countr++;
    }
    return countr;
}

function SubMenu(thisUL, wrappingLI, parentLink, ix, debug) {

    this.id = "_id_" + ix;
    this.ix = ix;
    this.thisUL = thisUL;
    this.wrappingLI = wrappingLI;
    this.parentLink = parentLink;
    this.debug = debug;
    this.IsVisible = false;
    this.IsHiding = false;
    this.ioj = "";

    this.Generate = function() {

        var ulSubMenu = thisUL;

        var $chlds = jqQDDN(ulSubMenu).children();
        jqQDDN(ulSubMenu).empty();
        jqQDDN(ulSubMenu).append("<li id='_subMenuInnerLI" + this.id + "'><ul id='_subMenuInnerUL" + this.id + "'></ul></li>");
        for (var n = 0; n < $chlds.length; n++) {
            jqQDDN('#_subMenuInnerUL' + this.id).append($chlds[n]);
        }

        jqQDDN('body').append(ulSubMenu);


        var subMenuInnerLI = jqQDDN('#_subMenuInnerLI' + this.id);
        var subMenuInnerUL = jqQDDN('#_subMenuInnerUL' + this.id);

        this.ioj = '_subMenuInnerLI' + this.id;

        var menuLI = wrappingLI;
        var menuLNK = parentLink;

        this.IsVisible = false;


        jqQDDN(subMenuInnerLI).css({ backgroundColor: 'transparent' });

        var o = jqQDDN(menuLNK);
        var off = o.offset();

        var hlpr = " border:2px solid Orange; ";
        if (!debug) hlpr = "";

        jqQDDN('<div style="width:200px; height:40px; ' + hlpr +
                'background:transparent;" id="_hlprDiv_' + this.id + '"></div>').appendTo(subMenuInnerLI);
        jqQDDN('#_hlprDiv_' + this.id).css({ width: o.width(), height: o.height(), margin: 0, padding: 0 });

        jqQDDN(ulSubMenu).css({ margin: 0, padding: 0,
            width: o.width(), height: o.height(), zIndex: 400,
            cursor: 'pointer', position: 'absolute',
            top: off.top, left: off.left
        });
        jqQDDN(ulSubMenu).bind('click', function() { location.href = menuLNK; });
        //jqQDDN(ulSubMenu).css({ border: '3px solid green' });

        _myDropDowns[_myDropDowns.length] = this;

        var me = this;

        jqQDDN(menuLNK).bind('mouseover', function() {
            //jqQDDN(menuLI).trigger('mouseover');
        });
        //jqQDDN(menuLNK).css({ border: '1px solid red' });
        jqQDDN(menuLNK).bind('mouseout', function() {
        });

    };

}



function _SubMenuRoot(root, debug) {
    var $obs = jqQDDN(root);

    for (var n = 0; n < $obs.length; n++) {
        var thisUL = jqQDDN($obs[n]);
        var wrappingLI = jqQDDN($obs[n]).parent().get(0);
        var parentLink = jqQDDN(jqQDDN($obs[n]).parent().get(0)).children().get(0);

        var b = new SubMenu(thisUL, wrappingLI, parentLink, n, debug);
        b.Generate();
    }



}

var _btm_ddn_configurator = {
    NavWrapperCSSName: ".nav",
    SubMenusCSSName: "sf-menu",
    NavBarStripIMG: "/images/carolinaalehouse/site/template/navbg.png",
    NavBarStripFullHeight: 104,
    Debug: false
}



var _btm_sub_menu_configurator = {
    OverallStyle:"Color: #FFF; text-align: center; text-transform:uppercase; font-size:16px; font-weight:bold;",
    BackgroundStyleOff: "border-top: 1px solid #fff; background-image:none; text-decoration:none; "+
	    "color:#fff; background-color:Maroon;",
    BackgroundStyleOn: "background: Black; color:#FFF;",
    DistanceTop: "50",  // Pixels
    ItemPadding: "10",    // Pixels
    ItemWidth: "160"    // Pixels
}









function _QuickBar_SetUp() {

    var navStripPath = _btm_ddn_configurator.NavBarStripIMG;
    var navStripFullHeight = _btm_ddn_configurator.NavBarStripFullHeight;
    var nav = _btm_ddn_configurator.NavWrapperCSSName;
    var subMenu = _btm_ddn_configurator.SubMenusCSSName;


    var $chlds = jqQDDN('.' + nav).children();

    var w = 0;
    var l = 0;
    var str = "";
    var halfHeight = parseInt(navStripFullHeight / 2);

    if (halfHeight == 0 || isNaN(halfHeight)) {
        alert('Wrong navigation strip height passed: [' + navStripFullHeight + ']');
    }

    for (var n = 0; n < $chlds.length; n++) {
        var className = jqQDDN($chlds[n]).attr('class');

        /// IF NO CLASS NAME WAS SUPPLIED, WE CAN AUTO-GENERATE ONE.
        ///
        if (className == "") {
            className = "auto_css_" + n;
            jqQDDN($chlds[n]).addClass(className);
        }


        /// NOW WE'LL SCAN THIS <LI> CHILDS LOOKING FOR A <UL>
        /// A <UL> IS A SUBMENU. WE ADD OUR SUB-MENU CLASS TO THEM.
        jqQDDN($chlds[n]).children("ul").addClass(subMenu);


        var width = jqQDDN($chlds[n]).css('width').replace('px', '');

        str +=
"	." + nav + " ." + className + " a:link, ." + nav + " ." + className + " a:visited {	" +
            "		top: 0px;	" +
            "		left:" + l + "px;	" +
            "		width: " + width + "px; border:0px; outline:none;	" +
            "	}	" +
            "	." + nav + " ." + className + " a:hover, ." + nav + " ." + className + " a:focus {	" +
            "		background: url('" + navStripPath + "') no-repeat " + w + "px -" + halfHeight + "px; 	" +
"		border:0px none; outline:none 0px; 	" +
"	}				" +
"	." + nav + " ." + className + " a:active {		" +
"		background: url('" + navStripPath + "') no-repeat " + w + "px 0px; 		" +
"	}		" +
"	" +
"	.current-" + className + " ." + className + " a:link, .current-" + className + " ." + className + " a:visited {	" +
"		background: url('" + navStripPath + "') no-repeat " + w + "px -" + halfHeight + "px; 	" +
"		cursor: default;	" +
"	}	" +
"	." + nav + "-" + className + ", ." + nav + "-" + className + "-click {	" +
"		position: absolute;	" +
"		top: 0px;		" +
"		left: " + l + "px;		" +
"		width: " + width + "px;		" +
"		height: " + halfHeight + "px;		" +
"		background: url('" + navStripPath + "') no-repeat " + w + "px -" + halfHeight + "px; 	" +
"	}		" +
"	." + nav + "-" + className + "-click {		" +
"		background: url('" + navStripPath + "') no-repeat " + w + "px 0px; 		" +
"	}	";

        w = w - parseInt(width);
        l = l + parseInt(width);

    }


    str += "." + nav + " " +
" {       " +
"     width: " + l + "px;   " +
"     height: " + halfHeight + "px;   " +
"     text-indent: -9000px;   /* helps hidding the actual text */ " +
"     background: url('" + navStripPath + "') no-repeat 0 0;  " +
"     position: absolute; " +
"     padding: 0px;   " +
"     list-style: none;" +
"     margin: 0px;    " +
" }   " +
"     " +
" ." + nav + " li " +
" {   " +
"     display: inline;    " +
" }   " +
"     " +
" ." + nav + " li a:link, ." + nav + " li a:visited    " +
" {    " +
"     position: absolute;  " +
"     height: " + halfHeight + "px;    " +
"     overflow: hidden;    " +
"     z-index: 10;     " +
"     border: 0px;     " +
" }    ";


    var pdng = _btm_sub_menu_configurator.ItemPadding * 2;
    str += ".sf-menu {			" + _btm_sub_menu_configurator.OverallStyle +
"	}			" +
"				" +
"	.sf-menu a, .sf-menu a:visited  { 			" +
_btm_sub_menu_configurator.BackgroundStyleOff +
"       padding: " + _btm_sub_menu_configurator.ItemPadding + "px;       " +
"       width: " + _btm_sub_menu_configurator.ItemWidth + "px;       " +
"	}			" +
"	.sf-menu li {			" +
"	}			" +
"	.sf-menu li li {			" +
"	}			" +
"	.sf-menu li li li {			" +
"	}			" +
"	.sf-menu li:hover, .sf-menu li.sfHover,			" +
"				" +
"	.sf-menu a:focus, .sf-menu a:hover, .sf-menu a:active {			" +
_btm_sub_menu_configurator.BackgroundStyleOn +
"	}			" +
"	.sf-menu ul 			" +
"	{			" +
"	    padding: " + pdng + "px;			" +
"	    margin: -" + pdng + "px;			" +
"	    width: " + _btm_sub_menu_configurator.ItemWidth + "px;			" +
"	}			" +
"				" +
"	.sf-menu li.sfHover ul {			" +
"		top:			" + _btm_sub_menu_configurator.DistanceTop + "px; /* match top ul list item height */			" +
"	}			";

    jqQDDN('head').append('<style type="text/css">' + str + '</style>');



    _hlprStr = str;
    setTimeout(function() {
        jqQDDN('head').append('<style type="text/css">' + _hlprStr + '</style>');
    }, 1);



    _SubMenuRoot('.' + nav + ' .' + subMenu, _btm_ddn_configurator.Debug);


    //    jqQDDN('.' + nav).css({ display: '' });

    if (_hlprReady) {
        jqQDDN('.' + nav).fadeIn();
    } else {
        jqQDDN(document).ready(function() {
            jqQDDN('.' + nav).fadeIn();
        });
    }

    



}
jqQDDN(document).ready(function() {
    _hlprReady = true;
});

var _hlprStr = "";
var _hlprReady = false;