window.onload = mladdevents;
function mladdevents(){
	if(window.mlrunShim == true){
		var Iframe = document.createElement("iframe");
		Iframe.setAttribute("src","about:blank");
		Iframe.setAttribute("scrolling","no");
		Iframe.setAttribute("frameBorder","0");
		Iframe.style.zIndex = "2";
		Iframe.style.filter = 'alpha(opacity=0)';
	}
	var effects_a = new Array();
	var divs = document.getElementsByTagName('div');
	for(var j=0;j<divs.length;j++){
		if(divs[j].className.indexOf('mlmenu') != -1){
			var lis = divs[j].getElementsByTagName('li');
			for(var i =0;i<lis.length;i++){
				lis[i].onmouseover = mlover;
				lis[i].onmouseout = mloutSetTimeout;
				if(window.mlrunShim == true){
					lis[i].appendChild(Iframe.cloneNode(false));
				}
				if(lis[i].getElementsByTagName('ul').length > 0){
					lis[i].className += 'haschild';
					if(divs[j].className.indexOf('arrow') != -1){
						if(divs[j].className.indexOf('vertical') != -1 || lis[i].parentNode.parentNode.nodeName != 'DIV'){
							lis[i].getElementsByTagName('a')[0].innerHTML += '<span class="vert">&rarr;</span>';
						}
						else{
							lis[i].getElementsByTagName('a')[0].innerHTML += '<span class="horiz">&darr;</span>';
						}
					}
					else if(divs[j].className.indexOf('plus') != -1){
						lis[i].getElementsByTagName('a')[0].innerHTML += '<span class="plus">+</span>';
					}
				}
				else{
					if(divs[j].className.indexOf('arrow') != -1){
						//This accounts for a wierd IE-specific bug in horizontal menus. CSS will set visibility: hidden;. This keeps the menu level(in IE)
						lis[i].getElementsByTagName('a')[0].innerHTML += '<span class="noshow">&darr;</span>';
					}
				}
				var uls = lis[i].getElementsByTagName('ul');
				for(var k=0;k<uls.length;k++){
					var found = 'no';
					for(var z=0;z<effects_a.length;z++){
						if(effects_a[z] == uls[k]){
							found = 'yes';
						}
					}
					if(found == 'no'){
						effects_a[effects_a.length] = uls[k];
						uls[k].style.zIndex = '100';
						mlEffectLoad(uls[k]);
					}
				}
			}
		}
	}
}


function mloutSetTimeout(e){
	if(!e){
		var the_e = window.event;
	}
	else{
		var the_e = e;
	}
	var reltg = (the_e.relatedTarget) ? the_e.relatedTarget : the_e.toElement;
	if(reltg){
		var under = ancestor(reltg,this);
		if(under === false && reltg != this){
			window.mlLast = this;
			var parent = this.parentNode;
			while(parent.parentNode && parent.className.indexOf('mlmenu') == -1){
				parent = parent.parentNode;
			}
			
			if(parent.className.indexOf('delay') != -1){
				window.mlTimeout = setTimeout(function(){mlout()},100);
			}else{
					mlout();
					
				}
		}
	}
}


function mlout(){
	if(window.mlLast==null)return false;
	var uls = window.mlLast.getElementsByTagName('ul');
	var sib;
	for(var i=0;i<uls.length;i++){
		mlEffectOut(uls[i]);
		if(window.mlrunShim == true){
			sib = uls[i];							
			while(sib.nextSibling && sib.nodeName != 'IFRAME'){
					sib = sib.nextSibling
			}
			sib.style.display = 'none';
		}
	}
	window.lastover = null;
}


function mlover(e){
	if(!e){
		var the_e = window.event;
	}
	else{
		var the_e = e;
	}
	the_e.cancelBubble = true;
	if(the_e.stopPropagation){
		the_e.stopPropagation();
	}
	clearTimeout(window.mlTimeout);
	if(window.mlLast && window.mlLast != this && ancestor(this,window.mlLast) == false){
		mlout();
	}
	else{
		window.mlLast = null;
	}
	var reltg = (the_e.relatedTarget) ? the_e.relatedTarget : the_e.fromElement;
	var ob = this.getElementsByTagName('ul');
	var under = ancestor(reltg,this);
	if(ob[0] && under == false){
		if(window.lastover != ob[0]){
			if(window.mlrunShim == true){
				var sib = ob[0];
				while(sib.nextSibling && sib.nodeName != 'IFRAME'){
					sib = sib.nextSibling
				}
				ob[0].style.display = 'block';
				sib.style.top = ob[0].offsetTop+'px';
				sib.style.left = ob[0].offsetLeft-2+'px';
				sib.style.width = ob[0].offsetWidth+'px';
				sib.style.height = ob[0].offsetHeight-2+'px';
				sib.style.border = '1px solid red';
				sib.style.display = 'block';
			}
			mlEffectOver(ob[0],this);
			window.lastover = ob[0];
		}
	}
}


function mlSetOpacity(ob,level){
	if(ob){
		//level is between 0 and 10
		//need to convert to decimal for standard
		var standard = level/10;
		//need to convert to 0-100 scale for IE filter
		var ie = level*10;
		if(navigator.appName!='Netscape'){
			ob.style.opacity = standard;
		}
		//ob.style.filter = "alpha(opacity="+ie+")"
	}
}

function mlIncreaseOpacity(ob){
	
		var current = ob.style.opacity;
		if(lastob == ob && lastop == current){
			//mlout has not interfered
			current = current *10;
			var upone = current +1;
			mlSetOpacity(ob,upone);
			lastob = ob;
			lastop = upone/10;
		}
}
function mlIncreaseHeight(ob){
	var current = parseInt(ob.style.height);
	var newh = current + 1;
	ob.style.height = newh+'px';
}
function mlIncreaseWidth(ob){
	var current = parseInt(ob.style.width);
	var newh = current + 1;
	ob.style.width = newh+'px';
}
function mlBlink(ob){
	var newb = '1px solid red';
	var old = '';
	if(ob.style.border==old){
		ob.style.border=newb;
	}
	else{
		ob.style.border=old;
		ob.style.borderTop = '1px solid';
	}
}
function mlShake(ob){
	var newp = '5px';
	var old = '';
	if(ob.style.paddingLeft==old){
		ob.style.paddingLeft=newp;
	}
	else{
		ob.style.paddingLeft=old;
	}
}

function mlEffectOver(ob,parent){
	switch(ob.className){
		case 'fade':
			ob.style.display = 'block';
			if(ob.style.opacity == 0){
				lastob = ob
				lastop = 0;
				for(var i = 1;i<=10;i++){
					setTimeout(function(){mlIncreaseOpacity(ob)},i*50);
				}
				setTimeout(function(){ob.style.filter = ''},500);
			}
			break;
		case 'blink':
			ob.style.display = 'block';
			for(var i=0;i<10;i++){
				setTimeout(function(){mlBlink(ob)},i*50);
			}
			break;
		case 'shake':
			ob.style.display = 'block';
			for(var i=0;i<10;i++){
				setTimeout(function(){mlShake(ob)},i*50);
			}
			break;
		case 'blindv':
			
			ob.style.display = 'block';
			if(ob.offsetHeight){
				var height = ob.offsetHeight
				ob.style.height = '0px';
// 							ob.style.overflow = 'hidden';
				for(var i=0;i<height;i++){
					setTimeout(function(){mlIncreaseHeight(ob)},i*3);
				}
				setTimeout(function(){ob.style.overflow='visible';},height*3)
			}
			break;
		case 'blindh':
			
			ob.style.display = 'block';
			if(ob.offsetWidth){
				var width = ob.offsetWidth;
				ob.style.width = '0px';
					ob.style.overflow = 'hidden';
					for(var i=0;i<width;i++){
					setTimeout(function(){mlIncreaseWidth(ob)},i*3);
				}
				setTimeout(function(){ob.style.overflow='visible';},width*3)
			}
			break;
		default:
			ob.style.display = 'block';
			break;
	}
}
function mlEffectOut(ob){
	switch(ob.className){
		case 'fade':
			mlSetOpacity(ob,0);
			ob.style.display = 'none';
			break;
		case 'blink':
			ob.style.border = '';
			ob.style.display = 'none';
			break;
		case 'shake':
			ob.style.paddingLeft = '';
			ob.style.display = 'none';
			break;
		default:
			ob.style.display = 'none';
			break;
	}
}
function mlEffectLoad(ob){
	var parent = ob.parentNode;
	while(parent.parentNode && parent.className.indexOf('mlmenu') == -1){
		parent = parent.parentNode;
	}
	if(parent.className.indexOf('fade') != -1){
			ob.style.display = 'none';
			ob.className = 'fade';
			mlSetOpacity(ob,0);
	}
	else if(parent.className.indexOf('blink') != -1){
		ob.className = 'blink';
		ob.style.display = 'none';
	}
	else if(parent.className.indexOf('shake') != -1){
		ob.className = 'shake';
		ob.style.display = 'none';
	}
	else if(parent.className.indexOf('blindv') != -1){
		ob.className = 'blindv';
		ob.style.display = 'none';
	}
	else if(parent.className.indexOf('blindh') != -1){
		ob.className = 'blindh';
		ob.style.display = 'none';
	}
	else{
		ob.className = 'none';
		ob.style.display = 'none';
	}
}
function ancestor(child, parent){
	if(child==null)return false;//Saves checking elsewhere
	//This is a fix for a Firefox bug *gasp*
	//Aparantly causes a bug in Opera!
	//I see no choice but a browser detect. *sigh* I didn't want to have to do this.
	if(navigator.userAgent.indexOf('Gecko') != -1 && navigator.userAgent.indexOf('Opera') == -1){
		//This should only be run by Gecko based browsers. this code should be fine in everything but Opera so forge away browsers.
		var allc = parent.getElementsByTagName('*');
		for(var i= 0;i<allc.length;i++){
			if(allc[i] == child){
				return true;
			}
		}
	}
	else{
		//http://www.dynamicdrive.com/forums/showthread.php?t=12341 Thanks Twey!
		for(; child.parentNode; child = child.parentNode){
			if(child.parentNode === parent) return true;
		}
	}
	return false;
}

function closePopUp(){
	var popObj = document.getElementById('popbox');
	popObj.style.visibility = 'hidden';
	popObj.style.display = 'none';
}

function openPopUp(genId,typeImg,heightImg){
	var popObj = document.getElementById('popbox');
	popObj.style.visibility = 'visible';
	popObj.style.display = 'block';
	
	var bodyObj = document.getElementsByTagName('body')[0];
								
	var popObj = document.getElementById('popbox');
	popObj.style.position = 'absolute';
	popObj.style.left = bodyObj.style.left + 220 + 'px';
	popObj.style.top = bodyObj.style.top + 12 + 'px';
	popObj.style.zIndex = '5';
		
	var swfdivObj = document.getElementById('swfDiv');	
	if (typeImg == 'gif'){
		swfdivObj.innerHTML = "<img src=\"../swfs/"+ genId + "."+ typeImg +"\" alt=\"\"  />";
		// un-hide if shown the share button.
		var shareObj = document.getElementById('sharebtn');
		if (shareObj){
			shareObj.className = 'visiblediv';						
		}
		var copyObj = document.getElementById('copyLink');
		if (copyObj){
			copyObj.className = 'visiblediv';
		}	
	}else if (typeImg == 'inlineframeflash'){
		var flash_content;
		flash_content = "<iframe src='../swfs/show_flash.php?part_number="+ genId +"' height='550' width='580' frameborder=0 >";		
		flash_content += "</iframe>";
		swfdivObj.innerHTML = flash_content;
		// un-hide if shown the share button.
		var shareObj = document.getElementById('sharebtn');
		if (shareObj){
			shareObj.className = 'visiblediv';				
		}
		var copyObj = document.getElementById('copyLink');
		if (copyObj){
			copyObj.className = 'visiblediv';
		}	
	}else{		
		swfdivObj.innerHTML = loadSWF(genId);
	}
	
								
	
}

function loadSWF(genId,flashWidth,flashHeight){
	
	flashWidth = (flashWidth > 0)? flashWidth : '600';
	flashHeight = (flashHeight > 0)? flashHeight : '600';
	
	if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
		if ( (hasRightVersion) && (genId > 0)) {  // if we've detected an acceptable version
			// embed the flash movie
			var alternateContent = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '
			+ 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" WIDTH="'+ flashWidth +'" HEIGHT="'+ flashHeight +'" id="hyvahead4" >'
			+ '<param name="allowScriptAccess" value="sameDomain" />'
			+ '<param name="wmode" value="opaque" />'		
			+ '<param name="movie" value="../swfs/'+ genId +'.swf?exturl=&exttarget=" />'
			+ '<param name="quality" value="high" />'
			+ '<embed id="fls_menu" src="../swfs/'+ genId +'.swf?exturl=&exttarget=" quality=high WIDTH="'+ flashWidth +'" HEIGHT="'+ flashHeight +'" quality="high" name="hyvahead4" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" WMode="opaque" />'
			+ '</object>';			
			// un-hide if shown the share button.
			var shareObj = document.getElementById('sharebtn');
			if (shareObj){
				shareObj.className = 'visiblediv';				
			}
			var copyObj = document.getElementById('copyLink');
			if (copyObj){
				copyObj.className = 'visiblediv';
			}	
			return alternateContent;
		} else {  // flash is too old or we can't detect the plugin
	
			// hide if shown the share button.
			var shareObj = document.getElementById('sharebtn');
			if (shareObj){
				shareObj.className = 'hiddendiv';
			}
			var copyObj = document.getElementById('copyLink');
			if (copyObj){
				copyObj.className = 'hiddendiv';
			}	
			
			var str = "<h2><img src=\"../images/alerticon.gif\" width=\"36\" height=\"38\" alt=\"Alert\" />";
			str += "<p>To view this content, JavaScript must be enabled, and you need the latest version of Flash Player.</p>";			
			return str;			
		}
	}
							
}

function click_load_media(format, uri, title,imageurl){
     var div_object = document.getElementById("media_series_1");
     var newInnerHTML;

     if (format == "image/jpeg" || format == "image/gif" || format == "image/png"){
        newInnerHTML = "<img src='" + uri + "'>";
        newInnerHTML = newInnerHTML + "<h4>" + title + "<\/h4>";
        div_object.innerHTML =  newInnerHTML;
     }else if (format == "video/x-flv"){
			newInnerHTML = '<div id="flashcontent">';
        newInnerHTML+= '<h2>Flash plug-in not found</h2>';
        newInnerHTML+= '<p>To view this site a Flash 8 plug-in must be installed. Just follow the link below to download the latest version from Adobe. It only takes a couple of minutes to do and you\'ll then have access to a wealth of Flash sites online.</p>';
        newInnerHTML+= '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&amp;promoid=BIOW" target="_blank">Get Flash player</a>';
        newInnerHTML+= '</div>';

        newInnerHTML = newInnerHTML + "<h4>" + title + "</h4>";
        div_object.innerHTML =  newInnerHTML;

		var so = new SWFObject("../flash/player.swf", "mymovie", "447px", "280px", "9", "#ffffff");
		

        so.addParam("quality", "high");
        so.addParam("scale", "noscale");
        so.addParam("salign", "top");
        so.addParam('wmode','transparent');
		so.addParam("allowfullscreen","true");
		so.addParam("allowscriptaccess","always");
		so.addParam("flashvars","file="+uri+"&image=" + imageurl);
		so.addVariable("moviefile", uri); // this line is optional, but this example uses the variable and displays this text inside the flash movie
		so.write("flashcontent");		   

	}
}

function showHideText(objId,imgId){
	var dObj = document.getElementById(objId);
	var imgObj = document.getElementById(imgId);
	
	if (dObj.style.visibility == 'hidden'){
		dObj.style.visibility = 'visible';
		dObj.style.display = 'block';
	}else{		
		dObj.style.visibility = 'hidden';
		dObj.style.display = 'none';		
	}
	
	if (imgObj){
		if (dObj.style.visibility == 'hidden'){
			imgObj.src = "/images/plus_sign.gif";	
			imgObj.title = 'Expand';
		}else{			
			imgObj.src = "/images/minus_sign.gif";	
			imgObj.title = 'Collapse';
		}
	}
}



function load_divsproperties(label,total,groupName){
	if (total  > 0){
		for (var i=1; i<= total ; i++){
			var divObj = document.getElementById(label + i);	
			if (groupName){
				animatedcollapse.addDiv(label + i, 'fade=2,speed=500,group='+groupName);
			}else{
				animatedcollapse.addDiv(label + i, 'fade=2,speed=500');
			}				
			
		}
		animatedcollapse.ontoggle=function($, divobj, state){ //fires each time a DIV is expanded/contracted			
			//$: Access to jQuery
			//divobj: DOM reference to DIV being expanded/ collapsed. Use "divobj.id" to get its ID
			//state: "block" or "none", depending on state
			var imgObj = document.getElementById('img_' + divobj.id);
			if (imgObj){
				if (state == 'block'){
					imgObj.src = "/images/minus_sign.gif";	
					imgObj.title = 'Collapse';
				}else if (state == 'none'){
					imgObj.src = "/images/plus_sign.gif";	
					imgObj.title = 'Expand';
				}
			}
		}
		
		//animatedcollapse.init()

	}
	
}

function load_divsproperties_groups(label,total,groupName){
	if (total  > 0){
		for (var i=1; i<= total ; i++){
			var divObj = document.getElementById(label + i);
			animatedcollapse.addDiv(label + i, 'fade=2,speed=500,group='+groupName);
		}
		animatedcollapse.ontoggle=function($, divobj, state){ //fires each time a DIV is expanded/contracted
			//$: Access to jQuery
			//divobj: DOM reference to DIV being expanded/ collapsed. Use "divobj.id" to get its ID
			//state: "block" or "none", depending on state
		}
		
		animatedcollapse.init()

	}
	
}
