var badie = false;

$.each(jQuery.browser, function(i, val) {
  var browsVersion = $.browser.version;
  if(i=="msie"){
	if(browsVersion < 8){
		//alert("msie");
		badie = true;
	}
	if(browsVersion < 7){
		alert("This website was developed to make use of modern browser techniques and features.  Your browser (Internet Explorer 6) is severely outdated.  Please upgrade to a modern browser to enjoy this website to its fullest potential.");
		//badie = true;
	}
  }
  //alert('You are using: '+i+' - '+val+' - '+browsVersion);
  //if(i=="mozilla" && jQuery.browser.version.substr(0,3)=="1.9")
  //   alert("Do stuff for firefox 3")
});

/*
$.maxZIndex = $.fn.maxZIndex = function(opt) {
    /// <summary>
    /// Returns the max zOrder in the document (no parameter)
    /// Sets max zOrder by passing a non-zero number
    /// which gets added to the highest zOrder.
    /// </summary>    
    /// <param name="opt" type="object">
    /// inc: increment value, 
    /// group: selector for zIndex elements to find max for
    /// </param>
    /// <returns type="jQuery" />
    var def = { inc: 10, group: "*" };
    $.extend(def, opt);
    var zmax = 0;
    $(def.group).each(function() {
        var cur = parseInt($(this).css('z-index'));
        zmax = cur > zmax ? cur : zmax;
    });
    if (!this.jquery)
        return zmax;

    return this.each(function() {
        zmax += def.inc;
        $(this).css("z-index", zmax);
		//alert(zmax);
    });
} */


var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  
	//alert('open');
	if(badie){
		//alert('hide obj');
		$('object').hide();
		$('span.sIFR-alternate').show();
		$('div.text_wrapper').hide();
	}
	jsddm_canceltimer();
   jsddm_close();
   $(".live_link").css( {backgroundPosition: "0 -999px"} );
   ddmenuitem = $(this).find('ul').css('visibility', 'visible').css('z-index', '1001'); //.maxZIndex();
}

function jsddm_close()
{  
	//alert('show obj');
   $(".live_link").css( {backgroundPosition: "center 32px"} );


	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  
	if(badie){//alert('hide obj');
		$('div.text_wrapper[rel*=active]').show();
		$('object').show();
		$('span.sIFR-alternate').hide();
	}
	
	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}
}

$(document).ready(function()
{
	
	$('#jsddm > li').bind('mouseover', jsddm_open);
	$('#jsddm > li').bind('mouseout',  jsddm_timer);
	
	var li_width = 0;
	$('#jsddm li.headlink').each(function(i) {
			
			var theDiv = $(this);
			var totalWidth = theDiv.width();
			totalWidth += parseInt(theDiv.css("padding-left"), 10) + parseInt(theDiv.css("padding-right"), 10); //Total Padding Width
			totalWidth += parseInt(theDiv.css("margin-left"), 10) + parseInt(theDiv.css("margin-right"), 10); //Total Margin Width
			totalWidth += parseInt(theDiv.css("borderLeftWidth"), 10) + parseInt(theDiv.css("borderRightWidth"), 10); //Total Border Width

   			li_width += totalWidth;
			//alert(li_width);
   
	});
	
	var old_w = $('#jsddm').width();
	var new_marg = (old_w - li_width)/2;
	$('#jsddm_').width(li_width).css('margin-left', new_marg);
	
});

document.onclick = jsddm_close;

/* from http://javascript-array.com/scripts/jquery_simple_drop_down_menu/ */
