/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;var getXmlHttpRequest = function() {
	 var http = null;
	 if (window.XMLHttpRequest) {
		 http = new XMLHttpRequest();
	 } else {
		var ver = ['MSXML2.XMLHttp.5.0', 'MSXML2.XMLHttp.4.0', 'MSXML2.XMLHttp.3.0', 'MSXML2.XMLHttp', 'Microsoft.XMLHttp'];
		for (var i = 0; i < ver.length; i++) {
			 try {
			 	http = new ActiveXObject(ver[i]);
			 } catch (err) {
				continue;
			 }
		}
	 }
	 if (!http) {
		 return false;
	 }
	 return http;
};

var ajaxLoading = function(canvs) {
	if (!canvs) {
		return;
	}
	var opacity = $$('div');
	if (canvs.form) {
		opacity = css(opacity, {
	  	 'width' : canvs.offsetWidth + 'px',
	    'height' : canvs.offsetHeight + 'px', 
	    'position' : 'absolute', 
	    'top' : offsetTop(canvs) + 'px', 
	    'left' : offsetLeft(canvs) + 'px'
	    
	  });
	  opacity = attr(opacity, {
	    'className' : 'ms-opacity'
	  });
	  document.body.appendChild(opacity);		
	  canvs.opacity = opacity;
	  opacity = null;
	} else {
		canvs = css(canvs, {
		  'position' : 'relative'
		});
		opacity = css(opacity, {
		  'width' : '100%',
		  'height' : '100%',
		  'position' : 'absolute',
		  'top' : '0',
		  'left' : '0'
		});
		opacity = attr(opacity, {
		  'className' : 'ms-opacity'
		});
		canvs.opacity = opacity;
		var loader = $$('div');
		if (loader) {
			loader = css(loader, {
			  'width' : '100%',
		     'height' : '100%',
		     'position' : 'absolute',
		     'top' : '0',
		     'left' : '0',
		     'zIndex' : '9999999',
		     'textAlign': 'center',
		     'overflow' : 'hidden'
			});
		}
		loader = attr(loader, {
		  'className' : 'ms-loader'
		});
		canvs.opacity = opacity;
		canvs.loader = loader;
		canvs.appendChild(opacity);
		canvs.appendChild(loader);
		loader = null, opacity = null;
	}
};

var ajaxHideLoading = function(canvs) {
	try {
		if (canvs.loader) {
			canvs.removeChild(canvs.loader);
			canvs.removeAttribute('loader');
		} 
		if (canvs.opacity) {
			if (canvs.form) {
				document.body.removeChild(canvs.opacity);
			} else {
				canvs.removeChild(canvs.opacity);
			}
			canvs.removeAttribute('opacity');
		} 
	} catch (err) {}
};

var ajaxError = function(canvs, txt) {
	if (canvs) {
		canvs = css(canvs, {
		  'position' : 'relative'
		});
		var err = $$('div');
		if (err) {
			err = css(err, {
			  'textAlign' : 'center',
			  'width' : '100%',
		     'height' : '100%',
		     'position' : 'absolute',
		     'top' : '0',
		     'left' : '0',
		     'zIndex' : '99999999',
		     'background' : '#fff',
		     'overflow' : 'hidden',
		     'lineHeight' : '3em'
			});
			err.innerHTML = txt;
			ajaxHideLoading(canvs);
			canvs.appendChild(err);
			setTimeout(function() {
			   fxFade(err, 'down');
			}, 3500);
			scrollToElement(canvs);
		}
	}
};

var ajaxXmlHttpRequest = function(e, t) {
	var element = e, target = t, error, loading, callback, wait, abort, uri, output, json, scroll;
	this.send = function() {
		if (!element) {
			return true;
		}
		var http = getHttpRequest();
		if (!http) {
			return true;
		}
		var data = null, url = null, method = 'GET';
		if (uri) {
			url = uri;
		} else {
			if (tag(element) == 'a') {
				url = element.href;
			} else {
				if (tag(element) == 'form') {
					url = element.action;
					var arr = Array();
					if (element.elements.length) {
						var e, i = 0;
						while (e = element.elements[i++]) {
							if (typeof e.type == 'undefined') {
								continue;
							}
							if (e.disabled === true) {
								continue;
							}
							if (e.type == 'checkbox' && !e.checked) {
								e.value = '0';
							}
							if (e.type == 'radio' && !e.checked) {
								continue;
							}
							if (e.tagName.toLowerCase() == 'select') {
								var o, t = 0;
								while (o = e.options[t++]) {
									if (o.selected) {
										arr.push(e.name+'='+encodeURIComponent(o.value));
									}
								}
							} else {
								arr.push(e.name+'='+encodeURIComponent(e.value));
							}
						}
					}
					data = arr.join('&');
				} else {
					return true;
				}
			}
		}
		if (!url) {
			return true;
		}
		if (abort) {
			setTimeout(function() {
				http.abort();
				if (error) {
					error(http);
				}
			}, abort);
		}
		output = (output == 'json' ? 'json' : 'html');
		http.onreadystatechange = function() {
			if (http.readyState == 4) {
				if (http.status == 200 || http.status == 304) {
					var res = http.responseText;
					if (res.length) {
						if (output == 'json') {
							if (json) {
								json(eval('(' + res + ')'));
							}
						} else {
							if (target && res.length) {
								if (target.form) {
									target.value = res;
								} else {
									target.innerHTML = res;
								}
							}
						}
					}
					
					if (callback) {
						callback();
					}
					
					if (scroll) {
						scrollToElement(target);
					}

					if (target) {
						target.focus();
					}
				} else {
					if (error) {
						error(http);
					}
					if (target) {
						target.focus();
					}
				}
			}
		};
		if (element.method) {
			if (element.method.toUpperCase() != 'GET') {
				method = 'POST';
			} else {
				if (data) {
					url = url.split('#')[0];
					if (url.match('\\?')) {
						url += '&'+data;
					} else {
						url += '?'+data;
					}
				}
			}
		} 
		if (loading) {
			loading();
		}
		http.open(method, url, true);
		if (method == 'POST') {
			http.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
		}
		http.setRequestHeader("X_REQUESTED_WITH", "XMLHttpRequest");
		if (wait && wait > 0) {
			setTimeout(function() {
				http.send(data);
			}, wait);
		} else {
			http.send(data);
		}
		return false;
	};
	var getHttpRequest = function() {
		return getXmlHttpRequest();
	};
	this.setError = function(e) {
		error = e;
	};
	this.setLoading = function(l) {
		loading = l;
	};
	this.setCallback = function(c, s) {
		callback = c;
		scroll = s;
	};
	this.disableScroll = function(s) {
		scroll = s;
	};
	this.setWait = function(w) {
		wait = w;
	};
	this.setAbort = function(a) {
		abort = a;
	};
	this.setUri = function(u) {
		uri = u;
	};
	this.setOutput = function(o) {
		output = o;
	};
	this.setJson = function(f) {
		json = f;
	};
};

var ajaxCanvs = function(c) {
	if (typeof c == 'string' && c.length) {
		if (c.match('_')) {
			var p = c.split('_');
			return p[1];
		}
	} 
};

var ajaxFrameRequestCallback = function(id, c, callback) {
	var canvs = $(c), fr = $(id);
	if (fr && canvs) {
		if (fr.contentDocument) {
      	var d = fr.contentDocument;
      } else if (fr.contentWindow) {
         var d = fr.contentWindow.document;
      } else {
         var d = window.frames[id].document;
      }
      
      if (d.location.href == "about:blank") {
         return;
      }
      
      canvs.innerHTML = d.body.innerHTML;
      
      ajaxHideLoading(canvs);
      fxFade(canvs, 'up');
		initAjax(canvs);
		
		canvs.focus();
	}
};

var ajaxFrameRequest = function(e, t) {
	var element = e, target = t, loading;
	this.send = function() {
		if (loading) {
			loading();
		}
		var id = 'target-' + Math.round(1000*Math.random());
		element = attr(element, {
		  	'target' : id
		});
		element.action = addQuery(element.action, 'ajax', 'true');
		var div = $$('div');
		div.innerHTML = '<iframe style="display:none" src="about:blank" id="' + id + '" name="' + id + '" onload="ajaxFrameRequestCallback(\'' + id + '\', \'' + target.id + '\');"></iframe>'; 
		document.body.appendChild(div);
	};
	this.setLoading = function(l) {
		loading = l;
	};
};

var doHttpRequest = function(o, uri, canvs) {
	if (!canvs) {
		canvs = ajaxCanvs(o.className);
	}
	if (!canvs) {
		return true;
	}
	var canvs = $(canvs);
	var http = new ajaxXmlHttpRequest(o, canvs);
	if (uri !== null) {
		http.setUri(uri);
	}
	http.setLoading(function() {
		ajaxLoading(canvs);
	});
	http.setCallback(function() {
		ajaxHideLoading(canvs);
		fxFade(canvs, 'up');
		initAjax(canvs);
	});
	http.setError(function(http) {
		var txt = '';
		if (http && http.status == 403) {
			txt = $('ms-forbidden').innerHTML;
		} else {
			txt = 'Nieprzewidziany błąd aplikacji. Przepraszamy';
		}
		ajaxError(canvs, txt);
	});
	return http.send();
};
 
var initAjax = function(target) {
	if (!target) {
		target = document.body;
	} 
	if (target) {
		var o = null, i = 0, a = target.getElementsByTagName('a');
		if (a) {
			while (o = a[i++]) {
				if (o) {
					if (o.className && o.className.match('^ms-use-http')) {
						o.onclick = function() {
							if (this.className && this.className.match('^ms-use-http-confirm')) {
								if (!confirm(this.title)) {
									return false;
								}
							}
							return doHttpRequest(this);
						};
					}
				}
			}
			a = null;
		}
		var o = null, i = 0, f = target.getElementsByTagName('form'); 
		if (f) {
			while (o = f[i++]) {
				if (o) {
					if (o.className && o.className.match('^ms-use-http')) {
						o.onsubmit = function() {
							if (this.className && this.className.match('^ms-use-http-confirm')) {
								if (!confirm(this.getAttribute('longdesc'))) {
									return false;
								}
							}
							return doHttpRequest(this);
						};
					} else {
						if (o.className && o.className.match('^ms-use-frame')) {
							o.onsubmit = function() {
								if (this.className && this.className.match('^ms-use-frame-confirm')) {
									if (!confirm(this.getAttribute('longdesc'))) {
										return false;
									}
								}
								canvs = $(ajaxCanvs(this.className));
								var http = new ajaxFrameRequest(this, canvs);
								http.setLoading(function() {
									ajaxLoading(canvs);
								});
								return http.send();
							};
						}
					}
				}
			}
			f = null;
		}
		var o = null, i = 0, s = target.getElementsByTagName('select'); 
		if (s) {
			while (o = s[i++]) {
				if (o) {
					if (o.className && o.className.match('^ms-use-http')) {
						o.onchange = function() {
							if (this.form) {
								var uri = addQuery(this.form.action, this.name, this.options[this.selectedIndex].value);
								return doHttpRequest(this, uri);
							}
						};
					} 
				}
			}
			s = null;
		}	
	}
	target = null;
};

var calculatePaS = function(canvs, shipping, payment) {
	var canvs = $(canvs);
	if (canvs) {
		var http = new ajaxXmlHttpRequest(canvs, canvs);
		http.setUri('/basket/calculate-pas/?shipping=' + shipping + '&payment=' + payment);
		http.setLoading(function() {
			ajaxLoading(canvs);
		});
		http.setCallback(function() {
			ajaxHideLoading(canvs);
			fxFade(canvs, 'up');
			initAjax(canvs);
		});
		http.disableScroll(false);
		http.send();
	}
};

var updateProductViewCount = function(id) {
	if (id) {
		var http = getXmlHttpRequest();
		if (http) {
			http.open('GET', '/view/?id='+id, true);
			http.setRequestHeader("X_REQUESTED_WITH", "XMLHttpRequest");
			setTimeout(function() {
				http.send(null);
			}, 2000);
		}
	}
};var allReadyLoading = false;

var LiveSearch = function(obj) {
	if (obj) {
		for (index in obj) {
			this[index] = obj[index];
		}
	}
	this.init();
};

LiveSearch.prototype.init = function() {
	var LS = this;
	var form = $(this.form);
	if (!form) {
		return;
	}
	var send = function(e, n) {
		if (!e) {
			e = window.event;
		}
		clearTimeout(LS.wait);
		var keyCode = e.keyCode;
		LS.userTxt = this.value;
		if (keyCode == 8 || keyCode == 46) {
			if (LS.loader && !allReadyLoading) {
				LS.loader();
				allReadyLoading = true;
			}
			LS.wait = setTimeout(function(){
				LS.send(n);
			}, 250);
		} else if ((keyCode < 32 && (keyCode != 17 && keyCode != 18 && keyCode != 16)) || (keyCode >= 33 && keyCode <= 46) || (keyCode >= 112 && keyCode <= 123)) {}
		else {
			if (LS.loader && !allReadyLoading) {
				LS.loader();
				allReadyLoading = true;
			}
			LS.wait = setTimeout(function(){
				LS.send(n);
			}, 250);
		}
	};
	form.txt.onkeyup = function(e) {
		send(e, 'txt');
	};
	if (form.priceFrom) {
		form.priceFrom.onkeyup = function(e) {
			send(e, 'priceFrom');
		};
	}
	if (form.priceTo) {
		form.priceTo.onkeyup = function(e) {
			send(e, 'priceTo');
		};
	}
};

LiveSearch.prototype.send = function(n) {
	var LS = this;
	var form = $(this.form);
	var http = getXmlHttpRequest();
	var uri = form.action;
	if (form.txt && form.txt.value.length) {
		uri = addQuery(uri, 'txt', encodeURIComponent(form.txt.value));
	}
	if (form.priceFrom) {
		if (form.priceFrom.value.length) {
			uri = addQuery(uri, 'priceFrom', form.priceFrom.value);
		}
	}
	if (form.priceTo) {
		if (form.priceTo.value.length) {
			uri = addQuery(uri, 'priceTo', form.priceTo.value);
		}
	}
	http.open('GET', uri, true);
	http.setRequestHeader('X_REQUESTED_WITH', 'XMLHttpRequest');
	http.onreadystatechange = function() {
		if (http.readyState == 4) {
			if (http.status == 200 || http.status == 304) {
				if (LS.target) {
					LS.target.innerHTML = http.responseText;
				}
				if (LS.callback) {
					LS.callback();
				}
				if (LS.target) {
					LS.target.focus();
				}
				switch (n) {
					case 'txt':
						$(LS.form).txt.focus();
					break;
					case 'priceFrom':
						$(LS.form).priceFrom.focus();
					break;
					case 'priceTo':
						$(LS.form).priceTo.focus();
					break;
				}
			}
		}
	};
	http.send(null);
};var Overlay = {};

Overlay.sClose = 'X';

Overlay.init = function(oConfig) {
 if (typeof oConfig == 'object') {
     var cLinks = document.getElementsByTagName("a");
     if (cLinks.length) {
         for (var i = 0; i < cLinks.length; i++) {
              if (oConfig.sClass == cLinks[i].className) {
                  cLinks[i].onclick = function() {
                    Overlay.show(this, oConfig);
                    return false;
                  }
              }
         }
     }
 }
};

Overlay.show = function(oObject) {
  if (arguments[1]) {
      var oConfig = arguments[1];
  }
  
  if ($('js-overlay-conteiner')) {
      document.body.removeChild($('js-overlay-conteiner'));
  }
      
  if (!$('js-overlay')) {
      var oOverlay = document.createElement('div');
      oOverlay.id = 'js-overlay';
      document.body.appendChild(oOverlay);
  }
      
  var oConteiner = document.createElement('div');
  oConteiner.id = 'js-overlay-conteiner';
  oConteiner.innerHTML = '<div id="js-overlay-window-wrapper"><div id="js-overlay-window"></div></div>';
  oConteiner.style.visibility = 'hidden';
  document.body.appendChild(oConteiner);
  
  function closeWindow() {
    Overlay.close();
    return false;
  }
  
  // fixed...
  if (window.ActiveXObject) {
      document.documentElement.style.overflow = 'hidden';
      document.body.style.overflow = 'hidden';
  }      
  
  document.documentElement.style.width = '100%';
  document.documentElement.style.height = '100%';
  document.body.style.height = '100%';
  document.body.style.width = '100%';
  
  if (!$('js-overlay-window-preloader')) {
      var oPreloader = document.createElement('div');
      oPreloader.id = 'js-overlay-window-preloader';
      document.body.appendChild(oPreloader);
  }
  
  $('js-overlay-window-preloader').style.display = 'block';
  
  if (/(.jpeg|.jpe|.jpg|.gif|.png|.bmp)$/i.test(oObject.href)) {
      var aImages = new Array;
      var tmp = new Array;
      if (oObject.rel != '') {
          for (var i = 0; i < document.links.length; i++) {
               if (document.links[i].className == oConfig.sClass && document.links[i].rel == oObject.rel) {
                   var is = false;
                   for (var m = 0; m < tmp.length; m++) {
                   	if (tmp[m] == document.links[i].href) {
                   	   is = true;
                   	}
                   }
                   if (!is) {
                   	aImages.push(document.links[i]);
                   	tmp.push(document.links[i].href) ;
                   }
               }
          }
      } else {
          aImages.push(oObject);
      }
      
      if (aImages.length) {
          for (var i = 0; i < aImages.length; i++) {
               if (aImages[i].href == oObject.href) {
                   var iIndex = i;
                   break;
               }
          }
      }
      
      var oLoadedImage = new Image();
      
      oLoadedImage.onload = function() {
        oLoadedImage.onload = null;
        
        var sHtml = '';
        
        if (oObject.getAttribute('title')) {
            sHtml += '<div id="js-overlay-gallery-desc">' + oObject.getAttribute('title') + '</div>';
        }
        
        $('js-overlay-window').style.width = (oLoadedImage.width + 20) + "px";
        
        if (aImages.length > 1) {
            sHtml += '<div id="js-overlay-gallery-nav">';
            if (iIndex > 0) {
                sHtml += '<a href="#" id="js-nav-prev" title="Przeglądaj zdjęcia używając strzałek w lewo i w prawo na klawiaturze">« Poprzednie</a>';
            }
            if (iIndex < aImages.length - 1) {
                sHtml += '<a href="#" id="js-nav-next" title="Przeglądaj zdjęcia używając strzałek w lewo i w prawo na klawiaturze">Następne »</a>';
            }
            sHtml += '</div>';
        }
        
        sHtml += '<img title="Zakmnij" id="js-overlay-gallery-img" src="' + oObject.href + '" width="' + oLoadedImage.width + '" height="' + oLoadedImage.height + '" alt="Zamknij" />';
        
        if (aImages.length > 1) {
            sHtml += '<div id="js-overlay-gallery-counter">Obrazek: <strong>' + (iIndex + 1) + '</strong> z ' + aImages.length + '</div>';
        }
        
        sHtml += '<a href="#" id="js-overlay-gallery-close" title="Zamknij">' + Overlay.sClose + '</a>';
        
        $('js-overlay-window-preloader').style.display = 'none';
        
        $('js-overlay-window').innerHTML = sHtml;
        $('js-overlay-conteiner').style.visibility = 'visible';
        
        if ($('js-nav-prev')) {
            function goPrev() {
              if (Overlay.iTimer) {
                  clearTimeout(Overlay.iTimer);
              }
              Overlay.show(aImages[iIndex - 1], oConfig);
              return false;
            }
            $('js-nav-prev').onclick = goPrev; 
        }
          
        if ($('js-nav-next')) {
            function goNext() {
              if (Overlay.iTimer) {
                  clearTimeout(Overlay.iTimer);
              }
              Overlay.show(aImages[iIndex + 1], oConfig);
              return false;
            }
            $('js-nav-next').onclick = goNext;
        }
        
        if ($('js-overlay-gallery-img')) {
            $('js-overlay-gallery-img').onclick = closeWindow;
        }
        
        if ($('js-overlay-gallery-close')) {
            $('js-overlay-gallery-close').onclick = closeWindow;
        }
        
        function nextSlide() {
          var iNext = iIndex == aImages.length - 1 ? 0 : iIndex + 1;
          oConfig.bSlide = true;
          Overlay.show(aImages[iNext], oConfig);
          return false;
        }
        
        if (oConfig.bRunSlideAtStart === true) {
            if ($('run-slide')) {
                $('run-slide').checked = true;
                oConfig.bRunSlideAtStart = false;
                Overlay.iTimer = setTimeout(function(){
                  nextSlide();
                }, oConfig.iDuration);
            }
        } else {
            if (oConfig.iDuration > 0) {
                if (oConfig.bSlide === true) {
                    if ($('run-slide')) {
                        $('run-slide').checked = true;
                    }
                    Overlay.iTimer = setTimeout(function(){
                      nextSlide();
                    }, oConfig.iDuration);
                }
            }
        }
        
        if ($('run-slide')) {
            $('run-slide').onclick = function() {
              if (this.checked === true) {
                  Overlay.iTimer = setTimeout(function() {
                    nextSlide();
                  }, oConfig.iDuration);
              } else {
                  clearTimeout(Overlay.iTimer);
                  oConfig.bSlide = false;
              }
            }
        }
         
        document.onkeydown = function(e) {
          if (window.event) {
              e = window.event;
          }
          
          if (e.keyCode == 27) {
              closeWindow()
          } else if (e.keyCode == 39) {
              if ($('js-nav-next')) {
                  document.onkeydown = '';
                  goNext();
              }
          } else if (e.keyCode == 37) {
              if ($('js-nav-prev')) {
                  document.onkeydown = '';
                  goPrev();
              }
          } 
        }
      }
      oLoadedImage.src = oObject.href;
  } else {
      var uri = oObject.href;
      var http = getXmlHttpRequest();
      http.open('GET', uri, true);
      http.setRequestHeader('X_REQUESTED_WITH', 'XMLHttpRequest');
      http.onreadystatechange = function() {
      	if (http.readyState == 4) {
      		if (http.status == 200 || http.status == 304) {
      			css($('js-overlay-window-preloader'), {
      			  'display' : 'none'
      			});
      			var html = http.responseText;
      			html += '<a href="#" id="js-overlay-gallery-close" title="Zamknij">' + Overlay.sClose + '</a>';
      			$('js-overlay-window').innerHTML = html;
      			css($('js-overlay-conteiner'), {
      			  'visibility' : 'visible'
      			});
      			if ($('js-overlay-gallery-close')) {
            		$('js-overlay-gallery-close').onclick = closeWindow;
        			}
        			document.onkeydown = function(e) {
          			if (window.event) {
              			e = window.event;
          			}
          			if (e.keyCode == 27) {
              			closeWindow()
          			} 
          		} 
          		loadOnReady();
      		}
      	}
      }  
      http.send(null);
  }
  return false;
};

Overlay.close = function() {
  if ($('js-overlay-conteiner')) {
      document.body.removeChild($('js-overlay-conteiner'));
  }
  
  if (Overlay.iTimer) {
      clearTimeout(Overlay.iTimer);
      delete Overlay.iTimer;
  }
  
  if ($('js-overlay')) {
      document.body.removeChild($('js-overlay'));
  }
  
  if ($('js-overlay-window-preloader')) {
      document.body.removeChild($('js-overlay-window-preloader'));
  }
  
  document.documentElement.removeAttribute('style');
  document.body.removeAttribute('style');
    
  document.onkeydown = '';
  
  return false;
};
if (typeof $ !== 'function') {
	var $ = function(id) {
		return document.getElementById(id);
	};
}

if (typeof $$ !== 'function') {
	var $$ = function(element) {
		return document.createElement(element);
	}
}

if (typeof css !== 'function') {
	var css = function(obj, css) {
		if (obj.nodeType == 1) {
			for (index in css) {
				obj.style[index] = css[index];
			}
			css = null;
		}
		return obj;
	};
}

if (typeof attr !== 'function') {
	var attr = function(obj, attr) {
		if (obj.nodeType == 1) {
			for (index in attr) {
				obj[index] = attr[index];
			}
			attr = null;
		}
		return obj;
	};
}

if (typeof txt !== 'function') {
	var txt = function(txt) {
		return document.createTextNode(txt);
	};
}

if (typeof tag !== 'function') {
	var tag = function(obj) {
		if (obj.nodeType == 1 && obj.tagName) {
			return obj.tagName.toLowerCase();
		}
	};
}

if (typeof offsetLeft !== 'function') {
	var offsetLeft = function(obj) {
		if (obj.nodeType == 1) {
			var left = obj.offsetLeft;
			while (obj.offsetParent && (obj.offsetParent != document.body)) {
				obj   = obj.offsetParent;
				left += obj.offsetLeft;
			}
			return left;
		}
	};
}

if (typeof offsetTop !=='function') {
	var offsetTop = function(obj) {
		if (obj.nodeType == 1) {
			var top = obj.offsetTop;
			while (obj.offsetParent && (obj.offsetParent != document.body)) {
				obj  = obj.offsetParent;
				top += obj.offsetTop;
			}
			return top;
		}
	};
}

var addEvent = function(o, e, fn) {
	if (window.addEventListener) {
		o.addEventListener(e, fn, false);
	} else {
		if (window.attachEvent) {
			o.attachEvent("on"+e, fn);
		} else {
		 	o["on"+e] = fn;
		}
	}
};

var removeEvent = function(o, e, fn) {
	if (o.detachEvent) {
		o.detachEvent('on'+e, fn);
	} else {
		o.removeEventListener(e, fn, false);
	}
};

var loadImage = function(files) {
	if (typeof files === 'string') {
		files = [files];
	}
	if (files.length) {
		for (var i = 0, len = files.length; i < len; i++) {
			var o = new Image();
			o.src = files[i];
		}
	} 
	files = null;
};

var addQuery = function(uri, key, val) {
	if (uri.match(key+'='+val)) {
		return uri;
	}
	var u = null, arg = '?';
	if (uri.match('\\?')) {
		arg = '&';
	}
	u = uri+arg+key+'='+val;
	if (uri.match('#')) {
		var p = uri.split('#');
		u = p[0]+arg+key+'='+val+'#'+p[1];
	}
	return u;
};

var fxFade = function(o, type) {
   var ie = ((window.attachEvent) ? true : false);
   var set = function(o, alpha) {
   	if (ie) {
   		return css(o, {
   		  'filter': 'Alpha(Opacity='+alpha+')'
   		});
   	} 
   	return css(o, {
   		'opacity': parseFloat(alpha/100)
   	});
   };
   var get = function(o) {
   	if (ie) {
   		return parseInt(o.style['filter'].slice(14, 17));
   	}
   	return o.style.opacity*100;
   };
   if (typeof o == 'string') {
		o = $(o);
	}
	if (!o) {
		return;
	}
   if (o.timer) {
   	clearTimeout(o.timer);
   } else {
   	if (type == 'up') {
   		o = set(o, 70);
   	}
   	if (type == 'up') {
   		o = css(o, {
   		  'visibility' : 'hidden'
   		});
   	}
   }
   var opacity = get(o);
   if (type == 'up') {
   	if (opacity >= 100) {
   		o = set(o, 100);
   		o.timer = null;
   		return;
   	} else {
   	  o = set(o, opacity+8);
   	  o = css(o, {
   	    'visibility' : 'visible'
   	  });
   	}
   } else {
   	if (opacity <= 0) {
   		o = css(o, {
   		  'display' : 'none'
   		});
   		return;
   	}
   	o = set(o, opacity-8);
   }
   var repeat = function() {
   	fxFade(o, type);
   }
   o.timer = setTimeout(repeat, 1);
};

var scrollToElement = function(obj) {
	if (obj.nodeType == 1) {
		var scroll2obj = offsetTop(obj);
		if (scroll2obj > 0) {
			var currentY = function() {
				var windowScroll = null;
				if (document.body.scrollTop) {
					windowScroll = document.body.scrollTop;
				} else if (document.documentElement.scrollTop) {
					windowScroll = document.documentElement.scrollTop;
				} else if (window.pageYOffset) {
					windowScroll = window.pageYOffset;
				}
				return windowScroll;
			};
			var step = parseInt((scroll2obj - currentY()) / 30);
			var smoothScroll = function() {
				var windowScroll = currentY();
				var isUp = (windowScroll < scroll2obj);
				window.scrollTo(0, windowScroll + step);
				var isUpNow = (currentY() < scroll2obj);
				if ((isUp != isUpNow) || (windowScroll == currentY())) {
					window.scrollTo(0, scroll2obj);
					return;
				} 
				setTimeout(smoothScroll, 5);
			};
			setTimeout(smoothScroll, 5);
		}
	}
};


var initSwfObjects = function(obj) {
	if (obj) {
		for (index in obj) {
			var flash = obj[index];
			if (typeof flash == 'object') {
				if (!$(flash.id)) {
					continue;
				}
				var so = new SWFObject(flash.path, "rfehkn", flash.width, flash.height, "9", "#fff");
				so.addParam("wmode", "transparent");
				so.addParam("quality", "hight");
				so.write(flash.id);
				so = null;
			}
		}
	}
};

var initSelects = function(selects) {
   if (selects.length) {
   	var s, i = 0;
   	while (s = selects[i++]) {
   		if (typeof s == 'string') {
   			s = $(s);
   		}
   		if (!s) {
   			continue;
   		}
   	 	s.onchange = function() {
   	 		var v = this.options[this.selectedIndex].value;
   	 		if (v) {
   	 			var uri = addQuery(this.form.action, this.name, this.options[this.selectedIndex].value);
   	 			redirect(uri);
   	 		}
   	 	};
   	}
   }
};

var initTabs = function() {
	var canvs = $('ms-product-nav-tabs');
	if (canvs) {
		var tabs = [];
		var links = canvs.getElementsByTagName('a');
		for (var i = 0, len = links.length; i < len; i++) {
			if (links[i].className && links[i].className == 'ms-product-tab') {
				tabs.push(links[i]);
			}
		}
		var fnDoActive = function(tab, ts) {
			for (var i = 0, len = ts.length; i < len; i++) {
				ts[i].href.match(/&tab=(.*)&?/i);
				attr(ts[i], {
				  'id' : (RegExp.$1 == tab ? 'ms-active-tab' : '')
				});
			}
		} ;
		var fn = function(obj, t) {
			obj.onclick = function() {
				this.href.match(/&tab=(.*)&?/i);
				var id = RegExp.$1;
				var content = $(id);
				if (!content) {
					var http = getXmlHttpRequest();
					ajaxLoading($('ms-tab-conteiner'));
					http.open('GET', this.href, true);
					http.setRequestHeader("X_REQUESTED_WITH", "XMLHttpRequest");
					http.onreadystatechange = function() {
						if (http.readyState == 4) {
							if (http.status == 200 || http.status == 304) {
								var content = $$('div');
								if (content) {
									content.innerHTML = http.responseText;
									content = attr(content, {
										'id' : id
									});	
									
									var conteiner = $('ms-tab-conteiner');
									conteiner.appendChild(content);
									
									for (var i = 0; i < conteiner.childNodes.length; i++) {
										var child = conteiner.childNodes[i];
										
										if (child.id) {
											if (child.id != id) {
												css(child, {
												  'display' : 'none'
												});
											} else {
												css(child, {
												  'display' : 'block'
												});
											}
										}
									}
									
									fnDoActive(id, t);

									ajaxHideLoading($('ms-tab-conteiner'));
									fxFade(conteiner, 'up');
									initAjax(conteiner);
									conteiner.focus();
									content = null;
								}
							}
						}
					}
					http.send(null);
				} else {
					for (var i = 0; i < $('ms-tab-conteiner').childNodes.length; i++) {
						 var child = $('ms-tab-conteiner').childNodes[i];
										
						 if (child.id) {
							 if (child.id != id) {
								 css(child, {
								 	'display' : 'none'
								 });
							 } else {
								 css(child, {
								   'display' : 'block'
								 });
							 }
						 }
					}
					fnDoActive(id, t);
				}
				return false;
			};
		};	
		for (var i = 0, len = tabs.length; i < len; i++) {
			fn(tabs[i], tabs);
		}
		tabs = null;
	}
};

var redirect = function(uri) {
	if (typeof uri == 'string' && uri.length) {
		window.top.location.href = uri;
	}
};

var initLiveSearch = function(obj) {
	new LiveSearch(obj);
};

var slideShowImages = [];
var currentShow = 0;
var slideShow = function() {
	var div = $('ms-banners-type-slideshow');
	if (div) {
		slideShowImages = div.getElementsByTagName('li');
		if (slideShowImages) {
			for (var i = 0; i < slideShowImages.length; i++) {
				var img = slideShowImages[i];
				if (img) {
					img = css(img, {
						'display' : 'none'
					});
					if (i == currentShow) {
						img = css(img, {
							'visibility' : 'hidden',
							'display' : 'block'
						});
						fxFade(img, 'up');
					}
				}
			}
			var run = function() {
				currentShow++;
				if (currentShow >= slideShowImages.length) {
					currentShow = 0;
				}
				slideShow();
			};
			setTimeout(run, 5000);
		}
	}
};

var locked = false;
var initBlockRightMouseClick = function() {
	if (!locked) {
		return;
	}
	var fn = function(obj) {
		obj.onmousedown = function(e) {
			if (window.event) {
         	e = window.event;
         }
         if (e.button > 1) {
         	alert('');
         }
		}
	};
	for (var i = 0, len = document.images.length; i < len; i++) {
		fn(document.images[i]);
	}
};

var captcha = function() {
	var captcha = $('captcha-img');
	if (captcha) {
		attr(captcha, {
		  'src' : '/captcha/?hash=' + Math.random()
		});
	}
	return false;
};

var advSearch = function(form) {
	if (form.method) {
		var inp = form.elements;
		if (inp) {
			for (var i = 0, len = inp.length; i < len; i++) {
				if (inp[i].type == 'text') {
					if (!inp[i].value) {
						inp[i].disabled = true;
					}
				}
				if (inp[i].type == 'checkbox') {
					if (!inp[i].checked) {
						inp[i].disabled = true;
					}
				}
			}
			var c = inp['category'];
			if (c) {
				if (!c.value) {
					c.disabled = true;
				}
			}
			var x = $('img');
			if (x) {
				if (!inp['txt'].value) {
					var hidden = $$('input');
					if (hidden) {
						hidden = attr(hidden, {
						  'name' : 'showResults', 'type' : 'hidden', 'value' : 'false'
						});
						form.appendChild(hidden);
					}
				}
				x.disabled = true;
			}
			var d = inp['days'];
			if (d) {
				if (d.value == '0') {
					d.disabled = true;
				}
			}
			var pf = inp['priceFrom'], pt = inp['priceTo'];
			if (pf && pt) {
				if (pf.value > 0 || pt.value > 0) {
					inp['ask4price'].disabled = true;
				}
			}
			d = x = c = null;
		}
	}
	return true;
};

var loadOnReady = function() {
	if (typeof initCartJS == 'boolean') {
		initTabs();
		if (Overlay) {
	  		Overlay.init({
        	  'sClass': 'overlay'
     		});
		}
	}	
	initAjax();
	initLiveSearch({
	  'form' : 'ms-lisvesearch-form',
	  'target' : $('ms-product-list'),
	  'callback' : function() {
	  	 fxFade($('ms-product-list'), 'up');
	  	 initAjax();
		 allReadyLoading = false;
	  },
	  'loader' : function() {
	    ajaxLoading($('ms-product-list'));
	  }
	});
	initSelects([
	  'ms-select-producer', 'Language', 'Skin', 'Currency', 'ms-paginate-select'
	]);
	slideShow();
	//initBlockRightMouseClick();
};

var onDomReady = function() {
	loadOnReady();
};

(function(fn) {
	var u = navigator.userAgent.toLowerCase();
	var ie = false;
	if (/webkit/.test(u)) {
		timeout = setTimeout(function(){
			if (document.readyState == 'loaded' || document.readyState == 'complete') {
				fn();
			} else {
				setTimeout(arguments.callee, 10);
			}
		}, 10);
	} else if ((/mozilla/.test(u) && !/(compatible)/.test(u)) || (/opera/.test(u))) {
		document.addEventListener('DOMContentLoaded', fn, false);
	} else if (ie) {
		(function(){
			var tempNode = document.createElement('document:ready'); 
			try {
				tempNode.doScroll('left');
				fn();
				tempNode = null; 
			} catch(e) { 
        		setTimeout(arguments.callee, 0); 
      	} 
		})();
	} else {
		window.onload = fn;
	}
})(onDomReady);
addEvent(window, 'load', function() {
  initSwfObjects({
	  'flash_1' : {
	    'id' : 'header-flash',
	    'path' : 'flash/avangarta/header-flash-left.swf',
	    'width' : '986',
	    'height' : '308'
	  }
	});
	loadImage([
	  'gfx/avangarta/preloader.gif'
	]);
});
