$(function(){
	$('#footer .footerNav li:last a').css('border-right', 'none');
	//nav and subnav
	var currentSubNav= null;
	$('.nav li a').bind('mouseover', function(){		
		$('.nav li a.selected').removeClass('selected');
		$(currentSubNav).css('display','none');
		currentSubNav=$('ul.'+$(this).attr('class')+'-subNav');
		if(($(currentSubNav).length > 0)){
			$(currentSubNav).css('display','block');
			$(this).addClass('selected');
			$(this).css({cursor : 'default'});
			$('.nav').css({ 
				  //background : 'url(_images/transparentBlack-bg.png)', 
				  width : '145px'
			})
		} else {
			$('.nav').css({background : 'none'});			
		}
		return false; 
	});	
	//photo gallery
	var photosIsPlaying=true; //keep track if photo gallery is playing
	function togglePlaying (doWhat){
		if(photosIsPlaying==true | doWhat=='stop'){
			$('.photos').cycle('pause');
			$('#startStop').text('Start Autoplay');
			photosIsPlaying=false;
		} else {
			$('.photos').cycle('resume');	
			$('#startStop').text('Stop Autoplay');
			photosIsPlaying=true;
		}
		
	}
	function onBefore(){
		if(parseInt(this.id.substr(this.id.indexOf('_')+1,this.id.length))<=0){
			$('#previousPhoto').css('display', 'none');								   
		} else {
			$('#previousPhoto').css('display', 'block');	
		}
		if(parseInt(this.id.substr(this.id.indexOf('_')+1,this.id.length))>=$('.photos li').length){
			$('#nextPhoto').css('display', 'none');								   
		} else {
			$('#nextPhoto').css('display', 'block');	
		}
		return false; 
	}
	function onAfter(){
		//update selected thumbnail
		$('.thumbnails a.selected').removeClass('selected');
		$('#thumbnail_'+parseInt(this.id.substr(this.id.indexOf('_')+1,this.id.length))).addClass('selected');
		return false; 
	}
	$('.photos').cycle({ 
		fx:     'fade', 
		speed:   800, 
		timeout: 8000, 
		pause:   1,
		startingSlide:0,
		next:   '#nextPhoto', 
		prev:   '#previousPhoto',
		before:   onBefore,
		after:   onAfter
	});	
	//attach the click action to the thumbnail links
	$('.thumbnails a').bind('click', function(){ 
		$('.photos').cycle(parseInt(this.id.substr(this.id.indexOf('_')+1,this.id.length))-1); 
		$('.photos').cycle('pause');
		togglePlaying ('stop');
		return false; 
	});
	/*//attach the click action to the pagination links
	$('.pagination a').bind('click', function(){
		//alert($('.pagination a').index(this));	
		$(".thumbnails", this).stop().animate({top:'100px'},{duration:300}); 
		return false; 
	});*/	
	$('#startStop').click(function () { 
		togglePlaying ();
		return false;	
	});
});