 SA.redirection_mobile ({
    redirection_paramName:"fullsite",
    mobile_prefix : "m",
    cookie_hours : "1" 
});

var siteid = 'SITE_071226_14295265_KUD81';

/********************************************
 * 
 * Generic Navigation Maker
 * 
 * DRB 7/5/2011
 * This looks for markup like this:
 * 
 * <ul class="navigation" level="2"></ul><script>pageid='<cfoutput>#pageid#</cfoutput>';</script>
 * 
 * or like this:
 * 
 * <ul class="navigation"></ul>
 * 
 * And turns it into navigation based on the json generated by all sites.
 * 
 *******************************************/
$(function(){
	$.ajax({
		url: '/i/'+siteid+'/sitemap.json',
		datatype: 'jsonp',
		success:function(pages){
			var getByParent = function(id){
				for(var i in pages){
					if(pages[i].PARENTID==id) return pages[i];
				} return false;
			}
			var getById = function(id){
				for(var i in pages){
					if(pages[i].PAGEID==id) return pages[i];
				} return false;
			}
			$('ul.navigation').each(function(){
				var $n = $(this);
				var addChildren = function(id,ul,andSelf){
					for(var i in pages){
						if(pages[i].PARENTID==id){
                                                   if(pages[i].ONNAV){
							if(document.location.href.match(/\?task\=builder&pageid=/i))
							pages[i].HREF = '?task=builder&pageid='+pages[i].PAGEID;
							var $li = $('<li><a href="'+pages[i].HREF+'">'+pages[i].NAV_LABEL+'</a><ul></ul></li>');
							ul.append($li);
							addChildren(pages[i].PAGEID,$li.find('ul'));
                                                    }
						}
					}
				}
				if($n.attr('level') && typeof(parentid)!='undefined'){
					addChildren(parentid,$n);
				}else{
					addChildren(getByParent('').PAGEID,$n); /* getByParent('') is the home page */					
				}
				
				/******************
				 * Clean out empty ul's
				 ******************/
				$n.find('ul').each(function(){
					if($(this).children().length==0)
						$(this).remove();
				});
			})
		}
	});
});






var pe = "";
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}


sfHover = function() {
	var sfEls = document.getElementById("nav1").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+="sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp("sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function writeHtml(elem,html){
document.getElementById(elem).innerHTML=html;
}

function spryMyLinks() 
	{
	var myDiv = document.getElementById('bionav');
	var aLinks=myDiv.getElementsByTagName('a');
	for(var i=0;i<aLinks.length;i++) 
		{
			var myCurrentItem = aLinks[i];
			//aLinks[i].setAttribute('onclick', 'pe.loadContent(this.href);return false;');
			if( myCurrentItem.attachEvent )
				{
				   myCurrentItem.setAttribute('name', myCurrentItem.href);
				   myCurrentItem.href = 'javascript: pe.loadContent("' + myCurrentItem.href + '")';				   
				} 
			else 
				{
				   myCurrentItem.setAttribute('name', myCurrentItem.href);
				   myCurrentItem.setAttribute('onClick', 'pe.loadContent(this.href);return false;');
				}
			
		}
	}

function spryMyNav()
{
if(document.getElementById('bionav'))
	{
	pe = new Spry.Widget.HTMLPanel("bioArea");	
	var mybDiv = document.getElementById('bionav');
	var bLinks=mybDiv.getElementsByTagName('a');
	var myFirstItem = bLinks[0];
	spryMyLinks();
	if ( (top.location.href) == (window.location.href) )
		{
		pe.loadContent(myFirstItem.name);
		}
	}
}



var buffer = false;
var loaded = false;
var aG = [];
function loadGallery(){
aG.push({
	totalW: totalW,
	totalH: totalH,
	path: path
});
$(function(){
	if(loaded) return false;
	loaded = true;
	for(var p in aG){
		var gSlideshow = $('div.slideshow:eq('+p+')')
		gSlideshow.data('mP',p);
		gSlideshow.height(aG[p].totalH);
		$.ajax({
			url: aG[p].path+'myimages.xml',
			dataType: 'xml',
			context: gSlideshow,
			success: function(data){
				var slideshow = $(this);
				var mP = slideshow.data('mP');
				var dataArray = [];
				$(data).find('data').each(function(){
					dataArray.push({img:$(this).attr('img'),imgcaption:$(this).attr('imgcaption')});
				});
				slideshow.append(
					'<img sr'+'c="'+aG[mP].path
					+dataArray[0].img
					+'" imagelabel="'
					+dataArray[0].imgcaption
					+'" style="position: absolute;display: none; ">'
				);
				dataArray.shift();
				var loaded = false;
				/* As soon as the first image is loaded, we may begin */
				slideshow.find('img:first').load(function(){
					if(loaded) return false;
					loaded = true;
					for(var i in dataArray){
						slideshow.append(
							'<img sr'+'c="'+aG[mP].path
							+dataArray[i].img
							+'" imagelabel="'
							+dataArray[i].imgcaption
							+'" style="position: absolute;display: none; ">'
						);
					}
					/* Variables */
					var transitionTime = 4000;
					
					/* Show First Image / Gallery / Hide Play Button */
					var n = slideshow.find('img:first');
					$('.descriptionText').html(n.attr('imageLabel').replace(/ /g,'')==''?' ':n.attr('imageLabel'));
					n.show();
					if(buffer){
						$('.buffer').css({
							'height':n.height(),
							'width':n.width(),
							'margin-left' : (aG[mP].totalW-n.width())/2,
							'margin-top' : (aG[mP].totalH-n.height())/2
						}).fadeOut(1000,function(){
							n.css('z-index','5');
							$('.buffer').show();
						});
						n.css({
							position : 'absolute',
							'margin-left' : (aG[mP].totalW-$(this).width())/2,
							'margin-top' : (aG[mP].totalH-$(this).height())/2
						});
					}
					
					$('.play').hide();
					var animating = false;
					var nextSlide = function(next){
						/* Make sure we're not already in transition */
						if(animating) return false;
						animating = true;
						var f = slideshow.find('img:visible');
						if(next){
							var n = slideshow.find('img:visible').prev('img');
							if(n.length==0) n = slideshow.find('img:last');
						}else{
							var n = slideshow.find('img:visible').next('img');
							if(n.length==0) n = slideshow.find('img:first');
						}
						/* Make sure the next image is loaded before proceeding (don't worry, the loop event will re-fire) */
						if(!n[0].complete) return false;
						
						/* Buffered Animation */
						if(buffer){
							$('.buffer').css({
								'z-index':'4',
								'height':f.height(),
								'width':f.width(),
								'margin-left' : (aG[mP].totalW-f.width())/2,
								'margin-top' : (aG[mP].totalH-f.height())/2
							});
							f.css('z-index','5').fadeOut(600,function(){
								$('.buffer').animate({
									'height':n.height(),
									'width':n.width(),
									'margin-left' : (aG[mP].totalW-n.width())/2,
									'margin-top' : (aG[mP].totalH-n.height())/2
								},300,'swing',function(){
									n.css({
										position : 'absolute',
										'margin-left' : (aG[mP].totalW-$(this).width())/2,
										'margin-top' : (aG[mP].totalH-$(this).height())/2,
										'z-index' : 3
									}).show();
									animating=false;
									/* Alter Text */
									$('.descriptionText').html(n.attr('imageLabel').replace(/ /g,'')==''?' ':n.attr('imageLabel'));
									
									$('.buffer').fadeOut(1000,function(){
										n.css('z-index','5');
										$('.buffer').show();
									});
								});
							});
						}else{
							/* Non Buffered Animation */
							f.css('z-index',5);
							n.css('z-index',4).show();
							f.fadeOut(1500,function(){
								animating=false;
								/* Alter Text */
								$('.descriptionText').html(n.attr('imageLabel').replace(/ /g,'')==''?' ':n.attr('imageLabel'));
							},'swing');
						}
					};
					var looping=true;
					var t = setTimeout(function(){beginLoop();},transitionTime);
					var beginLoop = function(){
						nextSlide();
						t = setTimeout(function(){beginLoop();},transitionTime);
					};
					var play = function(){
						clearTimeout(t);
						$('.play').hide();
						$('.pause').show();
						beginLoop();
					};
					var pause = function(){
						clearTimeout(t);
						$('.play').show();
						$('.pause').hide();
					};
					$('.play').click(play);
					$('.pause').click(pause);
					$('.back').click(function(){nextSlide(true);play();});
					$('.next').click(function(){nextSlide();play();});
				/* If the image is loaded from cache, the load event doesn't fire, this checks if it's already loaded and the load event missed */
				}).each(function(){
					if(this.complete) $(this).trigger("load");
				});
			}
		});
	}
});
}



$(document).ready(function(){
	/* Search Loading */
	$('input.searchtxt').closest('form').submit(function(){
		var keywords = this.q.value;
		
		$(document.body).append('<div id="searchResults" style="position:absolute;z-index:9999;background:#666b6f;padding: 5px;" /><div class="modal" style="position:absolute;background:#000;z-index:9998;left:0;top:0;"></div>');
		$('#searchResults')
		.html('<div class="title" style="background:url(/i/SITE_071226_14295265_KUD81/lightbox-title.jpg) no-repeat;padding:8px 10px;color:#FFF;margin-bottom:10px;">Search Results for "'+keywords+'"</div><div id="scrolling" style="height:500px;width:775px;overflow:auto;" >Searching ...</div>');
		var $win = $(window);
		$('#searchResults').css({left:($win.width()-$('#searchResults').width())/2,top:($win.height()-$('#searchResults').height())/2});
		$('.modal').height($win.height()).width($win.width()).fadeTo(0,.8);
		$('.modal,#searchResults .title').click(function(){
			$('.modal,#searchResults').remove();
		});
		
		$.ajax({
			url: '/i/SITE_071226_14295265_KUD81/cfcs/search.cfc',
			cache: false,
			dataType: 'json',
			data:{
				returnFormat: 'json',
				method: 'search',
				keywords: keywords
			},
			success:function(r){
				var r = convertCFQuery(r);
				$('#scrolling').html('');
				for(var i in r){
					$('#scrolling').append(
						'<div class="subcopy" style="overflow:hidden;background:#FFF;padding:10px;margin:10px 10px 10px 0;cursor:pointer;" onClick="document.location.href=\''+r[i].URL+'\';">'
							+'<img src="/i/SITE_071226_14295265_KUD81/webshots/ws_'+r[i].PAGEID+'.jpg" style="float:left;margin:0 10px 0 0;">'
							+'<h2>'+(i- -1)+'. '+r[i].TITLE.replace(new RegExp('('+keywords+')','gi'),'<span style="background:#99FFFF;">$1</span>')+'</h2>'
							+'<p>'+r[i].URL+'</p>'
							+'<p>'+r[i].SUMMARY.replace(new RegExp('('+keywords+')','gi'),'<span style="background:#99FFFF;">$1</span>')+'</p>'
						+'</div>'
					);
				}
				if(r.length == 0){
					$('#scrolling').html('<div style="padding:10px;background:#FFF;">No results found, please try another search term.</div>');
				}
				/* _gaq.push(['_trackPageview', '/search/?q='+escape(keywords)]); */
			}
		});
		return false;
	});
});
var convertCFQuery = function(original){
	var data = [];
	for(var i=0;i<original.DATA.length;i++){
		var item = {};
		for(var j=0;j<original.COLUMNS.length;j++){
			item[original.COLUMNS[j]]=original.DATA[i][j];
		}
		data.push(item);
	}
	return data;
};



$(document).ready(function(){
	$('.newscopy').each(function(){
		var $n = $(this);
		$.ajax({
			url: '/i/SITE_071226_14295265_KUD81/cfcs/press.cfc',
			cache: false,
			dataType: 'json',
			data:{
				returnFormat: 'json',
				method: 'getReleases'
			},
			success:function(r){
				var releases = convertCFQuery(r);
				$n.html('<a href="/news/press_releases/index.cfm?task=detail&id='+releases[0].RELEASEID+'">'+releases[0].TITLE+'</a>')
				var i = 0;
				setInterval(function(){
					i++;
					if(i>=releases.length)i=0;
					$n.find('a').fadeOut(function(){
						$n.html('<a style="display:none;" href="/news/press_releases/index.cfm?task=detail&id='+releases[i].RELEASEID+'">'+releases[i].TITLE+'</a>')
						$n.find('a').fadeIn();
					});
				},5000)
			}
		});
		
	});
});
