//var DIR_WS_IMAGES = '/lasystems2/images/';
var DIR_WS_IMAGES = '/images/';
/**
 * jQuery.Preload - Multifunctional preloader
 * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com
 * Dual licensed under MIT and GPL.
 * Date: 3/12/2008
 * @author Ariel Flesler
 * @version 1.0.7
 */
;(function($){var n=$.preload=function(c,d){if(c.split)c=$(c);d=$.extend({},n.defaults,d);var f=$.map(c,function(a){if(!a)return;if(a.split)return d.base+a+d.ext;var b=a.src||a.href;if(typeof d.placeholder=='string'&&a.src)a.src=d.placeholder;if(b&&d.find)b=b.replace(d.find,d.replace);return b||null}),g={loaded:0,failed:0,next:0,done:0,total:f.length};if(!g.total)return m();var h='<img/>',j=d.threshold;while(--j>0)h+='<img/>';h=$(h).load(k).error(k).bind('abort',k).each(l);function k(e){g.found=e.type=='load';g.image=this.src;var a=g.original=c[this.index];g[g.found?'loaded':'failed']++;g.done++;if(d.placeholder&&a.src)a.src=g.found?g.image:d.notFound||a.src;if(d.onComplete)d.onComplete(g);if(g.done<g.total)l(0,this);else{if(h.unbind)h.unbind('load').unbind('error').unbind('abort');h=null;m()}};function l(i,a,b){if($.browser.msie&&g.next&&g.next%n.gap==0&&!b){setTimeout(function(){l(i,a,1)},0);return!1}if(g.next==g.total)return!1;a.index=g.next;a.src=f[g.next++];if(d.onRequest){g.image=a.src;g.original=c[g.next-1];d.onRequest(g)}};function m(){if(d.onFinish)d.onFinish(g)}};n.gap=14;n.defaults={threshold:2,base:'',ext:'',replace:''};$.fn.preload=function(a){n(this,a);return this}})(jQuery);
/* SCROLL ANIMATION */
var Timer;
function ScrollLeft() {
	Timer = setInterval("document.getElementById('productImagesContainer').scrollLeft -= 2", 15);
}
function ScrollRight() {
	Timer = setInterval("document.getElementById('productImagesContainer').scrollLeft += 2", 15);
}
/* END SCROLL ANIMATION */

//product info
function change_thumb(href, pos, zoomed_href) {
	$j('#zoomed').val(zoomed_href);
	$j('#current_zoomed').val(pos);
	var urls = [ href ];
	$j.preload( urls, {
		base: DIR_WS_IMAGES,
		ext:'.jpg',
		onComplete: function(data) {
			var img = new Image();
			img.src = data.image;
			var newWidth = img.width;
			var newHeight = img.height;
			var maxWidth = 176;
			var maxHeight = 176;
			if (newWidth > maxWidth) {
				newHeight = maxWidth/newWidth*newHeight;
				newWidth = maxWidth;
			}
			if (newHeight > maxHeight) {
				newWidth = maxHeight/newHeight*newWidth;
				newHeight = maxHeight;
			}
			$j('#image_small_preview').attr('width', newWidth);
			$j('#image_small_preview').attr('height', newHeight);
			$j('#image_small_preview').attr('src', img.src);
		}
	});
	if ( pos == 0) {
		$j('#product_save_percent').show();
	} else {
		$j('#product_save_percent').hide();
	}
}
function show_zoom(href) {
	$j('#image_small_preview').fadeOut(200);
	$j('#zoom_tool').hide(200);
	$j('#zoom_animation').slideDown(500);
	var urls = [ href ];
	$j.preload( urls, {
		base: DIR_WS_IMAGES,
		ext:'.jpg',
		onComplete: function(data) {
			var img = new Image();
			img.src = data.image;
			var newWidth = img.width;
			var newHeight = img.height;
			var maxWidth = 510;
			var maxHeight = 420;
			if (newWidth > maxWidth) {
				newHeight = maxWidth/newWidth*newHeight;
				newWidth = maxWidth;
			}
			if (newHeight > maxHeight) {
				newWidth = maxHeight/newHeight*newWidth;
				newHeight = maxHeight;
			}
			$j('#image_big_preview').attr('width', newWidth);
			$j('#image_big_preview').attr('height', newHeight);
			$j('#image_big_preview').attr('src', img.src);
		}
	});
	if ($j('#current_zoomed').val() == 0) {
		$j('#arrow_left_slide').attr('src', DIR_WS_IMAGES + 'arrow_left_off.gif');
	} else {
		$j('#arrow_left_slide').attr('src', DIR_WS_IMAGES + 'arrow_left.gif');
	}
	if ($j('#current_zoomed').val() == $j('#total_pic').val() - 1) {
		$j('#arrow_right_slide').attr('src', DIR_WS_IMAGES + 'arrow_right_off.gif');
	} else {
		$j('#arrow_right_slide').attr('src', DIR_WS_IMAGES + 'arrow_right.gif');
	}
	var current = $j('#current_pic').val();
	$j('#current_page_it').html(current);
}
function hide_zoom() {
	$j('#zoom_animation').slideUp(500);
	$j('#image_small_preview').fadeIn(200);
	$j('#zoom_tool').show(200);
}
function slide_image(type) {
	var current = $j('#current_pic').val();
	var total = $j('#total_pic').val();
	var product = '';
	if (type == 0) {//left
		current--;
		if (current >= 1) {
			product = $j('#product_picture_' + current).val();
			product = product.replace('.jpg', '');
			product = product.replace('/thumb/', '/large/');
			if (current == 1) {
				product = product.split('images/');
			} else {
				product = product.split('../images/');
			}
			product = product[product.length-1];
			show_zoom(product);
			$j('#current_pic').val(current);
			$j('#current_page_it').html(current);
			if (current > 1) {
				$j('#arrow_left_slide').attr('src', DIR_WS_IMAGES + 'arrow_left.gif');
			} else {
				$j('#arrow_left_slide').attr('src', DIR_WS_IMAGES + 'arrow_left_off.gif');
			}
			if (current < total) {
				$j('#arrow_right_slide').attr('src', DIR_WS_IMAGES + 'arrow_right.gif');
			} else {
				$j('#arrow_right_slide').attr('src', DIR_WS_IMAGES + 'arrow_right_off.gif');
			}
		}
	} else {//right
		current++;
		if (current <= total) {
			product = $j('#product_picture_' + current).val();
			product = product.replace('.jpg', '');
			product = product.replace('/thumb/', '/large/');
			product = product.split('/images/');
			product = product[product.length-1];
			show_zoom(product);
			$j('#current_pic').val(current);
			$j('#current_page_it').html(current);
			if (current > 1) {
				$j('#arrow_left_slide').attr('src', DIR_WS_IMAGES + 'arrow_left.gif');
			} else {
				$j('#arrow_left_slide').attr('src', DIR_WS_IMAGES + 'arrow_left_off.gif');
			}
			if (current < total) {
				$j('#arrow_right_slide').attr('src', DIR_WS_IMAGES + 'arrow_right.gif');
			} else {
				$j('#arrow_right_slide').attr('src', DIR_WS_IMAGES + 'arrow_right_off.gif');
			}
		}
	}
}
//end product info
