jQuery(function(){
	jQuery(".page-template-contact-php .post h4").each(function() {
		var header = jQuery(this);
		var paragraphs = jQuery.grep(
		    header.next('p'),
				     function(n) {
			         return jQuery(n).prevAll('h4').text() == header.text();
		    });

		  	jQuery.merge(header, paragraphs).wrapAll(jQuery('<div class="column">'));
	});
	jQuery('.column').css({
		'float':'left',
		'width': 860/jQuery('.column').length+'px'
	});
	jQuery('#nav li:not(ul ul li):not(:last)').append('|');
	jQuery('.disciplines li:not(:last), .clients li:not(:last)').css({'border-right-width':'1px','border-right-style':'solid'});
	jQuery('#nav li li:not(:last-child)').css({'border-right-width':'1px','border-right-style':'solid'});
	jQuery('ul.galleries li img').each(function(){
		if(!this.complete){
			jQuery(this).load(function(){jQuery(this).fadeIn(300)}); 
		}else{
			jQuery(this).fadeIn(300);
		}
	});
	
	jQuery('#filter select').change(function(){
		jQuery(this).parent('form').submit();
	}).next('button').css('display','none');
					
	jQuery('ul.galleries .gallery a').click(function(){
		if(!tripline){
		var clicked = jQuery(this).attr('href');
		tripline = true;
		jQuery.get(jQuery(this).attr('href'),function(data){
			Shadowbox.open({
				content: jQuery(data).find('#gallery').html(),
				player: "html",
				width: 940,
				height: 560,
				title: jQuery(data).find('h2').html(),
				options: { onFinish: function(){killThumbLinks(clicked)}, onClose: resetOverflow, onOpen: temporaryHide}
			});
			
		},'html');
		}
		return false;
	});
	jQuery('#all-galleries h2').each(function(){
		jQuery(this).css({
			'top':jQuery(this).next('ul').find('li:first-child').offset().top - jQuery('#all-galleries').offset().top,
			'left':jQuery(this).next('ul').find('li:first-child').offset().left - jQuery('#all-galleries').offset().left,
			'display':'block'
		})
	});
	jQuery("#rotator").cycle({ 
			pager: '#pager',
			fx: 'scrollHorz',
			timeout: 4000,
		speed: 1000,
		pause: 1,
		fit: 1,
		easing: 'easeInOutQuad',
		pagerClick: navPager,
		after: afterSlide,
		before: beforeSlide
	});
	
});
function navPager(index, element){
	
}
function temporaryHide(){
	jQuery('#sb-body-inner').css('opacity','0');
}
function beforeSlide(current, next, options, flag){
	for(i=0; i<galleryText.length; i++){
		if('img-'+galleryText[i].index == jQuery(next).attr('class')){
			var title = galleryText[i].title;
			var desc = galleryText[i].desc;
			var link = galleryText[i].link;
			var album = galleryText[i].album;
			//console.log(title);
		}
	}	
	jQuery('#feature h3').fadeOut(500, function(){
		jQuery(this).html(title+': ');
		jQuery(this).fadeIn(500);
	});
	jQuery('#feature p').fadeOut(500, function(){
		jQuery(this).html(desc);
		jQuery(this).fadeIn(500);
	});
	jQuery('#feature a.album-link').fadeOut(500, function(){
		jQuery(this).children('span').html(album);
		jQuery(this).attr('href', link);
		jQuery(this).fadeIn(500);
	});
				
}
function afterSlide(current, next, options, flag){
	
}
function resetOverflow(){
	jQuery('#sb-body').css('overflow','hidden');
	tripline = false;
}

function killThumbLinks(test){
	jQuery('.flviewer').each(function(){
	permalink = permalink.replace('&','%26');
		var flashvars = {
  			file: jQuery(this).children('a').attr('href'),
  			image: jQuery(this).children('img').attr('src'),
  			fullscreen: true,
  			controlbar: 'over',
  			stretching: 'uniform',
  			'viral.link': permalink,
  			'viral.onpause': false,
  			'viral.oncomplete' : false,
  			skin : videoSkin
  		};
  		var params = {
  			allowfullscreen: true,
  			allowscriptaccess: 'always',
  			wmode: 'transparent'
 		 };
  		var attributes = {
  			styleclass: jQuery(this).children('img').attr('class')
 		 };
 		 swfobject.embedSWF(playerPath,jQuery(this).attr('id'),'580','450','9.0.0','expressInstall.swf', flashvars, params, attributes);
		 
	});
	jQuery('#sb-body').css('overflow','auto');
	jQuery('.feature img').each(function(){
		jQuery(this).css('margin-top', (460-jQuery(this).height())/2+"px");
	});
	jQuery('.feature img').load(function(){
		jQuery(this).css('margin-top', (460-jQuery(this).height())/2+"px");
	});
	
	jQuery('#sb-body-inner').animate({
		'opacity':'1'
	});
	jQuery('.thumbs a').click(function(){
		var clicked = jQuery(this);
		jQuery('a.current').removeClass('current');
		jQuery('p.caption.current').removeClass('current').hide();
		jQuery('.feature .current img, .feature .current object').fadeOut(200, function(){
			jQuery(this).parent().removeClass('current');
			jQuery('.feature .'+clicked.attr('class')).fadeIn(200);
			jQuery('p.caption.'+clicked.attr('class')).fadeIn(200).addClass('current');
			jQuery('.feature .'+clicked.attr('class')).parent().addClass('current');
			clicked.addClass('current');
		});
		return false;
	});
	
}