jQuery(function($){
	
	
	
	/* js for inputs */
	$('.blink').focus(function () {
		if ($(this).val() == $(this).attr('title')) {
			$(this).val('');
		}
	}).blur(function () {
		if ($(this).val() == '') {
			$(this).val($(this).attr('title'));
		}
	}).blur();
	
						
	// inner nav event dispatchers - should move?		
						
	$('.home-inner-nav a').click(function(){
	
		if(!disableClick){
		
			var subMenuItem = "";
			if($(this).attr("id") == "subnav-btn-home"){
				subMenuItem = "home";
			}
			if($(this).attr("id") == "subnav-btn-work"){
				subMenuItem = "work";
			}
			if($(this).attr("id") == "subnav-btn-people"){
				subMenuItem = "people";
			}
			if($(this).attr("id") == "subnav-btn-services"){
				subMenuItem = "services";
			}
			
			$("#wrapper").trigger('subNavClicked',{ subMenuItem: subMenuItem, animateReps : true });
		
		}
	});
	
	
	//people inner nav
	
	$('.people-inner-nav a').click(function(){
	
		$('.subnav-btn-people').removeClass('active');
		$(this).addClass('active');
				
		var subMenuItem = "";
		if($(this).attr("id") == "subnav-btn-people-team"){
			subMenuItem = "team";
		}
		if($(this).attr("id") == "subnav-btn-people-keith"){
			subMenuItem = "keith-browning";
		}
		if($(this).attr("id") == "subnav-btn-people-minsoo"){
			subMenuItem = "minsoo-pak";
		}
		if($(this).attr("id") == "subnav-btn-people-rob"){
			subMenuItem = "rob-sherrell";
		}
		
		$("#wrapper").trigger('subNavClicked',{ subMenuItem: subMenuItem, animateReps : false });
	});
	
	
	
	//subnav listeners for indiv page templates - **NEED SLUG NAME UPDATES!!!
	
	//home
	$("body.page-id-176").bind('subNavClicked',function(e, data){
	
		
		repSelector = "#home-main-" + data.subMenuItem;
		backgroundFile = "home-background-" + data.subMenuItem + ".jpg";
		
		if(data.subMenuItem == "home"){
			repSelector = "#home-main";
			backgroundFile = "home-background.jpg";
		}
	
		$(".home-main").hide();
		$(repSelector).show();
		//alert(data.subMenuItem);
		
		//alert('trying to reset bg');
		$("body").css("background", "#ffffff url('/wp-content/themes/sparksgrove/images/" + backgroundFile + "') no-repeat center top");
		
		
		
		//trying to animate bg on/off, doesn't work quite right
		/*
		
		$('body').animate({
			backgroundPosition: "(0px 0px)"
		}, 
		1000, 
		function() {
			// Animation complete.
			$("body").css("background", "#ffffff url('/wp-content/themes/sparksgrove/images/home-background-" + data.subMenuItem + ".jpg') no-repeat center -1000");
			$('body').animate({
				backgroundPosition: "(50% 0px)"
			}, 
			1000, 
			function() {
				// Animation complete.
			});
		});
		*/
		
		
		
		
		


	});
	
	//people
	
	/* old:
	
	$("body.page-id-179").bind('subNavClicked',function(e, data){
		$(".people-main-current").slideUp(function(){
			$(".people-main-current").removeClass("people-main-current");
			$("#people-"+data.subMenuItem).addClass("people-main-current");
			$("#people-"+data.subMenuItem).slideDown();
		});
	});
	
	*/
	
	$('#peopleshow').cycle({
        fx:       'scrollHorz',
        timeout:   0,
        after:     function() {
            //nothing
        }
    });
	
	
	$("body.page-id-179").bind('subNavClicked',function(e, data){
	
		//this should be updated to select the slide by the slug name
		var peopleSlideMap = new Array();
		peopleSlideMap["team"] = 0;
		peopleSlideMap["keith-browning"] = 1;
		peopleSlideMap["minsoo-pak"] = 2;
		peopleSlideMap["rob-sherrell"] = 3;
	
		$('#peopleshow').cycle(peopleSlideMap[data.subMenuItem]);
		
	});
	
	
	
	
	
	
	
	
	//work page
	
	$(".work-more-toggle").click(function () {
      $(".work-middle").slideToggle("slow");
    });
    
	
    $('#slideshow').cycle({
        fx:       'scrollHorz',
        timeout:   0,
        pager:  '#work-middle-gallery-pager',
        next:   '#next2',
        cleartypeNoBg: true,  
        after:     function(currSlideElement, nextSlideElement, options, forwardFlag) {
        	
        	//alert('wtf');
        	//alert($(this).children("img:first").attr("alt"));
        	
            $('#work-middle-gallery-title').html($(this).children("img:first").attr("title"));
            $('#work-middle-gallery-caption').html($(this).children("img:first").attr("alt"));
        }
    });
    
    
    
    //news page
    
    $(".news-more-btn").click(function () {
    	
    	/*
	    var el = $('.top-news'),
	    curHeight = el.height(),
	    autoHeight = el.css('height', 'auto').height();
		el.height(curHeight).animate({height: autoHeight}, 1000, function(){
			$(".news-more-btn").fadeOut();
		});
		*/
		
		$('.top-news-more').slideDown(function(){
			$(".news-more-btn").fadeOut();
		});
    
    });
    
    
    
    //services page
    
    $('.services-subnav').click(function () {
    	
    	//nav state changes are handled by accordian directly
    	//$('.services-subnav').removeClass("active");
    	//$(this).addClass("active");
    	
    	var serviceId = $(this).attr("sid");
    	$("#serv" + serviceId).trigger("click");
    
    });
    
    //generic representation slideout listener
    
    
    jQuery.fn.extend({
	  slideOn: function() {
	    return this.each(function() {
	      jQuery(this).css("margin-left", "310px"); 
	      jQuery(this).css('display', 'block');
	      jQuery(this).animate({marginLeft: 0});
	    });
	  },
	  slideOff: function() {
	    return this.each(function() {
	      jQuery(this).animate(
	      	{marginLeft: 300},
	      	500,
	      	function(){
	      		jQuery(this).css('display', 'none');
	      	}
	      );
	    });
	  },
	  slideToggleMargin: function() {
	    return this.each(function() {
	      var el = jQuery(this);
	      if (el.css('display') == 'none') {
	        el.slideOn();
	      } else {
	        el.slideOff();
	      }
	    });
	  }
	});
	
	
	
	jQuery.fn.extend({
	  slideRight: function() {
	    return this.each(function() {
	      jQuery(this).animate({width: 'show'});
	    });
	  },
	  slideLeft: function() {
	    return this.each(function() {
	      jQuery(this).animate({width: 'hide'});
	    });
	  },
	  slideToggleWidth: function() {
	    return this.each(function() {
	      var el = jQuery(this);
	      if (el.css('display') == 'none') {
	        el.slideRight();
	      } else {
	        el.slideLeft();
	      }
	    });
	  }
	});
	
	
	
	
	
    

	
	
							
	
})
