	// Preloading Lens Overlay
	var zoomlensover = new Image();
	zoomlensover.src = '/images/zoom/zoom-lens.png';
	
	//--------------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	// JS-Zoom Lens
	// Copyright 2009 by Flori G. Seeger
	// v 0.85
	// Visit www.jszoom.com for more Information
	//--------------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	
	jszoomlens = {
		
		// init jszoomlens
		init: function(event, object){
			jsz('magnifying').style.display = 'block';
			jsz('magnify_overlay').style.display = 'block';
			object.onmousemove = this.overupdate;
			object.onmouseout = this.outupdate;
			//object.oncontextmenu = this.optionsmenu;
			// global var to carry object
			mylensobject = object;
			realposx = this.realposition(jsz('standard_image')).x;
			realposy = this.realposition(jsz('standard_image')).y
			
		},
		
		// get current mouse position
		mouse: {
			coordinates: function(event){
				if (!event){
					var event = window.event;
				}
					
				if (event){ 
					if (event.pageX || event.pageY){
						return {
							x: event.pageX,
							y: event.pageY
						};
					}
					else { 
						if (event.clientX || event.clientY){
							return {
								x: event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
								y: event.clientY + document.body.scrollTop + document.documentElement.scrollTop
							};
						}
					}
				}
			}
		},
		
		reinit: function(event){
			jszoomlens.init(event, jsz('transparent'));
			jszoomlens.overupdate(event);
		},
		
		// show options menu on right click
		optionsmenu: function(event){
			jsz('optionsmenu').style.display = 'block';
			jsz('optionsmenu').style.left = jszoomlens.mouse.coordinates(event).x - realposx - 10 + "px";
			jsz('optionsmenu').style.top = jszoomlens.mouse.coordinates(event).y - realposy - 10 + "px";
			return false;
		},
		
		// get real position of element
		realposition: function(findobj){
			var curleft = 0;
			var curtop = 0; 
			if (findobj.offsetParent) {
				do	{
					curleft += findobj.offsetLeft;
					curtop += findobj.offsetTop;
				} 
				while (findobj = findobj.offsetParent);
				return {
					x: curleft,
					y: curtop
				}
			}
		},
		
		// calculate image ration magnification_image / standard_image
		imageratio: function(){
			return {
				x: zoom_img_pre.width / standard_img_pre.width,
				y: zoom_img_pre.height / standard_img_pre.height
			};
		},
		
		// calculate lens position
		lensposition: function(event){
			return {
				x: this.mouse.coordinates(event).x - jsz('magnifying').offsetWidth / 2 - realposx,
				y: this.mouse.coordinates(event).y - jsz('magnifying').offsetHeight / 2 - realposy
			}
		},
		
		// set transparent overlay size
		transsize: function(){
			jsz('transparent').style.width = standard_img_pre.width + "px";
			jsz('transparent').style.height = standard_img_pre.height + "px";
		},
		
		// calculate magnification_image position {
		magnification_imageposition: function(event){
			return {
				x: -1 * (this.mouse.coordinates(event).x - realposx) * this.imageratio().x + jsz('magnifying').offsetWidth / 2 + "px",
				y: -1 * (this.mouse.coordinates(event).y - realposy) * this.imageratio().y + jsz('magnifying').offsetHeight / 2 + "px"
			}
		},
		
		// core logic
		overupdate: function(event){
			if (jsz('xdisable').value == 'false'){
				jsz('magnifying').style.left = jszoomlens.lensposition(event).x + "px";
				jsz('magnification_image').style.left = jszoomlens.magnification_imageposition(event).x;
			}
			else {
				jszoomlens.lenssizecustom(zoom_img_pre.width, 150);
				jsz('magnification_image').style.left = '0px';
				jsz('magnifying').style.left = -1 * (zoom_img_pre.width - standard_img_pre.width) / 2 + "px";
			}
			if (jsz('ydisable').value == 'false'){
				jsz('magnifying').style.top = jszoomlens.lensposition(event).y + "px";
				jsz('magnification_image').style.top = jszoomlens.magnification_imageposition(event).y;	
			}
			else {
				jszoomlens.lenssizecustom(150, zoom_img_pre.height);
				jsz('magnification_image').style.top = '0px';
				jsz('magnifying').style.top = -1 * (zoom_img_pre.height - standard_img_pre.height) / 2 + "px";
			}
			jsz('magnify_overlay').style.left = jszoomlens.lensposition(event).x - 3 + "px";
			jsz('magnify_overlay').style.top = jszoomlens.lensposition(event).y - 2 + "px";		
		},
		
		// out of standard_image object
		outupdate: function(){
			jsz('magnify_overlay').style.display = 'none';
			jsz('magnifying').style.display = 'none';
			document.onmousemove = null;
		},
		
		// set lens size
		lenssize: function(size){
			jsz('magnifying').style.width = size + "px";
			jsz('magnifying').style.height = size + "px";
		},
		
		// set custom lens size
		lenssizecustom: function(width, height){
			jsz('magnifying').style.width = width + "px";
			jsz('magnifying').style.height = height + "px";
		}
		
	}
	
	
	// show active size
	var activesizeid = 'size1';
	var sizeswitch = function(event, elementid) {
		jsz('xdisable').checked = false;
		jsz('ydisable').checked = false;
		jsz('xdisable').value = false;
		jsz('ydisable').value = false;
		jsz(activesizeid).style.color = '#888';
		jsz(elementid).style.color = '#000';
		activesizeid = elementid;
		jsz('optionsmenu').style.display = 'none';
		jszoomlens.reinit(event);
		toggleoverlay(event, false);
	}
	
	// show active zoom level
	var activelevelid = 'level1';
	var levelswitch = function(event, elementid) {
		jsz(activelevelid).style.color = '#888';
		jsz(elementid).style.color = '#000';
		activelevelid = elementid;
		jsz('optionsmenu').style.display = 'none';
		jszoomlens.reinit(event);
	}
	
	// enable / disbale vertical and horizontal zoom only
	var vertical_horizontal_zoom = function(event, ischecked, id){
		toggleoverlay(event, false);
		if(ischecked == true){
			jsz(id).value = true;
		}
		else{
			jsz(id).value = false;
		}
		if (id == 'xdisable'){
			if(jsz('ydisable').checked == true){
				jsz('ydisable').checked = false;
				jsz('ydisable').value = false;
			}
		}
		else {
			if(jsz('xdisable').checked == true){
				jsz('xdisable').checked = false;
				jsz('xdisable').value = false;
			}
		}
		jsz('optionsmenu').style.display = 'none';
	}
	
	// show magnification overlay image
	var toggleoverlay = function(event, ischecked){
		if (ischecked == true){
			jszoomlens.lenssize(248);
			jsz('xdisable').checked = false;
			jsz('ydisable').checked = false;
			jsz('xdisable').value = false;
			jsz('ydisable').value = false;
			jsz('magnify_overlay').src = zoomlensover.src;
			jsz('magnifying').style.border = 'none'
		}
		else {
			jsz('overlay').checked = false;
			jsz('magnify_overlay').src = '/images/common/clear.gif';
			jsz('magnifying').style.border = '1px solid #000000';
		}
		jsz('optionsmenu').style.display = 'none';
		jszoomlens.reinit(event);
	}
	
	// replace document.getElement
	var jsz = function(element) {
		element = document.getElementById(element);
		return Elementfunction(element);
	}
	var Elementfunction = function(x) {return x;}
	
	
	// Preloading Logic and Sequencing	
	// check if images loaded
	function init_loading_sequence(standard_img, zoom_img){	
		jsz('loadingAnimStandard').style.display = 'block';
		jsz('loading_anim').style.display = 'block';
		load_standard_img(standard_img);
		load_zoom_img(zoom_img);
	}
	
	// load standard image and check if loaded
	function load_standard_img(standard_img){
		standard_img_pre = new Image();
		standard_img_pre.src = image_path + "hero/" + standard_img;
		// check if image already loaded
		if(standard_img_pre.complete){
			load_standard_img_init();
		}
		else {
			standard_img_pre.onload = load_standard_img_init;
		}
	}
	
	var load_standard_img_init = function(){
		jsz('loadingAnimStandard').style.display = 'none';
		jsz('standard_image').src = standard_img_pre.src;
		// center standard image
		jsz('magnifier_space').style.marginLeft = (420 - standard_img_pre.width) / 2 + 'px';
		jsz('magnifier_space').style.marginTop = (420 - standard_img_pre.height) / 2 + 'px';
		jszoomlens.transsize();	
	}
	
	// load zoom image and check if loaded
	var load_zoom_img = function (zoom_img, event){
		myevent = event;
		zoom_img_pre = new Image();
		zoom_img_pre.src = image_path + "zoom/" + zoom_img; 
		// check if image already loaded
		if(zoom_img_pre.complete){
			zoom_img_init();
		}
		else {
			zoom_img_pre.onload = zoom_img_init;
			jsz('loading_anim').style.display = 'block';
		}
	}
	
	var zoom_img_init = function(){	
		jsz('loading_anim').style.display = 'none';
		jsz('magnification_image').src = zoom_img_pre.src;
		if(typeof myevent != 'undefined'){
			jszoomlens.reinit(myevent);
		}
	}
	
	// toggle advanced settings
	var toggle_advanced_settings = function(){
		if (jsz('advanced_settings').style.display == 'none'){
			jsz('advance_settings_link').innerHTML = 'Close (x)';
			jsz('advanced_settings').style.display = 'block';
		}
		else {
			jsz('advance_settings_link').innerHTML = 'Advanced Settings';
			jsz('advanced_settings').style.display = 'none';
		}
	}
	
	// onload 
	window.onload = function(){
		isie6 = true;
		if(navigator.userAgent.indexOf('MSIE 6') <= -1){
			isie6 = false;
			jsz('magnify_overlay').src = '/images/zoom/zoom-lens.png';
		}
	}
		
