/**
 * Compact labels plugin
 */
(function($){$.fn.compactize=function(){return this.each(function(){var label=$(this),input=$('#'+label.attr('for'));input.focus(function(){label.hide();}).blur(function(){if(input.val()===''){label.show();}});window.setTimeout(function(){if(input.val()!==''){label.hide();}},50);});};})(jQuery);

/*
 * hrefID jQuery extention - returns a valid #hash string from link href attribute in Internet Explorer
 */
(function($){$.fn.extend({hrefId:function(){return $(this).attr('href').substr($(this).attr('href').indexOf('#'));}});})(jQuery);

/*
 * Scripts
 *
 */
jQuery(function($) {
 
	var Engine = {
		utils : {
			links : function(){
				$('a[rel*=external]').click(function(e){
					e.preventDefault();
					window.open($(this).attr('href'));						  
				});
			},
			mails : function(){
				$('a[href^=mailto:]').each(function(){
					var mail = $(this).attr('href').replace('mailto:','');
					var replaced = mail.replace('/at/','@');
					$(this).attr('href','mailto:'+replaced);
					if($(this).text() == mail) {
						$(this).text(replaced);
					}
				});
			}
		},
		fixes : {
			lists : function(){
				if ($.browser.msie !== true || $.browser.version !== '6.0'){
					return;
				}
				$('li:first-child').addClass('first');
			},
			applications : function(){
				$('ul.applications-a li').each(function(){
					$(this).wrapInner('<span />');
					var h = $(this).find('span').height();
					
					if (h < 20) {
						$(this).addClass('oneliner');
					}
					else if (h > 20 && h < 30) {
						$(this).addClass('twoliner');
					}
					else {
						$(this).addClass('threeliner');
					}
				})
			}
		},
		
		tweaks : {
			
			selectedNav : function(){
				
				// primary
				if (document.location.href.indexOf("why-thin-paper") != -1){    
					$("#nav_950562 li:nth-child(2)").addClass('selected');                 
				}
				
				if (document.location.href.indexOf("our-papers") != -1){    
					$("#nav_950562 li:nth-child(3)").addClass('selected');                 
				}
				
				if (document.location.href.indexOf("sustainability") != -1){    
					$("#nav_950562 li:nth-child(4)").addClass('selected');                 
				}
				
				if (document.location.href.indexOf("resources") != -1){    
					$("#nav_950562 li:nth-child(5)").addClass('selected');                 
				}
				
				if (document.location.href.indexOf("about-us") != -1){    
					$("#nav_950562 li:nth-child(6)").addClass('selected');                 
				}	
				
				// secondary nav action
				
				if (document.location.href.indexOf("case-histories") != -1){    
					$("#nav_951878 li:nth-child(4)").addClass('selected');                 
				}
				
				if (document.location.href.indexOf("applications") != -1){    
					$("#nav_952409 li:nth-child(3)").addClass('selected');                 
				}
				
				if (document.location.href.indexOf("life-cycle-planning") != -1){    
					$("#nav_952428 li:nth-child(3)").addClass('selected');                 
				}
				
				if (document.location.href.indexOf("basic-calculators") != -1){    
					$("#nav_952437 li:nth-child(3)").addClass('selected');                 
				}
				
				if (document.location.href.indexOf("knowledge-training") != -1){    
					$("#nav_952437 li:nth-child(4)").addClass('selected');                 
				}
				
				if (document.location.href.indexOf("about-us") != -1){    
					$("#nav_950650 li:nth-child(1)").addClass('selected');                 
				}
				
				if (document.location.href.indexOf("about-us/news") != -1){    
					$("#nav_950650 li:nth-child(2)").addClass('selected');
					$("#nav_950650 li:nth-child(1)").removeClass('selected');
				}
				
				if (document.location.href.indexOf("about-us/primanews") != -1){    
					$("#nav_950650 li:nth-child(3)").addClass('selected');
					$("#nav_950650 li:nth-child(1)").removeClass('selected');
				}	
				
				if (document.location.href.indexOf("brands") != -1){    
					$("#nav_952409 li:nth-child(4)").addClass('selected');
				}
				
				if (document.location.href.indexOf("bollore-sustainability") != -1){    
					$("#nav_952428 li:nth-child(4)").addClass('selected');
				}
				
				if (document.location.href.indexOf("AnnouncementRetrieve") != -1){    
					$("#nav_950650 li:nth-child(2)").addClass('selected');
					$("p.breadcrumbs-a").html("<a href='/index.htm'>home</a> &gt; <a href='/about-us/about-us.htm'>about us</a> &gt; <a href='/about-us/news.htm' style='color: rgb(210, 210, 212);'>news</a>");
				}
				
				if (document.location.href.indexOf("/our-papers/brands/") != -1){    
					$(".sidenav-a").css('margin-top','16px');
				}
				
				if (document.location.href.indexOf("/about-us/") != -1){    
					$(".sidenav-a").css('margin-top','14px');
				}
				
				
			}, // end selectedNav
			
			breadCrumbHighlight : function(){
				
			$(".breadcrumbs-a a:last").css("color","#d2d2d4");
			
			},
			
			headingFix : function(){
				
				// hide page name heading
				$(".columns-b h1.a:first").hide();
				$("#content h1.a:first").hide();
				
			
			}
		
		}
	};

	Engine.utils.links();
	Engine.utils.mails();
	
	Engine.fixes.lists();
	Engine.fixes.applications();
	Engine.tweaks.selectedNav();
	Engine.tweaks.breadCrumbHighlight();
	// Engine.tweaks.headingFix();
	
	//jQuery("#nav_943008 li:nth-child(1).selected, #nav_943009 li:nth-child(1).selected").css("margin-top","-15px");
	/*
	if(jQuery("#aside li.selected").text().length > 26){
	jQuery("#aside li.selected").css("margin-bottom","25px");
	}
	
	if(jQuery("#aside li.selected").text().length < 26){
	jQuery("#aside li.selected").css("margin-top","25px");
	}
	*/	
});