(function( $ ) {
	var BP = function() {
		jQuery(function() {
			BP.init();
		});
		var _P = {
			optionValues : function() {
				jQuery(".option_color").change(function() {
					var $thisIdx = jQuery(".option_color").index( this );
					var thisOptionSize = [ ".option_size:eq(", $thisIdx, ")" ].join( "" );
					for ( i = 0; i < optionValues[$thisIdx].length; i++ ) {
						jQuery("option", thisOptionSize).each(function() {
							if ( jQuery(this).attr( "value" ) != "" ) {
								jQuery(this).remove();
							}
						});
						if ( optionValues[$thisIdx][i].color == jQuery(this).val() ) {
							var optionValuesArr = optionValues[$thisIdx][i].size;
							for ( j = 0; j < optionValuesArr.length; j++ ) {
								jQuery(thisOptionSize).append( [ "<option value='", optionValuesArr[j], "'>", optionValuesArr[j], "</option>" ].join( "" ) );
							}
							jQuery(thisOptionSize).removeAttr( "disabled" );
							break;
						} else {
							jQuery(thisOptionSize).attr( "disabled", "disabled" );
						}
						
					}
				});
			},
			productTabs : function() {
				jQuery(".tabs a").each(function( i ) {
					if ( i == 0 ) {
						jQuery(this).css( "background-position", "0 0" );
						jQuery(".tabs_content:eq(0)").css( "display", "block" );
					}
					jQuery(this).click(function() {
						jQuery(".tabs a").css( "background-position", "0 -29px" );
						jQuery(this).css( "background-position", "0 0" );
						jQuery(".tabs_content").css( "display", "none" );
						jQuery(".tabs_content:eq(" + i + ")").css( "display", "block" );
						jQuery(this).blur();
						return false;
					});
				});
			},
			buildProductImages : function() {
				jQuery("#product_images_thumbnails .inner").html( "<ul class='reset_display'></ul>" );
				var productImagesWidth = 0;
				for ( i = 0; i < productImages.length; i++ ) {
					productImagesWidth += 79; // 69px + 10px right margin
					jQuery("#product_images_thumbnails .inner ul").append( [ "<li><a href='#'><img src='", productImages[i].thumbnail, "' alt='",productImages[i].aaa,"' title='",productImages[i].aaa,"' /></a></li>" ].join( "" ) );
					if ( i == 0 ) {
						jQuery("#product_images_thumbnails .inner a:eq(0)").addClass( "on" );
					}
				}
				jQuery("#product_images_thumbnails .inner ul").css( "width", productImagesWidth );
				jQuery("#product_images_thumbnails .inner a").mouseover(function() {
					var imgIdx = jQuery("#product_images_thumbnails .inner a").index( this );
					jQuery("#product_images_swatches").html( "" );
					jQuery("#product_image_large").attr( "src", productImages[imgIdx].large );
					jQuery("#product_image_large").attr( "alt", productImages[imgIdx].bbb );
					jQuery("#product_image_large").attr( "title", productImages[imgIdx].bbb );
					_P.runProductImagesSwatches( imgIdx );
					jQuery("#product_images_thumbnails .inner a").removeClass( "on" );
					jQuery(this).addClass( "on" ).blur();
					return false;
				});
				_P.runProductImages();
				_P.runProductImagesSwatches( 0 );
			},
			runProductImages : function() {
				var animating = false;
				var $jObj = jQuery("#product_images_thumbnails .inner ul");
				var $jObjArrowL = jQuery(".arrow_left");
				var $jObjArrowR = jQuery(".arrow_right");
				if ( productImages.length > 4 ) {
					$jObjArrowR.removeClass("arrow_opacity_off");
				}
				$jObjArrowL.click(function() {
					if ( animating == false ) {
		                animating = true;
		                animateLeft = parseInt( $jObj.css( "left" ) ) + ( 79 * 4 );
		                if ( ( animateLeft + parseInt( $jObj.css( "width" ) ) ) <= parseInt( $jObj.css( "width" ) ) ) {
							$jObjArrowR.removeClass( "arrow_opacity_off" );
		                    $jObj.animate({left: animateLeft}, "normal", function() {
		                        jQuery(this).css( "left", animateLeft );
		                        if ( parseInt( $jObj.css( "left" ) ) == 0 ) {
									$jObjArrowL.addClass( "arrow_opacity_off" );
		                        }
		                        animating = false;
		                    });
		                } else {
		                    animating = false;
		                }
		            }
					return false;
				});
				$jObjArrowR.click(function() {
					if ( animating == false ) {
		                animating = true;
		                animateLeft = parseInt( $jObj.css( "left" ) ) - ( 79 * 4 );
		                if ( animateLeft + parseInt( $jObj.css( "width" ) ) > 0 ) {
		                    $jObjArrowL.removeClass( "arrow_opacity_off" );
		                    $jObj.animate({left: animateLeft}, "normal", function() {
		                        jQuery(this).css( "left", animateLeft );
		                        if ( parseInt( $jObj.css( "left" ) ) + parseInt( $jObj.css( "width" ) ) <= 79 * 4 ) {
		                            $jObjArrowR.addClass( "arrow_opacity_off" );
		                        }
		                        animating = false;
		                    });
		                } else {
		                    animating = false;
		                }
		            }
		            return false;
				});
			},
			runProductImagesSwatches : function( idx ) {
				if ( productImages[idx].alt != null ) {
					var altImages = productImages[idx].alt;
					for ( i = 0; i < altImages.length; i++ ) {
						jQuery("#product_images_swatches").append( [ "<a href='#'><img src='", altImages[i].swatch, "' alt='",altImages[i].ccc,"' title='",altImages[i].ccc,"' /></a>" ].join( "" ) );
						jQuery("#product_images_swatches a:eq(" + i + ")").mouseover(function() {
							jQuery("#product_image_large").attr( "src", altImages[ jQuery("#product_images_swatches a").index( this ) ].large );
							jQuery("#product_image_large").attr( "alt", altImages[ jQuery("#product_images_swatches a").index( this ) ].ddd );
							jQuery("#product_image_large").attr( "title", altImages[ jQuery("#product_images_swatches a").index( this ) ].ddd );
							jQuery(this).blur();
							return false;
						});
					}
				}
			}
		}
		return {
			init : function() {
				_P.optionValues();
				_P.productTabs();
				_P.buildProductImages();
			}
		}
	}();
})( jQuery );