
var featured_timer = 0;
var gallery_timer = 0;

// rotate featured in milliseconds
var featured_count = 5000;

// rotate gallery in milliseconds
var gallery_count = 5000;


	$(document).ready(function(){
	$.ajaxSetup({cache:false});
	$('.excerpt').css('background', "#ffffff");
	$('.excerpt').css('opacity', 0.5);
	
	
			
	if ($('.excerpt').length) {
		$(".excerpt").click(function(){
			$('.excerpt').css('opacity', 0.5);
			$(this).fadeTo('fast', 1.0);
			$(".excerpt").removeClass('selected');
			$(this).addClass('selected');
			var post_id = $("a", this).attr("rel");
			$("#container").html("<div class='loading'></div>");
			$('.slider.loading').css('opacity', 1.0);
			$('.slider.loading').show();
			social_load($(".excerpt.selected .excerpt-title").html(), $("a", this).attr("href"));
			$("#container").load("http://brooklandscape.com/post-load/",{id:post_id}, function(){
				
				
				gallery_load();
				cufon_load();
				
				
			
			}).hide().fadeIn('slow');
			
			
			
			return false;
		});
		$(".excerpt").removeClass('selected');
		var first_post =  $(".excerpt:first");
		
		$(".excerpt:first").addClass('selected');
		$('.excerpt').css('opacity', 0.5);
		$(".excerpt:first").fadeTo('slow', 1.0);
		var post_id =$("a", first_post).attr("rel");
		$("#container").html("<div class='loading'></div>");
		
		social_load($(".excerpt-title", first_post.parent()).html(), $("a", first_post).attr("href"));
		
		
		
	$.post("http://brooklandscape.com/post-load/",{id:post_id}, function(data) {
				var preload_img = '';
				var preload_img = new Array();
				
				$("#slideshow img", data).each(function(){
					preload_img.push($(this).attr('src'));
				});
				 
				$.each(preload_img, function(i) {
				  preload_img[i] = new Image();
				  preload_img[i].src = this;
				});
				
				
				
				container_load(post_id);
				
			});
		

		
		
		if ($('#featured-posts .excerpt').length) {
			$(".slides li").hide();
			featured_timer = setInterval ( "featured_rotate()", featured_count );
			
			$(".slides li:eq(0)").fadeTo('slow', 1.0);
			
			
		}
		
		
		
		
		
	
		$(".bookmark_link").click(function() {
			bookmark_us($(this).attr("href"), $(this).attr("title"));
			return false;		
		});
		
		$("#slideshow .excerpt").mouseover(function(evt) {
			  evt.stopPropagation();
			  $("#slideshow .excerpt:not('.hovered'):not('.selected')").css('opacity', 0.5);
			  $("#slideshow .excerpt").removeClass("hovered");
			  $(this).addClass("hovered");
			  $(this).css('opacity', 1.0);
		});
		$("#slideshow .excerpt").mouseout(function(evt) {
			 evt.stopPropagation();
			 $("#slideshow .excerpt").css('opacity', 0.5);
			 $("#slideshow .excerpt").removeClass("hovered");
			 $("#slideshow .excerpt.selected").css('opacity', 1.0);
		});
		$("#slideshow .excerpt").click(function() {
			
			window.location = $("a", this).attr('href');
		});
		
		$("#posts .excerpt").mouseover(function(evt) {
			  evt.stopPropagation();
			  $("#posts .excerpt:not('.hovered'):not('.selected')").css('opacity', 0.5);
			  $("#posts .excerpt").removeClass("hovered");
			  $(this).addClass("hovered");
			  $(this).css('opacity', 1.0);
		});
		$("#posts .excerpt").mouseout(function(evt) {
			 evt.stopPropagation();
			 $("#posts .excerpt").css('opacity', 0.5);
			 $("#posts .excerpt").removeClass("hovered");
			 $("#posts .excerpt.selected").css('opacity', 1.0);
		});
	}
});
function container_load(post_id) {
	
	$.post("http://brooklandscape.com/post-load/",{id:post_id}, function(data) {
					//$('.slider.loading').css('opacity', 1.0);
					//$('.slider.loading').show();
					$("#container").html(data);
					gallery_load();
					cufon_load();	
					
					
					
					
					
				});	
}
function featured_rotate() {
	
		var featured_count = $(".excerpt").length;
		var current_index = $(".slides-nav li").index($('.excerpt.selected').parent());
		$(".slides li").css('position', 'relative');
		if (current_index + 1 >= featured_count) {
			$(".slides-nav li .excerpt").removeClass("selected");
			$(".slides-nav li:eq(0) .excerpt").addClass("selected");
			$('.slides-nav li .excerpt').css('opacity', 0.5);
			$(".slides-nav li:eq(0) .excerpt").fadeTo('slow', 1.0);
			$(".slides li").fadeTo('slow', 0.0);
			$(".slides li").css('z-index', 0);
			$(".slides li:eq(0)").fadeTo('slow', 1.0);
			$(".slides li:eq(0)").css('z-index', 100);
		}
		else {
			current_index =  current_index + 1;
			$(".slides-nav li .excerpt").removeClass("selected");
			$(".slides-nav li:eq(" + current_index + ") .excerpt").addClass("selected");
			$('.slides-nav li .excerpt:not(".hovered")').css('opacity', 0.5);
			$(".slides-nav li:eq(" + current_index + ") .excerpt").fadeTo('slow', 1.0);
			$(".slides li").fadeTo('slow', 0.0);
			$(".slides li").css('z-index', 0);
			$(".slides li:eq(" + current_index + ")").fadeTo('slow', 1.0);
			$(".slides li:eq(" + current_index + ")").css('z-index', 100);
		}
	
		
		
		
		
	
	
}


function gallery_rotate() {
		var gallery_count = $(".new_gallery a").length;
		var current_index = $(".new_gallery a").index($('a.selected'));
		
		
		if (current_index + 1 >= gallery_count) {
			
			
			var index = $(".new_gallery a:first").index(".new_gallery a");
			
			if (index < $(".gallery-item").size() - 1) {
				
				$(".current_image img").fadeTo("slow", 0.0, function() {
					
					//$('.slider.loading').css('opacity', 1.0);	
					$(".new_gallery	a").removeClass("selected");
					$(".new_gallery a:eq(" + index + ")").addClass("selected");
					$(".current_image img").attr("src", "/images/blank.gif");
					$(".current_image img").attr("src", $(".article-wrapper .gallery a:eq(" + index + ")").attr("href"));
					$(".current_image img").fadeTo("slow", 1.0, function() {
						
						//$('.slider.loading').css('opacity', 0.0);	
					});
				});
				
				
				
			}
		}
		else {
			var index = $(".new_gallery a.selected").index(".new_gallery a");
		
			if (index < $(".gallery-item").size() - 1) {
				$(".current_image img").fadeTo("slow", 0.0, function() {
					
					//$('.slider.loading').css('opacity', 1.0);	
					index = index + 1;	
					$(".new_gallery	a").removeClass("selected");
					$(".new_gallery a:eq(" + index + ")").addClass("selected");
					$(".current_image img").attr("src", "/images/blank.gif");
					$(".current_image img").attr("src", $(".article-wrapper .gallery a:eq(" + index + ")").attr("href"));
					$(".current_image img").fadeTo("slow", 1.0, function() {
						
						//$('.slider.loading').css('opacity', 0.0);	
					});
				});
				
				
				
			}
		}
	
		
	
	
}
function bookmark_us(url, title){

if (window.sidebar) // firefox
    window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
}
else if(document.all)// ie
    window.external.AddFavorite(url, title);
}
function gallery_load() {
		clearTimeout(gallery_timer);
		if ($('#posts .excerpt').length || $('#page').length) {
			//$('.slider.loading').css('opacity', 0.0);
			//$('.slider.loading').show();
			gallery_timer = setInterval ( "gallery_rotate()", gallery_count );
				
		}
		
		
		
		if($(".gallery-item").size() > 0) {
			
			$(".article-wrapper .gallery-spot").after('<div class="current_image"><img src="/wp-content/themes/brooklandscape/images/smallsquare.png" border="0" alt=""/></div><div class="nav_outside"><div class="nav_container"><img src="/wp-content/themes/brooklandscape/images/r.back.png" border="0" alt="" class="back" /><img src="/wp-content/themes/brooklandscape/images/r.zoom.png" border="0" alt="" class="zoom" /><img src="/wp-content/themes/brooklandscape/images/r.next.png" border="0" alt="" class="next" /></div></div><div class="new_gallery"><h3></h3></div>');
			
			var smallsquare = '';
			
			$(".gallery-item").each(function() {
				
				smallsquare = smallsquare + '<a href="#" onclick="return false;"><img src="/wp-content/themes/brooklandscape/images/smallsquare.png" border="0" alt="" /></a>';
			
				
			});
			
			$(".new_gallery h3").after(smallsquare);
			onclick_thumbnail();
			$(".new_gallery a:eq(0)").addClass("selected");
			$(".current_image img").attr("src", $(".article-wrapper .gallery a:eq(0)").attr("href"));
			hover_gallery();
			
			
			
			
		}
		
		
	
}

function hover_gallery() {
	
	$(".current_image img").mouseover(function(evt) {
		evt.stopPropagation();
		$(".nav_container").fadeIn("fast", function() { navigate_hover(); } );
		return false
	});
	$(".current_image").mouseover(function(evt) {
		evt.stopPropagation();
		$(".nav_container").fadeIn("fast", function() { navigate_hover(); });
		return false
	});
	$(".nav_container img").mouseover(function(evt) {
		evt.stopPropagation();
	});
	$('body').mouseover(function() {
		$(".nav_container").fadeOut("fast"); 
	});
	
	
}
function navigate_hover() {
	
	
			
	 $(".nav_container img").unbind();
	 $(".nav_container img").mouseover(function(evt) {
		evt.stopPropagation();
	});
	 $(".nav_container img.back").click(function() {
		clearTimeout(gallery_timer);
		if ($('#posts .excerpt').length) {
			$('.slider.loading').css('opacity', 0.0);
			$('.slider.loading').show();
			gallery_timer = setInterval ( "gallery_rotate()", gallery_count );
				
		}
		
		var index = $(".new_gallery a.selected").index(".new_gallery a");
		
		if (index > 0) {
			index = index - 1;	
			$(".current_image img").fadeTo("slow", 0.0, function() {
				
				$('.slider.loading').css('opacity', 1.0);
				$(".new_gallery	a").removeClass("selected");
				$(".new_gallery a:eq(" + index + ")").addClass("selected");
				$(".current_image img").attr("src", "/images/blank.gif");
				$(".current_image img").attr("src", $(".article-wrapper .gallery a:eq(" + index + ")").attr("href"));
				$(".current_image img").fadeTo("slow", 1.0, function() {
					
					$('.slider.loading').css('opacity', 0.0);	
				});
			});
		}
		
	 });
	 
	  $(".nav_container img.next").click(function() {
		clearTimeout(gallery_timer);
		if ($('#posts .excerpt').length) {
			$('.slider.loading').css('opacity', 0.0);
			$('.slider.loading').show();
			gallery_timer = setInterval ( "gallery_rotate()", gallery_count );
				
		}
		var index = $(".new_gallery a.selected").index(".new_gallery a");
		
		if (index < $(".gallery-item").size() - 1) {
			$(".current_image img").fadeTo("slow", 0.0, function() {
				
				$('.slider.loading').css('opacity', 1.0);
				index = index + 1;	
				$(".new_gallery	a").removeClass("selected");
				$(".new_gallery a:eq(" + index + ")").addClass("selected");
				$(".current_image img").attr("src", "/images/blank.gif");
				$(".current_image img").attr("src", $(".article-wrapper .gallery a:eq(" + index + ")").attr("href"));
				$(".current_image img").fadeTo("slow", 1.0, function() {
					
					$('.slider.loading').css('opacity', 0.0);	
				});
			});
			
			
			
		}
		
	 });
	 
	 
	  $(".nav_container img.zoom").click(function() {
		$('.gallery-icon a').attr('rel', 'prettyPhoto[1]');
		$("a[rel^='prettyPhoto']").prettyPhoto();
		var index = $(".new_gallery a.selected").index(".new_gallery a");
		
		$(".gallery-icon a:eq(" + index + ")").click();
		
	 });
	
}
function onclick_thumbnail() {
	
	$(document).ready(function() {
		
		$(".new_gallery	a").click(function() {
			clearTimeout(gallery_timer);
			if ($('#posts .excerpt').length) {
				$('.slider.loading').css('opacity', 0.0);
				$('.slider.loading').show();
				gallery_timer = setInterval ( "gallery_rotate()", gallery_count );
					
			}
			$(".new_gallery	a").removeClass("selected");
			$(this).addClass("selected");
			$(".current_image img").attr("src", $(".article-wrapper .gallery a:eq(" + $(".new_gallery a").index(this) + ")").attr("href"));
			hover_gallery();

		});
	});
}
function cufon_load() {
	$(document).ready(function(){
		Cufon.replace('h1');
		Cufon.replace('h1.title');
		Cufon.replace('span.quote_left');
		Cufon.replace('span.quote_right');
		Cufon.replace('.cform legend');
		Cufon.replace('h1.green');
		Cufon.replace('.excerpt-content h2');
		Cufon.replace('.excerpt.selected h2');
		Cufon.replace('.failure');
		Cufon.replace('h2');
		Cufon.replace('h2 a', { fontFamily: 'Neutraface 2 Display Bold',  hover: {
		color: '-linear-gradient(#4B4B4B, #4B4B4B)'
	}
});
		Cufon.replace('h3');
		Cufon.replace('h3 a.share_link');
		Cufon.replace('.filter_type');
		Cufon.replace('.filter_type .selected');
		Cufon.replace('h2.featured');
		Cufon.replace('h4');
		Cufon.replace('label span');
		Cufon.replace('.textonly');
		Cufon.replace('.widget h3 a', { fontFamily: 'Neutraface 2 Display Bold',  hover: {
				color: '-linear-gradient(#4B4B4B, #4B4B4B)'
			}
		});
				Cufon.replace('h4 a', { fontFamily: 'Neutraface 2 Display Bold',  hover: {
				color: '-linear-gradient(#4B4B4B, #4B4B4B)'
			}
		});
		Cufon.replace('#sidebar nav a', { fontFamily: 'Neutraface 2 Display Bold',  hover: {
				color: '-linear-gradient(#4B4B4B, #4B4B4B)'
			}
		});
		Cufon.replace('ul#navi a', { fontFamily: 'Neutraface 2 Display Bold',  hover: {
				color: '-linear-gradient(#4B4B4B, #4B4B4B)'
			}
		});
		Cufon.replace('a.share-button', { fontFamily: 'Neutraface 2 Display Bold',  hover: {
				color: '-linear-gradient(#4B4B4B, #4B4B4B)'
			}
		});
		
		Cufon.replace('#footer-content p');	
		
	});
}
function social_load(title, href) {
	$(".email_link").attr({'href': "mailto:?subject=" + title + "&body=" + href});
	$(".bookmark_link").attr({'href': href});
	$(".bookmark_link").attr({'title': title});
	$(".facebook_link").attr({'href': "http://www.facebook.com/sharer.php?u=" + href + "&t=" + title });
	$(".facebook_link").attr({'title': title});
	$(".twitter_link").attr({'href': "http://twitter.com/home?status=" + "Check out:" + " " + href});
	$(".twitter_link").attr({'title': title});
	
	
	
}
function social_toggle() {
	$(document).ready(function() {
		$(".article-wrapper .share_link_body_content").html($("#share-holder").html());
		$(".article-wrapper .share_link_body_content").slideToggle("fast");
	});
	return false;
}

