function SmoothScroll() {
	$('.scroll').click(function() {
	  if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
	  && location.hostname == this.hostname) {
		var $target = $(this.hash);
		$target = $target.length && $target
		|| $('[name=' + this.hash.slice(1) +']');
		if ($target.length) {
		  var targetOffset = $target.offset().top;
		  $('html,body')
		  .animate({scrollTop: targetOffset}, 1000);
		 return false;
		}
	  }
	});
}

$(document).ready(function(){
	
	SmoothScroll();
	$(document).pngFix();
	$('input').customInput();
	$("a[rel*='external']").attr({ target: "_blank" });

	var volatile = $("input[type=text], textarea")
	volatile.focus(function(event){
        if ($(this).val() == $(this).attr("title") ){        
            $(this).val("");
        }}, volatile.blur(function(event){
            if ($(this).val() == "" ){        
                $(this).val($(this).attr("title"));
            }
        }
    ));

	$(".faqAccordion").accordion({autoHeight: false});

	//Lightbox
	$(".lightbox").each(function() {
		$(this).ariaLightbox({
			pos: "auto",
			em: false,
			zIndex: "9999",
			titleText: getLightboxTitle(this),
			makeHover: false,
			disableWidth: 1,
			disableHeight: 1,
			descText: function() {
				return $(this).find("img").attr("rel");
			}
		});
	});
	
	function getLightboxTitle(link) {
		var img = $(link).find("img");
		return (img.attr("alt")) ? img.attr("alt") : 'Image';
	}

	//Lightbox Gallery
	
	var lightbox = $(".imageGallery").ariaLightbox({
		imageArray: "a.galleryLightbox",
		altText: function() {
			return $(this).find("img").attr("alt");
		},
		descText: function() {
			return $(this).find("img").attr("alt");
		},
		useDimmer: true,
		pos: "auto",
		disableWidth: 1,
		disableHeight: 1,
		makeHover: false,
		titleText: 'Gallery',
		em: false
	});		
	
	// Image Swapper
	$(".galleryContainer .imageGallery a").click(function() {
		var mainImagePath = $(this).attr("rel"); //Find Main Image
		var lightboxImagePath = $(this).attr("href"); //Find Full Size Image (Lightboxed)
		var imageName = $(this).children().attr("alt"); // Name of the image
		var mainImage = $(".imageContainer img"); // Image to replace
		mainImage.fadeOut('normal',
			function() {
				$(this).attr({ src: mainImagePath, alt: imageName });
				$(this).parent().attr({ href: lightboxImagePath });
				$(this).fadeIn();
			}
		);
		return false;		
	});
	
	$('#customVideoPlayer').flash({
		src: '/_images/flash/YoutubePlayer.swf',
		width:650,
		height: 400,
		flashvars:	{
			videoID:"yAJn3CD2atU", 
			videoQuality:"hd1080", 
			videoBackgroundColor:"0x666666",
			strokeColor:"0x999999",
			controlColor:"0x333333",
			controlHoverColor:"0xed1c24",
			defaultVol:30
		}
	});
	
});
