var removeFontTags = function(obj){

	var tags= ['font','FONT','span','SPAN','em','EM'];
	
	jQuery.each(tags,function(i){
		var re= new RegExp('<'+tags[i]+'[^><]*>|<.'+tags[i]+'[^><]*>','g')
		obj.html(obj.html().replace(re,''));
	})

}

jQuery(document).ready(function(){
	jQuery('<img src="/mentor/images/ui/bg-tpwindow.png" />')
	jQuery("div.block").hover(function(){
		if((!jQuery(this).is("div.nomore"))){
			jQuery(this).addClass("hover");
		}
	},function(){
		jQuery(this).removeClass("hover");
	});
	var cleartpwindows = function(){
		if (jQuery.browser.msie) {
			if(parseInt(jQuery.browser.version)==6){
				jQuery("div.results select").css({visibility: 'visible'});
			};
		}
		jQuery("div.tpwindow").remove();
		jQuery("div.block").css({'z-index':1}).removeClass("hover");
		return false;
	}
	jQuery("div.blocks div.block").each(function(){					//for each content panel
		var $this = jQuery(this)
		var textLength=0							//get the length of the text
		textLength=jQuery("div.inner",$this).height();
		if (textLength>176){											//if the text is longer then 630 characters
			jQuery(this).append('<a class="more moreless" href="#"><span>More</span></a>');	//add the more link
		}else{
			jQuery(this).addClass("nomore");
		}
		$this.find("div.inner").height(171);
	});
	jQuery("div.block a.more").each(function(){									//attach a toggle event to each added link
		var $originalblock = jQuery(this).parents("div.block:first");
		jQuery(this).add($originalblock.find("div.abstract-inner")).click(function(){
			jQuery("div.tpwindow").remove();
			jQuery("div.block").css({'z-index':1});
			var $modaldiv = jQuery('<div class="tpwindow"></div>');
			var $block = $originalblock.clone();
			$block.removeClass("block").removeClass("hover").css({'z-index':9999}).find("div.inner").removeClass("inner").height('');
			$modaldiv.html($block).find("a.moreless").removeClass("more").addClass("less").text("Less").click(cleartpwindows);
			if (jQuery.browser.msie) {
				if(parseInt(jQuery.browser.version)==6){
					jQuery("div.results select").css({visibility: 'hidden'});
				};
			}
			$modaldiv.find("div.abstract").attr("title","")
			$originalblock.css({'z-index':9999}).append($modaldiv)
			return false;
		});
	});
	jQuery("div.list h2").hover(function(){
		var $block = jQuery(this).parents("div.block:first");
		jQuery("div.list div.block").css({'z-index':1})
		$block.css({'z-index':9998}).find("a.download-techpub").css({'display':'block'}).end().find("div.abstract").show();
	},function(){
	})
	jQuery("div.list div.block").hover(function(){
	},function(){
		var $block = jQuery(this);
		$block.find("div.abstract").hide().end().find("a.download-techpub").hide();
	})
	jQuery("div.featured div.block").each(function(){					//for each content panel
		var $this = jQuery(this)
		var textLength=0							//get the length of the text
		textLength=parseInt(jQuery("div.inner",$this).outerHeight());
		if($this.parents("div.featured:first").hasClass("one")){
			if (textLength>110){											//if the text is longer then 630 characters
				jQuery(this).append('<a class="fmore moreless" href="#"><span>More</span></a>');	//add the more link
			}
			$this.find("div.inner").height(100);
			if (jQuery.browser.msie) {
				if(parseInt(jQuery.browser.version)==6){
					$this.find("div.inner").height(110);
				}
			}
		}else{
			if (textLength>162){											//if the text is longer then 630 characters
				jQuery(this).append('<a class="fmore moreless" href="#"><span>More</span></a>');	//add the more link
			}
			$this.find("div.inner").height(152);
		}
	});
	jQuery("a.fmore").each(function(){									//attach a toggle event to each added link
		var $this = jQuery(this)
		var featuredheight;
		if($this.parents("div.featured:first").hasClass("one")){
			featuredheight=100
		}else{
			featuredheight=152
		}
		var $originalblock = jQuery(this).parents("div.block:first");
		$originalblock.find("div.abstract-inner").add(jQuery(this)).toggle(function(){
			$originalblock.find("div.inner").height('').end().find("a.moreless").removeClass("fmore").addClass("fless").text("Less");
			return false;
		},function(){
			$originalblock.find("div.inner").height(featuredheight).end().find("a.moreless").removeClass("fless").addClass("fmore").text("More");
			return false;
		});
	});
/*
	//url handling for when filter changes
	var techpaperurl = window.location.href;
	var techpaperurlsplit = techpaperurl.replace(/\/$/, "").split("?")
	var techpaperurlbase = techpaperurlsplit[0]
	var tpvalues={};
	if(techpaperurlsplit.length>1){
		var techpaperquerystring = techpaperurlsplit[1];
		var techpaperarray = techpaperquerystring.split("&")
		jQuery.each(techpaperarray, function(i,n){
			var tempval = n.split("=")
			if(tempval.length>1){
				tpvalues[tempval[0]]=tempval[1]
			}
		})
	}
	// cull the last segment if it's a dash-separated-title-with-EMAID or dash-separated-design-task-with-UUID name
	if (techpaperurlbase.match(/.*-[0-9]+\/?$/) || techpaperurlbase.match(/.*-[a-fA-F0-9]+-dt\/?$/)) {
		var parts = techpaperurlbase.split("/");
		delete parts[parts.length - 1];
		techpaperurlbase = parts.join("/");
	}
	if (techpaperurlbase.substr(techpaperurlbase.length - 1) != "/") {
		techpaperurlbase += "/";
	}
	if(!document.getElementById("gridpage")){
		jQuery("#tpselector").change(function(){
			tpstring = techpaperurlbase + jQuery("option:selected", this).text().toLowerCase().replace(/[^a-z0-9]+/g, "-") + "-" + jQuery(this).val() + "-dt";
			if(tpvalues['resultsPerPage']){
				tpstring += "?resultsPerPage=" + tpvalues['resultsPerPage'];
			}
			window.location.href=tpstring;
		})
	}
*/
	jQuery("div.request-more :checkbox").each(function(){
		if(jQuery(this).attr("checked")==true){
			jQuery(this).parents("li:first").addClass("checked")
		}else{
			jQuery(this).parents("li:first").removeClass("checked")
		}
	}).click(function(){
		if(jQuery(this).attr("checked")==true){
			jQuery(this).parents("li:first").addClass("checked")
		}else{
			jQuery(this).parents("li:first").removeClass("checked")
		}
		jQuery(this).trigger("blur");
	})
	//code for ajaxing optins
/*
	var $ajaxoptins = jQuery("#ajaxoptins");
	var $optinsform = $ajaxoptins.find("form")
	var $customquestiondiv = jQuery("div.custom-question",$ajaxoptins)
	$optinsform.submit(function(){
		jQuery("div.submit",$ajaxoptins).remove()
		var optinsarr=[];
		jQuery("input[name=optin]",$optinsform).each(function(){
			optinsarr.push(jQuery(this).val())
		})
		var dataobjpass={};
		dataobjpass['optin']=optinsarr.join(",")
		jQuery("input[type=hidden]",$optinsform).each(function(){
			dataobjpass[jQuery(this).attr("name")]=jQuery(this).val()
		})
		$customquestiondiv.html('<img src="/mentor/images/forms/anim-loading.gif" />')
		jQuery.ajax({
			data: dataobjpass,
			type: 'POST',
			url: $optinsform.attr("action"),
			success: function(data){
				$customquestiondiv.html('<h2>Thank you.</h2><p>You have successfully signed up for enews subscriptions.&nbsp; You will begin to receive the requested enews subscription from Mentor Graphics.</p> <p>If you have any questions or would like to speak to a mentor representative, please contact us at:&nbsp; <a href="mailto:sales_info@mentor.com">sales_info@mentor.com</a> or call 800-547-3000</p>')
			},
			error: function(){
				$customquestiondiv.html('<h2>Sorry.</h2><p>There was an error signing up for enews subscriptions.</p>')
			}
		})
		return false;
	});
*/
/*
	if(tpvalues['expanded']){
		if(tpvalues['expanded']=='yes'){
			jQuery("div.request a.abstracttoggler").trigger("click");
			//jQuery("div.request-more").css({top:0}).css({position:'absolute'})
		}
	}
*/

	jQuery("div.abstract-inner").each(function(){
		removeFontTags(jQuery(this))
	})


});

