function initSlide(){
	var _duration = 400; //in ms
	$('a.opener').each(function(){
		if($(this).parent('ul.hold')){
			var _hold = $(this).parent('li').children('div.slide').eq(0);
			var _box = _hold.find('ul.hold-second');
			var _boxChild = _box.find('div.slide-second');
			var _btnSecond = _boxChild.parent('li').find('a.opener-second');
			var _h = _box.height();
			if(_hold.hasClass('opened')){
				_box.show();
				_boxChild.each(function(){
					if ($(this).hasClass('opened')) {
						$(this).show();
					}
					else {
						$(this).hide();
					}
					var _btnSecond = $(this).find('a.opener')
					_btnSecond.click(function(){
						if($(this).parent('ul').parent('div.slide-second').hasClass('opened')){
							_hold.removeClass('opened');
							_box.stop().animate({height:0}, _duration, function(){
								$(this).css({display:'none', height:'auto'});
							});
						}
						else{
							_hold.addClass('opened');
							if(_box.is(':hidden')){
								_box.show();
								_h = _box.height();
								_box.height(0);
							}
							_box.stop().animate({height: _h}, _duration, function(){ 
								$(this).height('auto');
							})
						}
						return false;
					});
				});
			} 
			else{
				_box.hide();
				_boxChild.hide();
			}
		}
		
		$(this).click(function(){
			if(_hold.hasClass('opened')){
				_hold.removeClass('opened');
				_box.stop().animate({height:0}, _duration, function(){
					$(this).css({display:'none', height:'auto'});
				});
			}
			else{
				_hold.addClass('opened');
				if(_box.is(':hidden')){
					_box.show();
					_h = _box.height();
					_box.height(0);
				}
				_box.stop().animate({height: _h}, _duration, function(){ 
					$(this).height('auto');
				})
			}
			return false;
		});
		
		_btnSecond.click(function(){
			var _slideSecond = $(this).parent('li').find('div.slide-second');
			var _slideb = _slideSecond.find('ul');
			if(_slideSecond.hasClass('opened')){
				_slideSecond.removeClass('opened');
				_slideb.stop().animate({height:0}, _duration, function(){
					$(this).css({display:'none', height:'auto'});
				});
			}
			else{
				_slideSecond.addClass('opened');
				if(_slideb.is(':hidden')){
					_slideb.show();
					_h = _slideb.height();
					_slideb.height(0);
				}
				_slideb.stop().animate({height: _h}, _duration, function(){ 
				})
			}
			return false;
		});
	});
}		
		
function initDropFade(){
	var _lt8 = ((navigator.appName.indexOf('Microsoft Internet Explorer') != -1) && (parseInt(navigator.appVersion) < 7)) ? true : false;
	_nav = $('#nav');
	var _li = _nav.children('li');
	$('body').append('<div id="jquery-overlay"> </div>');
	var _fader = $('#jquery-overlay');
	_fader.css({
		'position':'absolute',
		'top':0,
		'left':0,
		'backgroundColor':'#000',
		'zIndex':'200',
		'opacity':'0'
	 });
	_li.mouseenter(function(){
		var _btn = $(this).children('div.drop');
		if(_btn.length !=0){
			var _height = 0;
			var _width = 0;
			var _page = $('body > div:eq(0)');
			var _minWidth = _page.outerWidth();
			if (window.innerHeight) {
				_height = window.innerHeight;
				_width = window.innerWidth;
			}
			else {
				_height = document.documentElement.clientHeight;
				_width = document.documentElement.clientWidth;
			}
			if (_width < _minWidth) {_fader.css('width',_minWidth);} else {_fader.css('width','100%');}
			if (_height > _page.innerHeight()) _fader.css('height',_height); else _fader.css('height',_page.innerHeight());
			_fader.stop().animate({'opacity':'0.6'}, 400);
			_btn.show();
		}
		else{
			_fader.stop().animate({'opacity':'0','width':'0'}, 200);
		}
	}).mouseleave(function(){
		var _btn = $(this).children('div.drop');
		_fader.stop().animate({'opacity':'0','width':'0'}, 200);
		_btn.hide();
	});
	if(jQuery.browser.msie && jQuery.browser.version < 7){
		$('#nav li').mouseenter(function(){
			$(this).addClass('hover');
		}).mouseleave(function(){
			$(this).removeClass('hover');
		});
	}
};

messageObj = new DHTML_modalMessage();	// We only create one object of this class
messageObj.setShadowOffset(5);	// Large shadow

function displayMessage(messageContent,cssClass)
{
	messageObj.setHtmlContent(messageContent);
	messageObj.setSize(500,350);
	messageObj.setCssClassMessageBox(cssClass);
	messageObj.setSource(false);	// no html source since we want to use a static message here.
	messageObj.setShadowDivVisible(false);	// Disable shadow for these boxes	
	messageObj.display();
};

function closeMessage()
{
    clearTimeout(messageObj.currentTimeout);
	messageObj.close();	
};

function generate_message(obj, text){
    if(text){
        destination = $(obj).attr('href');
    } else {
        destination = $(obj).attr('href');
        text = destination;
    }
    displayMessage(
        '<a id="modal-cancel" href="javascript:closeMessage()">Close</a><h2>YOU ARE NOW LEAVING <br />THE LADENBURG THALMANN SITE</h2>'
        + '<p>Click the link below to continue or wait <strong>30 seconds</strong> to be transferred to:</p>'
        + '<p><strong>Continue to: <a href="' + destination + '" target="_blank" onclick="closeMessage()">' + text + '</a></strong></p>'
        
        + '<p>We are providing links to this third party website <strong>' + text + '</strong> '
        + 'only as a convenience and the inclusion of links to the linked site does not imply any endorsement, approval,'
        + 'investigation, verification or monitoring by us of any content or information contained within or accessible '
        + 'from the linked site.&nbsp; Ladenburg Thalmann does not control the accuracy, completeness, timeliness or appropriateness'
        + 'of the content or information on the linked site.  If you choose to visit the linked site you will be subject to '
        + 'its terms of use and privacy policies, over which Ladenburg Thalmann has no control.&nbsp; In no event will Ladenburg Thalmann '
        + 'be responsible for any information or content within the linked site or your use of the linked site.&nbsp; By continuing '
        + 'to the linked site you agree to the foregoing.</p>    Thank you for visiting <strong>http://www.ladenburg.com</strong>'
    , false);
    messageObj.currentTimeout = setTimeout("open_new_window(destination,'Ladenburg')",30*1000);
}

function open_new_window(url,name){
    closeMessage();
    window.open(url,name);
}


$(document).ready(function(){
    initDropFade();
    $('#slogan').flash(
        { 
            src: '/swf/home_header.swf',
            width: 600,
            height: 200,
            wmode: 'transparent'
        },
        { 
            version: 8 
        }
    );

    // Change Outbound Links
    $("a[href^='http']").click(function(el) {
        if(this.hostname != 'www.ladenburg.com' 
            && this.hostname != 'ladenburg.com' 
            && this.hostname != 'ir.stockpr.com' 
            && this.hostname != 'www.ladenburg.sites.stockpr.com'
            && this.hostname != 'ladenburg.sites.stockpr.com'
            && this.hostname != 'content.stockpr.com'
            && this.hostname != 'app.quotemedia.com'){
            generate_message(this);
            return false;
        };
    });
    $('a.client-login-link').click(function(el) {
        generate_message(this, "Client Login");
        return false;
    });
}); 

function popupWindow(strPage,intWidth,intHeight){
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(strPage, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=" + intWidth + ",height=" + intHeight + ",left=100,top=100');");
}
