$(document).ready(function() {  

	//Adds a selected class to the selected menu item, also adds a selected class to the parent menu item if a dropdown menu item is selected
	$(function () {
	var path = location.pathname;
	if (path) {
		var Selector = $('#menu a[href$="' + path + location.search + '"]');

		$(Selector).parent("li").attr('class', 'selected');
		$(Selector).parent("li").parent("ul").parent("li").attr("class", "selected"); //Adds selected class to the drop down menus parent li
		$("#menu li ul li").removeAttr("class", "selected"); //Remove selected class for drop down menu items
	}
	});
	
//	var splited = $('#content h2').text().split(' ');
//	var words = splited[splited.length-2] + ' ' + splited[splited.length-1];
//
//	$('#content h2').each(function() {
//  		$(this).html($(this).html().replace(words, '<span>' + words + '</span>'));
//	});


	if ($('#home_slideshow').length) {
		$('#home_slideshow').cycle({ 
		fx:     'fade', 
		next:   '#next', 
		prev:   '#prev',
		pause:  1
		});
		$('#home_slideshow').each(function(i) { 
			if( $(this).children().length<2){
				$('p#prevButt, p#nextButt').hide();
			}
		});
	};
	
	if ($('#blogroll_articles').length) {
		$('#blogroll_articles') 
		.before('<div id="blog_nav">') 
		.cycle({ 
			fx:     'fade', 
			timeout: 0, 
			pager:  '#blog_nav',
			pagerAnchorBuilder: function(idx, slide) {
			  return '<li><a href="#">' + (idx+1) + '</a></li>';
			}
		});
		$('#blogroll_articles').each(function(i) { 
			if( $(this).children().length<2){
				$('#blog_nav').hide();
			}
		});
	};
	
	if ($('#generic_slideshow').length) {
		$('#generic_slideshow') 
		.before('<div id="gp_nav">') 
		.cycle({ 
			fx:     'fade', 
			timeout: 0, 
			pager:  '#gp_nav',
			pagerAnchorBuilder: function(idx, slide) {
			  return '<li><a href="#">' + (idx+1) + '</a></li>';
			}
		});
		$('#generic_slideshow').each(function(i) { 
			if( $(this).children().length<2){
				$('#gp_nav').hide();
			}
		});
	};
	
	$('#color_roof li a').each(function() { $(this).css({ backgroundColor: $(this).attr('href') }) });
	
	$("#color_roof li a").click(function() { 
		$("#roof").css("backgroundColor", $(this).attr('href'));
		$("#roof_text").html($(this).html());
		return false;
	});
	
	$('#color_brick li a').each(function() { $(this).css('backgroundColor', '#' + $(this).attr('href')) });
	
	$("#color_brick li a").click(function() {
		$("#brick").css('background-image', 'url(uploads/images/' + $(this).attr('href') + '.jpg)');
		$("#brick_text").html($(this).html());
		return false;
	});

});
