// Global Javascript 

// Preloads images
jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
}

//simple style slide swapper (SSSS)
function initgallery() {
	$('a').each(function() {
		if (this.getAttribute('href') && (this.getAttribute('rel') == 'slide')){
			this.onclick = function () {
				$theLink = $(this).attr('href');
				$("#projectimage").fadeOut("slow",
				function () {
					$("#projectimageholder").html('<img src="'+$theLink+'" alt="'+this.getAttribute("title")+'" title="'+this.getAttribute("title")+'" />');
					setTimeout("$('#projectimage').fadeIn('slow')", 1000);
				}
				);
				return false;
			}
		}
	});
}
	


$(document).ready(
// extra space separator

	function() {//top level function

//init SSSS
		initgallery();

// strip right margin from last global nav li
		$('#global_nav>ul>li:last-child').addClass("last");//set the class of last LI in ul#nav-left to last
		
//protect email addresses
$theText = "info@katiewinter.com";
$("div.email").children("a").text($theText, true).attr("href", "mailto:"+$theText);

		var $state="closed";
		$('a.toggler').click(//open click
			function()
			{
				var $nextDiv = $('div.clever');
				var $nextSpan = $('span.tricky');
				if($state=="closed")
				{
					$nextDiv.fadeIn("slow", 
						function() {
							$nextSpan.fadeIn("slow");
						}
					);
					$state="open";
				}
				else
				{
					$nextSpan.fadeOut('slow',
						function() {
							$nextDiv.fadeOut("slow");
						}
					);
					$state="closed";
				}
				return false;
				
			}
		);//close click
		
		/*open imageswapper
			$theTarget = $('div#projectimage');
			$theImage = $theTarget.children("img");

		$('a.projectimagelink').each(					//open each
			function() {
				$(this).bind(											//open bind
				"click",
					function() {
						$theLink = $(this).attr("href");
						$theImage.fadeOut("slow",			//fade out, replace src in callback
							function() {								//the callback
								$theImage.attr("src", function() { return $theLink });
							}														//end callback
						);														//end fade out (.pause(1200))
						$theImage.fadeIn("slow");
						return false;
					}
				)																	//close bind
			}
		);																		//close each
		//end imageswapper*/ 
		
		// make links with rel=external open in new window
    $("a[@rel='external']").addClass("external").attr("title","Link to an external site").click(
    	function() {
    		window.open($(this).attr("href")); return false;//window.open
    	}
    );
		
		
		
	}//close top level function




// extra space separator
); //close doc.ready
