jQuery(function( $ ){		
	

	//hide Imgages later Loading
 	$('.product-image img').css('display','none'); // since .hide() failed in safari
	$('.product-image').addClass('loading');
});

var _max_height = null;

(function($)
{	
    $(document).ready(function()
    {
    
    	// ########Start Loading All Product Images
    	
    	
    		$.preload( '.product-image img', {//the first argument is a selector to the images
    			enforceCache: true,
    			onRequest:request,
    			onComplete:complete,
    			onFinish:finish,
    			//placeholder:'skin/frontend/acorii/default/images/load.gif',//this is the really important option
    			notFound:'skin/frontend/acorii/default/images/err.png',//optional image if an image wasn't found
    			threshold: 9 //'2' is the default, how many at a time, to load.
    		});
    		
    		function update( data ){
    			// alert(data);
    		};
    		
    		function complete( data ){
    			//alert("loaded Image"+data.index)
    			if($.browser.msie && jQuery.browser.version == "6.0"){DD_belatedPNG.fix('.product-image img');			}
    			$('.product-image img').eq(data.index).fadeIn('slow');//fadeIn('slow'); // since .hide() failed in safari
    			$('.product-image').eq(data.index).removeClass('loading');
    		};
    		
    		function request( data ){
    			//alert("requesting Image"+data.index)
    		};
    		
    		function finish(){
    		//	alert('all Images Loaded');
    		
    		};
    	
    	
    	//####
    	
    	
        $('#gototop').click(function()
        {
            $('html, body').animate({
                scrollTop: 0
            }, 'medium');
        });
        
        //DEFINE JqueryTools Tooltips
        
        toolTip_account = $(".account a").tooltip({tip: '#account-tooltip', effect: 'fade', delay: 300, offset: [0, 0], slideFade: true, relative: true, api: true});
        //toolTip_account = $(".account a").tooltip(); //definde API CALL
        
       	toolTip_miniCart = $(".cart-tooltip-link").tooltip({tip: '.mini-cart', effect: 'fade', delay: 500, position: "top center", offset: [0, -110], slideFade: true, relative: true, api: true});
       	//toolTip_miniCart = $(".cart-tooltip-link").tooltip();//definde API CALL
        //DEFINE jQueryTools Expose
        
        expose_ACPprogress = $(".ajaxcartpro_progress").expose({api: true,loadSpeed: 'fast', closeSpeed:'slow',color: '#222222', opacity:0.45});
        //expose_ACPprogress = $('.ajaxcartpro_progress').expose();	//definde API CALL	
        
        expose_miniCart = $(".mini-cart").expose({api: true,loadSpeed: 'fast',closeSpeed:'slow',color: '#222222', opacity:0.45, delay: 500});	
        //expose_miniCart = $('.mini-cart').expose();	//definde API CALL	
        
        expose_Overlay = $(".simple_overlay").expose({api: true,loadSpeed: 'fast', closeSpeed:'slow',closeOnClick: false ,color: '#222222', opacity:0.9});
       	//expose_Overlay = $('.simple_overlay').expose();	//definde API CALL	
       	

        $("#mini-cart-close").live('click', function()
        {
         	toolTip_miniCart.hide()
        })
        
        $("a.stepUp").click(function()
        {
            el = $(this);
            if (el.attr('rel') != "") {
                input = $(el.attr('rel'));
                value = input.val();
            }
            else {
                input = $(this).parent().find('input.qty');
                value = input.val();
            }
            
            valueMin = $('input#qty-min').val();
            if (valueMin == '') valueMin = 1;
            
            if (value == null) value = valueMin;
            else value++;
            
            input.val(value);
            return false;
        });
        
        $("a.stepDown").click(function()
        {
            el = $(this);
            if (el.attr('rel') != "") {
                input = $(el.attr('rel'));
                value = input.val();
            }
            else {
                input = $(this).parent().find('input.qty');
                value = input.val();
            }

            valueMin = $('input#qty-min').val();
			if (valueMin==undefined) valueMin = 1;            

			value--;

            if (value == null || value == 0) value = valueMin;
            input.val(value);

            return false;
        });
		
		$products = $("a.product-image");
		if ($products.length>0) {
			$products.overlay({ 
					target: '#gallery', 
					onLoad: function() {expose_Overlay.load();}, 
				    onClose: function() {expose_Overlay.close();}
			}).gallery({ speed: 'fast',  autohide: false, opacity: 1 });
		}
		
		// IE6 fix for floating bar
		if($.browser.msie && jQuery.browser.version == "6.0")
		{
			_max_height = jQuery(document).height();
			positionFooterFloat();
			$(window).scroll(function() { positionFooterFloat(); });
			$(window).resize(function() { positionFooterFloat(); });
			
			//fixPNG
		
			DD_belatedPNG.fix('.scrollable IMG, .navi A, H1#logo, .shadow140, .shadow300, IMG.product-image, .view360, .video, .cartItem IMG, .arrow, table IMG, #page');
		
			//crosssell Hover fix
			$('.crosssell UL LI').mouseenter(function(){
			   $(this).addClass('hover');
		    }).mouseleave(function(){
		    	$(this).removeClass('hover');
		    });
			
		}
    });
})(jQuery);


function positionFooterFloat()
{
	var windowHeight = jQuery(window).height();
	var windowWidth = jQuery(window).width();
	
	var barDiv = jQuery("#floatingFoot");
	var barHeight = barDiv.height();
	var scrollTop = jQuery(document).scrollTop();
	
	var _top = windowHeight + scrollTop - barHeight - 2;
	
	if( _top > _max_height ) return; 
	
	barDiv.css( {
		'position': 'absolute',
		'left': 0,
		'top': _top,
		'width' : windowWidth
	} );
}

