﻿var _myDropDowns = new Array();

function _hoveritup(o) {
    //return;
    for (var n = 0; n < _myDropDowns.length; n++) {
        var myID = _myDropDowns[n].ioj;
        if ($(o).attr('id') == myID) {
            $(_myDropDowns[n].wrappingLI).trigger('mouseover');
        }
    }
}
function _hoveritout(o) {
    //return;
    for (var n = 0; n < _myDropDowns.length; n++) {
        var myID = _myDropDowns[n].ioj;
        if ($(o).attr('id') == myID) {
            $(_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 = $(ulSubMenu).children();
        $(ulSubMenu).empty();
        $(ulSubMenu).append("<li id='_subMenuInnerLI" + this.id + "'><ul id='_subMenuInnerUL" + this.id + "'></ul></li>");
        for (var n = 0; n < $chlds.length; n++) {
            $('#_subMenuInnerUL' + this.id).append($chlds[n]);
        }

        $('body').append(ulSubMenu);


        var subMenuInnerLI = $('#_subMenuInnerLI' + this.id);
        var subMenuInnerUL = $('#_subMenuInnerUL' + this.id);

        this.ioj = '_subMenuInnerLI' + this.id;

        var menuLI = wrappingLI;
        var menuLNK = parentLink;

        this.IsVisible = false;


        $(subMenuInnerLI).css({ backgroundColor: 'transparent' });

        var o = $(menuLNK);
        var off = o.offset();

        var hlpr = " border:2px solid Orange; ";
        if (!debug) hlpr = "";

        $('<div style="width:200px; height:40px; ' + hlpr +
                'background:transparent;" id="_hlprDiv_' + this.id + '"></div>').appendTo(subMenuInnerLI);
        $('#_hlprDiv_' + this.id).css({ width: o.width(), height: o.height(), margin: 0, padding: 0 });

        $(ulSubMenu).css({ margin: 0, padding: 0,
            width: o.width(), height: o.height(), zIndex: 400,
            cursor: 'pointer', position: 'absolute',
            top: off.top, left: off.left
        });
        $(ulSubMenu).bind('click', function() { location.href = menuLNK; });
        //$(ulSubMenu).css({ border: '3px solid green' });

        _myDropDowns[_myDropDowns.length] = this;

        var me = this;

        $(menuLNK).bind('mouseover', function() {
            //$(menuLI).trigger('mouseover');
        });
        //$(menuLNK).css({ border: '1px solid red' });
        $(menuLNK).bind('mouseout', function() {
        });

    };

}



function _SubMenuRoot(root, debug) {
    var $obs = $(root);

    for (var n = 0; n < $obs.length; n++) {
        var thisUL = $($obs[n]);
        var wrappingLI = $($obs[n]).parent().get(0);
        var parentLink = $($($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;

    $('.' + nav).css({ display: '' });

    var $chlds = $('.' + 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 = $($chlds[n]).attr('class');

        /// IF NO CLASS NAME WAS SUPPLIED, WE CAN AUTO-GENERATE ONE.
        ///
        if (className == "") {
            className = "auto_css_" + n;
            $($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.
        $($chlds[n]).children("ul").addClass(subMenu);


        var width = $($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 */			"+
"	}			";

    $('head').append('<style type="text/css">' + str + '</style>');



	_hlprStr = str;
	setTimeout(function(){
	    	$('head').append('<style type="text/css">' + _hlprStr + '</style>');
						}, 1);



    _SubMenuRoot('.' + nav + ' .' + subMenu, _btm_ddn_configurator.Debug);


}
var _hlprStr = ""
