$(document).ready(
	function() {
$('#mdcLink').mdcInsertSeperatorImg('Seperator.gif');
		$('#mdcWelcome').mdcInsertSeperatorImg('Seperator.gif');
		$('#mdcFootNav').mdcInsertSeperatorImg('FooterSeperator.gif');
		$('#mdcPolicy').mdcInsertSeperatorImg('FooterSeperator.gif');
		$('#Menu2>li>a>img').mdcSwitchImage();
		$('#Menu1>li>a>img').mdcSwitchImage2();
		$('#mdcGuided div.mdcRefine>ul>li>ul').mdcInsertShowMore(12);
		// For vintage dimension only.
		$('#mdcGuided div.mdcRefine ul.mdcVintageDim').mdcInsertShowMore(4);
		$('#mdcBackPrevious>a').click(function(){$.mdc.clearPreviousPageCookie();});
		$('#mdcSearch>div>input').blur(function(){if(!$.mdc.MouseOnTypeAhead) $('#mdcTypeAheadSpace, #mdcTypeAheadSpaceBottom, #mdcTypeAheadSpaceRight').addClass('mdcHide');}).focus(function(){if($(this).val().length>=3&&$(this).val()!="Search entire site")$('#mdcTypeAheadSpace, #mdcTypeAheadSpaceBottom, #mdcTypeAheadSpaceRight').removeClass('mdcHide');});
		$('#mdcTypeAheadSpace').hover(function(){$(this).addClass('mdcShow');},function(){$(this).removeClass('mdcShow');});
		$('#mdcSearch>div>input').keydown(function(event){
			if(event.which!=13&&event.which!=38&&event.which!=40&&$("#mdcTypeAheadContainer").length==0) {$.mdc.typeAheadIndex=-1;return;}
			if(event.which==38||event.which==40) {
				var aLinkLength=$("#mdcTypeAheadContainer tr").length;
				if(typeof $.mdc.typeAheadIndex!="undefined") {
					$("#mdcTypeAheadContainer tr").eq($.mdc.typeAheadIndex).removeClass('mdcTypeAheadSelected');
				}
				if(event.which==38){//Key is Arrow-Up
					$.mdc.typeAheadIndex=((typeof $.mdc.typeAheadIndex=="undefined")||$.mdc.typeAheadIndex<0)?(aLinkLength-1):(($.mdc.typeAheadIndex-1+aLinkLength)%aLinkLength);
				}
				if(event.which==40){
					$.mdc.typeAheadIndex=(typeof $.mdc.typeAheadIndex=="undefined")?0:(($.mdc.typeAheadIndex+1)%aLinkLength);
				}
				$("#mdcTypeAheadContainer tr").eq($.mdc.typeAheadIndex).addClass('mdcTypeAheadSelected');
			}
			if(event.which==13){
				if($.mdc.typeAheadIndex>=0){
					$.mdc.pushPreviousPageCookie();
					document.location=$("#mdcTypeAheadContainer tr>td>input").eq($.mdc.typeAheadIndex).val();
					$('#mdcSearch>div>input').unbind('keydown');
					event.preventDefault();
				}
			}
		}).keyup(function(event){$.mdc.typeAhead(event,$(this).val());});
		$('#mdcSearch>div>input').mdcTriggerButtonClickInput($('#mdcSearch>div>a'),'Search entire site');
		$('#mdcContainer .mdcSearchWithin input').mdcTriggerSiblingClickInput('Search within results');
		$('#Menu1>li:eq(0)>ul>li:eq(8)>a').click(function(){$.mdc.pushPreviousPageCookie();});
		
		$('#mdcTypeAheadSpace').mouseover(function(){$.mdc.MouseOnTypeAhead=true;}).mouseout(function(){$.mdc.MouseOnTypeAhead=false;});
		$('#mdcHomeLink').hover(function(){$('#mdcHomeLink div').removeClass('mdcHide');},function(){$('#mdcHomeLink div').addClass('mdcHide');});
		
		/* Preload Images*/
		if (document.images)
		{
			preload_image_object = new Image();
			// set image url
			image_url = new Array();
			image_url[0] = "/_Layouts/Mdc/Images/ResearchRatingsOn.gif";
			image_url[1] = "/_Layouts/Mdc/Images/ResearchRatingsOver.gif";
			image_url[2] = "/_Layouts/Mdc/Images/ProductsSolutionsOn.gif";
			image_url[3] = "/_Layouts/Mdc/Images/ProductsSolutionsOver.gif";
			image_url[4] = "/_Layouts/Mdc/Images/NewsEventsOn.gif";
			image_url[5] = "/_Layouts/Mdc/Images/NewsEventsOver.gif";
			image_url[6] = "/_Layouts/Mdc/Images/MyMoodysOn.gif";
			image_url[7] = "/_Layouts/Mdc/Images/MyMoodysOver.gif";
			image_url[8] = "/_Layouts/Mdc/Images/SearchGoOver.gif";
			image_url[9] = "/_Layouts/Mdc/Images/LoginOver.gif";			

			var i = 0;
			for(i=0; i<=9; i++){preload_image_object.src = image_url[i];}
		}	
		//Region click
		$('#mdcRegion select').change(function(){if($(this).val()==$('#mdcRegion option:first').val()) {return;} window.open($(this).val())});
	    $('#mdcSetAlertForCriteriaImg').mdcSwitchImage();
	}
);

jQuery.mdc.researchAlert={
    GetDimensionInfo:function(){
			return $('#mdcDimensionDetailInfo').text();
		},
    SetAlertForCriteria:function(theUrl){
	    if(null==theUrl || ""==theUrl)
	    {
				var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
				var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
				var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
			
				var   sWidth,sHeight;   
			    sWidth = document.body.offsetWidth;
			    sHeight = document.body.offsetHeight;
				//var backgroundDiv = $('<div id="backgroundDiv" style="position:absolute; top:0; left:0; background:0xffffff; filter:progid:DXImagesTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75); opacity:0.5;width:' 
				//		+ sWidth + 'px; height:' + sHeight + 'px; z-index:10000;"></div>');
				var bgObj = document.getElementById('backgroundDivForSetAlert');
				if(null == bgObj)	
				{
					bgObj=document.createElement("div");
			    // <div   id="bgDiv"   style="position:absolute;   top:0;   background-color:#777;   filter:progid:DXImagesTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75);   opacity:0.6;   left:0;   width:918px;   height:768px;   z-index:10000;"> </div>   
			    bgObj.setAttribute("id","backgroundDivForSetAlert");
			    bgObj.style.position="absolute";   
			    bgObj.style.top="0";     
			    bgObj.style.left="0";
			    bgObj.style.background="#ffffff";   
			    bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";   
			    bgObj.style.opacity="0.5"; 
			    bgObj.style.width=sWidth + "px";   
			    bgObj.style.height=sHeight + "px";   
			    bgObj.style.zIndex = "10000";   
			    document.body.appendChild(bgObj);
			  }
		    bgObj.style.display = "";
		    
		    var popUpObj = document.getElementById('mdcSetAlertPopUpDiv');
		    if(null == popUpObj)
		    {
		      popUpObj=document.createElement("div");
		      popUpObj.setAttribute("id","mdcSetAlertPopUpDiv");  
			    popUpObj.style.position   =  "absolute";   
			    popUpObj.style.left   =  "50%";   
			    popUpObj.style.top   =  "50%";
			    popUpObj.style.marginLeft   =  "-270px"   ;   
			    popUpObj.style.marginTop   =   -120+document.documentElement.scrollTop+"px"; ; 
			    popUpObj.style.width   =   "700px";   
			    popUpObj.style.height   =  "400px";  
			    popUpObj.style.zIndex   =  "10002";	   
			    document.body.appendChild(popUpObj);
			  }
			    //Must after OuterDiv has been added to DOM
			    if (isIE && isWin && !isOpera)
			  			popUpObj.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="mdcSetAlertPopUp" width="700" height="400" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"><param name="loop" value="false"/><param name="movie" value="/_Layouts/Mdc/Swfs/AlertPopUp.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#869ca7" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent" /></object>';
			  	else
			  			popUpObj.innerHTML = '<embed id="mdcSetAlertPopUp" src="/_Layouts/Mdc/Swfs/AlertPopUp.swf" quality="high" bgcolor="#869ca7" width="700" height="400" name="mdcSetAlertPopUp" align="middle" play="true" loop="false" quality="high" allowscriptaccess="sameDomain" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer"></embed>';
			  popUpObj.style.display = "";
			  document.getElementById('mdcSetAlertPopUp').focus();
			}
			else
		  	location.href = theUrl;
	  }
}

function closeSetAlert(){
	var bkDiv = document.getElementById('backgroundDivForSetAlert');
	bkDiv.style.display = "none";
	var popUp = document.getElementById('mdcSetAlertPopUpDiv');
	popUp.style.display = "none";
}

function sessionTimeout(){
		var aUrl = window.location;
		aUrl = unescape(aUrl);
		var aHeader = 'http://';
		var beginIndex = aUrl.indexOf(aHeader);
		if(-1!=beginIndex)
		{
			aUrl = aUrl.substring(beginIndex, aUrl.indexOf('/', beginIndex+aHeader.length));
			aUrl += "/login.aspx?ReturnUrl=";
			aUrl += window.location;
			self.location = aUrl;
		}
}