/* clearTimeOut Keeps the Menu Open */
$clearTimeOut = 0;
Cufon.replace('h3, .replace-type, .meta-title, .notes-title, .page-menu-item, a.prev-page, a.next-page, h4.footer-title, .post-link ');
Cufon.replace('.tag-list li, .next-page, .prev-page, .notes-bubble');
// Keep the Menu Open if we're highlighting a sub-menu item
function keep_open()
	{$clearTimeOut = 0;}
// Begin the closing procedure with a countdown
function close_menu($id)
	{
		$clearTimeOut = 1;
		$temp_timeout = setTimeout("close_menu_final('"+$id+"');", 0);					
	}			
// Do the final menu clearing
function close_menu_final($id)
	{
		// Check whether or not we've scrolled over a menu item
		if($clearTimeOut == 1)
			{
				$use_id = "#"+$id;				
				$($use_id).animate({"padding-top": "0px"}, {duration: 150});
			}
	}
function feature_slide($newid, $oldid, $moveby)
	{
			//Set selectors for the "old" feature element
			$old_copy_id = "#feature-copy-"+$oldid;
			$old_href_id = "#feature-li-"+$oldid;
			
			//Set selectors for the "new" feature element
			$new_copy_id = "#feature-copy-"+$newid;
			$new_href_id = "#feature-li-"+$newid;
			
			//Switch li class and fade out old feature element
			$($old_href_id).removeClass("active");			
			$($old_copy_id).slideUp({duration: 400});	
			
			//Switch li class and fade in new feature element
			$($new_href_id).addClass("active");
			$($new_copy_id).slideDown({duration: 400});//setTimeout(function(){}, 401);
			
			
			$new_left_attr = -($newid-1)*$moveby;
			$("#feature-slider").animate({"left": $new_left_attr}, {duration: 350});
	}
function load_posts(data)
	{
		$.each(data.posts, function(i,posts){ 
			var id = this.id; 
			var type = this.type; 
			var title = this.title; 
			var date = this.date; 
			var url = this.url; 
			var caption = this["photo-caption"]; 
			var photo500 = this["photo-url-500"];
			var photo1280 = this["photo-url-1280"]; 
			
			j = (i/1)+1;
			if(i !== 0)
				{$("#post_details").append("<div style=\"display: none;\" id=\"feature-copy-"+j+"\">");}
			else
				{$("#post_details").append("<div id=\"feature-copy-"+j+"\">");}
				
			if(title !== undefined)
				{$("#feature-copy-"+i).append("<h2><a href=\""+url+"\">"+title+"</a></h2>");}
				
			$("#feature-copy-"+j).append(caption);
				
			$("#feature-slider").append("<a href=\""+url+"\" class=\"feature-image\" id=\"feature-image-"+j+"\"><img src=\""+photo500+"\" /></a>\n");
			$("#feature-count").html(j);
		});
	}
function slideFrame($thumbid, $move_by, $direction, $type, $match_height)
	{
		/* Set the new position & frame number */
		$frame_left = $($thumbid).css($type).replace("px", "");
		$max_clicks = $($thumbid).children().size();	
		
		$frame_no = (-($frame_left/$move_by)+1);
		
		if($direction == 0)
			{
				$new_frame_no = (($frame_no/1)+1);
				$new_left = (($frame_left/1) - $move_by);
				/* Check if we're moving too far over */
				if($new_frame_no > $max_clicks)
					{		
						/* Move all the way right, to the beginning*/
						$new_left = 0;
						$new_frame_no = 1;
					}		
			}
		else
			{
				$new_frame_no = (($frame_no/1)-1);
				$new_left = (($frame_left/1) + $move_by);
				
				/* Check if we're moving too far over */
				if($new_frame_no <= 0)
					{
						/* Move the images all the way left, minus one frame */
						$new_left = -($move_by*$max_clicks)+$move_by;
						$new_frame_no = $max_clicks;
					}
			}
		$new_left_attr = $new_left;
		if($type == "left")
			{$($thumbid).animate({"left": $new_left_attr}, {duration: 350});}
		else
			{$($thumbid).animate({"top": $new_left_attr}, {duration: 300});}
	}	
function focus_search(search_value)
	{
		if(search_value == "Search")
			{document.getElementById("s").value = "";}
	}
function blur_search(search_value)
	{
		if(search_value == "")
			{document.getElementById("s").value = "Search";}
	}
	
$(document).ready(function()
	{
		$.current_feature = 1;
		
		if(document.getElementById("feature-auto-slide") && $("#feature-auto-slide").html() !== "0")
			{
				$slide_interval = ($("#feature-auto-slide").html()*1000);
				
				if(!isNaN($slide_interval))
					{
						$auto_slider = setInterval(function()
							{
								$move_by = 500;
								$max_clicks = $("#feature-count").html();
								if($.current_feature == $max_clicks)
									$newid = 1;
								else
									$newid = (($.current_feature/1)+1);
								
								feature_slide($newid, $.current_feature, $move_by);
								
								$.current_feature = $newid;
							}, $slide_interval);
					}
			}
		else
			{$slide_interval = 0;}
		
		$("[id^='post-']").mouseover(function(){
			keep_open();
			$get_hrefs = $(".post-type");
			$use_id = "#"+$(this).attr("id").replace("post-", "post-type-");
			$.each($get_hrefs,
				function(i,get_hrefs){ 
					$this_id = "#"+this.id;
					if($this_id !== $use_id)
						{$($this_id).animate({"padding-top": "0px"}, {duration: 100});}
					else
						{$($use_id).animate({"padding-top": "5px"}, {duration: 100});}
				});
		});
		
		
		$("[id^='post-']").mouseout(function(){
			$use_id = $(this).attr("id").replace("post-", "post-type-");
			close_menu($use_id);
		});
			
		$("a[id^='feature-href-']").live("click", function(){
			if(!isNaN($slide_interval)){clearInterval($slide_interval);}
			$move_by = 500;
			$newid = $(this).attr("id").replace("feature-href-", "");			
			feature_slide($newid, $.current_feature, $move_by)
			$.current_feature = $newid;
			return false;
		});
		$("#feature-next").live("click", function(){
			if(!isNaN($slide_interval)){clearInterval($slide_interval);}
			$move_by = 500;
			$max_clicks = $("#feature-count").html();	
			if($.current_feature == $max_clicks)
				$newid = 1;
			else
				$newid = (($.current_feature/1)+1)
			feature_slide($newid, $.current_feature, $move_by)
			$.current_feature = $newid;
			return false;
		});
			
		$("#feature-previous").live("click", function(){
			if(!isNaN($slide_interval)){clearInterval($slide_interval);}
			$move_by = 500;
			$max_clicks = $("#feature-count").html();
			if($.current_feature == 1)
				$newid = $max_clicks;
			else
				$newid = (($.current_feature/1)-1)
			feature_slide($newid, $.current_feature, $move_by)
			$.current_feature = $newid;
			return false;
		});		
	});