$(document).ready(function(){
			
			//makes the tabs change while you zoom
			$('.jqzoom').hover(			
					function(){
						$('.imgzoontab').fadeIn();
						$('.normaltab').hide();
						$('#dpip1').hide();
						//$('.picol-1').fadeTo('fast',0.10);
						//$('.jqZoomWindow').fadeIn('fast');					
					},function(){
						//$('.jqZoomWindow').fadeOut('fast');
						//$('.picol-1').fadeTo('fast',1.0);
						$('.imgzoontab').hide();
						$('.normaltab').show();
						$('#dpip1').show();
					}
			);	
			

			$(".jqzoom").jqzoom();
			
			//product info tabs desc/specs/reviews etc..
			$('.pipcontrol').click(function(){
				var id = this.id;
				$('.show-true').addClass('show-false');
				$('.show-true').removeClass('show-true');
				$('#d'+id).addClass('show-true');
				$('.selected').removeClass('selected');
				$('#'+id+' span.citem').addClass('selected');
				return false;
			});
			
			//onload show the correct default image
			$('.large-img-c').fadeOut('fast');
			$('#largeimg-th1').fadeIn('fast');
			
			//image thumbnail click functionality
			$('.imgthumb').click(function(){
				var thisid = this.id;
				//no longer have default image as top of stack - user defined
				$('#largeimg-th1').removeClass('z-index-top');	
				$('.large-img-c').fadeOut('fast');
				$('#largeimg-'+thisid).fadeIn('fast');
				return false;
			});

			//set default image as top of stack
			$('#largeimg-th1').addClass('z-index-top');	
			
			
			//help tooltips
			$('.popup-default-state').removeClass('popup-default-state');
			$('.helpicon .popup').hide();
			
			$('.helpicon').hover(
			function(){
				$(this).children('.popup').fadeIn('fast');
			},function(){
				$(this).children('.popup').fadeOut('fast');
			});
			
			//zoom instructions
			$('#large-img-rel').mouseover(function(){
				$('#large-img-zoom-instr').fadeOut();
			});
			
			$('.errorInfoText').hide();
			
			$('form[name=product_reviews_write]').submit(function(){
				$review_length = $tarea.val().length;
				$form_error = 0;
				if($review_length<50){
					$form_error++;
					$('.validate_review').slideDown();
				} else {
					$('.validate_review').hide();
				}
				if($('#rating').val().length==0){
					$form_error++;
					$('.validate_rating').slideDown();
				} else {
					$('.validate_rating').hide();
				}
				if($form_error>0){
					return false;
				} else {
					return true;
				}
			});
			
			$tarea = $('textarea[name=review]');
			$tarea.keydown(function(){
				$review_length = $tarea.val().length;
				$('#reviewlength').html($review_length);
			});
			$('.rating-star').hover(
				function(){ 
					$star_rating = this.id.substring(7);
					for(var rating_sel = 0; rating_sel <= $star_rating; rating_sel++){
						$('#rating-'+rating_sel).addClass('rating-star-on');
					}
					$(this).click(function(){
						$('#rating').val($star_rating);
					});
				}
				,
				function(){
					$star_rating = this.id.substring(7);
					$selected_rating = $('#rating').val();
					if($selected_rating.length==0){
						for(var rating_sel = 0; rating_sel <= $star_rating; rating_sel++){
							$('#rating-'+rating_sel).removeClass('rating-star-on');
						}
					} else {
						for(var rating_sel = 0; rating_sel <= 5; rating_sel++){
							if(rating_sel<=$selected_rating){
								$('#rating-'+rating_sel).addClass('rating-star-on');
							} else {
								$('#rating-'+rating_sel).removeClass('rating-star-on');
							}
						}
					}
				}
				
			);

			// Dialog			
			$('#dialog').dialog({
				autoOpen: false,
				width: 500,
				height: 500,
				zIndex: 1600,
				buttons: {
					"Close Window": function() { 
						$(this).dialog("close"); 
					}
				}
			});
			
			// Dialog Link
			$('#dialog_link').click(function(){
				$.ajax({
					  url: 'page/sizingguide/?contentonly=1',
					  cache: false,
					  contentType: "text/html; charset=ISO-8859-1",
					  success: function(html){
					    $("#dialog").html(html);
					  }
					});

					$("#dialog").ajaxStart(function(){
						   $(this).html('<img src="/objs/loading.gif" />&nbsp;&nbsp;Loading \'Sizing Guide\'');
					});
				$('#dialog').dialog('open');
				return false;
			});
			//hover states on the static widgets
			$('#dialog_link, ul#icons li').hover(
				function() { $(this).addClass('ui-state-hover'); }, 
				function() { $(this).removeClass('ui-state-hover'); }
			);
			
			function IsNumeric(sText)

			{
			   var ValidChars = "0123456789.";
			   var IsNumber=true;
			   var Char;

			 
			   for (i = 0; i < sText.length && IsNumber == true; i++) 
			      { 
			      Char = sText.charAt(i); 
			      if (ValidChars.indexOf(Char) == -1) 
			         {
			         IsNumber = false;
			         }
			      }
			   return IsNumber;
			   
			   }

			//quanity
			$quantity_input = $('input[name=products_quantity]');
			$quantity_add_button = $('#add-quantity');
			$quantity_input.change(function(){
				$quantity_set = $(this).val();
				if(!IsNumeric($quantity_set)){
					$(this).val(1);
				}
			});
			$quantity_add_button.click(function(){
				var curval_qty = $quantity_input.val();
				$quantity_input.val(Number(curval_qty) + 1);
			});
});

//BOF Product Type Feature
/* DDB - 041031 - Form Field Progress Bar */
/***********************************************
* Form Field Progress Bar- By Ron Jonk- http://www.euronet.nl/~jonkr/
* Modified by Dynamic Drive for minor changes
* Script featured/ available at Dynamic Drive- http://www.dynamicdrive.com
* Please keep this notice intact
***********************************************/
function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        
	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	} else { 
	// progress bar percentage
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	document.getElementById(counter).innerHTML="Limit: "+percentage+"%"
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}
function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}