/* xCartMod.com Dynamic Images 2 */
var main_image_height = 0;
var main_image_width = 0;
var detailed_imgs = [];
var dissolve_timer = 0;
var dissolve_opacity;
var dissolve_id = null;
var opacity_step = 1;
var msie_opacity_step = 3;
var thumb_width = 0;
var thumb_height = 0; 
var switch_timer = 0;
var orig_image_src = '';

function thumbMouse_Out () {
	if (dissolve_mode == "slow") {
		blendimage('product_thumb_div', 'product_thumbnail', orig_image_src, 1);
	} else {
		switch_timer = setTimeout("switch_back_to_orig()", switch_delay);
	}
}

function switch_back_to_orig() {
	document.getElementById('product_thumbnail').src = orig_image_src;
	if (keep_dimension == 'height') {
    	document.getElementById('product_thumb_div').style.width = main_image_width+"px";
    	document.getElementById('product_thumbnail').width = main_image_width;
	} else if (keep_dimension == 'width') {
    	document.getElementById('product_thumb_div').style.height = main_image_height+"px";
    	document.getElementById('product_thumbnail').height = main_image_height;
	}
	switch_timer = 0;
}

function blendimage(divid, imageid, imagefile, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;
    
    //set the current image as background
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
    
    //make image transparent
    changeOpac(0, imageid);
    
    //make new image
    document.getElementById(imageid).src = imagefile;

	dissolve_opacity = 0;
	dissolve_id = imageid;
	dissolve_timer = setInterval("dissolve_cycle()",millisec);
} 

function dissolve_cycle() {

if (localBrowser == 'MSIE') opacity_step = msie_opacity_step;

	dissolve_opacity += opacity_step;
	changeOpac(dissolve_opacity, dissolve_id);

	if (keep_dimension == 'height') {
		temp_width = (main_image_width-thumb_width)*dissolve_opacity/100+thumb_width; 
    	document.getElementById('product_thumb_div').style.width = temp_width+"px";
    	document.getElementById('product_thumbnail').width = temp_width;
	} else if (keep_dimension == 'width') {
		temp_height = (main_image_height-thumb_height)*dissolve_opacity/100+thumb_height;
		document.getElementById('product_thumb_div').style.height = main_image_height+"px";
    	document.getElementById('product_thumbnail').height = main_image_height;
	}

//	if (dissolve_opacity >= 90) {
//		document.getElementById('product_thumb_div').style.backgroundImage = "none";
//	}

	if (dissolve_opacity >= 100) {
		clearInterval(dissolve_timer);
		dissolve_timer = 0;
		dissolve_id = null;
	}
} 

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

//----------------------------------------
function thumbMouse_Over (imgid, image_x, image_y) {


if (localBrowser == 'MSIE') opacity_step = msie_opacity_step;

	if (dissolve_mode == "slow") {
		if (dissolve_timer != 0) {	
			dissolve_opacity = 100-opacity_step;	
			dissolve_cycle();
		}
		document.getElementById('product_thumb_div').style.backgroundImage = "none";
	} else {
		if (switch_timer != 0) {
			clearTimeout(switch_timer);
			switch_back_to_orig();	
		}
	}

	orig_image_src = document.getElementById('product_thumbnail').src; 
	document.getElementById('product_thumbnail').src = detailed_imgs[imgid].src;
	ratio_thumb = image_x/image_y;

	if (keep_dimension == 'height') {
		thumb_width = document.getElementById('product_thumbnail').height*ratio_thumb;
		main_image_width = document.getElementById('product_thumbnail').width;
		document.getElementById('product_thumb_div').style.width = thumb_width+"px";
		document.getElementById('product_thumbnail').width = thumb_width; 
	} else if (keep_dimension == 'width') {
		thumb_height = document.getElementById('product_thumbnail').width/ratio_thumb;
		main_image_height = document.getElementById('product_thumbnail').height;
		document.getElementById('product_thumb_div').style.height = thumb_height+"px";
		document.getElementById('product_thumbnail').height = thumb_height;
	}
}

function thumbMouse_Click (thumb_path, image_x, image_y) {
__image_x = image_x+20;
__image_y = image_y+20;
	window.open(thumb_path,'images','width='+__image_x+',height='+__image_y+',toolbar=no,status=no,scrollbars=yes,resizable=no,menubar=no,location=no,direction=no');
}

/* xCartMod.com Dynamic Images 2 */

