/*
*
* ARLOdesign.com scripts
* 
* UPDATES
* 7/24/08 Moved line to hide portfolio images to top to prevent flashes
*
*/




$(document).ready(function(){
	
	$('#images img').css("display","none"); // We hide the portfolio images with JavaScript for accessibility
	
/* Preload Rollover Images
---------------------------*/

	$.preloadImages([
		'/images/icons/category_on.png',
		'/images/icons/comments_on.png',
		'/images/icons/next_on.png',
		'/images/icons/pause_on.png',
		'/images/icons/permalink_on.png',
		'/images/icons/play_on.png',
		'/images/icons/prev_on.png',
		'/images/icons/rss_on.png',
		'/images/icons/trackback_on.png',
		'/images/icons/extlink_on.png'
	]);
	
	
/* Portfolio Images
--------------------*/

	// create caption and nav areas
	$('#images').after('<div id="images-info"></div>');
	$('#images-info').html('<div id="images-caption"><p id="images-caption-p">&nbsp;</p></div><p id="images-nav"></p>');
		
/*	$(window).bind('load', function () { // Start image slideshow once all images have loaded
	    $('#images img:first').fadeIn(2000,function(){$('#images').css("background","none");});
	   	$('#images')
			.cycle({ 
			    fx:     'fade',
			    speed:  'slow',
			    timeout: 5000,
			    pager:  '#images-nav',
			    before:  onBefore, 
			    after:   onAfter 
			});
*/

		$(window).bind('load', function () { // Start image slideshow once all images have loaded
			    $('#images img:first').fadeIn(2000,function(){$('#images').css("background","none");});
			   	$('#images')
					.cycle({ 
					    fx:     'fade',
					    speed:  'slow',
					    timeout: 5000,
					    pager:  '#images-nav',
					    before:  function () {
							$('#images-caption-p').slideUp("slow");
						}, 
					    after:   function () {
						    $('#images-caption-p')
								.html(this.alt)
								.slideDown("slow");
						}
					});

		if ($('p#images-nav').text()) { // add the play/pause button if there is more than one image
			$('#images-nav')
				.append(' <img src="/images/icons/pause_off.png" width="9" height="9" style="cursor: pointer;" id="play-pause" title="Pause slideshow" />')
				.slideDown("slow");
		} else { // Otherwise, populate the caption; cycle won't do it if there is only one image
			$('#images-caption-p')
				.html($('#images img:first').attr("alt"))
				.slideDown("slow");
		}
		
		// add functionality to play/pause button
		
		$("img#play-pause")
			.hover(
				function() {
					current_src = $(this).attr("src");
					$(this).attr("src",current_src.replace(/off.png/,"on.png"));
				}, 
				function() {
					current_src = $(this).attr("src");
					$(this).attr("src",current_src.replace(/on.png/,"off.png"));
				}
		);

		$("img#play-pause")
			.toggle(
				function() {
					current_src = $(this).attr("src");
					$(this).attr("src",current_src.replace(/pause/,"play"));
					$(this).attr("title","Play slideshow");
					$('#images').cycle('pause');
				}, 
				function() {
					current_src = $(this).attr("src");
					$(this).attr("src",current_src.replace(/play/,"pause"));
					$(this).attr("title","Pause slideshow");
					$('#images').cycle('resume');
				}
		);		
	});

/* External Links
----------------------*/

	$("a").filter(function() {
    	return this.hostname && this.hostname !== location.hostname;
  	}).addClass('external')
		.attr('target','_blank')
		.attr('title','Open in New Window');
		
	
/* Blog Images
--------------------*/
		
	$('div.post[id!=post-319] .alignnone').each(function() {
		if (this.alt)
		{
			image_caption = this.alt;
			$(this).parents("p").after('<p class="post-image-caption">' + image_caption + '</p>');
		};
		$(this).parents("p").css("margin-left",0);
		$(this).removeClass('size-full');
	});

	$("div.post[id!=post-319] img.size-full").each(function() {
		if (this.alt)
		{
			image_caption = this.alt;
			$(this).parents("p").after('<p class="post-image-caption">' + image_caption + '</p>');
		};
		$(this).parents("p").css("margin-left",0);
	});
	
	$(".post-story object").each(function() {
		$(this).parents("p").css("margin-left",0);
	});

	
/* Page Navigation
--------------------*/

	$(".pagebar a").each(function(){
		if($(this).text()=='Prev') $(this).addClass('previous');
		if($(this).text()=='Next') $(this).addClass('next');
	});
	
/* Search Field
--------------------*/

	$("input#s").focus(function() { $(this).attr("value",""); });
	$("input#s").blur(function() { $(this).attr("value","Search blog..."); });
	

	
});