/* $Id: toolbar-functions-v35.js,v 1.7 2012/01/24 08:22:42 Ondrej Exp $ */

/* <![CDATA[ */

// Set width to these two divs according to theirs children
// (work around for IE7 bug with css float)
$(document).ready(function() {
    if (!$.support.cssFloat) {
        setWidthAccordingToChildren($('#quickOrderWrapper'));
        setWidthAccordingToChildren($('#preorderWrapper'));
        setWidthAccordingToChildren($('#basketWrapper'));
        setWidthAccordingToChildren($('#shoppingPanel'));
        setWidthAccordingToChildren($('#currentCatalogPanel'));
    }
});


// preloading bubble images
var bubbleImgs = [];

function preloadBubbleImages() {
	var imgSources = [
		"/image/footer/bubbleBgCaptionShadow.png",
		"/image/footer/bubbleBgContentsShadow.png",
		// "/image/footer/bubbleBgCaption.png",
		// "/image/footer/bubbleBgContents.png",
		"/image/footer/bubbleCaption.gif"
	];
	for( var i = 0; i < imgSources.length; i++ ) {
		bubbleImgs.push( new Image() );
		bubbleImgs[ i ].src = imgSources[ i ];
	}
}

preloadBubbleImages();

// displaying basket bubble
var bubble = "basketBubble";
var bubbleTimeout = null;

// creating bubble
function createBubble() {
	var bubbleExists = ( jQuery( "#" + bubble ).length > 0 );
	if( bubbleExists ) return;

    var bubbleHtml = "<div id='" + bubble + "'>" +
"				<div class='bubbleContents'>" +
"					<img id='bubbleProductImage' src='' alt='' \/>" +
"					<div id='bubbleProductText' >" +
"         <p class='bubbleCaption'>" + msg_product_common_addToBasketMessage + "<\/p>" +
"					<p id='bubbleProductName' class='caption'><\/p>" +
"					<p id='productCode'><b>" + msg_product_common_product + "</b>&nbsp;<span id='bubbleProductCode'><\/span><\/p>" +
"					<\/div>" +
            "<p id='bubbleProductPrice'><\/p>" +
            "<\/div><\/div>";

	jQuery( "#basketWrapper" ).append(bubbleHtml);

	if( ! jQuery.browser.msie )
        jQuery( "#" + bubble ).animate( { opacity : 0 }, 0 );
}

// shows basket bubble
function showBubble() {
	jQuery( "#" + bubble ).stop();
	if( jQuery.browser.msie ) {
		jQuery( "#" + bubble ).fadeIn( 0, setBubbleTimeout );
	} else {
		jQuery( "#" + bubble ).css( "display", "block" );
		jQuery( "#" + bubble ).fadeTo( jQuery.browser.msie ? 0 : 500, 1, setBubbleTimeout );
	}
}

// sets timeout after which hiding function is called
function setBubbleTimeout() {
	bubbleTimeout = setTimeout( "hideBubble()", 3000 );
}

// hides selected bubble
function hideBubble() {
	jQuery( "#" + bubble ).fadeTo(
		jQuery.browser.msie ? 0 : 1000, 0,
		function() {
			jQuery( "#" + bubble ).css( "display", "none" );
			removeBubble();
		}
	);
}

// removes selected bubble from DOM
function removeBubble() {
	jQuery( "#" + bubble ).remove();
}

// allow display BP points in bubble
var _isBPVisible = true;

// call this with propper values to show basket notification bubble
// after successful check of adding product(s) to shopping basket
function refreshBasketTotals( itemsCount, totalPrice, totalBP, prodCode, prodName, prodImgUrl, prodPrice, prodSkubp, skubpLabel) {
	jQuery( "#basketItems" ).html( itemsCount );
	jQuery( "#basketTotalPrice" ).html( totalPrice );
	jQuery( "#basketTotalBP" ).html( totalBP );
	if( ! prodCode ) return;

	createBubble();
	jQuery( "#" + bubble ).stop( true );
	clearTimeout( bubbleTimeout );
	jQuery( "#bubbleProductCode" ).html( prodCode );
	jQuery( "#bubbleProductName" ).html( prodName );
	
    if (prodSkubp == undefined || !_isBPVisible)
    {
        jQuery( "#bubbleProductPrice" ).html( prodPrice );
    }
    else
    {
        jQuery( "#bubbleProductPrice" ).html( prodPrice + " / " + product_detail_bp + " " + prodSkubp);
    }

	prodImgUrl = prodImgUrl.replace("_5.png", "_4.png");
	jQuery( "#bubbleProductImage" ).attr( "src", "" );
	console.log("prodImgUrl : ",prodImgUrl);
	if( prodImgUrl ) {
		jQuery( "#bubbleProductImage" ).load( function() {
			jQuery( this ).css( "display", "block" );
			showBubble();
		} );
		jQuery( "#bubbleProductImage" ).error( function() {
			jQuery( this ).css( "display", "none" );
			showBubble();
		} );
		jQuery( "#bubbleProductImage" ).attr( "src", prodImgUrl );
	} else {
		jQuery( "#bubbleProductImage" ).css( "display", "none" );
		showBubble();
	}
}

/* ]]> */

// -----------------------------------------------------------------------------
// Show catalog brochure
// -----------------------------------------------------------------------------



function bigBrochure(){
  showBrochure();
  showShadow();
};
  
function showBrochure() {
 jQuery("#bigBrochureImage").animate({ height: '170px', bottom: '0px', opacity: 1 }, 500, function() {
      $(this).show();
  });
  }

function showShadow() {  
 jQuery("#shadow").animate({ height: '160px', bottom: '0px', opacity: 0.25 }, 500, function() {
      $(this).show();
  });
  
  }
  
function smallBrochure(){
  hideBrochure();
  hideShadow();
 };
   
function hideBrochure() {
  jQuery("#bigBrochureImage").animate({ height: '170px', opacity: 0 }, 500, function() {
      $(this).hide();
  });
}

function hideShadow() {
    jQuery("#shadow").animate({ height: '160px', opacity: 0 }, 500, function() {
      $(this).hide();
  });
  }
  

