 var $j = jQuery.noConflict();

$j(function(){
	
	$j(document).pngFix(); 
	
	
	//search
	$j('#search-input')
		.focus(function(){
			$j(this).css('background-position', '0 -27px');
		})
		.blur(function(){
			if(!$j(this).val()) {
				$j(this).css('background-position', '0 -3px');
			}
		});
		
	//footer
	positionFooter();   
	function positionFooter(){

		var winHeight = $j(window).height();	
		var footerHeight = $j("#footer").height();
		var wrapHeight = $j("#wrapper").height();
		
		if((winHeight - footerHeight ) < wrapHeight ) {
			$j("#footer").css({top: "0px"})	
	 	} else {
			$j("#footer").css({top: ((winHeight - wrapHeight ) - footerHeight )+"px"})	
		}
	}
 
	$j(window)
		.scroll(positionFooter)
		.resize(positionFooter);

	// gallery
	var $thumbs = $j('#thumbs');
	if( $thumbs[0] ){

		 var gallery = $thumbs.galleriffic({
		 			numThumbs:                 5,
		 			preloadAhead:              5,
					renderNavControls:         false,
					enableBottomPager:         false,
					defaultTransitionDuration: 500,
					imageContainerSel:      '#slideshow1',
					controlsContainerSel:   '#controlss', captionContainerSel: '#caption' ,
					onPageTransitionIn:        function() {
						var prevPageLink = this.find('a.prev').css('visibility', 'hidden');
						var nextPageLink = this.find('a.next').css('visibility', 'hidden');
						
						// Show appropriate next / prev page links
						if (this.displayedPage > 0)
							prevPageLink.css('visibility', 'visible');

						var lastPage = this.getNumPages() - 1;
						if (this.displayedPage < lastPage)
							nextPageLink.css('visibility', 'visible');

						this.fadeTo('fast', 1.0);
					}

				});
				
				$j( $j('#thumbs li ')[4] ).css('margin', '0');
				
				
				gallery.find('a.prev').click(function(e) {
					gallery.previousPage();
					e.preventDefault();
				});

				gallery.find('a.next').click(function(e) {
					gallery.nextPage();
					e.preventDefault();
				});

	}

});

