// MM functions
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//main js

var CoxMenu={
	init:function(){
		//cache link and menu
		this.menu_count=7;
		this.timeout=0;
		this.CLEAR_TIME=400;
		
		var tmp;
		for (var i=1;i<=this.menu_count;i++) {
			tmp=$('#link_div_'+i);
			tmp.hover(this.menuOver, this.menuOut);
			this['link_'+i]=tmp;
			
			tmp=$('#apDiv'+i);
			tmp.hover(this.subOver, this.subOut);
			this['div_'+i]=tmp;
		}
		
		//create modal layer
		this.tab_content=$('#tab_content');
		$('body').append('<div id="modal_layer"></div>');
		this.modal=$('#modal_layer');
		this.updateModal();
	},
	updateModal:function(){
		CoxMenu.modal.css('width', CoxMenu.tab_content.width());
		CoxMenu.modal.css('height', CoxMenu.tab_content.height());
		var offset=CoxMenu.tab_content.offset();
		CoxMenu.modal.css('top', offset.top+'px');
		CoxMenu.modal.css('left', offset.left+'px');
	},
	showModal:function(){
		//CoxMenu.modal.stop().fadeIn('fast');
		CoxMenu.modal.stop().fadeTo(200, 0.5);
	},
	hideModal:function(){
		CoxMenu.modal.stop().fadeOut('fast');
		//CoxMenu.modal.fadeTo(200, 0);
	},
	menuOver:function(){
		if (CoxMenu.timeout) {
			clearTimeout(CoxMenu.timeout);
			CoxMenu.hideMenu(CoxMenu.focus_id);
		}
		
		var id=CoxMenu.getId(this.id);
		CoxMenu.focus_id=id;
		
		//get offset
		var targ=CoxMenu['div_'+id];
		var offset=$(this).offset();
		
		//custom offsets
		if (id==4) offset.left-=548;
		
		//ie shit
		if (!$.support.cssFloat) {
			CoxMenu.version=$.browser.version.substr(0,1);
			if (CoxMenu.version=='8') {
				offset.top-=11;
			} else {
				offset.top+=12;
				if (id>=3) offset.top+=15;
			}
			
			//ie6 shit
			if (CoxMenu.version=='6') {
				var xx=$('select');
				xx.each(function(){$(this).css('visibility', 'hidden')});
				//$(':input').each(function(){$(this).css.('visibility', 'false');});
			}
		}
		
		targ.css('left', offset.left+'px');
		targ.css('top', (offset.top+14)+'px');
		targ.fadeIn('fast');
		
		CoxMenu.showModal();
	},
	menuOut:function(){
		var id=CoxMenu.getId(this.id);
		CoxMenu.outid=Math.abs(id);
		//alert(CoxMenu.outid);
		CoxMenu.timeout=setTimeout(CoxMenu.hideMenu, CoxMenu.CLEAR_TIME);
	},
	hideMenu:function(id){
		//alert('!'+id)
		id=CoxMenu.outid;
		//alert('!'+id)
		if (CoxMenu.timeout) clearTimeout(CoxMenu.timeout);
		
		if (CoxMenu['div_'+id]) CoxMenu['div_'+id].fadeOut('fast');
		CoxMenu.timeout=0;
		
		CoxMenu.hideModal();

		//ie6 shit
		if (CoxMenu.version=='6') {
			var xx=$(':input');
			xx.each(function(){$(this).css('visibility', 'visible')});
			//$(':input').each(function(){$(this).css.('visibility', 'false');});
		}
	},
	subOver:function(){
		//stop timeout
		if (CoxMenu.timeout) {
			clearTimeout(CoxMenu.timeout);
		}
	},
	subOut:function(){
		var id=CoxMenu.getId(this.id);
		CoxMenu['div_'+id].fadeOut('fast');
		
		CoxMenu.hideModal();
		
		//ie6 shit
		if (CoxMenu.version=='6') {
			var xx=$(':input');
			xx.each(function(){$(this).css('visibility', 'visible')});
			//$(':input').each(function(){$(this).css.('visibility', 'false');});
		}
	},
	hideSub:function(){
		
	},
	getId:function(str){
		//alert(str)
		var id=str.substr(str.length-1, 1);
		return id;
	}
};

$(document).ready(function(){
	CoxMenu.init();
	
	doc_ready();
	
	$(window).resize(CoxMenu.updateModal);
});
