function popEmb() {
	window.open("/popup/embroidery.html", "Name", "width=600,height=750,resizable=no,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=no,left=20,top=20");
}

function popTether() {
	window.open("/popup/tethered-collar.html", "Name", "width=600,height=550,resizable=no,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=no,left=20,top=20");
}

function popWeight() {
	window.open("/popup/material-weights.html", "Name", "width=650,height=850,resizable=no,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=no,left=20,top=20");
}

function popPrivacy() {
	window.open("/popup/privacy.html", "Name", "width=600,height=800,resizable=no,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=no,left=20,top=20");
}

function popDisclaimer() {
  window.open("/popup/disclaimer.html", "Name", "width=600,height=180,resizable=no,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=no,left=20,top=20");
}

function popSize(style) {
	var link = "/popup/apron_style_" + style + ".html";
	// Window Heigh and Width properties
	switch(style) {
		case 5:
			// Demi Aprons
			var windowWidth = 600;
			var windowHeight = 250;
			break;
		case 6:
			// Patient Aprons
			var windowWidth = 600;
			var windowHeight = 250;
			break;
		case 7:
			// Super Belt
			var windowWidth = 600;
			var windowHeight = 250;
			break;
		default:
			// All others
			var windowWidth = 600;
			var windowHeight = 750;
			break;
	}
	var windowProperties = "width=" + windowWidth + ",height=" + windowHeight + ",resizable=no,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=no,left=20,top=20";
	window.open(link, "Name", windowProperties);
}

$(document).ready(function() {
	$(".inches,.centimeters").hide();
  $("input[name=units]:checked").each(function() {
		console.log($(this).val());
    $("."+$(this).val()).show();
  });
  $("#inches,#centimeters").change(function() {
    $(".inches,.centimeters").hide();
    $("."+$(this).val()).show();
  });

	$('ul.faq li .answer').hide();
	$('ul.faq li > a').click(function(){ $(this).parent().find('.answer').slideToggle(); return false;});

	$(".img-swap").hover(
          function(){this.src = this.src.replace("_off","_on");},
          function(){this.src = this.src.replace("_on","_off");
     });
	$('#nav_tertiary ul li:last-child').css("background","none");
	$('#designer_prints').hide();
	$('#regis_prints').hide();
	$('#pick-your-own').hide();
	$('#slider').mousedown(function(){
		$('#moreSwatchBtn').fadeOut('slow');
	});
/*
	$('#a1').hover(function(e){
		$('#flyout_variweight').show().css({
		   left:  e.pageX,
		   top:   e.pageY
		});
	});
*/
	if ($('#swatches div#nylons a').length <= 16) {
		$('#slider').hide();
		$('#moreSwatchBtn').hide();
	} else {
		$('#slider').slideDown();
		$('#moreSwatchBtn').slideDown();
	}

	$('#control_center ul li:first').addClass('on');
	$('#control_center ul li a').click(function(){
		var currID = $(this).parent().parent().attr("id");
		if( $('#control_center ul li').hasClass('on') ){ $('#control_center ul li').removeClass('on'); } // REMOVE .on FROM PREVIOUS <li>
		$(this).parent().addClass('on'); // set 'on' class for <li> just clicked by user

		if ($('#control_center ul li:nth-child(1)').hasClass('on')) { // VIEW FRONT OF APRON
			$('#control_center ul').css('background-position','0px 0px');
			$('#apron_mask img').attr('src', '/images/mask/'+$('#product_id').val()+'_front.png');
		}
		if ($('#control_center ul li:nth-child(2)').hasClass('on')) { // VIEW BACK OF APRON
			$('#control_center ul').css('background-position','0px 23px');
			$('#apron_mask img').attr('src', '/images/mask/'+$('#product_id').val()+'_back.png');
		}
		if ($('#control_center ul li:nth-child(3)').hasClass('on')) { // SHOW 360 VIEW OF APRON OVERLAY
			$('#control_center ul').css('background-position','0px 46px');
		}
		if ($('#control_center ul li:nth-child(4)').hasClass('on')) { // SHOW HOW TO PUT APRON ON VID
			$('#control_center ul').css('background-position','0px 69px');
		}
		if ($('#control_center ul li:nth-child(5)').hasClass('on')) { // SHOW APRON STYLE SWAPPER
			$('#control_center ul').css('background-position','0px 92px');
		}
		return false;
	});

	$('#thumb_back').click(function(){
		$('#apron_mask img').attr('src','/images/apron-mask-wide-belt-wrap-around-back.png');
	});

	$('#thumb_front').click(function(){
		$('#apron_mask img').attr('src','/images/apron-mask-wide-belt-wrap-around.png');
	});
	$('#thumb_back_vf').click(function(){
		$('#apron_mask img').attr('src','/images/apron-mask-variweight-back.png');
	});

	$('#thumb_front_vf').click(function(){
		$('#apron_mask img').attr('src','/images/apron-mask-variweight.png');
	});

	var clearMePrevious = "";
	$('.clearMeFocus').focus(function() { // clear input on focus
		if($(this).val()==$(this).attr('title')) {
			clearMePrevious = $(this).val();
			$(this).val("");
		}
	});

	$('ul#tabnav li a').click(function(){
		if ($(this).parent().hasClass('tab1') && (!$(this).parent().parent().parent().hasClass('current_tab1'))) { // clicked "Nylons"
			$(this).parent().parent().parent().removeClass();
			$(this).parent().parent().parent().addClass('current_tab1');
			if ($('#designer_prints:visible')) { $('#designer_prints').slideUp('fast'); }
			if ($('#regis_prints:visible')) { $('#regis_prints').slideUp('fast'); }
			$('#nylons').slideDown();
			if ($('#swatches div#nylons a').length <= 16) {
				$('#slider').hide();
				$('#moreSwatchBtn').hide();
			} else {
				$('#slider').slideDown();
				$('#moreSwatchBtn').slideDown();
			}

		}
		if ($(this).parent().hasClass('tab2') && (!$(this).parent().parent().parent().hasClass('current_tab2'))) { // clicked "Designer Prints"
			$(this).parent().parent().parent().removeClass();
			$(this).parent().parent().parent().addClass('current_tab2');
			if ($('#nylons:visible')) { $('#nylons').slideUp('fast'); }
			if ($('#regis_prints:visible')) { $('#regis_prints').slideUp('fast'); }
			$('#designer_prints').slideDown();
			if ($('#swatches div#designer_prints a').length <= 16) {
				$('#slider').hide();
				$('#moreSwatchBtn').hide();
			} else {
				$('#slider').slideDown();
				$('#moreSwatchBtn').slideDown();
			}
		}
		if ($(this).parent().hasClass('tab3') && (!$(this).parent().parent().parent().hasClass('current_tab3'))) { // clicked "Regis Prints"
			$(this).parent().parent().parent().removeClass();
			$(this).parent().parent().parent().addClass('current_tab3');
			if ($('#designer_prints:visible')) { $('#designer_prints').slideUp('fast'); }
			if ($('#nylons:visible')) { $('#nylons').slideUp('fast'); }
			$('#regis_prints').slideDown();
			if ($('#swatches div#regis_prints a').length <= 16) {
				$('#slider').hide();
				$('#moreSwatchBtn').hide();
			} else {
				$('#slider').slideDown();
				$('#moreSwatchBtn').slideDown();
			}
		}

		if ($(this).parent().hasClass('tab4') && (!$(this).parent().parent().parent().hasClass('current_tab4'))) { // clicked "Regis Prints"
			$(this).parent().parent().parent().removeClass();
			$(this).parent().parent().parent().addClass('current_tab4');
			if ($('#designer_prints:visible')) { $('#designer_prints').slideUp('fast'); }
			if ($('#nylons:visible')) { $('#nylons').slideUp('fast'); }
			$('#regis_prints').slideDown();
			if ($('#swatches div#regis_prints a').length <= 16) {
				$('#slider').hide();
				$('#moreSwatchBtn').hide();
			} else {
				$('#slider').slideDown();
				$('#moreSwatchBtn').slideDown();
			}
		}
		if ($(this).parent().hasClass('tab5') && (!$(this).parent().parent().parent().hasClass('current_tab5'))) { // clicked "Regis Prints"
			$(this).parent().parent().parent().removeClass();
			$(this).parent().parent().parent().addClass('current_tab5');
			if ($('#designer_prints:visible')) { $('#designer_prints').slideUp('fast'); }
			if ($('#nylons:visible')) { $('#nylons').slideUp('fast'); }
			$('#regis_prints').slideDown();
			if ($('#swatches div#regis_prints a').length <= 16) {
				$('#slider').hide();
				$('#moreSwatchBtn').hide();
			} else {
				$('#slider').slideDown();
				$('#moreSwatchBtn').slideDown();
			}
		}

	});

	// if field is empty afterward, add text again
	$('.clearMeFocus').blur(function() { if($(this).val()=="") { $(this).val(clearMePrevious); } });

	/* **************************************************************************** TOOL TIP CODE START */

	$('a.tooltip').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		fade: 250
	});

	/* **************************************************************************** TOOL TIP CODE END */
//	if($.cookie('pV')) { $("#switch-"+$.cookie('pV')).css('display','block'); } else { $.cookie('pV','GridView'); }
	$("#swatch_switch_link").click(function(){
			$('.switchView').slideToggle();
			return false;
		});

/*
			 * stickyfloat - jQuery plugin for verticaly floating anything in a constrained area
			 *
			 * Example: jQuery('#menu').stickyfloat({duration: 400});
			 * parameters:
			 * 		duration 	- the duration of the animation
			 *		startOffset - the amount of scroll offset after it the animations kicks in
			 *		offsetY		- the offset from the top when the object is animated
			 *		lockBottom	- 'true' by default, set to false if you don't want your floating box to stop at parent's bottom
			 * $Version: 05.16.2009 r1
			 * Copyright (c) 2009 Yair Even-Or
			 * vsync.design@gmail.com
			 */

			$.fn.stickyfloat = function(options, lockBottom) {
				var $obj 				= this;
				var parentPaddingTop 	= parseInt($obj.parent().css('padding-top'));
				var startOffset 		= $obj.parent().offset().top;
				var opts 				= $.extend({ startOffset: startOffset, offsetY: parentPaddingTop, duration: 200, lockBottom:true }, options);

				$obj.css({ position: 'absolute' });

				/*
				if(opts.lockBottom){
					//var bottomPos = $obj.parent().height() - $obj.height() + parentPaddingTop - 400; //get the maximum scrollTop value
					var bottomPos = $obj.parent().height() - $obj.height() + parentPaddingTop - 0; //get the maximum scrollTop value
					if( bottomPos < 0 )
						bottomPos = 0;
				}
				*/

				$(window).scroll(function () {
					$obj.stop(); // stop all calculations on scroll event

					if(opts.lockBottom){
						//var bottomPos = $obj.parent().height() - $obj.height() + parentPaddingTop - 400; //get the maximum scrollTop value
						var bottomPos = $obj.parent().height() - $obj.height() + parentPaddingTop - 0; //get the maximum scrollTop value
						if( bottomPos < 0 )
							bottomPos = 0;
					}

					var pastStartOffset			= $(document).scrollTop() > opts.startOffset;	// check if the window was scrolled down more than the start offset declared.
					var objFartherThanTopPos	= $obj.offset().top > startOffset;	// check if the object is at it's top position (starting point)
					var objBiggerThanWindow 	= $obj.outerHeight() < $(window).height();	// if the window size is smaller than the Obj size, then do not animate.

					// if window scrolled down more than startOffset OR obj position is greater than
					// the top position possible (+ offsetY) AND window size must be bigger than Obj size
					if( (pastStartOffset || objFartherThanTopPos) && objBiggerThanWindow ){
						var newpos = ($(document).scrollTop() -startOffset + opts.offsetY );
						if ( newpos > bottomPos )
							newpos = bottomPos;
						if ( $(document).scrollTop() < opts.startOffset ) // if window scrolled < starting offset, then reset Obj position (opts.offsetY);
							newpos = parentPaddingTop;

						$obj.animate({ top: newpos }, opts.duration );
					}
				});
			};
			if($('#internal #right').length > 0) {
				$('#internal #right').stickyfloat({ duration: 400, offsetY:60, startOffset:60 });
			}


	if($("#add_special_request").length > 0) {
		if($("#add_special_request").is(":checked")) {
			$("#special_requests").slideDown("fast");
		} else {
			$("#special_requests").slideUp("fast");
		}
		$("#add_special_request").change(function() {
			if($("#add_special_request").is(":checked")) {
				$("#special_requests").slideDown("fast");
			} else {
				$("#special_requests").slideUp("fast");
			}
		});
	}
});
