$(function() {
	$("#main_navigation .collapsed > a").click(function() {
		$(this).parents("li").toggleClass("collapsed")
		return false;
	});
	
	$("#main_navigation .placeholder > a").click(function() {
		return false;
	});
	
	initialize_gallery(".text, .images");
	colorizeHeading1("#content .text, .category #content");

});

function verbiage_updated_callback(content_area) {
	initialize_gallery(content_area);
	colorizeHeading1(content_area);
}

function colorizeHeading1(content_area) {
	$(content_area).find("h1").each(function() {
	
		var h1 = $(this);
		if (h1.find("em").length == 0) {
			var text = h1.text();
			var html = text.replace(/(\S+)\s+([^\s]+)/g, "$1<em>$2</em>").replace(" ", "");
			h1.html(html);
		}
   	sIFR.replace(myriadpro, {
      selector: 'h1',
      css: [
        '.sIFR-root { color: #BD311A; }',
				'em {font-style:normal; color: #002E8D; text-transform:lowercase;}'
      ],
			modifyContent: function(node, selector) {
				$(node).find("em").each(function() {
					$(this).text($(this).text().toLowerCase());
				});
			}
    });
	});
}

var myriadpro = {
      src: '/javascripts/sIFR/myriadpro.swf',
      ratios: [6, 1.41, 9, 1.35, 15, 1.29, 21, 1.25, 22, 1.22, 27, 1.24, 29, 1.21, 34, 1.22, 41, 1.21, 45, 1.2, 46, 1.21, 59, 1.2, 68, 1.19, 69, 1.2, 96, 1.19, 97, 1.18, 102, 1.19, 103, 1.18, 107, 1.19, 108, 1.18, 112, 1.19, 114, 1.18, 116, 1.19, 120, 1.18, 121, 1.19, 1.18],
			forceTextTransform: true,
			wmode:"transparent"
    };

sIFR.activate(myriadpro);

function initialize_gallery(content_area) {
	
	var galleries = $("p.gallery");
	
	$(content_area).find("p.gallery img").each(function() {
		var img = $(this);
		var path = img.attr("src");
		
		var group = jQuery.inArray(img.parent(), galleries);
		
		img.attr("src", path.replace("/assets/images", "/assets/images/.thumbnails"));
		img.wrap('<a href="'+path+'" rel="group'+group+'"></a>');
		img.show();
	});
	
	$(content_area).find("p.gallery a").fancybox({'zoomSpeedIn': 300, 'zoomSpeedOut': 300});
	
}

var wymeditor_config = {
	classesItems: [    
		{'name': 'gallery', 'title': 'Gallery', 'expr': 'p'}
	]
};

