// HGI Scripts

function setPortfolioServiceActionsGLOBAL(){
	jQuery('.nav-box dl dt ul li a').click(function(){
		var target = jQuery(this).attr('id');
		jQuery('.nav-box dl').removeClass('current');
		jQuery('.nav-box').find('dl[id="' + target + '"]').addClass('current');
		return false;
	});
}

// -----------------------------------------------------------------------------
// -- Homepage FlashRHS (start) ------------------------------------------------
// -----------------------------------------------------------------------------

function flashRHS_Prep(){
	var totalHeight = $('#flashrhs').height();
	var totalWidth = $('#flashrhs').width();
	
	flashRHS_MiniNavPrep();
	$('#flashrhs #alt-nav, #flashrhs #client-logos, #flashrhs #mini-nav, #flashrhs #client-urls').css({'visibility':'hidden'});
	$('#flashrhs').css({'background-color':'#ffffff'});
	flashRHS_BgAnim(totalHeight,totalWidth);
}


function flashRHS_BgAnim(totalHeight,totalWidth){
	
	// hide everything and create intro-animation spans
	$('#flashrhs').prepend('<span class="bgslide"></span>');
		
	// animate bg down
	$('#flashrhs span.bgslide').css({'top':'-' + (totalHeight + 40) + 'px'}).animate({'opacity':'1'},500,function(){
			flashRHS_NavAnim();
			setTimeout("flashRHS_LogoBgAnim("+totalHeight+","+totalWidth+")",250);
		$(this).animate({'top':'0'},500,"easeOut",function(){
			$('#flashrhs').css({'background-color':''}).find('span.bgslide').remove();
			//flashRHS_LogoBgAnim(totalHeight,totalWidth);
		});
	});
}


function flashRHS_LogoBgAnim(totalHeight,totalWidth){
	$('#flashrhs').append('<span class="logoslide"></span>');
	
	// animate logos bg across, inits the logo cycle, fades-in logos
	$('#flashrhs span.logoslide').css({'left':'-' + (totalWidth - 25) + 'px','opacity':'.5'}).animate({'left':'0','opacity':'1'},350,"easeOut",function(){
		flashRHS_initCycle();
		$('#flashrhs #client-logos').css({'visibility':'visible'}).parent().find('span.logoslide').animate({opacity: 1}, 50).fadeOut(500,function(){
			$(this).remove();
			flashRHS_initMini();
		});
	});
}	

function flashRHS_MiniNavPrep(){
	jQuery('#flashrhs').append('<ul id="client-urls"></ul>');
	jQuery('#client-logos li').each(function(){
		
		var clientName = jQuery(this).find('img').attr('alt');
		var clientClass = jQuery(this).children('a').attr('class');
		var clientURL = jQuery(this).children('a').attr('href');
		var linkText;

		if(clientClass == 'case-study'){
			linkText = 'View Case Study';
		} else if(clientClass == 'project'){
			linkText = 'View Project';
		} else {
			linkText = 'View Client List';
		}
		
		jQuery('#client-urls').append('<li><a href="' + clientURL + '" alt="' + clientName + '" title="' + clientName + '">' + linkText + '</a></li>');
		/*
			var clientClass = jQuery(this).children('a').attr('class');
			var clientClassCapitalized = clientClass.substring(0,1).toUpperCase() + clientClass.substring(1,clientClass.length);
		*/		
	});
}

function flashRHS_NavAnim(){
	// staggers-in the nav, inits hover	
	$('#flashrhs #alt-nav').css({'opacity':'1','visibility':'visible'}).children('li').css({'opacity':'0'});
	
	// the staggered fade-in animation		
	var timer = 200; 
	var time = 100;
	var multiplier = 1;

	jQuery('#flashrhs #alt-nav li').each(function(){
		$(this).find('a').before('<span><img src="themes/horngroup/images/alt-nav-arrow.gif" alt=""/></span>').parents('li').find('span').css({'opacity':'0'}).children('img').css({'opacity':'0'});
		$(this).animate({opacity:0}, timer).animate({opacity: 1}, 250,function(){
			$(this).removeAttr('style')
		});
		timer = (timer*multiplier + time);
	});
	
	flashRHS_initNav();
}


function flashRHS_initCycle(){
	// creates the logo cycle
	
	var cycleTime = 5000;
	var cycleSpeed = 750;
	if($.browser.msie){
		var cycleTrans = 'scrollDown';
	} else {
		var cycleTrans = 'fade';
	}
	$('#client-logos').cycle({ 
		fx:     cycleTrans, 
		speed:  cycleSpeed, 
		prev:   '#mini-nav a.prev', 
		next:   '#mini-nav a.next', 
		timeout: cycleTime 
	});

	// creates the url cycle
	$('#client-urls').cycle({ 
		fx:     cycleTrans, 
		speed:  cycleSpeed, 
		prev:   '#mini-nav a.prev', 
		next:   '#mini-nav a.next', 
		timeout: cycleTime 
	});
	
	if($.browser.msie){
		$('#client-logos li').css({'top':'170px'}).filter(':first').css({'top':'0px'});
		$('#client-urls li').css({'top':'48px'}).filter(':first').css({'top':'0px'});
	}
}


function flashRHS_initNav(){
	// sets the nav hover event
	$('#flashrhs #alt-nav li a').hover(function(){
		$(this).parents('li').find('span').animate({'opacity':'1'},{duration:200, queue:false});
		$(this).parents('li').find('img').animate({'opacity':'0'},100,function(){
			$(this).animate({'opacity':'1','left':'10px'},{duration:50}).animate({'opacity':'1','left':'7px'},{duration:25});
		});
		$(this).animate({'textIndent':'22px'},{duration:150, queue:false});
	},function(){
		$(this).parents('li').find('span').animate({'opacity':'0'},{duration:200, queue:false});
		$(this).parents('li').find('img').stop().animate({'opacity':'0','left':'0px'},{duration:25, queue:false});
		$(this).animate({'textIndent':'10px'},{duration:150, queue:false});
	});
}


function flashRHS_initMini(){
	$('#flashrhs #mini-nav, #flashrhs #client-urls').css({'visibility':'visible','top':'361px'}).animate({'opacity':'1','top':'322px'},{duration:300, easing:"easeOutCirc"});
	
	// sets the logo hover event
	$('#flashrhs #client-logos, #flashrhs #mini-nav, #flashrhs #client-urls').hover(function(){
		$('#flashrhs #mini-nav, #flashrhs #client-urls').animate({'opacity':'1','top':'322px'},{duration:300, queue:false, easing:"easeOutCirc"});
	},function(){
		$('#flashrhs #mini-nav, #flashrhs #client-urls').animate({'opacity':'1','top':'361px'},{duration:300, queue:false});
	});
}

// -----------------------------------------------------------------------------
// -- Homepage FlashRHS (end) ------------------------------------------------
// -----------------------------------------------------------------------------


jQuery(document).ready(function() {
/*
	// IE6 redirect
	if(jQuery.browser.msie && jQuery.browser.version == 6) {
		if(jQuery.browser.msie && jQuery.browser.version == 7) {
			// do nothing
		} else {
			window.location = "http://www.horngroup.com/ie6/index.html"
		}
	}
*/	
	jQuery('div#slider').codaSlider();

	var currentView = 'thumb'
	var lastProject = null

// Homepage > Flash RHS init
	if(jQuery('#flashrhs').length >= 1){
		flashRHS_Prep();
	}
	
// Homepage > News/Blog Feeders - Cycle
	jQuery('#newsticker').cycle({ 
		fx:     'fade', 
		speed:  500, 
		timeout: 0, 
		next:   '#next1', 
		prev:   '#prev1', 
		timeout:  4000,
		pause:  1
	});
	
	jQuery('#blogticker').cycle({ 
		fx:     'fade', 
		speed:  500, 
		timeout: 0, 
		next:   '#next2', 
		prev:   '#prev2', 
		pager:  '#nav'
	});
	
	
// Homepage > OurSection Mouseovers (w/ Hover Intent)
	var config = {    
		sensitivity: 100,   
		interval: 100,
		over: bringItIn,
		timeout: 0,
		out: sendItOut 
	};
	
	jQuery(".oursection ul li a").hoverIntent(config)
	jQuery(".oursection ul li").prepend("<img src='themes/horngroup/images/arrow_red_sm.gif'/>");

	jQuery('.oursection ul li img').css({opacity: 0}).animate({left: '-=' + 15 + 'px', top: '+=' + 8 + 'px'});
	
	function bringItIn(){
		jQuery(this).prev().animate({
			opacity: 1,
			left: '+=' + 10 + 'px'
		}, 250);
	}	
	
	function sendItOut(){
		jQuery(this).prev().animate ({
			opacity: 0,
			left: '-=' + 10 + 'px'
		}, 250);
	}
	
// ------------------------------------------------------------------	
// -- Homepage > HG Headlines Feeder - Mouseover (w/ Hover Intent) --
// ------------------------------------------------------------------	
	var config2 = {    
		sensitivity: 100,
		interval: 100,   
		over: showIt,
		timeout: 500,
		out: hideIt
	};
	
	jQuery('.headlines').hoverIntent( config2 )
	jQuery('.headlines #mininav').css({opacity: 0});
	jQuery('.headlines #newsticker').css({marginLeft: -45});
			
	function showIt(){
		jQuery('.headlines #newsticker').animate({marginLeft: '+=' + 45 + 'px'}, 350);
		jQuery('.headlines #mininav').animate({opacity: 0}, 250).animate({opacity: 1}, 250);
	}
	
	function hideIt(){
		jQuery('.headlines #newsticker').animate({marginLeft: '-=' + 45 + 'px'}, 500);
		jQuery('.headlines #mininav').animate({opacity: 0}, 250);
	}
	
// ---------------------------------
// -- Sub-Nav Behaviors ------------
// ---------------------------------
	jQuery('.sub-nav li a').prepend('<span><img src="themes/horngroup/images/side-nav-circle.png"/></span>');
	jQuery('.sub-nav li a.current span').replaceWith('<span><img src="themes/horngroup/images/side-nav-whitearrow.png"/></span>');

	var timer = 0; 
	var time = 100;
	var multiplier = 1;
	
    jQuery('.sub-nav li').each(function(i) {  

		jQuery(this).css({opacity: 0}); 
		timer = (timer*multiplier + time); 
		jQuery(this).animate({opacity: 0}, timer).animate({opacity: 1}, 250);

    });	
	
	jQuery('.sub-nav li a.current').parent().append('<span></span>');
	jQuery('.sub-nav li a.current').next().css({'background':'url(themes/horngroup/images/side-nav-bg.png) 0px 0px repeat', 'display':'block', 'height':'28px', 'width':'211px'});
	jQuery('.sub-nav li a.current').next().animate({opacity:1},250).animate({backgroundPosition: '(211px 0px)'}, 750, 'easeInOutExpo');
	jQuery('.sub-nav li:has(a.current)').css({'position':'relative', 'line-height':'100%', 'padding':'1px 0px 0px 0px'});
	jQuery('.sub-nav li a.current').prev().css({'position':'absolute'});
	jQuery('.sub-nav li a.current').css({'position':'absolute'});
/*	
	jQuery('.sub-nav li:not(:has(a.current))').each(function(i) {  
		jQuery(this).hover(function() {  
			jQuery(this).animate({ paddingLeft: '40px' }, 250);  
			jQuery(this).children('a').children('span').children('img').replaceWith('<img src="themes/horngroup/images/side-nav-arrow.png"/>');
		}, function() {  
			jQuery(this).animate({ paddingLeft: '19px' }, 250);  
			jQuery(this).children('a').children('span').children('img').replaceWith('<img src="themes/horngroup/images/side-nav-circle.png"/>');
		});  
	});
*/
	var configSubNav = {    
		sensitivity: 100,
		interval: 100,   
		over: subnavOn,
		timeout: 100,
		out: subnavOut
	};
	
	jQuery('.sub-nav li:not(:has(a.current))').hoverIntent(configSubNav);
			
	function subnavOn(){
		jQuery(this).animate({ paddingLeft: '40px' }, 250);  
		jQuery(this).children('a').children('span').children('img').replaceWith('<img src="themes/horngroup/images/side-nav-arrow.png"/>');
	}
	
	function subnavOut(){
		jQuery(this).animate({ paddingLeft: '19px' }, 250);  
		jQuery(this).children('a').children('span').children('img').replaceWith('<img src="themes/horngroup/images/side-nav-circle.png"/>');
	}


// ---------------------------------
// -- Animate Background Position --
// ---------------------------------

(function($){
	
	if(!document.defaultView || !document.defaultView.getComputedStyle){
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
})(jQuery);

(function($) {
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			
			var start = $.curCSS(fx.elem,'backgroundPosition');
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			fx.start = [start[0],start[2]];
			
			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);


// ---------------------------------
// -- Portfolio Landing Nav --------
// ---------------------------------

portfolioLandingPrep();

// -----------------------------------------------------
// -- Capabilities > PR "View Case Study" PopUp --------
// -----------------------------------------------------
	jQuery('.pr-module div span em').css({'display':'none'});	

	jQuery('.pr-module').hover(function(){
		jQuery('.pr-module div span em').slideDown(100);
	},function(){
		jQuery('.pr-module div span em').slideUp(250);
	});


// -----------------------------------------------------
// -- Various Fixes ------------------------------------
// -----------------------------------------------------
	//jQuery('.info p:last').css('height','175px');

	// Capabilities Landing page - adds the "+" between list items and formats accordingly
	jQuery('.content ul#capabilities').css({'list-style':'none','margin':'0px 0px 0px 0px'});
	jQuery('.content ul#capabilities li a').css({'display':'block'});
	jQuery('.content ul#capabilities li ul').each(function(){
		jQuery(this).children('li').css({'list-style':'none', 'display':'inline','font-size':'1.3em'}).filter(':not(:first)').prepend('<span style="color: #de2816;"> + </span>');
	});
/*	
	// Capabilities Landing page - adds the "+" between list items and formats accordingly
	jQuery('.maincontent-bg:has(h2:contains("Capabilities")) div.content ul').css({'margin':'0px 0px 20px 0px'});
	jQuery('.maincontent-bg:has(h2:contains("Capabilities")) div.content ul').each(function(){
		jQuery(this).children('li').css({'list-style':'none', 'display':'inline'}).filter(':not(:first)').prepend('<span style="color: #de2816;"> + </span>');
	});
*/
	jQuery('.content ul:has(ul):not(#capabilities)').css({'list-style':'none','margin':'0px 0px 0px 0px'});
	jQuery('.content ul:has(ul):not(#capabilities) ul li').css({'font-size':'1.3em'});
	
	//jQuery('#casestudy').children('h4').next().next().css({'width':'400px'});
	//setTimeout(jQuery('#sIFR_callback_3').css({'width':'400px'})),5000);
	
// -----------------------------------------------------
// -- Team Bios Tabs -----------------------------------
// -----------------------------------------------------

	var tabContainers = jQuery('div.tabs > div');
	
    jQuery('div.tabs > ul:has(li[id="executive"]) a').click(function () {
		sIFR.rollback();
		tabContainers.hide().filter(this.hash).show();
		do_sIFR();
		
        jQuery('div.tabs ul li').removeClass('selected');
        jQuery(this).parent().addClass('selected');
        
        return false;
		
    }).filter(':first').click();

	// remove Advisory Council Images
	jQuery('div.team-module')
		.parent('div#advisory')
		.children('div.team-module').css({'padding':'10px 0px 10px 10px'})
		.children('div.right').css({'float':'none'})
		.parent().children('div.left').remove();
	


// -----------------------------------------------------
// -- News Show/Hide -----------------------------------
// -----------------------------------------------------

	jQuery(".news ul li ul").css('display','none');
    jQuery(".news ul li ul li:last").css({'border-bottom':'none'});
    jQuery(".news ul.archive li ul li:last-child").css({'border-bottom':'none'});
    jQuery(".news ul.archive li p").hover(function(){
		jQuery(this).css('cursor','pointer')
		jQuery(this).children('a').css('color','#de2816')
	}, function(){
		jQuery(this).children('a').css('color','')
	});

	jQuery(".news ul li:has(ul)").toggle(
		function () {
			jQuery(this).children('ul').slideDown(250);
			jQuery(this).children('p').animate({backgroundColor: '#f8f8f8'},250);
			
			var target = jQuery(this).children('p').children('a');
			var targetOffset = target.offset().top;
			var targetOffsetTweaked = targetOffset - 10;
			jQuery('html,body').animate({scrollTop: targetOffsetTweaked}, 500);
		},
		function () {
			jQuery(this).children('ul').slideUp(250);
			jQuery(this).children('p').animate({backgroundColor: '#ffffff'},250);
			setTimeout("jQuery('.news ul li:has(ul)').children('p').css('background', 'transparent');",250);
		}
	);	

// -----------------------------------------------------
// -- Testimonials -------------------------------------
// -----------------------------------------------------

	var timer = 0; 
	var time = 1000;
	var multiplier = 1;
	
if(location.href.indexOf("horngroup.blogs.com") != 7){
    jQuery('blockquote').each(function(i) { 
		jQuery(this).children('p').prepend("<img src='themes/horngroup/images/line-start.png'/>");
		jQuery(this).children('p').append("<img src='themes/horngroup/images/line-end.png'/>");
		jQuery(this).children('p:first').prepend("<img src='themes/horngroup/images/open-quote.png' class='open-quote'/>");
		jQuery(this).children('p:last').append("<img src='themes/horngroup/images/close-quote.png' class='close-quote'/>");
		jQuery(this).children('p:not(:first)').css('margin-left','32px');
	});	
}
/*	
    jQuery('blockquote > p').each(function(i) { 
		jQuery(this).css({opacity: 0}); 
		jQuery(this).animate({opacity: 0}, 500); 
		timer = (timer*multiplier + time); 
		jQuery(this).animate({opacity: 0}, timer).animate({opacity: 1}, 1000);
    });	
*/	


// -----------------------------------------------------
// -- Contact Form -------------------------------------
// -----------------------------------------------------


jQuery('fieldset div:has([id])').css('margin','0px 0px 20px 0px');
jQuery("fieldset div:has(label:contains('First'))").css({'float':'left', 'padding':'0px 40px 0px 0px'});
jQuery("fieldset div:has(label:contains('Phone'))").css({'float':'left', 'padding':'0px 40px 0px 0px'});
jQuery("fieldset div:has(label:contains('Address'))").children('span').children('input').after('<br/>');
jQuery("fieldset div:has(label:contains('Address'))").children('span').children('input').css('margin','0px 0px 10px 0px');
var address2 = jQuery("fieldset div:has(label:contains('Address 2'))").children('span').html();
jQuery("fieldset div:has(label:contains('Address'))").children('span').children('br').after(address2);
jQuery("fieldset div:has(label:contains('Address 2'))").empty();
jQuery("fieldset div:has(label:contains('City'))").css({'display':'inline', 'float':'left', 'padding':'0px 40px 0px 0px'});
jQuery("fieldset div:has(label:contains('State'))").css({'display':'inline', 'float':'left', 'width':'60px', 'padding':'0px 20px 0px 0px'});
jQuery("fieldset div:has(label:contains('State'))").children('span').children('input').css({'background':'transparent url(themes/horngroup/images/form_textfield2_bg.png) 0px 0px no-repeat'});
jQuery("fieldset div:has(label:contains('Zip'))").css({'width':'150px', 'float':'left'});
jQuery("fieldset div:has(label:contains('Zip'))").children('input').css({'display':'inline'});
jQuery("fieldset div:has(label:contains('Zip'))").children('span').children('input').css({'background':'transparent url(themes/horngroup/images/form_textfield2_bg.png) 0px 0px no-repeat'});
jQuery("fieldset div:has(label:contains('Tell'))").css({'clear':'both', 'background':'transparent url(themes/horngroup/images/form_textarea_bg.png) 0px 20px no-repeat','width':'465px', 'height':'160px'});
jQuery("fieldset div:has(label:contains('Tell'))").children('span').children('textarea').css({'width':'445px', 'height':'125px', 'margin':'5px', 'background':'transparent'});
//jQuery("fieldset div#EditableTextField51").css({'clear':'both', 'background':'transparent url(themes/horngroup/images/form_textarea_bg.png) 0px 20px no-repeat','width':'465px', 'height':'160px'});
//jQuery("fieldset div#EditableTextField51").children('span').children('textarea').css({'width':'445px', 'height':'125px', 'margin':'5px', 'background':'transparent'});

jQuery('fieldset div').children('span').children('input').focus(function(){
	jQuery(this).css('background-position','0px -29px');
});

jQuery('fieldset div').children('span').children('input').blur(function(){
	jQuery(this).css('background-position','0px 0px');
});

jQuery('fieldset div').children('span').children('textarea').focus(function(){
	jQuery(this).parent().parent().css('background-position','0px -150px');
	jQuery(this).css('background-position','0px -170px');
});

jQuery('fieldset div').children('span').children('textarea').blur(function(){
	jQuery(this).parent().parent().css('background-position','0px 20px');
	jQuery(this).css('background-position','0px 0px');
});

jQuery('#SearchForm_SearchForm_Search').focus(function(){
	jQuery(this).parent().parent().css('background-position','0px -30px');
});

jQuery('#SearchForm_SearchForm_Search').blur(function(){
	jQuery(this).parent().parent().css('background-position','0px 0px');
});



// -----------------------------------------------------
// -- Awards Modals ------------------------------------
// -----------------------------------------------------
/*
jQuery.nyroModalSettings({height: '630px'});
jQuery('#awards .awards-module a').nyroModal(do_sIFR());
//jQuery('#past-clients').nyroModal(do_sIFR());
*/


// -- the end --	
});
// ---------------------------------
// -- Sifr 3 -----------------------
// ---------------------------------

do_sIFR();