/* IE6 flicker fix
-------------------------------------------------- */
try { document.execCommand("BackgroundImageCache", false, true); } catch(err){}
var menu01timer;

/* Togglers */

function toggleId(id) {
    $(id).style.display = ($(id).style.display == "none") ? "" : "none";
}

function toggleItems() {
	$A(toggleItems.arguments).each(function(id){
	    toggleId(id);
	});
}

function HasClassName(objElement, strClass){
	if ( objElement.className ){
		var arrList = objElement.className.split(' ');
		var strClassUpper = strClass.toUpperCase();
		for ( var i = 0; i < arrList.length; i++ ){
			if ( arrList[i].toUpperCase() == strClassUpper ){
				return true;
			}
		}
	}
   return false;
}

/* Class manipulation */

function AddClassName(objElement, strClass, blnMayAlreadyExist){
	if ( objElement.className ){
		var arrList = objElement.className.split(' ');
		if ( blnMayAlreadyExist ){
			var strClassUpper = strClass.toUpperCase();
			for ( var i = 0; i < arrList.length; i++ ){
				if ( arrList[i].toUpperCase() == strClassUpper ){
					arrList.splice(i, 1);
					i--;
				}
			}
		}
		arrList[arrList.length] = strClass;
		objElement.className = arrList.join(' ');
	} else {
		objElement.className = strClass;
	}
}

function RemoveClassName(objElement, strClass){
	if ( objElement.className ){
		var arrList = objElement.className.split(' ');
		var strClassUpper = strClass.toUpperCase();
		for ( var i = 0; i < arrList.length; i++ ){
			if ( arrList[i].toUpperCase() == strClassUpper ){
				arrList.splice(i, 1);
				i--;
			}
		}
		objElement.className = arrList.join(' ');
	}
}

function showMe(ref){
	$(ref).toggleClass('open').toggleClass('closed'); $($(ref).attr('href')).slideToggle(200).toggleClass('hidden');
	return false;
}
$(document).ready(function(e) {
	$('iframe').each(function(){
		var url = $(this).attr("src");
		$(this).attr("src",url+"?wmode=transparent");
	});

	// #menu1 functions
	
	$('#menu1 LI:has(UL) > A').addClass('haschildren').bind('mouseenter',function(){
		$t = $(this);
		$top  = parseInt($t.parent().css('top'));
		$left  =  parseInt($t.parent().css('left'));
		$h  = $t.parent().outerHeight();
		$w  = $t.parents('UL').eq(0).outerWidth()+1
		$offset  = $t.parent().offset().left+$t.width();
		$docw = $(window).width();
		if($left+$w>$docw){ }
		if( $t.parents('UL').length == 1 ){
			$t.addClass('open').parents('LI').eq(0).find('UL').eq(0).css({ display: 'block', left: $left + 'px', top: $top+$h-3 + 'px' });
		} else {
			$left = $t.parents('UL').eq(0).outerWidth() + 1;
			if($offset+$w>$docw || parseInt($t.parent().parent().css("left"))<0){ $left -=$w+$t.outerWidth()+1; }
			if($offset+$w>$docw) { $left-=1; }
			$t.addClass('open').parents('LI').eq(0).find('UL').eq(0).css({ display: 'block', left: $left + 'px',top: -3 + 'px' });
			if($offset+$w>$docw) { 
				$t.addClass('open').parents('LI').eq(0).find('UL').eq(0).css({width: 140+"px"});
			}
		}
	});
	$('#menu1 A')
		.bind('mouseenter',function(){
			window.clearTimeout(menu01timer);
			$('#menu1 LI:has(A.open)').not($(this).parents('LI')).each(function(){
				$(this).find('UL').hide();
				$(this).find('A.open').removeClass('open');
			});
		})
		.bind('mouseleave',function(){
			window.clearTimeout(menu01timer);
			menu01timer = window.setTimeout(function(){
				$('#menu1 LI UL').hide();
				$('#menu1 A.open').removeClass('open');
			},500);
		})
	;
});
