jQuery(function(){

	//blink fields
	 jQuery('.blink').
	    focus(function() {
	        if(this.title==this.value) {
	            this.value = '';
	        }
	    }).
	    blur(function(){
	        if(this.value=='') {
	            this.value = this.title;
	        }
	    });

	//navigation dropdown
	jQuery('#navigation > li').hover(function(){
		jQuery(this).find('.dd').toggle();
	});

	//home slideshow
	jQuery("#slideshow li").simpleFade({
		speed: 1200,
		auto: 5,
		init: function(){
			slideshowFader = this;

			//create external controls
//			jQuery("#slideshow-thumbs .slider ul li").click(function(){
//				var idx = jQuery(this).index();
//				slideshowFader.fadeTo(idx);
//				return false;
//			});
		},
		onFade: function(index){
			jQuery('#slideshow-thumbs .slider ul li a').removeClass('active');
			jQuery('#slideshow-thumbs .slider ul li a').eq(index).addClass('active');
		}
	});

	//home slideshow thumbs
	jQuery("#slideshow-thumbs ul").jcarousel({
		auto: 5,
		visible: 4,
		scroll: 1,
		wrap: 'circular',
		buttonNextHTML: null,
		buttonPrevHTML: null,
		initCallback: slideshowThumbs_initCallback
	});

	//product page slideshow
	jQuery(".product-overview .slideshow #big-img-slider a").simpleFade({
		speed: 700,
		auto: false,
		init: function(){
			productFader = this;

			//create external controls
			jQuery('.product-overview .slideshow #thumbs a').click(function(){
				var idx = jQuery(this).index();
				productFader.fadeTo(idx);
				return false;
			})
		}
	});

	//colorbox
		jQuery('a[rel="colorboxsizechart"]').colorbox({
			opacity: 0,
			scrollling: false,
			current: '',
			onComplete: function() {
				jQuery.colorbox.resize();
			}
		});

		//close colorbox
		jQuery(".ajax-popup .close, #email-friend-popup input[type='button'] ").live('click', function(){
			jQuery.colorbox.close();
			return false;
		});

	//size chart tabs
		jQuery("#size-chart .links a").live('click', function(){
			var idx = jQuery(this).parent().index();
			jQuery('#size-chart .links a').removeClass('active');
			jQuery(this).addClass('active');
			jQuery('#size-chart .tab').hide();
			jQuery('#size-chart .tab').eq(idx).show();
			jQuery.colorbox.resize();
			return false;
		});

	//zoom product image
	jQuery('.product-overview .slideshow .main a').jqzoom({
            zoomType: 'standard',
            lens:false,
            preloadImages: true,
            alwaysOn:false,
            zoomWidth: 349,
            zoomHeight: 375,
            xOffset:0,
            yOffset:0,
            title: false,
            position:'right'
        });

    jQuery(".custom-selectbox .jquery-selectbox-item").live('click', function(){
    	//jQuery(this).parents('.custom-selectbox').find('.LV_validation_message').hide();
     })

    //IE6 png fix
    if(jQuery.browser.msie && jQuery.browser.version == 6 ){
    	DD_belatedPNG.fix('.dd, .box-container-tb');
    }

    //custom radio
    jQuery('.custom-radio span').click(function(){
    	var thisName = jQuery(this).parent().find('input').attr('name');
    	jQuery('.custom-radio span').each(function(){
    		if( jQuery(this).parent().find('input').attr('name') == thisName){
    			jQuery(this).removeClass('checked');
    			jQuery(this).parent().find('input').attr('checked', false);
    		}
    	});
    	jQuery(this).addClass('checked');
    	jQuery(this).parent().find('input').attr('checked', true);
    });

    jQuery(".member-address-select .jquery-selectbox-item").live("click", function(){
    	var value = jQuery(this).text();
    	if(value == "New Address"){
    		jQuery(this).parents('.container').find('.col, .newsletter-signup').show();
    		if (jQuery('.ship-options').length) {
    			jQuery('.ship-options').show();
    		}
    	}else{
			jQuery(this).parents('.container').find('.col, .newsletter-signup').hide();
			if (jQuery('.ship-options').length) {
    			jQuery('.ship-options').hide();
    		}
    	}
    });

});

function slideshowThumbs_initCallback(carousel){

	jQuery("#slideshow-thumbs .arrow-prev").click(function(){
		carousel.prev();
		return false;
	 })

	 jQuery("#slideshow-thumbs .arrow-next").click(function(){
		carousel.next();
		return false;
	})
}
