/* jQuery Corner Plugin */
(function($){var style=document.createElement('div').style,moz=style['MozBorderRadius']!==undefined,webkit=style['WebkitBorderRadius']!==undefined,radius=style['borderRadius']!==undefined||style['BorderRadius']!==undefined,mode=document.documentMode||0,noBottomFold=$.browser.msie&&(($.browser.version<8&&!mode)||mode<8),expr=$.browser.msie&&(function(){var div=document.createElement('div');try{div.style.setExpression('width','0+0');div.style.removeExpression('width');}catch(e){return false;}return true;})();$.support=$.support||{};$.support.borderRadius=moz||webkit||radius;function sz(el,p){return parseInt($.css(el,p))||0;};function hex2(s){s=parseInt(s).toString(16);return(s.length<2)?'0'+s:s;};function gpc(node){while(node){var v=$.css(node,'backgroundColor'),rgb;if(v&&v!='transparent'&&v!='rgba(0, 0, 0, 0)'){if(v.indexOf('rgb')>=0){rgb=v.match(/\d+/g);return'#'+hex2(rgb[0])+hex2(rgb[1])+hex2(rgb[2]);}return v;}if(node.nodeName.toLowerCase()=='html')break;node=node.parentNode;}return'#ffffff';};function getWidth(fx,i,width){switch(fx){case'round':return Math.round(width*(1-Math.cos(Math.asin(i/width))));case'cool':return Math.round(width*(1+Math.cos(Math.asin(i/width))));case'sharp':return width-i;case'bite':return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));case'slide':return Math.round(width*(Math.atan2(i,width/i)));case'jut':return Math.round(width*(Math.atan2(width,(width-i-1))));case'curl':return Math.round(width*(Math.atan(i)));case'tear':return Math.round(width*(Math.cos(i)));case'wicked':return Math.round(width*(Math.tan(i)));case'long':return Math.round(width*(Math.sqrt(i)));case'sculpt':return Math.round(width*(Math.log((width-i-1),width)));case'dogfold':case'dog':return(i&1)?(i+1):width;case'dog2':return(i&2)?(i+1):width;case'dog3':return(i&3)?(i+1):width;case'fray':return(i%2)*width;case'notch':return width;case'bevelfold':case'bevel':return i+1;case'steep':return i/2+1;case'invsteep':return(width-i)/2+1;}};$.fn.corner=function(options){if(this.length==0){if(!$.isReady&&this.selector){var s=this.selector,c=this.context;$(function(){$(s,c).corner(options);});}return this;}return this.each(function(index){var $this=$(this),o=[$this.attr($.fn.corner.defaults.metaAttr)||'',options||''].join(' ').toLowerCase(),keep=/keep/.test(o),cc=((o.match(/cc:(#[0-9a-f]+)/)||[])[1]),sc=((o.match(/sc:(#[0-9a-f]+)/)||[])[1]),width=parseInt((o.match(/(\d+)px/)||[])[1])||10,re=/round|bevelfold|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dogfold|dog|invsteep|steep/,fx=((o.match(re)||['round'])[0]),fold=/dogfold|bevelfold/.test(o),edges={T:0,B:1},opts={TL:/top|tl|left/.test(o),TR:/top|tr|right/.test(o),BL:/bottom|bl|left/.test(o),BR:/bottom|br|right/.test(o)},strip,pad,cssHeight,j,bot,d,ds,bw,i,w,e,c,common,$horz;if(!opts.TL&&!opts.TR&&!opts.BL&&!opts.BR)opts={TL:1,TR:1,BL:1,BR:1};if($.fn.corner.defaults.useNative&&fx=='round'&&(radius||moz||webkit)&&!cc&&!sc){if(opts.TL)$this.css(radius?'border-top-left-radius':moz?'-moz-border-radius-topleft':'-webkit-border-top-left-radius',width+'px');if(opts.TR)$this.css(radius?'border-top-right-radius':moz?'-moz-border-radius-topright':'-webkit-border-top-right-radius',width+'px');if(opts.BL)$this.css(radius?'border-bottom-left-radius':moz?'-moz-border-radius-bottomleft':'-webkit-border-bottom-left-radius',width+'px');if(opts.BR)$this.css(radius?'border-bottom-right-radius':moz?'-moz-border-radius-bottomright':'-webkit-border-bottom-right-radius',width+'px');return;}strip=document.createElement('div');$(strip).css({overflow:'hidden',height:'1px',minHeight:'1px',fontSize:'1px',backgroundColor:sc||'transparent',borderStyle:'solid'});pad={T:parseInt($.css(this,'paddingTop'))||0,R:parseInt($.css(this,'paddingRight'))||0,B:parseInt($.css(this,'paddingBottom'))||0,L:parseInt($.css(this,'paddingLeft'))||0};if(typeof this.style.zoom!=undefined)this.style.zoom=1;if(!keep)this.style.border='none';strip.style.borderColor=cc||gpc(this.parentNode);cssHeight=$(this).outerHeight();for(j in edges){bot=edges[j];if((bot&&(opts.BL||opts.BR))||(!bot&&(opts.TL||opts.TR))){strip.style.borderStyle='none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');d=document.createElement('div');$(d).addClass('jquery-corner');ds=d.style;bot?this.appendChild(d):this.insertBefore(d,this.firstChild);if(bot&&cssHeight!='auto'){if($.css(this,'position')=='static')this.style.position='relative';ds.position='absolute';ds.bottom=ds.left=ds.padding=ds.margin='0';if(expr)ds.setExpression('width','this.parentNode.offsetWidth');else
ds.width='100%';}else if(!bot&&$.browser.msie){if($.css(this,'position')=='static')this.style.position='relative';ds.position='absolute';ds.top=ds.left=ds.right=ds.padding=ds.margin='0';if(expr){bw=sz(this,'borderLeftWidth')+sz(this,'borderRightWidth');ds.setExpression('width','this.parentNode.offsetWidth - '+bw+'+ "px"');}else
ds.width='100%';}else{ds.position='relative';ds.margin=!bot?'-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px':(pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px';}for(i=0;i<width;i++){w=Math.max(0,getWidth(fx,i,width));e=strip.cloneNode(false);e.style.borderWidth='0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';bot?d.appendChild(e):d.insertBefore(e,d.firstChild);}if(fold&&$.support.boxModel){if(bot&&noBottomFold)continue;for(c in opts){if(!opts[c])continue;if(bot&&(c=='TL'||c=='TR'))continue;if(!bot&&(c=='BL'||c=='BR'))continue;common={position:'absolute',border:'none',margin:0,padding:0,overflow:'hidden',backgroundColor:strip.style.borderColor};$horz=$('<div/>').css(common).css({width:width+'px',height:'1px'});switch(c){case'TL':$horz.css({bottom:0,left:0});break;case'TR':$horz.css({bottom:0,right:0});break;case'BL':$horz.css({top:0,left:0});break;case'BR':$horz.css({top:0,right:0});break;}d.appendChild($horz[0]);var $vert=$('<div/>').css(common).css({top:0,bottom:0,width:'1px',height:width+'px'});switch(c){case'TL':$vert.css({left:width});break;case'TR':$vert.css({right:width});break;case'BL':$vert.css({left:width});break;case'BR':$vert.css({right:width});break;}d.appendChild($vert[0]);}}}}});};$.fn.uncorner=function(){if(radius||moz||webkit)this.css(radius?'border-radius':moz?'-moz-border-radius':'-webkit-border-radius',0);$('div.jquery-corner',this).remove();return this;};$.fn.corner.defaults={useNative:true,metaAttr:'data-corner'};})(jQuery);

/* jQuery Blockster Plugin */


Blockster=function(params,indexOfSlideToTurnOn){var thiss=this;this.conf={};this.conf.blocks={rows:10,cols:10}
this.conf.pause=4000;this.conf.animType='fade';this.conf.blockAnimSpeed=50;this.params=params;this.clickActionQueueInt=false;if(!this.params.holder||$(this.params.holder).length!=1){console.log("Blockster error: could not find holder element '"+this.params.holder+"'");return false;}
this.params.holder=$(this.params.holder);if(!this.params.pause||!parseInt(this.params.pause))this.params.pause=this.conf.pause;if(!this.params.blockAnimSpeed||!parseInt(this.params.blockAnimSpeed))this.params.blockAnimSpeed=this.conf.blockAnimSpeed;if(!this.params.rows||!parseInt(this.params.rows))this.params.rows=this.conf.blocks.rows;if(!this.params.cols||!parseInt(this.params.cols))this.params.cols=this.conf.blocks.cols;this.params.holder.dimensions={width:this.params.holder.width(),height:this.params.holder.height()};this.params.dimensions={width:Math.ceil(this.params.holder.dimensions.width/this.params.cols),height:Math.ceil(this.params.holder.dimensions.height/this.params.rows)};if(!indexOfSlideToTurnOn)this.params.holder.children('div').not(':first-child').hide();if(this.params.startWithoutDelay)thiss.func(indexOfSlideToTurnOn);if(!this.params.runOnceOnly){var delay=this.params.pause+((this.params.rows*this.params.cols)*this.params.blockAnimSpeed);if(!indexOfSlideToTurnOn)
thiss.autoInt=setInterval(function(){thiss.func();},delay);}};Blockster.prototype.func=function(indexOfSlideToTurnOn){var thiss=this;var currentSlide=this.params.holder.children('div:visible');var nextSlide=!indexOfSlideToTurnOn?currentSlide.nextAll().length!=0?currentSlide.next():this.params.holder.children('div').first():this.params.holder.children('div').eq(indexOfSlideToTurnOn);for(var u=0;u<(this.params.rows*this.params.cols);u++){var block=document.createElement('div');var left,top;$(block).css({width:this.params.dimensions.width,height:this.params.dimensions.height,left:(left=(u%this.params.cols)*this.params.dimensions.width),top:(top=Math.floor(u/this.params.cols)*this.params.dimensions.height),zIndex:10000,overflow:'hidden',position:'absolute'}).hide().addClass('block');var nextSlide_clone=nextSlide.get(0).cloneNode(true);$(nextSlide_clone).show().css({height:this.params.holder.height(),width:this.params.holder.width(),position:'relative',left:-left,top:-top});$(block).append(nextSlide_clone);this.params.holder.append($(block));}
var animInt=setInterval(function(){if(thiss.params.holder.children('.block:not(:visible)').length>0){var blocks=thiss.params.holder.children('.block:not(:visible)');with($(blocks.get(!thiss.params.random?0:Math.floor(Math.random()*blocks.length))))thiss.params.animType=='simple'?show():fadeIn();}
else if($('.block:animated').length==0){clearInterval(animInt);nextSlide.siblings().hide();nextSlide.show();$('.block').remove();if(thiss.params.callback&&typeof thiss.params.callback=='function')thiss.params.callback();}},thiss.params.blockAnimSpeed);}
Blockster.prototype.jump=function(slideIndex){if(this.clickActionQueueInt){clearInterval(thiss.clickActionQueueInt);thiss.clickActionQueueInt=false;}
var thiss=this;this.clickActionQueueInt=setInterval(function(){if(thiss.params.holder.children('.block').length==0){clearInterval(this.autoInt);thiss.func(slideIndex);clearInterval(thiss.clickActionQueueInt);thiss.clickActionQueueInt=false;}},10);}

$(document).ready(function()
	{

	/* Carousel */
	var totalItems = $(".carousel>.carousel_item").size();
	var currentItem = 1;
	var mouseOverFlag = false;
	$(".carousel").mouseenter(function()
		{
		mouseOverFlag = true;
		}).mouseleave(function()
		{
		mouseOverFlag = false;
		});
	
	var carouselnavigation = "<div class='centered_first'><div class='relative'><ul class='carousel_navigation'>";
	$(".carousel_item").each(function(i)
		{
		var humanNum = i + 1;
		$(this).attr("id", "item_no_" + humanNum);
		carouselnavigation += "<li><a id='item_no_" + humanNum + "' href='#item_no_" + humanNum + "' title='Show slide " + humanNum + "'>Show slide " + humanNum + "</a></li>";
		});
	carouselnavigation += "</ul></div></div>";
	$(".carousel").append(carouselnavigation);

	function showItem(num)
		{
		oldCurrent = currentItem * 1;
		currentItem = num * 1;
		$(".carousel_navigation a").removeClass("current");
		$(".carousel_item").fadeOut();
		$(".carousel_item").eq(num-1).fadeIn();
		$(".carousel_navigation a").eq(num-1).addClass("current");
		};

	$(".carousel_navigation a").eq(0).addClass("current");
	$(".carousel_navigation a").click(function(e)
		{
		e.preventDefault();
		var itemToShow = $(this).attr("id").replace("item_no_", "");
		showItem(itemToShow);
		});
	
	showItem(currentItem);
	
	function nextImage()
		{
		if (mouseOverFlag == false) 
			{
			currentItem += 1;
			if (currentItem > totalItems) currentItem = 1;
			showItem(currentItem);
			};
		};
	setInterval(function()
		{
		nextImage();
		}, 6000);

	
	/* Submenu engine */
	
	$(".main_menu>ul>li>ul").parent().addClass("hasSubmenu");
	$(".main_menu>ul>li.hasSubmenu").mouseenter(function()
		{
		$(this).addClass("hovered");
		}).mouseleave(function()
		{
		$(this).removeClass("hovered");
		});
	var listSubmenuLinkWidth = $(".main_menu ul li.hasSubmenu ul li a").outerWidth();
	var listSubmenuLinkPadding = $(".main_menu ul li.hasSubmenu ul li a").css('padding-left').replace("px", "") * 2;
	var listSubmenuColumnWidth = listSubmenuLinkWidth + listSubmenuLinkPadding; /* Gotta do this cause element is hidden, otherwise would use outerWidth() */
	$(".main_menu ul li.hasSubmenu ul[class^='columns_']").each(function(n)
		{
		var submenuColumnsNumber = $(this).attr("class").replace("columns_", "") * 1;
		$(this).width(listSubmenuColumnWidth * submenuColumnsNumber);
		});
	
	/* Rounded corners for modern browsers */
	function roundCorners()
		{
		$(".main_menu>ul>li").corner('5px top');
		$(".main_menu>ul>li.hasSubmenu>ul").corner('5px bottom');
		$(".main_menu>ul>li.hasSubmenu>ul li a").corner('3px');
		};
	if(jQuery.browser.msie)
		{
		if(parseFloat(jQuery.browser.version) <= 8)
			{
			/* Versions of IE less than 8 */
			
			}else{
			/* code for versions of IE at least 8 (currently 8 and 9) */
			roundCorners();
			}
		}else{
		/* code for browsers other than IE (Firefox Safari, chrome, Opera, etc.) */
		roundCorners();
		}
	
	/* Blur links after click, nice for Carousel navigation */
	$("a").click(function()
		{
		$(this).blur();
		});
	
	/* Additional info on inner page */
	function changeToggleLinkText()
		{
		if ($(".toggle_content a").text() == "View Additional Information")
			{
			$(".toggle_content a").text("Hide Additional Information");
			}else{
			$(".toggle_content a").text("View Additional Information");
			};
		};
	if ($(".toggle_content").is("*"))
		{
		$(".toggle_content").parent().append("<div class='no_more_content' />");
		$(".toggle_content").nextUntil('.no_more_content').wrapAll('<div class="additional_info" />'); 
		$(".additional_info").hide();
		$(".toggle_content").click(function(e)
			{
			e.preventDefault();
			$(".additional_info").slideToggle(function()
				{
				changeToggleLinkText();
				});
			});
		};
	
	/* Load and display page image and slogan if exist */
	var okBrowser = ($.browser.msie && parseInt($.browser.version) <= 8) ? false : true;
	if ($(".page_bg_image")[0])
		{
		$(".page_bg_image").hide();
		if (okBrowser)
			{
			$(".page_slogan").hide();
			};
		var imageToLoad = $(".page_bg_image").attr("title");
		var sloganToLoad = $(".page_slogan").attr("title");
		$(".page_bg_image").attr("title", "Safetyman");
		$(".page_slogan").attr("title", "Safetyman");
		var img = new Image();
		$(img).load(function()
			{
			/* When image is loaded */
			
			$(".page_bg_image").css({'background-image' : 'url("' + imageToLoad + '")'});
			var blocksterInstance = new Blockster
					({
					holder: '.block_holder',
					runOnceOnly: true,
					startWithoutDelay: true,
					random: true,
					blockAnimSpeed: 50,
					rows: 2,
					cols: 6,
					callback: function()
						{
						if (okBrowser)
							{
							$(".page_slogan").delay(200).slideDown(500);
							};
						/* Also display the page_banners */
						$(".page_banners li").each(function(i)
							{
							$(this).delay((i * 400) + 1300).fadeIn(400);
							});
						}
					});
			}).attr('src', imageToLoad);
		};
	var img2 = new Image();
	$(img2).load(function()
		{
		var sloganHeight = img2.height;
		var sloganWidth = img2.width;
		$(".page_slogan").css({'background-image' : 'url("' + sloganToLoad + '")', 'background-position' : 'left top', 'width' : sloganWidth + 'px', 'height' : sloganHeight + 'px'});
		}).attr('src', sloganToLoad);
	
	});
