

/**
 * @name  inputPlaceholder
 * @desc  Polyfill for placeholder text
 */
function inputPlaceholder(){
     if (!Modernizr.input.placeholder) {
          jQuery("input[placeholder], textarea[placeholder]").each(function(){
               if (jQuery(this).val() == "") {
                    jQuery(this).val(jQuery(this).attr("placeholder"));
                    jQuery(this).focus(function(){
                         if (jQuery(this).val() == jQuery(this).attr("placeholder")) {
                              jQuery(this).val("");
                              jQuery(this).removeClass('placeholder');
                         }
                    });
                    jQuery(this).blur(function(){
                         if (jQuery(this).val() == "") {
                              jQuery(this).val(jQuery(this).attr("placeholder"));
                              jQuery(this).addClass('placeholder');
                         }
                    });
               }
          });
	
          jQuery('form').submit(function(){
               // first do all the checking for required element and form validation. 
               // Only remove placeholders before final submission
               var placeheld = jQuery(this).find('[placeholder]');
               for (var i = 0; i < placeheld.length; i++) {
                    if ((jQuery(placeheld[i]).val() == jQuery(placeheld[i]).attr('placeholder'))) {
                         // if not required, set value to empty before submitting
                         jQuery(placeheld[i]).attr('value', '');
                    }
               }
		
          });
     }
}

/**
 * Clickable thumbnails for product detail page
 */
function thumbGallery(){
    var thumb_links = $('#thumb-slider a');

    thumb_links.each(function(){
        
        $(this).click(function(e){
            var thumb_link = this;
            var new_image = $(thumb_link).index('#thumb-slider a');

                $('#thumb-slider a').removeClass('active');	
                		
			    var src = $(this).attr('href');
			    $(this).addClass('active');

				if (src != $('img#largeImg').attr('src').replace(/\?(.*)/,'')){
					$('img#largeImg').stop().animate({
						opacity: '0'
					}, function(){
						$(this).attr('src', src+'?'+Math.floor(Math.random()*(10*100)));
					}).load(function(){
						$(this).stop().animate({
							opacity: '1'
						});
					});
				}
			    return false;
		})
	})
}
