﻿// Functions specific to a site.

//Cufon.replace('h1, h2, .subtitle, .featured-title, .staff-name, ');
//Cufon.replace('#mainnavigation ul li a, .next, .views li a, .left_ourwork', {hover: 'true'});
//Cufon.now();

/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);




/* Very customized from original hSlides plugin */
(function($) {


$.fn.hSlides = function(settings) {
	// override default configuration
	settings = $.extend({}, $.fn.hSlides.defaults, settings);
	// for each accordion
  return this.each(function(){
		var wrapper = this;
		var panelLeft = 0;
		var panels = $(settings.panelSelector, wrapper);
		var panelPositioning = 1;
		if (settings.panelPositioning != 'top'){
			panelLeft = ($(settings.panelSelector, wrapper).length - 1) * settings.minPanelWidth;
			panels = $(settings.panelSelector, wrapper).reverse();
			panelPositioning = -1;
		}
		settings.totalWidth = settings.totalWidth == 0 ? $(this).width() : settings.totalWidth;
		settings.totalHeight = settings.totalHeight == 0 ? $(this).height() : settings.totalHeight;
		settings.midPanelWidth = Math.floor(settings.totalWidth / panels.length);
		settings.maxPanelWidth = settings.totalWidth - (settings.minPanelWidth*(panels.length-1));
		
		// necessary styles for the wrapper
		$(this).css('position', 'relative').css('overflow', 'hidden').css('width', settings.totalWidth).css('height', settings.totalHeight);
		// set the initial position of the panels
		var zIndex = 0;
		var thisWidth = settings.maxPanelWidth;
		
		panels.each(function(){
			// necessary styles for the panels
			//thisWidth = settings.maxPanelWidth == 0 ? $(this).width() : settings.maxPanelWidth;
			thisWidth = $(this).outerWidth();
			
			$(this).css('position', 'absolute').css('left', panelLeft).css('zIndex', zIndex).css('height', settings.totalHeight).css('width', thisWidth);
			zIndex ++;
			// if this panel is the activated by default, set it as active and move the next (to show this one)
			if ($(this).hasClass(settings.activeClass)){
				$.data($(this)[0], 'active', true);
				if (settings.panelPositioning != 'top'){
					panelLeft = ($(settings.panelSelector, wrapper).index(this) + 1) * settings.minPanelWidth - settings.maxPanelWidth;
				}else{
					panelLeft = panelLeft + settings.maxPanelWidth;
				}
			}else{
				// check if we are centering and some panel is active
				// this is why we can't add/remove the active class in the callbacks: positioning the panels if we have one active
				if (settings.midPanelWidth && $(settings.panelSelector, wrapper).hasClass(settings.activeClass) == false){
					panelLeft = panelLeft + settings.midPanelWidth * panelPositioning;
				}else{
					panelLeft = panelLeft + settings.minPanelWidth * panelPositioning;
				}
			}
		});
		// iterates through the panels setting the active and changing the position
		var movePanels = function(){
			// index of the new active panel
			var activeIndex = $(settings.panelSelector, wrapper).index(this);
			var activeWidth = $(this).width();
			if(activeWidth > settings.maxPanelWidth) activeWidth = settings.maxPanelWidth;
			var closeWidth = (settings.totalWidth-activeWidth)/(panels.length-1);
			
			// iterate all panels
			panels.each(function(){
				// deactivate if is the active
				if ( $.data($(this)[0], 'active') == true ){
					$.data($(this)[0], 'active', false);
					$(this).removeClass(settings.activeClass).each(settings.onLeave);
				}
				
				// set position of current panel
				var currentIndex = $(settings.panelSelector, wrapper).index(this);
				//panelLeft = settings.minPanelWidth * currentIndex;
				// if the panel is next to the active, we need to add the opened width 
				if(currentIndex <= activeIndex)
					panelLeft = closeWidth * currentIndex;
				else
					panelLeft = (closeWidth * (currentIndex-1)) + activeWidth;
				
//				if ( (currentIndex * panelPositioning) > (activeIndex * panelPositioning)){
//					 panelLeft = panelLeft + (activeWidth - settings.minPanelWidth) * panelPositioning;
//				}
				// animate
				$(this).animate({left: panelLeft}, settings.speed, settings.easing, settings.onComplete);
			});
			// activate the new active panel
			$.data($(this)[0], 'active', true);
			$(this).addClass(settings.activeClass).each(settings.onEnter);
		};
		// center the panels if configured
		var centerPanels = function(){
			var panelLeft = 0;
			if (settings.panelPositioning != 'top'){
				panelLeft = ($(settings.panelSelector, wrapper).length - 1) * settings.minPanelWidth;
			}
			panels.each(function(){
				$(this).removeClass(settings.activeClass).animate({left: panelLeft}, settings.speed, settings.easing);
				if ($.data($(this)[0], 'active') == true){
					$.data($(this)[0], 'active', false);
					$(this).each(settings.onLeave);
				}
				panelLeft = panelLeft + settings.midPanelWidth * panelPositioning ;
			});
		};
		// event handling
		if(settings.eventHandler == 'click'){
			$(settings.panelSelector, wrapper).click(movePanels);
		}else{
			var configHoverPanel = {
				sensitivity: settings.sensitivity,
				interval: settings.interval,
				over: movePanels,
				timeout: settings.timeout,
				out: function() {}
			}
			var configHoverWrapper = {
				sensitivity: settings.sensitivity,
				interval: settings.interval,
				over: function() {},
				timeout: settings.timeout,
				out: centerPanels
			}
			$(settings.panelSelector, wrapper).hoverIntent(configHoverPanel);
			if (settings.midPanelWidth != 0){
				$(wrapper).hoverIntent(configHoverWrapper);
			}
		}
	});
};
// invert the order of the jQuery elements
$.fn.reverse = function(){
	return this.pushStack(this.get().reverse(), arguments);
};
// default settings
$.fn.hSlides.defaults = {
	totalWidth: 0, 
	totalHeight: 0,
	minPanelWidth: 0,
	maxPanelWidth: 0,
	midPanelWidth: 0,
	speed: 500,
	easing: 'swing',
	sensitivity: 3,
	interval: 100,
	timeout: 300,
	eventHandler: 'click',
	panelSelector: 'li',
	activeClass: 'active',
	panelPositioning: 'top',
	onEnter: function() {},
	onLeave: function() {},
	onComplete: function() {}
};
})(jQuery);


$(window).load(function(){
		
		// Fade in images so there isn't a color "pop" document load and then on window load
		//$(".sf_photoListSimple img").fadeIn(500);
		
		// clone image
		$('.sf_photoListSimple img').css({"opacity": "1"}).each(function(){
			var el = $(this);
			el.css({"position":"absolute"}).clone().addClass('img_grayscale').css({"position":"absolute","z-index":"998","opacity":"1"}).insertBefore(el).queue(function(){
				var el = $(this);
				el.parent().css({"width":this.width,"height":this.height});
				el.dequeue();
			});
			if (!$.browser.msie) {
				this.src = grayscale(this.src);
			} else {
				//$.each($('.img_grayscale').next('img'), function() {
				//	grayscaleImageIE(this);
				//});
				this.src = this.src;

			}

		});
		
		
	});
	
	

(function($) {
   
	$(document).ready(function() {
    //Cufon.replace('#mainnavigation ul li a, .next, .views li a, .left_ourwork', {hover: 'true'});
		// Place document manipulation code here
		
		// Navighation Class
//        $('#mainnavigation ul li:nth-child(1)').addClass('nav-firm');
//        $('#mainnavigation ul li:nth-child(2)').addClass('nav-work');

		//$('.cycle').cycle({
		//	fx: 'fade' 
		//});
		
		var galleryImageCount = $('.sf_photoListSimple img').length;
		var c = 0;
		$('.sf_photoListSimple').css('visibility','hidden');
       	$('.sf_photoListSimple img').load(function() {
			$(this)
				.parent().css('width',$(this).width()).css('opacity',0);
			c++;
			//$(this).parent().css('opacity',0);	
			if(c==galleryImageCount) { 
				$('.sf_photoListSimple').hSlides({
					minPanelWidth: 25, 
					eventHandler: 'click',
					speed: 750,
					interval: 50,
					onEnter: function() {
						$(this).find('.img_grayscale').animate({opacity:1}, 500);
					},
					onLeave: function() {
						$(this).find('.img_grayscale').animate({opacity:0}, 500);
					}

				});
				
				$('.sf_photoListSimple').css('visibility','visible');
				var panels = $('.sf_photoListSimple li')
				var i=0;
				function loadPanels() {
					if(i == panels.length) {
						//$(panels).find('img:last-child').css('opacity',1);
						//$(panels).not('.active').find('.img_grayscale').animate({opacity: 0});
						$(panels[Math.floor(panels.length/2)]).click();
						return;
					};
					var animTime = (i==0) ? 2000 : 250;
					
					function onComplete() {
						setTimeout(loadPanels,2000-animTime);
					}

					$(panels[i++]).click().find('img:first-child').parent().animate({opacity: 1},animTime, 'swing', onComplete);
				}
				loadPanels();
			}
				
		});
		function enterPanel() {
			//$(this)
		}
		
		$('.column:last-child').addClass('last-column');
		$('.featured-list li:last-child').addClass('last-child');
		
		// BLUE BAR - START //
		
		$('.fader li .fader-link, .contact-fader li .fader-link').mouseenter(function (){
			//$('.fader li, .contact-fader li').find('span').stop().animate({
            $('.fader li, .contact-fader li a').find('span').stop().animate({
				'width': '0', 
				'margin-left': '0%', 
				'opacity': '0'
			}, 0);	
			
			$(this).find('span').css({
				'width':'0px', 
				'margin-left': '0%', 
				'opacity': '100'
			});		
			$(this).find('span').stop().animate({
				'width': '100%', 
				'margin-left': '-50%'
			}, 500);		
		});
		
		$('.contact-fader li .fader-link').mouseout(function (){
			$(this).find('span').stop().animate({
				'width':'0px', 
				'margin-left': '0%', 
				'opacity': '100'
			}, 500);		
		});
		
		// BLUE BAR - END //
			
		var building = $('.fader li:first-child img').attr('alt');			
		$('.featured-building').text(building);
		
		if ($.browser.msie) {
			$('.fader li img, .contact-fader li img').mouseover(function(){
				var building = $(this).attr('alt');												  	
				$('.featured-building').text(building);
			})
		}  else {
			$('.fader li img, .contact-fader li img').mouseover(function(){
				var building = $(this).attr('alt');												  
				$('.featured-building').text(building);
			})
		}
	
	}); 
})(jQuery);

// GRAY SCALE FADER - START //
	
	$('.fader li img, .contact-fader li img').each(function(){
		var el = $(this);
		el.css({"position":"absolute"}).wrap("<div class='img_wrapper' style='display: block'>").clone().addClass('img_grayscale').css({"position":"absolute","z-index":"998","opacity":"0"}).insertBefore(el).queue(function(){
			var el = $(this);
			el.parent().css({"width":this.width,"height":this.height});
			el.dequeue();
		});
		if ($.browser.msie) {
			$.each($('.img_grayscale').next('img'), function() {
				grayscaleImageIE(this);
			});
		} else {
			this.src = grayscale(this.src);
		}
		
	});
	
	
	$('.fader li:first-child img').animate({opacity:1}, 0);
	$('.fader li:first-child').find('span').css({
		'width': '100%', 
		'margin-left': '-50%'
	});	
	
	if ($.browser.msie) {
		$('.fader li img, .contact-fader li img').mouseover(function(){
			$('.img_grayscale').stop().animate({opacity:0}, 500);
			$(this).parent().find('img:first').stop().animate({opacity:1}, 500);
		})
		$('.contact-fader li img').mouseout(function(){
			$(this).stop().animate({opacity:0}, 500);
		});
	}  else {
		$('.fader li img, .contact-fader li img').mouseover(function(){
			$('.img_grayscale').stop().animate({opacity:0}, 500);
			$(this).parent().find('img:first').stop().animate({opacity:1}, 500);
		})
		$('.contact-fader li img').mouseout(function(){
			$(this).stop().animate({opacity:0}, 500);
		});
	}
	
		
// GRAY SCALE FADER - END //



