$(window).ready(function () {
	$('.post').each(function() {
		$(this).hover(
			function() {
				$(this).find('.meta').css({'visibility':'visible'});
			}, 
			function() {
				$(this).find('.meta').css({'visibility':'hidden'});
			}
		);
	});
	
	// vimeo
	$("object[data^='http://vimeo.com']").each(function() {
		var parent = $(this).parent();
		var vimeoCode = parent.html();
		var params = "";
		if (vimeoCode.toLowerCase().indexOf("<param") == -1) {
			$("param", this).each(function() {
				params += $(this).get(0).outerHTML;
			});
		}
		var oldOpts = /show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF/g;
		var newOpts = "show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=CC5555";
		vimeoCode = vimeoCode.replace(oldOpts, newOpts);
		if (params != "") {
			params = params.replace(oldOpts, newOpts);
			vimeoCode = vimeoCode.replace(/<embed/i, params + "<embed");
		}
		parent.html(vimeoCode);
	});
	
	// youtube
	$("object").each(function() {
		if ($(this).find("param[value^='http://www.youtube.com']").length > 0) {
			var parent = $(this).parent();
			var youtubeCode = parent.html();
			var params = "";
			if (youtubeCode.toLowerCase().indexOf("<param") == -1) {
				$("param", this).each(function() {
					params += $(this).get(0).outerHTML;
				});
			}
			var oldOpts = /rel=0/g;
			var newOpts = "rel=0&amp;color1=0xFFFFFF&amp;color2=0xFFFFFF";
			youtubeCode = youtubeCode.replace(oldOpts, newOpts);
			if (params != "") {
				params = params.replace(oldOpts, newOpts);
				youtubeCode = youtubeCode.replace(/<embed/i, params + "<embed");
			}
			parent.html(youtubeCode);
		}
	});
	
	
});


$(window).load(function initOverlays() {
	imageOverlayProduction()
});


$(function(){
	bubbleToggle();
	searchControl();
	zoomLink();	
});

function bubbleToggle() {
	$('a#bubbleToggle').mouseover(function() {
		$('.bubble').fadeIn('fast');
	});
	
	$('a#bubbleToggle').mouseout(function() {
		$('.bubble').fadeOut('fast');
	});
};

function searchControl() {
	$('#search').click(function() {
		$(this).find('#searchForm').show();
		$('#searchField').focus();
	});
	$('#searchField').blur(function() {
		if ($(this).val() == "") {
			$('#searchForm').hide();
		};
	});
};

function zoomLink() {
	$('.zoom').each(function(){
		var destination = $(this).find('.destination');		
		if (destination.attr('title') == $(this).find('a').attr('href')) {
			destination.addClass('zoom');
			//$(this).find('a').attr('rel', 'lightbox');
			$(this).find('a').addClass('thickbox');
		};		
	});
	
};
	
function imageOverlayProduction() {	
	$('.photo').each(function() {
		var overlayTarget = $(this).find('.media img'); 
		var imageWidth = overlayTarget.width();	
		$(this).find('.media a').css({'width':imageWidth});
	});	
}
