
// jQuery History Event Plugin v0.1 (http://plugins.jquery.com/project/historyevent) - (c)2008 Tom Rodenberg <tarodenberg gmail com> - Licensed under the GPL (http://www.gnu.org/licenses/gpl.html) license.
(function($){var currentHash,previousNav,timer,hashTrim=/^.*#/;var msie={iframe:null,getDoc:function(){return msie.iframe.contentWindow.document;},getHash:function(){return msie.getDoc().location.hash;},setHash:function(hash){var d=msie.getDoc();d.open();d.close();d.location.hash=hash;}};if($.browser.msie&&$.browser.version==8){msie=false;}var historycheck=function(){var hash=msie.iframe?msie.getHash():location.hash;if(hash!=currentHash){currentHash=hash;if(msie.iframe){location.hash=currentHash;}var current=$.history.getCurrent();$.event.trigger("history",[current,previousNav]);previousNav=current;}};$.history={add:function(hash){hash="#"+hash.replace(hashTrim,"");if(currentHash!=hash){var previous=$.history.getCurrent();location.hash=currentHash=hash;if(msie.iframe){msie.setHash(currentHash);}$.event.trigger("historyadd",[$.history.getCurrent(),previous]);}if(!timer){timer=setInterval(historycheck,100);}},getCurrent:function(){return currentHash.replace(hashTrim,"");}};$.fn.history=function(fn){$(this).bind("history",fn);};$.fn.historyadd=function(fn){$(this).bind("historyadd",fn);};$(function(){currentHash=location.hash;if($.browser.msie&&$.browser.version!=8){msie.iframe=$('<iframe style="display:none" src="javascript:false;"></iframe>').prependTo("body")[0];msie.setHash(currentHash);currentHash=msie.getHash();}});})(jQuery);

// jQuery Form Plugin - written by mKafka for HornGroup
(function($){$.fn.form=function(options){var defaults={container:"select-container",preselectText:"Please Select",speed:250,ajaxSubmit:false};var options=$.extend(defaults,options);return this.each(function(){obj=$(this);var selectTitle=obj.attr("name");obj.hide().before('<div class="'+options.container+'" id="'+selectTitle+'"><p>'+options.preselectText+"</p><ul></ul></div>");obj.children("option").each(function(){if($(this).val()!=""){$("#"+selectTitle+" ul").append('<li><a href="#">'+$(this).text()+"</a></li>");}});var ulHeight=$("#"+selectTitle+" ul").height();$("#"+selectTitle+" ul").append("<span></span>");$("#"+selectTitle+" ul").css({"display":"none","height":ulHeight});$("#"+selectTitle+" p").toggle(function(){$("body").click();$("~ul",this).slideDown(options.speed).addClass("open");$("body").click(function(){if($("#"+selectTitle+" ul").hasClass("open")){$("#"+selectTitle+" p").click();$("body").unbind();}});},function(){$("~ul",this).slideUp(options.speed).removeClass("open");});$("#"+selectTitle+" li a").click(function(){$(this).parents("#"+selectTitle).next().find('option:contains("'+$(this).text()+'")').attr({selected:"selected"});$(this).parents("#"+selectTitle).children("p").text($(this).text()).click();return false;});});};})(jQuery);


function newsroomSidebarSearchPrep(){
	// Sidebar -> Search -> Dropdown
	jQuery('#newsroom-search form select').form({
		container: 'select-dropdown',
		preselectText: 'Categories',
		speed: 250
	});

	// Sidebar -> Search -> Input
	jQuery('#newsroom-search input[type="text"]').each(function(){
		jQuery(this)
			.data('defaultVal', jQuery(this).val())
			.bind('focus',function(){
				if(jQuery(this).val() == jQuery(this).data('defaultVal')){
					jQuery(this).val('');
				}
			})
			.bind('blur',function(){
				if(jQuery(this).val() == ''){
					jQuery(this).val(jQuery(this).data('defaultVal'));
				}
			})
		;
	});
}


function newsroomSidebarNavPrep(){
	// Sidebar -> Nav -> Current & Hover
	jQuery('#sub-nav li').append('<span></span>');
	
	var currentSection;
	jQuery('#sub-nav li:has(a.current)').length > 0 ? currentSection = 'current' : currentSection = 'section' ;
	
	jQuery('#sub-nav li:has(a.'+currentSection+')').children('span').addClass('selected');
	
	jQuery('#sub-nav li:not(:has(a.'+currentSection+'))').hoverIntent({    
		sensitivity: 5,
		interval: 100,   
		over: NRsubnavOn,
		timeout: 100,
		out: NRsubnavOut
	});
			
	function NRsubnavOn(){
		jQuery(this).children('span').stop().animate({backgroundPosition: '(-28px 0px)'}, 750, 'easeOutExpo');  
		jQuery(this).children('a').animate({opacity:1}, 50, function(){
			jQuery(this).css({'color':'#ffffff'});
		});
	}
	
	function NRsubnavOut(){
		jQuery(this).children('span').stop().animate({backgroundPosition: '(-215px 0px)'}, 750, 'easeInExpo');  
		jQuery(this).children('a').animate({opacity:1}, 750, function(){
			jQuery(this).css({'color':''});	 
		});
	}

}


function newsroomMostRecentPrep(){
	var recentNews = jQuery('#recent_news');
	var recentKids = recentNews.addClass('enhanced').children('div').children('ul').children('li');
	
	recentKids.hide().filter(':first').show();
	
	recentKids.each(function(){
		var titleText = $(this).children('p').text();
		$(this).attr('title',titleText);
	});
	
	recentNews.children('div').append('<span id="recent_nav"></span>').children('ul').cycle({ 
		fx: 'fade', 
		speed: 500, 
		timeout: 5000, 
		pager: '#recent_nav',
		pause: true
	});
}


function newsroomEqualHeightCols(){
	altContainers = jQuery('#newsroom').find('.alt-layout');
	altContainers.each(function(){
	var tallestDiv = 0;
		jQuery(this).children('div:not(".clear")').each(function(){
			if(jQuery(this).height() > tallestDiv){
				tallestDiv = jQuery(this).height();
			}
		});
		jQuery(this).children('div:not(".clear")').height(tallestDiv).children('p.meta').css({'position':'absolute','bottom':'5px','width':'auto'});
	});
}




function newsroomModuleHover(){
	jQuery('#newsroom').find('.news-module').hover(
		function(){
			if(jQuery(this).hasClass('Awards')){
				return;
			} else {
				jQuery(this).addClass('hover');
				jQuery(this).click(function(event){
					if(event.target.tagName == 'A'){
						return;
					} else {
						linkage = jQuery(this).children('h5').children('a').attr('href');
						//alert("HAS \"http://\"");
						if(linkage.indexOf("/preview.horngroup.net/")==-1) {
							window.open(linkage, 'new_win');
						} else {
							window.location = jQuery(this).children('h5').children('a').attr('href');
						}
						return false;
					}
				});
			}
		},function(){
			jQuery(this).removeClass('hover');
		}
	);
}


function newsroomPhotoGallery(){
	jQuery.nyroModalSettings({
		endFillContent: function(elts, settings){
			var newHash = settings.url.substring(settings.url.lastIndexOf('/') + 1)/*.replace('.', '-')*/;
			jQuery.history.add(newHash);
			var tagHTML = jQuery('#photo-gallery').find('img[src='+settings.url+']').parent().siblings('p#tags').html()
			if(tagHTML){
				jQuery('#nyroModalWrapper').append('<div class="modalExtras">'+ tagHTML +'</div>');
			}
		},
		hideContent: function(elts, settings, callback) {
			jQuery.history.add('');
			elts.contentWrapper.fadeOut(250, callback);
		},
		closeButton: '<a href="#" class="nyroModalClose" id="closeBut" title="close"><i>Close</i></a>',
		galleryLinks: '<a href="#" class="nyroModalPrev"><i>Prev</i><span></span></a><a href="#"  class="nyroModalNext"><i>Next</i><span></span></a>'
	});
}

function newsroomDrilldownTweaks(){
	// corrects Slideshare's horrid embed code
	var slideshareEmbed = {};
	slideshareEmbed.div = jQuery('#newsroom .drilldown div:has(object)');
	slideshareEmbed.object = slideshareEmbed.div.find('object').removeAttr('style').clone();
	slideshareEmbed.div.prev().append(slideshareEmbed.object);
	slideshareEmbed.div.remove();
	
	// applies 'speech bubble' to flash objects
	jQuery('#newsroom .drilldown p:has(object)').addClass('enhanced').append('<span class="bottom"></span><span class="speech"></span>');
	
	// fixes CitN image position
	var $this = jQuery('#newsroom .alt-layout .ClientsInTheNews a.image img');
	$this.css({'position':'relative','top':'50%','margin-top':($this.height() / -2)});
}

jQuery(document).ready(function() {
								
	newsroomSidebarSearchPrep();
	newsroomSidebarNavPrep();
	newsroomMostRecentPrep();
	newsroomEqualHeightCols();
	newsroomModuleHover();
	newsroomPhotoGallery();
	newsroomDrilldownTweaks();
	hashInit();

});


function hashInit(){
	if(window.location.hash && window.location.hash != '#'){
		jQuery('#photo-gallery a[href*="' + window.location.hash.substring(1) + '"]').filter(':first')
			.animate({'opacity':1},500,function(){
				jQuery(this).click();
		});
	}
	jQuery(window).history(function(e, hash) {
		if(window.location.hash == '' || window.location.hash == '#'){
			jQuery('#closeBut').click();
		} else {
			jQuery('#photo-gallery a[href*="'+hash+'"]').filter(':first').click();
		}
    });
}
















