/* BOSTIK 2008 */
/* COMMON JAVASCRIPT FUNCTIONS */

/* SAME HEIGHT FOR SAME CLASS ELEMENTS */
function sameHeight(elt) {
	var heightBlockMax=0;
	jQuery(elt).each(function(){ if( jQuery(this).height() > heightBlockMax ) heightBlockMax = jQuery(this).height(); }); // get max height
	if (jQuery.browser.msie) {
		if (parseInt(jQuery.browser.version) <= "6") {
			jQuery(elt).each(function(){ jQuery(this).css("height",heightBlockMax); }); // assign max height
		} else {
			jQuery(elt).each(function(){ jQuery(this).css("min-height",heightBlockMax); }); // assign max height
		}
	} else {
		jQuery(elt).each(function(){ jQuery(this).css("min-height",heightBlockMax); }); // assign max height
	}
	heightBlockMax=0;
}

/* ENABLE ROLLOVER ON TARGETED IMAGES (ALL BROWSERS) */
function imgRollover(elt) {
    jQuery(elt).each( function() {
		jQuery(this).hover(
			function() {
				jQuery(this).attr("src", jQuery(this).attr("src").replace("-off","-on"));
			},
			function () {
				jQuery(this).attr("src", jQuery(this).attr("src").replace("-on","-off"));
			}
		);
	});
}

/* PRELOAD FUNCTION FOR DISTRIBUTORS MAP */
jQuery.preloadImages = function() {
	var a = (typeof arguments[0] == 'object')? arguments[0] : arguments;
	for(var i = a.length -1; i > 0; i--) {
		jQuery("<img>").attr("src", a[i]);
	}
}
/* images to preload */
var preload = ["img/distribmapxoff.gif", "img/distribmapxzonea.gif", "img/distribmapxzoneb.gif", "img/distribmapxzonec.gif", "img/distribmapxzoned.gif", "img/distribmapxzonee.gif"];

/* DISTRIBUTORS MAP */
function distributorsMap() {
   	jQuery('#distribMapAreas area')
	.each(function() {
           jQuery(this).removeAttr('onmouseover').removeAttr('onmouseout');
   	})
	.hover(
        function () { distribOn(this); },
		function () { distribOff(); }
	).click(
		function () { return false; }
	);
}

function distribOn(elt) {
	jQuery('.zone').removeClass('activeZone');
	var zoneToActivate = jQuery(elt).attr('href');
	var srcZoneToActivate = jQuery(zoneToActivate).attr('id');
	var srcZoneToActivate = srcZoneToActivate.toLowerCase();
	var srcZoneToActivate = 'x'+srcZoneToActivate;
	var currentSrc = jQuery('#distribMapImg img').attr('id');
	jQuery('#distribMapImg img').attr('src',jQuery('#distribMapImg img').attr('src').replace(currentSrc,"xoff"));
	jQuery('#distribMapImg img').attr('src',jQuery('#distribMapImg img').attr('src').replace("xoff",srcZoneToActivate));
	jQuery('#distribMapImg img').attr('id',srcZoneToActivate);
	jQuery(zoneToActivate).addClass('activeZone');
}

function distribOff() {
   	jQuery('.zone').removeClass('activeZone');
	var currentSrc = jQuery('#distribMapImg img').attr('id');
	jQuery('#distribMapImg img').attr('src',jQuery('#distribMapImg img').attr('src').replace(currentSrc,"xoff"));
}


/* PACKAGES ZOOM */
function packagesZoom(elt) {
	jQuery(elt).each(function() {
        var toLoad = jQuery(this).children('.zoomPackshot').attr('href');
        var imgToMove = jQuery(this).children('.zoomPackshot').html();
		jQuery(this).append(imgToMove);
		jQuery(this).children('.zoomPackshot').remove();
		jQuery(this).append('<a class="tips" href="'+toLoad+'" rel="'+toLoad+'"><img src="img/bt-zoom-off.gif" alt="Zoom" /></a>').children('.tips').hide();
        jQuery(this).children('.tips').children('img').bind("mouseenter", function(e){
	        imgRollover(jQuery(this));
	    });
		jQuery(this).hover(
        	function () {
        		jQuery(this).children('.tips').show();
        	},
        	function () {
        		jQuery(this).children('.tips').hide();
        	}
		);
		var myOffset = 150;
		jQuery(this).children('.tips').cluetip({
        	cursor: 'pointer',
			tracking: true,
			width: 358,
			height: 356,
			attribute: 'href',
			showTitle: false,
			dropShadow: false
        });
	});
}


jQuery(document).ready(function() {

    /* ADD hasJS CLASS TO BODY FOR ABS/REL POSITIONNING */
	jQuery("body").addClass("hasJS");

    /* HIDE QUICK LINKS */
	jQuery('#quickAccess').addClass('offLeft');

    /* SAME HEIGHT FOR PRODUCT LISTING ON HOME */
	if (jQuery('#applicationList > li').size() > 1) { initSameHeight = sameHeight('#applicationList > li'); }

    /* DISTRIBUTORS MAP */
	if (jQuery('#distribMapAreas').size() > 0 ) {
		jQuery.preloadImages(preload);
		if (!jQuery.browser.msie) {
			initDistributorsMap = distributorsMap();
		}
	}

	/* PACKAGES ZOOM */
	if (jQuery('.productsList .zoomPackshot').size() > 0 || jQuery('#photoAndLinks .zoomPackshot').size() > 0) { initPackagesZoom = packagesZoom('.productImgContainer'); }

});























/* END */
