// Nashua Symphony
//
// Site by Drexler [drxlr.com]
// Matt Coleman [mynameismattcoleman.com]


jQuery(function ($) {

	$('input[name*="man"]').val('has man in it!');

	//Remove after 6_25_11
	$(function() {
    	var killbutton = $('.page-id-5 a[href*="?retail=nsoc"]');
    //	$(killbutton).remove();
	});

	$('h1 a').hover( function() {
		$('#nav li').fadeTo(50, 0);
		$('#header h2').css('z-index','500');
		$('#header h2').fadeTo(100, 1);
		}, function() {
		$('#nav li').fadeTo(250, 1);
		$('#header h2').css('z-index','0');		
		$('#header h2').fadeTo(50, 0);
		});

		$('#social a').fadeTo(50, .5);
		$('#social a').hover( function() {
			$(this).fadeTo(50, 1);
			}, function() {
			$(this).fadeTo(50, .5);
		});

	
	$('.jp-playlist-player').hover( function() {
		$('#playlist-wrap').slideDown();
		}, function() {
		$('#playlist-wrap').slideUp();
	});

	//Gallery Expand
	//$('.wide-gall-nav a').fadeTo(0, .5);
	//$('.wide-gall-nav a').hover( function() {
		//$(this).fadeTo(150, 1);
		//}, function() {
		//$(this).fadeTo(150, .5);
		//});

    // Pad in the Nav Bar
    var viewportWidth = $(window).width();
		$('#nav').width(viewportWidth - 94);

	$(window).resize(function(){
		var viewportWidth = $(window).width();
		$('#nav').width(viewportWidth - 94);
	});

//	$('#dd-events li a').each(function() {
//	    var curr = $(this).text().length;
//	    if(curr >= 33){ //Set threshold of characters
//	    	$(this).substring(0,33);
//	    }
//	});

$('#dd-events li a').each(function() {
		var text = $(this).text();
		if(text.length > 18) {
			text = text.substring(0, 18);
			$(this).text(text).append('&hellip;');
		}
	});
	
	//Collapse Feature
	//$('.collapse').click( function(h) {
	//	var featHeight = $('#feature-wrap').height();
	//		if( featHeight > 84 ) {
	//		$('#feature-wrap').animate({
	//			height: '84'
	//		}, 300, function() {
	//			$('.collapse').addClass('collapsed').attr('title', 'Open');
	//		});		
	//	}else {
	//		$('#feature-wrap').animate({
	//			height: '400'
	//		}, 300, function() {
	//			$('.collapse').removeClass('collapsed').attr('title', 'Close');
	//		});
	//	
	//	}
	//	h.preventDefault();
	//});

	$('#mini-events tr:even').addClass('odd');

	// Cycles
	
	$('#feature-wrap #feature').cycle({ 
	    fx: 'fade',
	    speed: 500,
	    pager: '#feat-nav',
	    timeout: 6000
	 });

	$('#photos').cycle({ 
	    fx: 'scrollLeft', 
	    speed: 250,
	    next: '.photo-next', 
	    prev: '.photo-prev',
	    timeout: 0
	 });

	$('#meet ul').cycle({ 
	    fx: 'fade', 
	    speed: 250,
	    next: '.meet-next', 
	    prev: '.meet-prev',
	    timeout: 0
	 });

	$('#sponsor-cycle ul').cycle({ 
	    fx: 'fade', 
	    speed: 250,
	    delay: -2000,
	    random: 1,
	 });

	$('#quotes').cycle({ 
	    fx: 'fade', 
	    speed: 250,
	    timeout: 6000,
	    delay: -2000,
	    random: 1,
	 });

	
	$('#to-top').hide();
	
	//To Top Functions
	$(window).scroll( function() {
		var windowTop = $(window).scrollTop();
	    if($(this).scrollTop() > 500) {
	        $('#to-top').fadeIn(400);
	        $('#to-top').css({ 'top' : '195px' , 'position' : 'fixed' , 'left' : '951px' });
	    } else {
	        $('#to-top').fadeOut(150);
	    }
	});
		
	function filterPath(string) {
		  return string
		    .replace(/^\//,'')
		    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
		    .replace(/\/$/,'');
		  }
		 
		  var locationPath = filterPath(location.pathname);
		  $('a[href*=#]').each(function() {
		    var thisPath = filterPath(this.pathname) || locationPath;
		    if (  locationPath == thisPath
		    && (location.hostname == this.hostname || !this.hostname)
		    && this.hash.replace(/#/,'') ) {
		      var $target = $(this.hash), target = this.hash;
		      if (target) {
		        var targetOffset = $target.offset().top;
		        $(this).click(function(event) {
		          event.preventDefault();
		          $('html, body').animate({scrollTop: targetOffset}, 600, function() {
		            location.hash = target;
		          });
		        });
		      }
		    }
		  }); 


		//$('.page-id-94 ul li').find('a').each(function() {
		//	var Surl = $(this).attr("href");
		//	$(this).parent().append('<span><a href="' + Surl + '">Link</a></span>');
		//});


// Set Initial Image Size
    var viewportWidth = $(window).width();
	var viewportHeight = $(window).height();
	var halfHeight = (viewportHeight / 2);
	
	$('#story img').hide();
	var imgHeight = (viewportHeight - 25);
	$('#story img').height(imgHeight).width("auto");
	$('#story img').fadeIn();


	//$("#bio:nth-child(-n+6)").wrap("<div class='bio'></div>");
	 
	$('.page-id-40 #copy h3').next('div').hide();
	$('.page-id-40 #copy h3 a').click(function() { 
		 if( $(this).parent().next('div').is(":visible") ){
		 	$(this).removeClass('expanded');
	     	$(this).parent().next('div').slideUp();
	        // alert(id); 
	        //}
	     	//if( $(this).parent().next('div').is(":visible") ){
			 //	$(this).addClass('expanded');
	     	//	$(this).parent().next('div').slideDown();
	        // alert(id); 
	     	//   }
        }else{
            $(this).addClass('expanded');
	     	$(this).parent().next('div').slideDown();
        }	        
	     return false; 
	     }); 


	//Toggle List & Calendar View
	
	$('.list-view-tog').addClass('active-view');
	
	$('.cal-view-tog').click( function() {
				$(this).addClass('active-view');
				$('.list-view-tog').removeClass('active-view');
				$('#copy').addClass('cal-view');
				$('#copy').removeClass('list-view');
				return false;
	});

	$('.list-view-tog').click( function() {
				$(this).addClass('active-view');
				$('.cal-view-tog').removeClass('active-view');
				$('#copy').addClass('list-view');
				$('#copy').removeClass('cal-view');
				return false;				
	});
	
	//Table Special Sauce
	
	
	$('#copy .events_list li:odd').addClass('alt');
	
	//$('.em-calnav:eq(0)').addClass('cal-prev');
	//$('.em-calnav:eq(1)').addClass('cal-next');
	
	$(function() {
    	var credits = $('#em-wrapper p:contains("Powered by")');
    	$(credits).remove();
	});

	$('.page-id-5 #copy .span-bar ul li').fadeTo(0, .4);
	$('.page-id-5 #copy .span-bar ul li').hover( function() {
		$(this).fadeTo(100, 1);
		}, function() {
		$(this).fadeTo(150, .4);
		});

		$('#social a').fadeTo(50, .7);
		$('#social a').hover( function() {
			$(this).fadeTo(50, 1);
			}, function() {
			$(this).fadeTo(50, .7);
		});
	
	//Make these pictures slide
				
				// Vars

    			var activeImg = 0;
				var TotalImgs = $('#wide-gallery img').size();

				
			    // IMAGE SLIDING
			    // First, NEXT

			    $(".wide-gall-nav .next a").click(function(){
			        if (activeImg < TotalImgs) {
			            var crntSlide = activeImg;
			            crntSlide++;
						$('#wide-gallery-wrap').scrollTo('#wide-gallery li:eq('+crntSlide+')', 200, {offset: -85, axis: 'x', onAfter:function(){
			            		activeImg = crntSlide;
			                }
			            }); 
			        }
			        
			        if (activeImg == TotalImgs) {
						$('#wide-gallery-wrap').scrollTo('#wide-gallery li:eq(0)', 200, {offset: -85, axis: 'x', onAfter:function(){
			            		activeImg = crntSlide;
			                }
			            });
			        } 
			        
			        else {
			        	
			        }
			        
			        event.preventDefault();
			        
			    });


				// Now, PREV

			    $(".wide-gall-nav .prev a").click(function(){
			        if (activeImg > 0) {
			            var crntSlide = activeImg;
			            crntSlide--;
						$('#wide-gallery-wrap').scrollTo('#wide-gallery li:eq('+crntSlide+')', 200, {offset: -85, axis: 'x', onAfter:function(){

			            		activeImg = crntSlide;
			                }
						});
					
					} else {
					
						
					}
					
					event.preventDefault();
			    });


	$('.classofbio').hide();
	
	//$('.collapse').click( function(h) {
	//	var featHeight = $('#feature-wrap').height();
	//		if( featHeight > 84 ) {
	//		$('#feature-wrap').animate({
	//			height: '84'
	//		}, 300, function() {
	//			$('.collapse').addClass('collapsed').attr('title', 'Open');
	//		});		
	//	}else {
	//		$('#feature-wrap').animate({
	//			height: '400'
	//		}, 300, function() {
	//			$('.collapse').removeClass('collapsed').attr('title', 'Close');
	//		});
	//	
	//	}
	//	h.preventDefault();
	//});

	//Set/Clear Default Input Value
	$('.fields_email').each(function() {
	       var default_value = this.value;
	       $(this).focus(function(){
	               if(this.value == default_value) {
	                       this.value = '';
	               }
	       });
	       $(this).blur(function(){
	               if(this.value == '') {
	                       this.value = default_value;
	               }
	       });
	});


	//Venue Map


	$('#single-map .em-location-map').css({
		'width' : '250px',
		'max-width:' : '250px',
		'height' : '300px'
	});

	$('#content h1').each(function() {
	    var curr = $(this).text().length;
	    if(curr >= 38){ //Set threshold of characters
	    $(this).css({
	    'font-size' : '2.4em',
	    'letter-spacing' : '-1px',
	    'margin-top' : '15px'
	    });
	    }
	});

// Conductor Bows...

});
