jQuery(document).ready(function($) {
	jQuery.fn.exists = function(){return jQuery(this).length>0;}
	
	$('#q').bind({
		click: function() {
			if (this.value === "Search bubba") this.value = "";
		},
		blur: function() {
			if (this.value === "") this.value = "Search bubba";
		}
	});
	
	$('#locate_store').bind({
		click: function() {
			if (this.value === "Zip Code") this.value = "";
		},
		blur: function() {
			if (this.value === "") this.value = "Zip Code";
		}
	});
	
	$('#join_team_name').bind({
		click: function() {
			if (this.value === "name") this.value = "";
		},
		blur: function() {
			if (this.value === "") this.value = "name";
		}
	});
	
	$('#join_team_email').bind({
		click: function() {
			if (this.value === "email") this.value = "";
		},
		blur: function() {
			if (this.value === "") this.value = "email";
		}
	});
	
	$('#nav li').bind({
		mouseenter: function() {
			$(this).children('.subnav').each(function() {
				$(this).css('display', 'block');
			});
		},
		mouseleave: function() {
			$(this).children('.subnav').each(function() {
				$(this).css('display', 'none');
			});
		}
	});
	
	$('#locate_go').bind({
		click: function() {
			$('#store_locator_form').submit();
		}
	});
	
	$('#join_team_submit').bind({
		click: function() {
			$('#join_team_form').submit();
		}
	});
	
	// Latest Work
	if($('#bubba_photos').exists()) {	
		var lwSlider = $('#bubba_photos').bxSlider({
			mode:'horizontal',
			controls: false,
			auto:false,		
			speed:500,			
			infiniteLoop: true,			
			easing: 'easeOutCubic',
			displaySlideQty: 6,
			onFirstSlide: function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject) {
				$('#show_prev').hide();
			}
		});		
		
		$('#show_prev').click(function() {
			var move = true;
			if (move) {
				lwSlider.goToPreviousSlide();
			}
            return false;
        });
        
        $('#show_next').click(function() {
            lwSlider.goToNextSlide();
            return false;
        });  
		
		$('#polaroid_flash').fadeOut();
		
		$('#bubba_photos li img').click(function() {
			$('#polaroid_flash').fadeIn(0);
			var path = $(this).attr('src').replace('86x59', '340x340');
			var title = $(this).attr('title');
			var post_id = $(this).attr("rel");
						
			$('.polo').attr('src', path);
			$('#poloroid h2').html(title);
			$('#polaroid_flash').fadeOut();
						
			$("#your_post_here").load("/triqui-ajax/",{id:post_id});
		
			return false;
		});
		
		$.ajaxSetup({cache:false});
		$("h2 a").click(function(){
			
			$("#your_post_here").html("loading...");
			$("#your_post_here").load("http://<?php echo $_SERVER[HTTP_HOST]; ?>/triqui-ajax/",{id:post_id});
			return false;
		});
	}
	
});
