MPW = 624; // main picture width
MPH = 508; // main picture height
GPW = 100; // gellery picture width
GPH = 100; // gallery picture height
TPW1 = 100; // small thumbnail picture width, for product cut-outs
TPH1 = 100; // small thumbnail picture height
TPW2 = 293; // large thumbnail picture width, for range scenes
TPH2 = 239; // large thumbnail picture height

FADETIME = 500; // image fade time in millisecs
SHOWTIME = 7500; // image show time in millisecs; total time = fadetime + showtime
IMAGESDIR = "./images/"

ZOOM_W = 400;
ZOOM_H = 400;
ZOOM_CLR = "#00558F";
ZOOM_RATIO = 100;
ZOOM_ISDRAWN = false;

JSCMAGNIFY_W = 275;
JSCMAGNIFY_H = 275;
JSCMAGNIFY_POS = 3;
JSCMAGNIFY_CLR = "#00558F";
JSCMAGNIFY_RATIO = 100;
JSCMAGNIFY_ISDRAWN = false;

CF="";
CFX="";
jsproductarray = new Array();
jsdocumentarray = new Array();

option = new Array();

i=0;
option[0] = new Array();
option[0][i++] = new Array('all categories','all categories');
option[0][i++] = new Array('','---------by category---------');
option[0][i++] = new Array('sanitaryware','sanitaryware');
option[0][i++] = new Array('bowls','bowls');
option[0][i++] = new Array('baths','baths');
option[0][i++] = new Array('taps','taps');
option[0][i++] = new Array('showers','showers');
option[0][i++] = new Array('wastes','wastes');
option[0][i++] = new Array('furniture','furniture');
option[0][i++] = new Array('','-----------by code-----------');
option[0][i++] = new Array('product code','product code');

i=0;
option[1] = new Array();
option[1][i++] = new Array('all products','all products');
option[1][i++] = new Array('','---------------by range---------------');
option[1][i++] = new Array('arco','arco')
option[1][i++] = new Array('bloque','bloque')
option[1][i++] = new Array('cresto','cresto');
option[1][i++] = new Array('dekka','dekka');
option[1][i++] = new Array('echo','echo');
option[1][i++] = new Array('essence','essence')
option[1][i++] = new Array('fyori','fyori')
option[1][i++] = new Array('ivo','ivo');
option[1][i++] = new Array('levo','levo');
option[1][i++] = new Array('millbrook','millbrook');
option[1][i++] = new Array('str8','str8');
option[1][i++] = new Array('urban','urban');
option[1][i++] = new Array('wave','wave');
option[1][i++] = new Array('xcite','xcite');
option[1][i++] = new Array('xl','xl');
option[1][i++] = new Array('','---------by sanitaryware type--------');
option[1][i++] = new Array('basins','basins');
option[1][i++] = new Array('bidets','bidets');
option[1][i++] = new Array('cisterns','cisterns');
option[1][i++] = new Array('concealed cisterns','concealed cisterns');
option[1][i++] = new Array('pedestals','pedestals');
option[1][i++] = new Array('seats','seats');
option[1][i++] = new Array('wc bowls','wc bowls');
option[1][i++] = new Array('','------------by bath type--------------');
option[1][i++] = new Array('double ended','double ended');
option[1][i++] = new Array('freestanding','freestanding');
option[1][i++] = new Array('panels','panels');
option[1][i++] = new Array('screens','screens');
option[1][i++] = new Array('showerbaths','showerbaths');
option[1][i++] = new Array('single ended','single ended');
option[1][i++] = new Array('','-------------by tap type--------------');
option[1][i++] = new Array('basin mixers','basin mixers');
option[1][i++] = new Array('basin pillar taps','basin pillar taps');
option[1][i++] = new Array('bath fillers','bath fillers');
option[1][i++] = new Array('bath pillar taps','bath pillar taps');
option[1][i++] = new Array('bidet mixers','bidet mixers');
option[1][i++] = new Array('floor mounted bath taps','floor mounted bath taps');
option[1][i++] = new Array('manual concealed valves','manual concealed valves');
option[1][i++] = new Array('shower mixers','showers mixers');
option[1][i++] = new Array('spouts','spouts');
option[1][i++] = new Array('stop cocks and diverters','stop cocks and diverters');
option[1][i++] = new Array('','-----------by shower type-------------');
option[1][i++] = new Array('body jets','body jets');
option[1][i++] = new Array('deluxe heads','deluxe heads');
option[1][i++] = new Array('deck mounted kits','deck mounted kits');
option[1][i++] = new Array('dual mode heads','dual mode heads');
option[1][i++] = new Array('handsets, hoses and brackets','handsets, hoses and brackets');
option[1][i++] = new Array('manual concealed valves','manual concealed valves');
option[1][i++] = new Array('riser rails','riser rails');
option[1][i++] = new Array('shower arms and wall outlets','shower arms and wall outlets');
option[1][i++] = new Array('slimline heads','slimline heads');
option[1][i++] = new Array('standard heads','standard heads');
option[1][i++] = new Array('stop cocks and diverters','stop cocks and diverters');
option[1][i++] = new Array('thermostatic concealed valves','thermostatic concealed valves');
option[1][i++] = new Array('thermostatic exposed showers','thermostatic exposed showers');
option[1][i++] = new Array('','------------by waste type-------------');
option[1][i++] = new Array('basin wastes','basin wastes');
option[1][i++] = new Array('bath wastes','bath wastes');
option[1][i++] = new Array('shower wastes','shower wastes');
option[1][i++] = new Array('traps','traps');
option[1][i++] = new Array('','----------by furniture type-----------');
option[1][i++] = new Array('basin stands','basin stands');
option[1][i++] = new Array('concealed cisterns','concealed cisterns');
option[1][i++] = new Array('mirrors and storage','mirrors and storage');
option[1][i++] = new Array('worktops','worktops');

i=0;
option[2] = new Array(); //sanitaryware
option[2][i++] = new Array('all products','all products');
option[2][i++] = new Array('','---------------by range---------------');
option[2][i++] = new Array('arco','arco');
option[2][i++] = new Array('bloque','bloque');
option[2][i++] = new Array('dekka','dekka');
option[2][i++] = new Array('echo','echo');
option[2][i++] = new Array('essence','essence');
option[2][i++] = new Array('ivo','ivo');
option[2][i++] = new Array('str8','str8');
option[2][i++] = new Array('urban','urban');
option[2][i++] = new Array('xcite','xcite');
option[2][i++] = new Array('','----------------by type---------------');
option[2][i++] = new Array('basins','basins');
option[2][i++] = new Array('bidets','bidets');
option[2][i++] = new Array('cisterns','cisterns');
option[2][i++] = new Array('concealed cisterns','concealed cisterns');
option[2][i++] = new Array('pedestals','pedestals');
option[2][i++] = new Array('seats','seats');
option[2][i++] = new Array('wc bowls','wc bowls');


i=0;
option[3] = new Array(); //bowls
option[3][i++] = new Array('all products','all products');
option[3][i++] = new Array('','---------------by range---------------');
option[3][i++] = new Array('cresto','cresto');
option[3][i++] = new Array('fyori','fyori');
option[3][i++] = new Array('ivo','ivo');
option[3][i++] = new Array('str8','str8');


i=0;
option[4] = new Array(); //baths
option[4][i++] = new Array('all products','all products');
option[4][i++] = new Array('','---------------by range---------------');
option[4][i++] = new Array('arco','arco');
option[4][i++] = new Array('bloque','bloque');
option[4][i++] = new Array('essence','essence');
option[4][i++] = new Array('fyori','fyori');
option[4][i++] = new Array('wave','wave');
option[4][i++] = new Array('','----------------by type---------------');
option[4][i++] = new Array('double ended','double ended');
option[4][i++] = new Array('freestanding','freestanding');
option[4][i++] = new Array('panels','panels');
option[4][i++] = new Array('screens','screens');
option[4][i++] = new Array('showerbaths','showerbaths');
option[4][i++] = new Array('single ended','single ended');


i=0;
option[5] = new Array(); //taps
option[5][i++] = new Array('all products','all products');
option[5][i++] = new Array('','---------------by range---------------');
option[5][i++] = new Array('bloque','bloque');
option[5][i++] = new Array('dekka','dekka');
option[5][i++] = new Array('essence','essence');
option[5][i++] = new Array('levo','levo');
option[5][i++] = new Array('str8','str8');
option[5][i++] = new Array('urban','urban');
option[5][i++] = new Array('xcite','xcite');
option[5][i++] = new Array('xl','xl');
option[5][i++] = new Array('','----------------by type---------------');
option[5][i++] = new Array('basin mixers','basin mixers');
option[5][i++] = new Array('basin pillar taps','basin pillar taps');
option[5][i++] = new Array('bath fillers','bath fillers');
option[5][i++] = new Array('bath pillar taps','bath pillar taps');
option[5][i++] = new Array('bidet mixers','bidet mixers');
option[5][i++] = new Array('floor mounted bath taps','floor mounted bath taps');
option[5][i++] = new Array('manual concealed valves','manual concealed valves');
option[5][i++] = new Array('shower mixers','shower mixers');
option[5][i++] = new Array('spouts','spouts');
option[5][i++] = new Array('stop cocks and diverters','stop cocks and diverters');

i=0;
option[6] = new Array(); //showers
option[6][i++] = new Array('all products','all products');
option[6][i++] = new Array('','---------------by range---------------');
option[6][i++] = new Array('bloque','bloque');
option[6][i++] = new Array('cresto','cresto');
option[6][i++] = new Array('dekka','dekka');
option[6][i++] = new Array('essence','essence');
option[6][i++] = new Array('levo','levo');
option[6][i++] = new Array('str8','str8');
option[6][i++] = new Array('urban','urban');
option[6][i++] = new Array('xcite','xcite');
option[6][i++] = new Array('xl','xl');
option[6][i++] = new Array('','----------------by type---------------');
option[6][i++] = new Array('body jets','body jets');
option[6][i++] = new Array('deluxe heads','deluxe heads');
option[6][i++] = new Array('deck mounted kits','deck mounted kits');
option[6][i++] = new Array('dual mode heads','dual mode heads');
option[6][i++] = new Array('handsets, hoses and brackets','handsets, hoses and brackets');
option[6][i++] = new Array('manual concealed valves','manual concealed valves');
option[6][i++] = new Array('riser rails','riser rails');
option[6][i++] = new Array('shower arms and wall outlets','shower arms and wall outlets');
option[6][i++] = new Array('slimline heads','slimline heads');
option[6][i++] = new Array('standard heads','standard heads');
option[6][i++] = new Array('stop cocks and diverters','stop cocks and diverters');
option[6][i++] = new Array('thermostatic concealed valves','thermostatic concealed valves');
option[6][i++] = new Array('thermostatic exposed showers','thermostatic exposed showers');


i=0;
option[7] = new Array(); //wastes
option[7][i++] = new Array('all products','all products');
option[7][i++] = new Array('','----------------by type----------------');
option[7][i++] = new Array('basin wastes','basin wastes');
option[7][i++] = new Array('bath wastes','bath wastes');
option[7][i++] = new Array('shower wastes','shower wastes');
option[7][i++] = new Array('traps','traps');

i=0;
option[8] = new Array(); //furniture
option[8][i++] = new Array('all products','all products');
option[8][i++] = new Array('','---------------by range----------------');
option[8][i++] = new Array('bloque','bloque');
option[8][i++] = new Array('echo','echo');
option[8][i++] = new Array('millbrook','millbrook');
option[8][i++] = new Array('','----------------by type----------------');
option[8][i++] = new Array('basin stands','basin stands');
option[8][i++] = new Array('concealed cisterns','concealed cisterns');
option[8][i++] = new Array('mirrors and storage','mirrors and storage');
option[8][i++] = new Array('worktops','worktops');

option[10] = new Array();


function submitform(formid){
    document.forms[formid].submit();
}

function make_list(list,num){
	if(num != 'all ranges'){	
		remove_all(list);
		list = getObject(list);
		var fragment = document.createDocumentFragment();
		for(i=0; i<option[num].length; i++){
			var new_option = document.createElement('option');
			var text = document.createTextNode(option[num][i][1]);
			new_option.appendChild(text);
			new_option.setAttribute('value',option[num][i][0]);
			if (option[num][i][0]==''){
				new_option.setAttribute('disabled','disabled');
			}
			fragment.appendChild(new_option);
		}
		list.appendChild(fragment);
	}
}

function remove_all(list){
	list = getObject(list);
	while(list.length > 0){
		list.remove(0);
	}
}

function make(list){
	list = list.options[list.selectedIndex].index;
	if(list==0)list++;
	make_list('q2',list);
}

function xzoomShow(obj,event) {
	//return;
	//var obj1=getObject("photo_gallery");
	//var obj2=getObject("product_image");

	//if ((obj1.style.opacity == 0 && obj1.filters.alpha.opacity == 0) || (obj2.style.opacity == 0 && obj2.filters.alpha.opacity == 0)) return;
	if (obj.style) obj.style.cursor="crosshair";
	event_x = (event.x?event.x:event.clientX);
	event_y = (event.y?event.y:event.clientY);

	scrpos = GetViewArea();
	event_x+= scrpos['x'];
	event_y+= scrpos['y'];

	tmp = new Image();
	tmp.src = obj.src;
	tmp.width = ((tmp.width/100)*ZOOM_RATIO);
	tmp.height = ((tmp.height/100)*ZOOM_RATIO);

	box_w = Math.floor(obj.width/(tmp.width/ZOOM_W));
	box_h = Math.floor(obj.height/(tmp.height/ZOOM_H));

	offsets = OBJ_GetOffsets(obj);

	if(!ZOOM_ISDRAWN) {
		divHTML = '<div style="background:'+ZOOM_CLR+';width:0px;height:0px;';
		divHTML+= 'left:0px;top:0px;display:block;position:absolute;';
		divHTML+= 'z-index:100;overflow:hidden;border:none;"';
		
		outHTML = divHTML+' id="id_ZOOM_box_t"></div>\n';
		outHTML+= divHTML+' id="id_ZOOM_box_r"></div>\n';
		outHTML+= divHTML+' id="id_ZOOM_box_b"></div>\n';
		outHTML+= divHTML+' id="id_ZOOM_box_l"></div>\n';

		outHTML+= '<div style="border:5px solid '+ZOOM_CLR+';background-color:#FFF;width:';
		outHTML+= ZOOM_W+'px;height:'+ZOOM_H+'px;left:0;top:0;display:';
		outHTML+= 'none;position:absolute;z-index:100;overflow:hidden;padding:0;margin:0;" ';
		outHTML+= 'id="id_ZOOM"></div>\n';
		document.body.innerHTML += outHTML;
		//var eid=["id_ZOOM"]
		//var transition=[1];
		//var duration=[FADETIME];
		//fade(eid,duration,transition);
		ZOOM_ISDRAWN = true;
	}

	box_x = (event_x-(box_w/2))<offsets['x']?offsets['x']:(event_x-(box_w/2));
	box_y = (event_y-(box_h/2))<offsets['y']?offsets['y']:(event_y-(box_h/2));

	box_x = (box_x+box_w)>(offsets['x']+offsets['width'])?(offsets['x']+offsets['width']-box_w):box_x;
	box_y = (box_y+box_h)>(offsets['y']+offsets['height'])?(offsets['y']+offsets['height']-box_h):box_y;

	box_x = Math.round(box_x);
	box_y = Math.round(box_y);

	img_x = Math.floor((box_x-offsets['x'])*(tmp.width/obj.width));
	img_y = Math.floor((box_y-offsets['y'])*(tmp.height/obj.height));

	jscBox = getObject("id_ZOOM_box_t"); //draw magnifier box
	jscBox.style.width = box_w+"px";
	jscBox.style.left = box_x+"px";
	jscBox.style.top = box_y+"px";
	jscBox = getObject("id_ZOOM_box_r");
	jscBox.style.height = box_h+"px";
	jscBox.style.left = (box_x+box_w)+"px";
	jscBox.style.top = box_y+"px";
	jscBox = getObject("id_ZOOM_box_b");
	jscBox.style.width = box_w+"px";
	jscBox.style.left = box_x+"px";
	jscBox.style.top = (box_y+box_h)+"px";
	jscBox = getObject("id_ZOOM_box_l");
	jscBox.style.height = box_h+"px";
	jscBox.style.left = box_x+"px";
	jscBox.style.top = box_y+"px";

	pos_x = (box_x+box_w);
	pos_y = (box_y+box_h);

	jscBox = getObject("id_ZOOM");
	jscBox.innerHTML = '<img src="'+tmp.src+'" width="'+tmp.width+'px" height="'+tmp.height+'px" style="position:relative;left:-'+img_x+'px;top:-'+img_y+'px;">\n';
	jscBox.style.left = pos_x+"px";
	jscBox.style.top = pos_y+"px";
	
	/*if(jscBox.style.opacity == 0 && jscBox.filters.alpha.opacity == 0){
		var eid=["id_ZOOM"];
		var transition=[1];
		var duration=[FADETIME];
		fade(eid,duration,transition);
	} else */
	
	jscBox.style.display = "block";
}


function zoomHide() {
	if(!ZOOM_ISDRAWN) { return; }
	//var x=-10;
	//getObject("id_ZOOM_box_l").style.left = x+"px";
	//getObject("id_ZOOM_box_r").style.left = x+"px";
	//getObject("id_ZOOM_box_t").style.top = x+"px";
	//getObject("id_ZOOM_box_b").style.top = x+"px";
	//getObject("id_ZOOM").style.opacity = 0;
	//getObject("id_ZOOM").style.filter = "alpha(opacity=0)";
	getObject("id_ZOOM").style.display = "none";
	return;
}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

String.prototype.capitalize = function() {
	return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
}

//functions to handle rotating image galleries
if (!Array.prototype.filter) {
    Array.prototype.filter = function(fun /*, thisp*/) {
        var len = this.length >>> 0;
        if (typeof fun != "function") {
            throw new TypeError();
        }

        var res = [];
        var thisp = arguments[1];
        for (var i = 0; i < len; i++) {
            if (i in this) {
                var val = this[i]; // in case fun mutates this
                if (fun.call(thisp, val, i, this)) {
                    res.push(val);
                }
            }
        }
        return res;
    }
}

crossfade = function(divs, fade, show){	
	this.nAct = -1;
	this.aDivs = divs;
	
	for (var i=0;i<divs.length;i++){
		getObject(divs[i]).style.opacity = 0;
		getObject(divs[i]).style.position = "absolute";
		getObject(divs[i]).style.filter = "alpha(opacity=0)";
		getObject(divs[i]).style.visibility = "hidden";
	}
	
	this.nDur = fade;
	this.nDelay = show;
	this.stopped = false;
	this._newfade();
}

crossfade.prototype.StopFade = function(){
	if (this.stopped){
		return;
	}
	this.stopped = true;
}

crossfade.prototype._newfade = function(){
	if (this.nID1){
		clearInterval(this.nID1);
	}
	if (this.stopped){
		return;
	}
	this.stopped = false;
	this.nOldAct = this.nAct;
	this.nAct++;
	if (!this.aDivs[this.nAct]){
		this.nAct = 0;
	}
	if (this.nAct == this.nOldAct){
		return false;
	}
	getObject(this.aDivs[this.nAct]).style.visibility = "visible";
	
	
	this.nInt = 50;
	this.nTime = 0;
	
	var p=this;
	this.nID2 = setInterval(function() { p._fade() }, this.nInt);
}

crossfade.prototype._fade = function(){
	this.nTime += this.nInt;
	
	if (this.stopped){
		return;
	}
	this.stopped = false;
	
	var ieop = Math.round( this._easeInOut(this.nTime, 0, 1, this.nDur) * 100 );
	var op = ieop / 100;
	getObject( this.aDivs[this.nAct] ).style.opacity = op;
	getObject( this.aDivs[this.nAct] ).style.filter = "alpha(opacity="+ieop+")";
	if (ieop==100 && document.all){
		getObject( this.aDivs[this.nAct] ).style.removeAttribute('filter'); //to prevent fuzzy text in IE8 and less
	}
	
	if (this.nOldAct > -1){
		getObject( this.aDivs[this.nOldAct] ).style.opacity = 1 - op;
		getObject( this.aDivs[this.nOldAct] ).style.filter = "alpha(opacity="+(100 - ieop)+")";
	}
	
	
	
	if (this.nTime == this.nDur){
		clearInterval( this.nID2 );
		
		if (this.nOldAct > -1){
			getObject( this.aDivs[this.nOldAct] ).style.visibility = "hidden";
		}
		
		var p=this;
		this.nID1 = setInterval(function() { p._newfade() }, this.nDelay);
	}
}

crossfade.prototype._easeInOut = function(t,b,c,d){
	return c/2 * (1 - Math.cos(Math.PI*t/d)) + b;
}

function update(x, selproduct, selrange){
	var obj;
	var images = "";
	var exclusion="";
	
	var code = jsproductarray[x][0];
	var description = jsproductarray[x][1];
	//var price = jsproductarray[x][2];
	//var feature = jsproductarray[x][3];
	//var guide = jsproductarray[x][2];
	var image0 = jsproductarray[x][2];
	var image1 = jsproductarray[x][3];
	var image2 = jsproductarray[x][4];
	var image3 = jsproductarray[x][5];
	var image4 = jsproductarray[x][6];
	
	/*description+= "<br /><a href='?additem="+x+"'><img src='/images/addtobasket.jpg' /></a>";*/
	
	if (image0){
		var newImg = new Image();
		newImg = image0;
		var imageSize = imageResize(newImg.width, newImg.height, GPW, GPH, 1);		
		var height = imageSize.height;
		var width = imageSize.width;
		
		var hvalue = (GPH-height)/2;
		var wvalue = (GPW-width)/2;
		
		images+="<div class='gallery_image'><a href='#' onfocus='this.blur()' onclick='swapimage("+x+","+0+")'><div class='wraptocenter'><span></span><img src='"+image0.src+"' width='"+width+"' height='"+height+"px;' style='position:absolute; top:"+hvalue+"px;left:"+wvalue+"px;' /></div></a></div>";
	}

	if (image1){
		var newImg = new Image();
		newImg = image1;
		var imageSize = imageResize(newImg.width, newImg.height, GPW, GPH, 2);		
		var height = imageSize.height;
		var width = imageSize.width;
		
		var hvalue = (GPH-height)/2;
		var wvalue = (GPW-width)/2;
		
		images+="<div class='gallery_image'><a href='#' onfocus='this.blur()' onclick='swapimage("+x+","+1+")'><div class='wraptocenter'><span></span><img src='"+image1.src+"' width='"+width+"' height='"+height+"px;' style='position:absolute; top:"+hvalue+"px;left:"+wvalue+"px;' /></div></a></div>";
	}
	if (image2){
		image2 = image2;//.src;
		
		var newImg = new Image();
		newImg = image2;
		var imageSize = imageResize(newImg.width, newImg.height, GPW, GPH, 2);		
		var height = imageSize.height;
		var width = imageSize.width;
		
		var hvalue = (GPH-height)/2;
		var wvalue = (GPW-width)/2;
	
		images+="<div class='gallery_image'><a href='#' onfocus='this.blur()' onclick='swapimage("+x+","+2+")'><span class='wraptocenter'><span></span><img src='"+image2.src+"' width='"+width+"' height='"+height+"px;' style='position:absolute; top:"+hvalue+"px;left:"+wvalue+"px;' /></span></a></div>";
	}
	if (image3){
		image3 = image3;

		var newImg = new Image();
		newImg = image3;
		var imageSize = imageResize(newImg.width, newImg.height, GPW, GPH, 2);		
		var height = imageSize.height;
		var width = imageSize.width;
		
		var hvalue = (GPH-height)/2;
		var wvalue = (GPW-width)/2;
		
		images+="<div class='gallery_image'><a href='#' onfocus='this.blur()' onclick='swapimage("+x+","+3+")'><div class='wraptocenter'><span></span><img src='"+image3.src+"' width='"+width+"' height='"+height+"px;' style='position:absolute; top:"+hvalue+"px;left:"+wvalue+"px;' /></div></a></div>";
	}
	if (image4 && (!image1 || !image2 || !image3)){
		images+="<div class='gallery_image'><a href='#' onfocus='this.blur()' onclick='swapimage("+x+","+4+")'><div class='wraptocenter'><span></span><img src='"+IMAGESDIR+"dimensions.png' height='100' width='100' /><img class='hide' src='"+image4.src+"' /></div></a></div>";
	}

	var newImg = new Image();
	newImg = image0;
	var imageSize = imageResize(newImg.width, newImg.height, 450, 350, 1);		
	var height = imageSize.height;
	var width = imageSize.width;
	
	var zoom="<img src='"+image0.src+"' width='"+width+"' height='"+height+"' alt='' onmousemove='zoomShow(this,event);' onmouseout='zoomHide();'>";

	CF.StopFade();

	obj=getObject("top");//.innerHTML="<div id='photo_gallery'></div>";

	//obj=getObject("photo_gallery");
	//obj.style.opacity = 0;
	//obj.style.filter = "alpha(opacity=0)";
	obj.innerHTML = "<div id='photo_gallery'><div id='product_frame'><div id='product_image'>"+zoom+"</div></div><div class='description'>"+description+"</div><div class='product_gallery'>"+images+"</div></div>";
	//obj.innerHTML = "<div id='product_image'>"+zoom+"</div><div class='description'>"+description+"</div><div class='product_gallery'>"+images+"</div>";
	obj=getObject("mid");
	obj.innerHTML = selproduct + "&nbsp;<span class='grey'>+</span>&nbsp;" + selrange + "&nbsp;<span class='grey'>+</span>&nbsp;" + code;

	//var eid=["photo_gallery"];
	//var transition=[1];
	//var duration=[100];
	//fade(eid,duration,transition);
}

function swapimage(x,y){
	var image = new Image();
	var newImg = new Image();
	image = jsproductarray[x][y+2];
	newImg = image;

	var imageSize = imageResize(newImg.width, newImg.height, 450, 350, 1);		
	var height = imageSize.height;
	var width = imageSize.width;
	
	var zoom="<img src='"+image.src+"' width='"+width+"' height='"+height+"' alt='' onmousemove='zoomShow(this,event);' onmouseout='zoomHide();'>";

	var eid=["product_image"];
		
	obj=getObject("product_image");
	obj.style.opacity = 0;
	obj.style.filter = "alpha(opacity=0)";
	obj.innerHTML=zoom;
	var transition=[1];
	var duration=[100];
	fade(eid,duration,transition);
}

function imageResize(width, height, maxwidth, maxheight, method){
	var ratio;
	switch (method){
		case 1: //longer axis takes precedence, oblong image fits within specified boundaries
			if (width!=maxwidth) {
				ratio=width/maxwidth;
				width=Math.floor(width/ratio);
				height=Math.floor(height/ratio);
			}
			if (height>maxheight) {
				ratio=height/maxheight;
				width=Math.floor(width/ratio);
				height=Math.floor(height/ratio);
			}
		break;
		
		case 2: //shorter axis take precedence, oblong image expands to the shortist axis, longer axis overflows
			if (width>maxwidth) {
				ratio=width/maxwidth;
				width=Math.floor(width/ratio);
				height=Math.floor(height/ratio);
			}
			if (height>maxheight) {
				ratio=height/maxheight;
				width=Math.floor(width/ratio);
				height=Math.floor(height/ratio);
			}
			if (width<maxwidth) {
				ratio=width/maxwidth;
				width=Math.floor(width/ratio);
				height=Math.floor(height/ratio);
			}
			if (height<maxheight) {
				ratio=height/maxheight;
				width=Math.floor(width/ratio);
				height=Math.floor(height/ratio);
			}
		break;
	}
	if (isNaN(height) || isNaN(width)){height=maxheight;width=maxwidth;}

	return {width : width, height : height};
}

//declare our class so we can use the "new" keyword to create multiple instances
var animateFade = function(elmOrElmId, duration, state) {
	this.setOptions(elmOrElmId, duration, state);
}
 
//prototype its helper functions
animateFade.prototype = {

	setOptions: function(elmOrElmId, duration, state) {
	
		//set options
		this.fadeDuration = duration;
		this.element = (typeof elmOrElmId == 'string') ? getObject(elmOrElmId) : elmOrElmId;
		this.fadeState = (state && state == 1) ? 1 : -1;//default -1 fade out, 1 fade in
		this.fadeTimeLeft = duration;//preset to passed duration, then overwrite
		this.lastTick = this.newTick();
		
		//start animation
		this.animate();
	},
	
	newTick: function() {
		return new Date().getTime();
	},
	
	returnElapsedTicks: function() {
		return this.currentTick - this.lastTick;
	},
	
	animate: function() {
		this.currentTick = this.newTick();
	
		var self = this;
		var elapsedTicks = this.returnElapsedTicks();
		
		//helper function, called in the timeout below, to recurse while maintaining correct reference of "this"
		var helper = function() {
			self.animate();
		};
	
		if (this.fadeTimeLeft <= elapsedTicks) {
			this.element.style.opacity = ((this.fadeState == -1) ? 0 : 1);
			this.element.style.filter = 'alpha(opacity = ' + ((this.fadeState == -1) ? 0 : 100) + ')';
			return;
		}
		
		
		this.fadeTimeLeft -= elapsedTicks;
		var newOptVal = this.fadeTimeLeft / this.fadeDuration;
		newOptVal = (this.fadeState == -1) ? newOptVal : (1 - newOptVal);
		
		this.element.style.opacity = newOptVal;
		this.element.style.filter = 'alpha(opacity = ' + (newOptVal * 100) + ')';
		
		this.lastTick = this.currentTick;
		this.currentTick = this.newTick();
		
		setTimeout(helper, 33);
	}
}
 
//initialize function
var fade = function(elmsOrElmIdArr, duration, state) {
	for (var i = 0, l = elmsOrElmIdArr.length; i < l; i++) {
		//use "new" keyword to create separate instances
		new animateFade(elmsOrElmIdArr[i], duration[i], state[i]);
	}
}

function getNewPage(){
	var q1 = (arguments[0]) ? arguments[0] : "all+categories" ;
	var q2 = (arguments[1]) ? arguments[1] : "all+products" ;
	var q3 = (arguments[2]) ? arguments[2] : "" ;
	var q4 = (arguments[3]) ? arguments[3] : "" ;
	var q5 = (arguments[4]) ? arguments[4] : "" ;
	
	var path = "product.php"
	path += "?q1="+q1+"&q2="+q2;
	if (q3!="") path+="&q3="+q3; //optional arg
	if (q4!="") path+="&q4="+q4; //optional arg
	if (q5!="") path+="&q5="+q5; //optional arg
	
	window.location=path;
}

function zoomShow(obj,event) {
		
	var verIE = getInternetExplorerVersion();
	if ( (verIE > -1) && (verIE < 8.0) ) return;
	if (obj.style) obj.style.cursor="crosshair";
  
	event_x = (event.x?event.x:event.clientX);
	event_y = (event.y?event.y:event.clientY);

	scrpos = GetViewArea();
	event_x+= scrpos['x'];
	event_y+= scrpos['y'];

	tmp = new Image();
	tmp.src = obj.src;
	tmp.width = ((tmp.width/100)*JSCMAGNIFY_RATIO);
	tmp.height = ((tmp.height/100)*JSCMAGNIFY_RATIO);

	box_w = 0;
	box_h = 0;

	box_w = Math.floor(obj.width/(tmp.width/JSCMAGNIFY_W));
	box_h = Math.floor(obj.height/(tmp.height/JSCMAGNIFY_H));

	offsets = OBJ_GetOffsets(obj);

	if(!JSCMAGNIFY_ISDRAWN) {
		divHTML = '<div style="background:'+JSCMAGNIFY_CLR+';width:1px;height:1px;';
		divHTML+= 'left:-10px;top:-10px;display:block;position:absolute;';
		divHTML+= 'z-index:100;overflow:hidden;border:none;"';
		outHTML = divHTML+' id="id_jscmagnify_box_t"></div>\n';
		outHTML+= divHTML+' id="id_jscmagnify_box_r"></div>\n';
		outHTML+= divHTML+' id="id_jscmagnify_box_b"></div>\n';
		outHTML+= divHTML+' id="id_jscmagnify_box_l"></div>\n';

		outHTML+= '<div style="border:1px solid '+JSCMAGNIFY_CLR+';background-color:#FFF;width:';
		outHTML+= JSCMAGNIFY_W+'px;height:'+JSCMAGNIFY_H+'px;left:0;top:0;display:';
		outHTML+= 'none;position:absolute;z-index:100;overflow:hidden;padding:0;margin:0;" ';
		outHTML+= 'id="id_jscmagnify_zoom"></div>\n';
		document.body.innerHTML+= outHTML;
		JSCMAGNIFY_ISDRAWN = true;
	}
	
	if(JSCMAGNIFY_POS<0 || JSCMAGNIFY_POS>9) { JSCMAGNIFY_POS = 3; }

	box_x = (event_x-(box_w/2))<offsets['x']?offsets['x']:(event_x-(box_w/2));
	box_y = (event_y-(box_h/2))<offsets['y']?offsets['y']:(event_y-(box_h/2));

	box_x = (box_x+box_w)>(offsets['x']+offsets['width'])?(offsets['x']+offsets['width']-box_w):box_x;
	box_y = (box_y+box_h)>(offsets['y']+offsets['height'])?(offsets['y']+offsets['height']-box_h):box_y;

	box_x = Math.round(box_x);
	box_y = Math.round(box_y);

	img_x = Math.floor((box_x-offsets['x'])*(tmp.width/obj.width));
	img_y = Math.floor((box_y-offsets['y'])*(tmp.height/obj.height));

	jscBox = getObject("id_jscmagnify_box_t");
	jscBox.style.width = box_w+"px";
	jscBox.style.left = box_x+"px";
	jscBox.style.top = box_y+"px";
	jscBox = getObject("id_jscmagnify_box_r");
	jscBox.style.height = box_h+"px";
	jscBox.style.left = (box_x+box_w)+"px";
	jscBox.style.top = box_y+"px";
	jscBox = getObject("id_jscmagnify_box_b");
	jscBox.style.width = box_w+"px";
	jscBox.style.left = box_x+"px";
	jscBox.style.top = (box_y+box_h)+"px";
	jscBox = getObject("id_jscmagnify_box_l");
	jscBox.style.height = box_h+"px";
	jscBox.style.left = box_x+"px";
	jscBox.style.top = box_y+"px";

	pos_x = (JSCMAGNIFY_POS>4?(box_x-(JSCMAGNIFY_W+12)):(JSCMAGNIFY_POS==0||JSCMAGNIFY_POS==4?(box_x-Math.round((JSCMAGNIFY_W-box_w+2)/2)):(box_x+box_w+10)));
	pos_y = (JSCMAGNIFY_POS==7||JSCMAGNIFY_POS<2?(box_y-(JSCMAGNIFY_H+12)):(JSCMAGNIFY_POS==2||JSCMAGNIFY_POS==6?(box_y-Math.round((JSCMAGNIFY_H-box_h+2)/2)):(box_y+box_h+10)));

	jscBox = getObject("id_jscmagnify_zoom");
	jscBox.innerHTML = '<img src="'+tmp.src+'" width="'+tmp.width+'px" height="'+tmp.height+'px" style="position:relative;left:-'+img_x+'px;top:-'+img_y+'px;">\n';
	jscBox.style.left = pos_x+"px";
	jscBox.style.top = pos_y+"px";
	jscBox.style.display = "block";
}

function zoomHide() {
	if(!JSCMAGNIFY_ISDRAWN) { return; }
	getObject("id_jscmagnify_box_l").style.left = "-10px";
	getObject("id_jscmagnify_box_r").style.left = "-10px";
	getObject("id_jscmagnify_box_t").style.top = "-10px";
	getObject("id_jscmagnify_box_b").style.top = "-10px";
	getObject("id_jscmagnify_zoom").style.display = "none";
	return;
}

if(typeof getObject!='function') {
	function getObject(objID) {
		if(document.getElementById) {
			return document.getElementById(objID);
		} else if(document.all) {
			return document.all[objID];
		}
		return null;
	}
}

if(typeof OBJ_GetOffsets!='function') {
	function OBJ_GetOffsets(obj) {
		offsets = new Array();
		offsets['width'] = obj.offsetWidth;
		offsets['height'] = obj.offsetHeight;

		offsets['x'] = 0;
		offsets['y'] = 0;

		tmpOBJ = obj;

		do {
			offsets['x']+= tmpOBJ.offsetLeft;
			offsets['y']+= tmpOBJ.offsetTop;
		} while (tmpOBJ = tmpOBJ.offsetParent);
		
		//offsets x and y are distances from left and top of browser to the left and top borders of whatever image is being zoomed
		
		return offsets;
	}
}

if(typeof GetViewArea!='function') {
	function GetViewArea() {
		scr = new Array();
		
		scr['x'] = document.body.scrollLeft;
		scr['y'] = document.body.scrollTop;
		
		if(window.innerWidth) {
			scr['w'] = window.innerWidth;
			scr['h'] = window.innerHeight;
		} else { //for older IE
			scr['w'] = document.body.offsetWidth;
			scr['h'] = document.body.offsetHeight;
		}
		
		if(document.all){ //adjust for IE
			if (scr['w']>985) { //correct for x-axis floating css positioning
				scr['x'] += (scr['w']/2)-(985/2);
			}
			scr['y'] += 60; //correct for y-axis static css positioning
		}

		
		return scr;
	}
}

