jQuery(document).ready(function(){

	jQuery("#navigation a").mousedown(function () {
		jQuery("#navigation a").removeClass("select");
		jQuery(this).addClass("select");
	});
	jQuery("#navigation a").mouseup(function () {
		jQuery("#navigation a").removeClass("select");
	});
	jQuery("ul.serviceCon h3.serviceName").removeClass("open").next().hide();
	jQuery("ul.serviceCon").each(function () {
		jQuery(this).find("h3.serviceName:last").addClass("open").next().show();
	})
	

	jQuery("ul.serviceCon h3.serviceName").click(function () {	
		jQuery(this).next().slideToggle(500,function () {jQuery(this).prev().toggleClass("open");ScrollBarReset(); });
	});
	// search
	/*
	jQuery("#search_form").click(function () {
		var text = jQuery("#SearchText").val();
		if(text != '')
		{
			var url = '/index.php/content/searchresults?SearchText='+UrlEncode(text);
			window.location = url;
		}else
		{
			alert("Please enter text");
		}

		return false;
	});
	*/
	jQuery("#SearchText").focus(function (){
		jQuery(this).val('');
		jQuery(this).css("color","#666666");		
	});
	
	jQuery(".scroll-pane").jScrollPane(
		{
			verticalDragMinHeight: 20,
			verticalDragMaxHeight: 74,
			showArrows: false
		}
	);
	
//	jQuery("#filters").css("display","block");
	jQuery("#filters a").click(function () {
		//jQuery(this).addClass("cover");
		
		if (jQuery(this).hasClass('cover'))
		{
			return false;
		}

		jQuery(".filterBox a").removeClass("cover");
		var title = jQuery(this).attr("title");
		Flilter(title);
		jQuery(".filterBox a").removeClass("cover");
		jQuery(".filterBox a[title="+title+"]").addClass("cover");
		jQuery.cookie('filter_name',title);
		return false;
	
	});
	
	if(Get_Cookie('filter_name') != undefined)
	{
		var current_flag = Get_Cookie('filter_name');
		//Flilter(current_flag);
		jQuery(".filterBox a").removeClass("cover");
		jQuery(".filterBox a[title="+current_flag+"]").addClass("cover");
		//jQuery(".box").hide();
		//jQuery("div[name*='"+current_flag+"']").show();
		if( current_flag != "All" ){
			jQuery(".box").hide();
			jQuery("div[name*='"+current_flag+"']").show();	
			UpdateClass();		
		}
		else{		
			jQuery(".box").show();	
			UpdateClass();
		}
		//jQuery(".scroll-pane").slideToggle(500);		
		ScrollBarReset();


	}else
	{
		jQuery(".filterBox a[title=All]").addClass("cover");
	}

	jQuery.OpenPage = function(mylink){
		jQuery.nyroModalManual({
		closeButton:'',
		rev:'modal',
		title:null,
		titleFromIframe:null,
		minWidth:1000,
		width: 1000,
		url: mylink
		});
	};
	
	jQuery("#footer a").filter(".nyroModal").attr("rev","modal");
	
	
	//var currentHash = window.location.hash;
	
	var currentHash = window.location.href;
	if( currentHash.indexOf("/overlay/") != -1 )
	{
		
		if( currentHash.indexOf("contact-us") != -1 || currentHash.indexOf("challenge-us") != -1 || currentHash.indexOf("locations") != -1 || currentHash.indexOf("sourcing-center") != -1 || currentHash.indexOf("investor-center") != -1 || currentHash.indexOf("site-map") != -1 || currentHash.indexOf("privacy-policy") != -1 || currentHash.indexOf("legal-disclaimer") != -1 || currentHash.indexOf("send-us-an-rfp") != -1 || currentHash.indexOf("login") != -1 || currentHash.indexOf("register-to-read") != -1 || currentHash.indexOf("forgetpassword") != -1 || currentHash.indexOf("thank-you") != -1 || currentHash.indexOf("thank-you-for-send-rfp") != -1 || currentHash.indexOf("thank-you-for-register") != -1 || currentHash.indexOf("IE6-Detected") != -1 )
		{
			var myurl = "/index.php" + currentHash.substring(currentHash.indexOf("/overlay/"));
		}
		else
		{
			//var myurl = "/index.php" + currentHash.replace("#","/");
			var myurl =currentHash.replace("#/","/");
		}
		//var myurl = "/index.php" + currentHash.substring(currentHash.indexOf("/overlay/"));
		jQuery.OpenPage(myurl);
	}
	
	//used for child page
		// add dongtai xiaoguo for sub aritle
		jQuery("ul.slideLi li").removeClass("open").find("span").next().hide();
		jQuery("span.slideTt:first").parent().addClass("open").find("ul").show();
		jQuery("ul.slideLi span.slideTt").click(function () {	
			jQuery(this).next().slideToggle(500,function () {jQuery(this).parent().toggleClass("open");ScrollBarReset(); });
		});
		// Used for article video
		jQuery("div[id^=flv_id]").each(function () {
			var id = jQuery(this).val();
			var flv_url = jQuery("#flv_url_"+id).val();
			var flv_title = jQuery("#flv_title_"+id).val();
			var flashvars = { 
				title:flv_title,
				videoUrl:flv_url
			};  
			var params = {  
			  menu: "true" ,
			  allowScriptAccess:"always",
			  wmode:"transparent"
			};  
			var attributes = {  
			  id: "myDynamicContent",  
			  name: "myDynamicContent"  
			};  
			var myDate=new Date();
			var _v=myDate.getTime();
			swfobject.embedSWF("/design/Catalent/images/videoPlayer.swf?v="+_v, "swfContent_"+id, "320", "225", "10.0.0","expressInstall.swf", flashvars, params, attributes); 
		
		});
		//Used for leadership page
		var scrollPos; 
		if(typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') { 
			scrollPos = document.documentElement; 
		} 
		else if (typeof document.body != 'undefined') { 
			scrollPos = document.body; 
		} 
		if (jQuery.browser.safari) {
			scrollPos = document.body; 
		}
		jQuery("a.back").click(function(){
			var first_top = jQuery(".mainArea").offset().top;
			jQuery(scrollPos).animate({ scrollTop : first_top }, "slow");
		});
		jQuery("p.anchor").click(function(){
			var id = jQuery(this).attr("id");
			var index = id.replace("name","");
			var first_top = jQuery("#leader"+index).offset().top;
			jQuery(scrollPos).animate({ scrollTop : first_top }, "slow");
		});		
});

/*
function: enter key for do the search
*/
function submit_form(id,code)
{
	if(code==13)
	{
		var text = jQuery("#"+id).val();
		if(text != '')
		{
			var url = '/index.php/content/searchresults?SearchText='+UrlEncode(text);
			window.location = url;
		}else
		{
			alert("Please enter text");
		}
		/*
		jQuery.history.load(url);
		jQuery("#SearchText").val(text);
		*/
		return false;
	}
}

