(function($){
   $.fn.clearDefault = function(){
      return this.each(function(){
         var default_value = $(this).val();
         $(this).focus(function(){
            if ($(this).val() == default_value) $(this).val("");
         });
         $(this).blur(function(){
            if ($(this).val() == "") $(this).val(default_value);
         });
      });
   };
})(jQuery);


$(function() {


	/*	CHANGE PAGE ON BUSINESS DIRECTORY DROP DOWN CHANGE
		-------------------------------------------------------------*/
		
		$("#submit").hide();
		
		$("#directory select").change(function() {
		    window.location = $("#directory select option:selected").val();
		})
		
		
		
		
	/*	PRINT PAGE WHEN CLICKING LINK WITH ID OF PRINT (MASTHEAD)
		-------------------------------------------------------------*/		
		$("li a#print").click(function() {
			window.print();
			return false;
		});



   
	/*	REMOVE DOTTED OUTLINE ON A:LIVE
		-------------------------------------------------------------*/
		 
		$('a')
		 .live('mousedown', function(e) { 
		    e.target.blur(); 
		    e.target.hideFocus = true; 
		    e.target.style.outline = 'none' 
		 })
		 .live('mouseout', function(e) { 
		    e.target.blur(); 
		    e.target.hideFocus = false; 
		    e.target.style.outline = null; 
		 });
		 
		 
		 
	/*	FORM VALIDATION
		-------------------------------------------------------------*/
		
		$("form").validate();
		$("#checkout_form").validate();
		
		
		
	/* 	COLORBOX LINKS
		-------------------------------------------------------------*/
		
		$(".colorbox").colorbox();
		
		
		
	/*	HOMEPAGE SCROLLER
		-------------------------------------------------------------*/
		       
		 show_caption = function(index) { $('.scroller .images ul').children('li:eq('+index+')').children('p').animate({ bottom: 0 }); }
		 hide_captions = function() { $('.scroller .images p').css({ bottom: -75 }); }
		 scroll_to = function(index) { $('.scroller .images ul').stop().animate({ top: index * -310 }, function() { hide_captions(); show_caption(index); }); }
		 
		 $('.scroller .nav a').click(function() {
		    scroll_to($(this).parent().index());
		    $('.scroller .nav .on').removeClass('on');
		    $(this).parent().addClass('on');
		    return false;
		 });
		 
		 show_caption(0);
		
		
	
	/*	SLIDERS
		-------------------------------------------------------------*/     
		   
		$('.grid_slider').mikos_slider();
	    $('.linear_slider').mikos_slider({
	       visibleElements: 4
	    });
		
		
		
	/*	TABS
		-------------------------------------------------------------*/
		
		$('.tabbed').each(function() {
			$(this).children(".content:gt(0)").hide();
		});
		    
		$('.tabs a').click(function() {
			$(this).parent().addClass('on').siblings().removeClass('on');
			$(this).parents('.tabbed').children('.content').hide().end().children('.content:eq('+$(this).parent().index()+')').show();
			return false;
		});
		  
		
		
	/*	EXTERNAL LINKS
		-------------------------------------------------------------*/
		
		$("a.external").click( function() {
			window.open( $(this).attr("href") );
			return false;
		});
		
		
		
	/*	CLEAR INPUT FIELDS ONFOCUS
		-------------------------------------------------------------*/
		  
		$("input.clearinput").clearDefault();  
		
		

	/*	INPUT MASKING
		-------------------------------------------------------------*/
				
		$("input.phone").mask("(999) 999-9999");
		$("input.zipcode").mask("99999");
		var creditcard = $("#credit_card_number").mask("9999 9999 9999 9999");
		
		$("#payment_type").change(
			function() {
				switch ($(this).val()){
				case 'American Express':
				creditcard.unmask().mask("9999 999999 99999");
				break;
				default:
				creditcard.unmask().mask("9999 9999 9999 9999");
				break;
			}
		});
				  

	});
