/* Excanvas */
// Copyright 2006 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
if(!document.createElement("canvas").getContext){(function(){var ab=Math;var n=ab.round;var l=ab.sin;var A=ab.cos;var H=ab.abs;var N=ab.sqrt;var d=10;var f=d/2;var z=+navigator.userAgent.match(/MSIE ([\d.]+)?/)[1];function y(){return this.context_||(this.context_=new D(this))}var t=Array.prototype.slice;function g(j,m,p){var i=t.call(arguments,2);return function(){return j.apply(m,i.concat(t.call(arguments)))}}function af(i){return String(i).replace(/&/g,"&amp;").replace(/"/g,"&quot;")}function Y(m,j,i){if(!m.namespaces[j]){m.namespaces.add(j,i,"#default#VML")}}function R(j){Y(j,"g_vml_","urn:schemas-microsoft-com:vml");Y(j,"g_o_","urn:schemas-microsoft-com:office:office");if(!j.styleSheets.ex_canvas_){var i=j.createStyleSheet();i.owningElement.id="ex_canvas_";i.cssText="canvas{display:inline-block;overflow:hidden;text-align:left;width:300px;height:150px}"}}R(document);var e={init:function(i){var j=i||document;j.createElement("canvas");j.attachEvent("onreadystatechange",g(this.init_,this,j))},init_:function(p){var m=p.getElementsByTagName("canvas");for(var j=0;j<m.length;j++){this.initElement(m[j])}},initElement:function(j){if(!j.getContext){j.getContext=y;R(j.ownerDocument);j.innerHTML="";j.attachEvent("onpropertychange",x);j.attachEvent("onresize",W);var i=j.attributes;if(i.width&&i.width.specified){j.style.width=i.width.nodeValue+"px"}else{j.width=j.clientWidth}if(i.height&&i.height.specified){j.style.height=i.height.nodeValue+"px"}else{j.height=j.clientHeight}}return j}};function x(j){var i=j.srcElement;switch(j.propertyName){case"width":i.getContext().clearRect();i.style.width=i.attributes.width.nodeValue+"px";i.firstChild.style.width=i.clientWidth+"px";break;case"height":i.getContext().clearRect();i.style.height=i.attributes.height.nodeValue+"px";i.firstChild.style.height=i.clientHeight+"px";break}}function W(j){var i=j.srcElement;if(i.firstChild){i.firstChild.style.width=i.clientWidth+"px";i.firstChild.style.height=i.clientHeight+"px"}}e.init();var k=[];for(var ae=0;ae<16;ae++){for(var ad=0;ad<16;ad++){k[ae*16+ad]=ae.toString(16)+ad.toString(16)}}function B(){return[[1,0,0],[0,1,0],[0,0,1]]}function J(p,m){var j=B();for(var i=0;i<3;i++){for(var ah=0;ah<3;ah++){var Z=0;for(var ag=0;ag<3;ag++){Z+=p[i][ag]*m[ag][ah]}j[i][ah]=Z}}return j}function v(j,i){i.fillStyle=j.fillStyle;i.lineCap=j.lineCap;i.lineJoin=j.lineJoin;i.lineWidth=j.lineWidth;i.miterLimit=j.miterLimit;i.shadowBlur=j.shadowBlur;i.shadowColor=j.shadowColor;i.shadowOffsetX=j.shadowOffsetX;i.shadowOffsetY=j.shadowOffsetY;i.strokeStyle=j.strokeStyle;i.globalAlpha=j.globalAlpha;i.font=j.font;i.textAlign=j.textAlign;i.textBaseline=j.textBaseline;i.arcScaleX_=j.arcScaleX_;i.arcScaleY_=j.arcScaleY_;i.lineScale_=j.lineScale_}var b={aliceblue:"#F0F8FF",antiquewhite:"#FAEBD7",aquamarine:"#7FFFD4",azure:"#F0FFFF",beige:"#F5F5DC",bisque:"#FFE4C4",black:"#000000",blanchedalmond:"#FFEBCD",blueviolet:"#8A2BE2",brown:"#A52A2A",burlywood:"#DEB887",cadetblue:"#5F9EA0",chartreuse:"#7FFF00",chocolate:"#D2691E",coral:"#FF7F50",cornflowerblue:"#6495ED",cornsilk:"#FFF8DC",crimson:"#DC143C",cyan:"#00FFFF",darkblue:"#00008B",darkcyan:"#008B8B",darkgoldenrod:"#B8860B",darkgray:"#A9A9A9",darkgreen:"#006400",darkgrey:"#A9A9A9",darkkhaki:"#BDB76B",darkmagenta:"#8B008B",darkolivegreen:"#556B2F",darkorange:"#FF8C00",darkorchid:"#9932CC",darkred:"#8B0000",darksalmon:"#E9967A",darkseagreen:"#8FBC8F",darkslateblue:"#483D8B",darkslategray:"#2F4F4F",darkslategrey:"#2F4F4F",darkturquoise:"#00CED1",darkviolet:"#9400D3",deeppink:"#FF1493",deepskyblue:"#00BFFF",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1E90FF",firebrick:"#B22222",floralwhite:"#FFFAF0",forestgreen:"#228B22",gainsboro:"#DCDCDC",ghostwhite:"#F8F8FF",gold:"#FFD700",goldenrod:"#DAA520",grey:"#808080",greenyellow:"#ADFF2F",honeydew:"#F0FFF0",hotpink:"#FF69B4",indianred:"#CD5C5C",indigo:"#4B0082",ivory:"#FFFFF0",khaki:"#F0E68C",lavender:"#E6E6FA",lavenderblush:"#FFF0F5",lawngreen:"#7CFC00",lemonchiffon:"#FFFACD",lightblue:"#ADD8E6",lightcoral:"#F08080",lightcyan:"#E0FFFF",lightgoldenrodyellow:"#FAFAD2",lightgreen:"#90EE90",lightgrey:"#D3D3D3",lightpink:"#FFB6C1",lightsalmon:"#FFA07A",lightseagreen:"#20B2AA",lightskyblue:"#87CEFA",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#B0C4DE",lightyellow:"#FFFFE0",limegreen:"#32CD32",linen:"#FAF0E6",magenta:"#FF00FF",mediumaquamarine:"#66CDAA",mediumblue:"#0000CD",mediumorchid:"#BA55D3",mediumpurple:"#9370DB",mediumseagreen:"#3CB371",mediumslateblue:"#7B68EE",mediumspringgreen:"#00FA9A",mediumturquoise:"#48D1CC",mediumvioletred:"#C71585",midnightblue:"#191970",mintcream:"#F5FFFA",mistyrose:"#FFE4E1",moccasin:"#FFE4B5",navajowhite:"#FFDEAD",oldlace:"#FDF5E6",olivedrab:"#6B8E23",orange:"#FFA500",orangered:"#FF4500",orchid:"#DA70D6",palegoldenrod:"#EEE8AA",palegreen:"#98FB98",paleturquoise:"#AFEEEE",palevioletred:"#DB7093",papayawhip:"#FFEFD5",peachpuff:"#FFDAB9",peru:"#CD853F",pink:"#FFC0CB",plum:"#DDA0DD",powderblue:"#B0E0E6",rosybrown:"#BC8F8F",royalblue:"#4169E1",saddlebrown:"#8B4513",salmon:"#FA8072",sandybrown:"#F4A460",seagreen:"#2E8B57",seashell:"#FFF5EE",sienna:"#A0522D",skyblue:"#87CEEB",slateblue:"#6A5ACD",slategray:"#708090",slategrey:"#708090",snow:"#FFFAFA",springgreen:"#00FF7F",steelblue:"#4682B4",tan:"#D2B48C",thistle:"#D8BFD8",tomato:"#FF6347",turquoise:"#40E0D0",violet:"#EE82EE",wheat:"#F5DEB3",whitesmoke:"#F5F5F5",yellowgreen:"#9ACD32"};function M(j){var p=j.indexOf("(",3);var i=j.indexOf(")",p+1);var m=j.substring(p+1,i).split(",");if(m.length!=4||j.charAt(3)!="a"){m[3]=1}return m}function c(i){return parseFloat(i)/100}function r(j,m,i){return Math.min(i,Math.max(m,j))}function I(ag){var i,ai,aj,ah,ak,Z;ah=parseFloat(ag[0])/360%360;if(ah<0){ah++}ak=r(c(ag[1]),0,1);Z=r(c(ag[2]),0,1);if(ak==0){i=ai=aj=Z}else{var j=Z<0.5?Z*(1+ak):Z+ak-Z*ak;var m=2*Z-j;i=a(m,j,ah+1/3);ai=a(m,j,ah);aj=a(m,j,ah-1/3)}return"#"+k[Math.floor(i*255)]+k[Math.floor(ai*255)]+k[Math.floor(aj*255)]}function a(j,i,m){if(m<0){m++}if(m>1){m--}if(6*m<1){return j+(i-j)*6*m}else{if(2*m<1){return i}else{if(3*m<2){return j+(i-j)*(2/3-m)*6}else{return j}}}}var C={};function F(j){if(j in C){return C[j]}var ag,Z=1;j=String(j);if(j.charAt(0)=="#"){ag=j}else{if(/^rgb/.test(j)){var p=M(j);var ag="#",ah;for(var m=0;m<3;m++){if(p[m].indexOf("%")!=-1){ah=Math.floor(c(p[m])*255)}else{ah=+p[m]}ag+=k[r(ah,0,255)]}Z=+p[3]}else{if(/^hsl/.test(j)){var p=M(j);ag=I(p);Z=p[3]}else{ag=b[j]||j}}}return C[j]={color:ag,alpha:Z}}var o={style:"normal",variant:"normal",weight:"normal",size:10,family:"sans-serif"};var L={};function E(i){if(L[i]){return L[i]}var p=document.createElement("div");var m=p.style;try{m.font=i}catch(j){}return L[i]={style:m.fontStyle||o.style,variant:m.fontVariant||o.variant,weight:m.fontWeight||o.weight,size:m.fontSize||o.size,family:m.fontFamily||o.family}}function u(m,j){var i={};for(var ah in m){i[ah]=m[ah]}var ag=parseFloat(j.currentStyle.fontSize),Z=parseFloat(m.size);if(typeof m.size=="number"){i.size=m.size}else{if(m.size.indexOf("px")!=-1){i.size=Z}else{if(m.size.indexOf("em")!=-1){i.size=ag*Z}else{if(m.size.indexOf("%")!=-1){i.size=(ag/100)*Z}else{if(m.size.indexOf("pt")!=-1){i.size=Z/0.75}else{i.size=ag}}}}}i.size*=0.981;return i}function ac(i){return i.style+" "+i.variant+" "+i.weight+" "+i.size+"px "+i.family}var s={butt:"flat",round:"round"};function S(i){return s[i]||"square"}function D(i){this.m_=B();this.mStack_=[];this.aStack_=[];this.currentPath_=[];this.strokeStyle="#000";this.fillStyle="#000";this.lineWidth=1;this.lineJoin="miter";this.lineCap="butt";this.miterLimit=d*1;this.globalAlpha=1;this.font="10px sans-serif";this.textAlign="left";this.textBaseline="alphabetic";this.canvas=i;var m="width:"+i.clientWidth+"px;height:"+i.clientHeight+"px;overflow:hidden;position:absolute";var j=i.ownerDocument.createElement("div");j.style.cssText=m;i.appendChild(j);var p=j.cloneNode(false);p.style.backgroundColor="red";p.style.filter="alpha(opacity=0)";i.appendChild(p);this.element_=j;this.arcScaleX_=1;this.arcScaleY_=1;this.lineScale_=1}var q=D.prototype;q.clearRect=function(){if(this.textMeasureEl_){this.textMeasureEl_.removeNode(true);this.textMeasureEl_=null}this.element_.innerHTML=""};q.beginPath=function(){this.currentPath_=[]};q.moveTo=function(j,i){var m=V(this,j,i);this.currentPath_.push({type:"moveTo",x:m.x,y:m.y});this.currentX_=m.x;this.currentY_=m.y};q.lineTo=function(j,i){var m=V(this,j,i);this.currentPath_.push({type:"lineTo",x:m.x,y:m.y});this.currentX_=m.x;this.currentY_=m.y};q.bezierCurveTo=function(m,j,ak,aj,ai,ag){var i=V(this,ai,ag);var ah=V(this,m,j);var Z=V(this,ak,aj);K(this,ah,Z,i)};function K(i,Z,m,j){i.currentPath_.push({type:"bezierCurveTo",cp1x:Z.x,cp1y:Z.y,cp2x:m.x,cp2y:m.y,x:j.x,y:j.y});i.currentX_=j.x;i.currentY_=j.y}q.quadraticCurveTo=function(ai,m,j,i){var ah=V(this,ai,m);var ag=V(this,j,i);var aj={x:this.currentX_+2/3*(ah.x-this.currentX_),y:this.currentY_+2/3*(ah.y-this.currentY_)};var Z={x:aj.x+(ag.x-this.currentX_)/3,y:aj.y+(ag.y-this.currentY_)/3};K(this,aj,Z,ag)};q.arc=function(al,aj,ak,ag,j,m){ak*=d;var ap=m?"at":"wa";var am=al+A(ag)*ak-f;var ao=aj+l(ag)*ak-f;var i=al+A(j)*ak-f;var an=aj+l(j)*ak-f;if(am==i&&!m){am+=0.125}var Z=V(this,al,aj);var ai=V(this,am,ao);var ah=V(this,i,an);this.currentPath_.push({type:ap,x:Z.x,y:Z.y,radius:ak,xStart:ai.x,yStart:ai.y,xEnd:ah.x,yEnd:ah.y})};q.rect=function(m,j,i,p){this.moveTo(m,j);this.lineTo(m+i,j);this.lineTo(m+i,j+p);this.lineTo(m,j+p);this.closePath()};q.strokeRect=function(m,j,i,p){var Z=this.currentPath_;this.beginPath();this.moveTo(m,j);this.lineTo(m+i,j);this.lineTo(m+i,j+p);this.lineTo(m,j+p);this.closePath();this.stroke();this.currentPath_=Z};q.fillRect=function(m,j,i,p){var Z=this.currentPath_;this.beginPath();this.moveTo(m,j);this.lineTo(m+i,j);this.lineTo(m+i,j+p);this.lineTo(m,j+p);this.closePath();this.fill();this.currentPath_=Z};q.createLinearGradient=function(j,p,i,m){var Z=new U("gradient");Z.x0_=j;Z.y0_=p;Z.x1_=i;Z.y1_=m;return Z};q.createRadialGradient=function(p,ag,m,j,Z,i){var ah=new U("gradientradial");ah.x0_=p;ah.y0_=ag;ah.r0_=m;ah.x1_=j;ah.y1_=Z;ah.r1_=i;return ah};q.drawImage=function(aq,m){var aj,ah,al,ay,ao,am,at,aA;var ak=aq.runtimeStyle.width;var ap=aq.runtimeStyle.height;aq.runtimeStyle.width="auto";aq.runtimeStyle.height="auto";var ai=aq.width;var aw=aq.height;aq.runtimeStyle.width=ak;aq.runtimeStyle.height=ap;if(arguments.length==3){aj=arguments[1];ah=arguments[2];ao=am=0;at=al=ai;aA=ay=aw}else{if(arguments.length==5){aj=arguments[1];ah=arguments[2];al=arguments[3];ay=arguments[4];ao=am=0;at=ai;aA=aw}else{if(arguments.length==9){ao=arguments[1];am=arguments[2];at=arguments[3];aA=arguments[4];aj=arguments[5];ah=arguments[6];al=arguments[7];ay=arguments[8]}else{throw Error("Invalid number of arguments")}}}var az=V(this,aj,ah);var p=at/2;var j=aA/2;var ax=[];var i=10;var ag=10;ax.push(" <g_vml_:group",' coordsize="',d*i,",",d*ag,'"',' coordorigin="0,0"',' style="width:',i,"px;height:",ag,"px;position:absolute;");if(this.m_[0][0]!=1||this.m_[0][1]||this.m_[1][1]!=1||this.m_[1][0]){var Z=[];Z.push("M11=",this.m_[0][0],",","M12=",this.m_[1][0],",","M21=",this.m_[0][1],",","M22=",this.m_[1][1],",","Dx=",n(az.x/d),",","Dy=",n(az.y/d),"");var av=az;var au=V(this,aj+al,ah);var ar=V(this,aj,ah+ay);var an=V(this,aj+al,ah+ay);av.x=ab.max(av.x,au.x,ar.x,an.x);av.y=ab.max(av.y,au.y,ar.y,an.y);ax.push("padding:0 ",n(av.x/d),"px ",n(av.y/d),"px 0;filter:progid:DXImageTransform.Microsoft.Matrix(",Z.join(""),", sizingmethod='clip');")}else{ax.push("top:",n(az.y/d),"px;left:",n(az.x/d),"px;")}ax.push(' ">','<g_vml_:image src="',aq.src,'"',' style="width:',d*al,"px;"," height:",d*ay,'px"',' cropleft="',ao/ai,'"',' croptop="',am/aw,'"',' cropright="',(ai-ao-at)/ai,'"',' cropbottom="',(aw-am-aA)/aw,'"'," />","</g_vml_:group>");this.element_.insertAdjacentHTML("BeforeEnd",ax.join(""))};q.stroke=function(al){var aj=[];var Z=false;var m=10;var am=10;aj.push("<g_vml_:shape",' filled="',!!al,'"',' style="position:absolute;width:',m,"px;height:",am,'px;"',' coordorigin="0,0"',' coordsize="',d*m,",",d*am,'"',' stroked="',!al,'"',' path="');var an=false;var ag={x:null,y:null};var ak={x:null,y:null};for(var ah=0;ah<this.currentPath_.length;ah++){var j=this.currentPath_[ah];var ai;switch(j.type){case"moveTo":ai=j;aj.push(" m ",n(j.x),",",n(j.y));break;case"lineTo":aj.push(" l ",n(j.x),",",n(j.y));break;case"close":aj.push(" x ");j=null;break;case"bezierCurveTo":aj.push(" c ",n(j.cp1x),",",n(j.cp1y),",",n(j.cp2x),",",n(j.cp2y),",",n(j.x),",",n(j.y));break;case"at":case"wa":aj.push(" ",j.type," ",n(j.x-this.arcScaleX_*j.radius),",",n(j.y-this.arcScaleY_*j.radius)," ",n(j.x+this.arcScaleX_*j.radius),",",n(j.y+this.arcScaleY_*j.radius)," ",n(j.xStart),",",n(j.yStart)," ",n(j.xEnd),",",n(j.yEnd));break}if(j){if(ag.x==null||j.x<ag.x){ag.x=j.x}if(ak.x==null||j.x>ak.x){ak.x=j.x}if(ag.y==null||j.y<ag.y){ag.y=j.y}if(ak.y==null||j.y>ak.y){ak.y=j.y}}}aj.push(' ">');if(!al){w(this,aj)}else{G(this,aj,ag,ak)}aj.push("</g_vml_:shape>");this.element_.insertAdjacentHTML("beforeEnd",aj.join(""))};function w(m,ag){var j=F(m.strokeStyle);var p=j.color;var Z=j.alpha*m.globalAlpha;var i=m.lineScale_*m.lineWidth;if(i<1){Z*=i}ag.push("<g_vml_:stroke",' opacity="',Z,'"',' joinstyle="',m.lineJoin,'"',' miterlimit="',m.miterLimit,'"',' endcap="',S(m.lineCap),'"',' weight="',i,'px"',' color="',p,'" />')}function G(aq,ai,aK,ar){var aj=aq.fillStyle;var aB=aq.arcScaleX_;var aA=aq.arcScaleY_;var j=ar.x-aK.x;var p=ar.y-aK.y;if(aj instanceof U){var an=0;var aF={x:0,y:0};var ax=0;var am=1;if(aj.type_=="gradient"){var al=aj.x0_/aB;var m=aj.y0_/aA;var ak=aj.x1_/aB;var aM=aj.y1_/aA;var aJ=V(aq,al,m);var aI=V(aq,ak,aM);var ag=aI.x-aJ.x;var Z=aI.y-aJ.y;an=Math.atan2(ag,Z)*180/Math.PI;if(an<0){an+=360}if(an<0.000001){an=0}}else{var aJ=V(aq,aj.x0_,aj.y0_);aF={x:(aJ.x-aK.x)/j,y:(aJ.y-aK.y)/p};j/=aB*d;p/=aA*d;var aD=ab.max(j,p);ax=2*aj.r0_/aD;am=2*aj.r1_/aD-ax}var av=aj.colors_;av.sort(function(aN,i){return aN.offset-i.offset});var ap=av.length;var au=av[0].color;var at=av[ap-1].color;var az=av[0].alpha*aq.globalAlpha;var ay=av[ap-1].alpha*aq.globalAlpha;var aE=[];for(var aH=0;aH<ap;aH++){var ao=av[aH];aE.push(ao.offset*am+ax+" "+ao.color)}ai.push('<g_vml_:fill type="',aj.type_,'"',' method="none" focus="100%"',' color="',au,'"',' color2="',at,'"',' colors="',aE.join(","),'"',' opacity="',ay,'"',' g_o_:opacity2="',az,'"',' angle="',an,'"',' focusposition="',aF.x,",",aF.y,'" />')}else{if(aj instanceof T){if(j&&p){var ah=-aK.x;var aC=-aK.y;ai.push("<g_vml_:fill",' position="',ah/j*aB*aB,",",aC/p*aA*aA,'"',' type="tile"',' src="',aj.src_,'" />')}}else{var aL=F(aq.fillStyle);var aw=aL.color;var aG=aL.alpha*aq.globalAlpha;ai.push('<g_vml_:fill color="',aw,'" opacity="',aG,'" />')}}}q.fill=function(){this.stroke(true)};q.closePath=function(){this.currentPath_.push({type:"close"})};function V(j,Z,p){var i=j.m_;return{x:d*(Z*i[0][0]+p*i[1][0]+i[2][0])-f,y:d*(Z*i[0][1]+p*i[1][1]+i[2][1])-f}}q.save=function(){var i={};v(this,i);this.aStack_.push(i);this.mStack_.push(this.m_);this.m_=J(B(),this.m_)};q.restore=function(){if(this.aStack_.length){v(this.aStack_.pop(),this);this.m_=this.mStack_.pop()}};function h(i){return isFinite(i[0][0])&&isFinite(i[0][1])&&isFinite(i[1][0])&&isFinite(i[1][1])&&isFinite(i[2][0])&&isFinite(i[2][1])}function aa(j,i,p){if(!h(i)){return}j.m_=i;if(p){var Z=i[0][0]*i[1][1]-i[0][1]*i[1][0];j.lineScale_=N(H(Z))}}q.translate=function(m,j){var i=[[1,0,0],[0,1,0],[m,j,1]];aa(this,J(i,this.m_),false)};q.rotate=function(j){var p=A(j);var m=l(j);var i=[[p,m,0],[-m,p,0],[0,0,1]];aa(this,J(i,this.m_),false)};q.scale=function(m,j){this.arcScaleX_*=m;this.arcScaleY_*=j;var i=[[m,0,0],[0,j,0],[0,0,1]];aa(this,J(i,this.m_),true)};q.transform=function(Z,p,ah,ag,j,i){var m=[[Z,p,0],[ah,ag,0],[j,i,1]];aa(this,J(m,this.m_),true)};q.setTransform=function(ag,Z,ai,ah,p,j){var i=[[ag,Z,0],[ai,ah,0],[p,j,1]];aa(this,i,true)};q.drawText_=function(am,ak,aj,ap,ai){var ao=this.m_,at=1000,j=0,ar=at,ah={x:0,y:0},ag=[];var i=u(E(this.font),this.element_);var p=ac(i);var au=this.element_.currentStyle;var Z=this.textAlign.toLowerCase();switch(Z){case"left":case"center":case"right":break;case"end":Z=au.direction=="ltr"?"right":"left";break;case"start":Z=au.direction=="rtl"?"right":"left";break;default:Z="left"}switch(this.textBaseline){case"hanging":case"top":ah.y=i.size/1.75;break;case"middle":break;default:case null:case"alphabetic":case"ideographic":case"bottom":ah.y=-i.size/2.25;break}switch(Z){case"right":j=at;ar=0.05;break;case"center":j=ar=at/2;break}var aq=V(this,ak+ah.x,aj+ah.y);ag.push('<g_vml_:line from="',-j,' 0" to="',ar,' 0.05" ',' coordsize="100 100" coordorigin="0 0"',' filled="',!ai,'" stroked="',!!ai,'" style="position:absolute;width:1px;height:1px;">');if(ai){w(this,ag)}else{G(this,ag,{x:-j,y:0},{x:ar,y:i.size})}var an=ao[0][0].toFixed(3)+","+ao[1][0].toFixed(3)+","+ao[0][1].toFixed(3)+","+ao[1][1].toFixed(3)+",0,0";var al=n(aq.x/d)+","+n(aq.y/d);ag.push('<g_vml_:skew on="t" matrix="',an,'" ',' offset="',al,'" origin="',j,' 0" />','<g_vml_:path textpathok="true" />','<g_vml_:textpath on="true" string="',af(am),'" style="v-text-align:',Z,";font:",af(p),'" /></g_vml_:line>');this.element_.insertAdjacentHTML("beforeEnd",ag.join(""))};q.fillText=function(m,i,p,j){this.drawText_(m,i,p,j,false)};q.strokeText=function(m,i,p,j){this.drawText_(m,i,p,j,true)};q.measureText=function(m){if(!this.textMeasureEl_){var i='<span style="position:absolute;top:-20000px;left:0;padding:0;margin:0;border:none;white-space:pre;"></span>';this.element_.insertAdjacentHTML("beforeEnd",i);this.textMeasureEl_=this.element_.lastChild}var j=this.element_.ownerDocument;this.textMeasureEl_.innerHTML="";this.textMeasureEl_.style.font=this.font;this.textMeasureEl_.appendChild(j.createTextNode(m));return{width:this.textMeasureEl_.offsetWidth}};q.clip=function(){};q.arcTo=function(){};q.createPattern=function(j,i){return new T(j,i)};function U(i){this.type_=i;this.x0_=0;this.y0_=0;this.r0_=0;this.x1_=0;this.y1_=0;this.r1_=0;this.colors_=[]}U.prototype.addColorStop=function(j,i){i=F(i);this.colors_.push({offset:j,color:i.color,alpha:i.alpha})};function T(j,i){Q(j);switch(i){case"repeat":case null:case"":this.repetition_="repeat";break;case"repeat-x":case"repeat-y":case"no-repeat":this.repetition_=i;break;default:O("SYNTAX_ERR")}this.src_=j.src;this.width_=j.width;this.height_=j.height}function O(i){throw new P(i)}function Q(i){if(!i||i.nodeType!=1||i.tagName!="IMG"){O("TYPE_MISMATCH_ERR")}if(i.readyState!="complete"){O("INVALID_STATE_ERR")}}function P(i){this.code=this[i];this.message=i+": DOM Exception "+this.code}var X=P.prototype=new Error;X.INDEX_SIZE_ERR=1;X.DOMSTRING_SIZE_ERR=2;X.HIERARCHY_REQUEST_ERR=3;X.WRONG_DOCUMENT_ERR=4;X.INVALID_CHARACTER_ERR=5;X.NO_DATA_ALLOWED_ERR=6;X.NO_MODIFICATION_ALLOWED_ERR=7;X.NOT_FOUND_ERR=8;X.NOT_SUPPORTED_ERR=9;X.INUSE_ATTRIBUTE_ERR=10;X.INVALID_STATE_ERR=11;X.SYNTAX_ERR=12;X.INVALID_MODIFICATION_ERR=13;X.NAMESPACE_ERR=14;X.INVALID_ACCESS_ERR=15;X.VALIDATION_ERR=16;X.TYPE_MISMATCH_ERR=17;G_vmlCanvasManager=e;CanvasRenderingContext2D=D;CanvasGradient=U;CanvasPattern=T;DOMException=P})()};

/*!
 * jQuery UI 1.8.6
 *
 * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * http://docs.jquery.com/UI
 */
(function(c,j){function k(a){return!c(a).parents().andSelf().filter(function(){return c.curCSS(this,"visibility")==="hidden"||c.expr.filters.hidden(this)}).length}c.ui=c.ui||{};if(!c.ui.version){c.extend(c.ui,{version:"1.8.6",keyCode:{ALT:18,BACKSPACE:8,CAPS_LOCK:20,COMMA:188,COMMAND:91,COMMAND_LEFT:91,COMMAND_RIGHT:93,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,
NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,WINDOWS:91}});c.fn.extend({_focus:c.fn.focus,focus:function(a,b){return typeof a==="number"?this.each(function(){var d=this;setTimeout(function(){c(d).focus();b&&b.call(d)},a)}):this._focus.apply(this,arguments)},scrollParent:function(){var a;a=c.browser.msie&&/(static|relative)/.test(this.css("position"))||/absolute/.test(this.css("position"))?this.parents().filter(function(){return/(relative|absolute|fixed)/.test(c.curCSS(this,
"position",1))&&/(auto|scroll)/.test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0):this.parents().filter(function(){return/(auto|scroll)/.test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0);return/fixed/.test(this.css("position"))||!a.length?c(document):a},zIndex:function(a){if(a!==j)return this.css("zIndex",a);if(this.length){a=c(this[0]);for(var b;a.length&&a[0]!==document;){b=a.css("position");
if(b==="absolute"||b==="relative"||b==="fixed"){b=parseInt(a.css("zIndex"),10);if(!isNaN(b)&&b!==0)return b}a=a.parent()}}return 0},disableSelection:function(){return this.bind((c.support.selectstart?"selectstart":"mousedown")+".ui-disableSelection",function(a){a.preventDefault()})},enableSelection:function(){return this.unbind(".ui-disableSelection")}});c.each(["Width","Height"],function(a,b){function d(f,g,l,m){c.each(e,function(){g-=parseFloat(c.curCSS(f,"padding"+this,true))||0;if(l)g-=parseFloat(c.curCSS(f,
"border"+this+"Width",true))||0;if(m)g-=parseFloat(c.curCSS(f,"margin"+this,true))||0});return g}var e=b==="Width"?["Left","Right"]:["Top","Bottom"],h=b.toLowerCase(),i={innerWidth:c.fn.innerWidth,innerHeight:c.fn.innerHeight,outerWidth:c.fn.outerWidth,outerHeight:c.fn.outerHeight};c.fn["inner"+b]=function(f){if(f===j)return i["inner"+b].call(this);return this.each(function(){c(this).css(h,d(this,f)+"px")})};c.fn["outer"+b]=function(f,g){if(typeof f!=="number")return i["outer"+b].call(this,f);return this.each(function(){c(this).css(h,
d(this,f,true,g)+"px")})}});c.extend(c.expr[":"],{data:function(a,b,d){return!!c.data(a,d[3])},focusable:function(a){var b=a.nodeName.toLowerCase(),d=c.attr(a,"tabindex");if("area"===b){b=a.parentNode;d=b.name;if(!a.href||!d||b.nodeName.toLowerCase()!=="map")return false;a=c("img[usemap=#"+d+"]")[0];return!!a&&k(a)}return(/input|select|textarea|button|object/.test(b)?!a.disabled:"a"==b?a.href||!isNaN(d):!isNaN(d))&&k(a)},tabbable:function(a){var b=c.attr(a,"tabindex");return(isNaN(b)||b>=0)&&c(a).is(":focusable")}});
c(function(){var a=document.body,b=a.appendChild(b=document.createElement("div"));c.extend(b.style,{minHeight:"100px",height:"auto",padding:0,borderWidth:0});c.support.minHeight=b.offsetHeight===100;c.support.selectstart="onselectstart"in b;a.removeChild(b).style.display="none"});c.extend(c.ui,{plugin:{add:function(a,b,d){a=c.ui[a].prototype;for(var e in d){a.plugins[e]=a.plugins[e]||[];a.plugins[e].push([b,d[e]])}},call:function(a,b,d){if((b=a.plugins[b])&&a.element[0].parentNode)for(var e=0;e<b.length;e++)a.options[b[e][0]]&&
b[e][1].apply(a.element,d)}},contains:function(a,b){return document.compareDocumentPosition?a.compareDocumentPosition(b)&16:a!==b&&a.contains(b)},hasScroll:function(a,b){if(c(a).css("overflow")==="hidden")return false;b=b&&b==="left"?"scrollLeft":"scrollTop";var d=false;if(a[b]>0)return true;a[b]=1;d=a[b]>0;a[b]=0;return d},isOverAxis:function(a,b,d){return a>b&&a<b+d},isOver:function(a,b,d,e,h,i){return c.ui.isOverAxis(a,d,h)&&c.ui.isOverAxis(b,e,i)}})}})(jQuery);
;/*
 * jQuery UI Datepicker 1.8.6
 *
 * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * http://docs.jquery.com/UI/Datepicker
 *
 * Depends:
 *	jquery.ui.core.js
 */
(function(d,G){function K(){this.debug=false;this._curInst=null;this._keyEvent=false;this._disabledInputs=[];this._inDialog=this._datepickerShowing=false;this._mainDivId="ui-datepicker-div";this._inlineClass="ui-datepicker-inline";this._appendClass="ui-datepicker-append";this._triggerClass="ui-datepicker-trigger";this._dialogClass="ui-datepicker-dialog";this._disableClass="ui-datepicker-disabled";this._unselectableClass="ui-datepicker-unselectable";this._currentClass="ui-datepicker-current-day";this._dayOverClass=
"ui-datepicker-days-cell-over";this.regional=[];this.regional[""]={closeText:"Done",prevText:"Prev",nextText:"Next",currentText:"Today",monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],monthNamesShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],dayNamesShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dayNamesMin:["Su",
"Mo","Tu","We","Th","Fr","Sa"],weekHeader:"Wk",dateFormat:"mm/dd/yy",firstDay:0,isRTL:false,showMonthAfterYear:false,yearSuffix:""};this._defaults={showOn:"focus",showAnim:"fadeIn",showOptions:{},defaultDate:null,appendText:"",buttonText:"...",buttonImage:"",buttonImageOnly:false,hideIfNoPrevNext:false,navigationAsDateFormat:false,gotoCurrent:false,changeMonth:false,changeYear:false,yearRange:"c-10:c+10",showOtherMonths:false,selectOtherMonths:false,showWeek:false,calculateWeek:this.iso8601Week,shortYearCutoff:"+10",
minDate:null,maxDate:null,duration:"fast",beforeShowDay:null,beforeShow:null,onSelect:null,onChangeMonthYear:null,onClose:null,numberOfMonths:1,showCurrentAtPos:0,stepMonths:1,stepBigMonths:12,altField:"",altFormat:"",constrainInput:true,showButtonPanel:false,autoSize:false};d.extend(this._defaults,this.regional[""]);this.dpDiv=d('<div id="'+this._mainDivId+'" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-helper-hidden-accessible"></div>')}function E(a,b){d.extend(a,
b);for(var c in b)if(b[c]==null||b[c]==G)a[c]=b[c];return a}d.extend(d.ui,{datepicker:{version:"1.8.6"}});var y=(new Date).getTime();d.extend(K.prototype,{markerClassName:"hasDatepicker",log:function(){this.debug&&console.log.apply("",arguments)},_widgetDatepicker:function(){return this.dpDiv},setDefaults:function(a){E(this._defaults,a||{});return this},_attachDatepicker:function(a,b){var c=null;for(var e in this._defaults){var f=a.getAttribute("date:"+e);if(f){c=c||{};try{c[e]=eval(f)}catch(h){c[e]=
f}}}e=a.nodeName.toLowerCase();f=e=="div"||e=="span";if(!a.id){this.uuid+=1;a.id="dp"+this.uuid}var i=this._newInst(d(a),f);i.settings=d.extend({},b||{},c||{});if(e=="input")this._connectDatepicker(a,i);else f&&this._inlineDatepicker(a,i)},_newInst:function(a,b){return{id:a[0].id.replace(/([^A-Za-z0-9_-])/g,"\\\\$1"),input:a,selectedDay:0,selectedMonth:0,selectedYear:0,drawMonth:0,drawYear:0,inline:b,dpDiv:!b?this.dpDiv:d('<div class="'+this._inlineClass+' ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>')}},
_connectDatepicker:function(a,b){var c=d(a);b.append=d([]);b.trigger=d([]);if(!c.hasClass(this.markerClassName)){this._attachments(c,b);c.addClass(this.markerClassName).keydown(this._doKeyDown).keypress(this._doKeyPress).keyup(this._doKeyUp).bind("setData.datepicker",function(e,f,h){b.settings[f]=h}).bind("getData.datepicker",function(e,f){return this._get(b,f)});this._autoSize(b);d.data(a,"datepicker",b)}},_attachments:function(a,b){var c=this._get(b,"appendText"),e=this._get(b,"isRTL");b.append&&
b.append.remove();if(c){b.append=d('<span class="'+this._appendClass+'">'+c+"</span>");a[e?"before":"after"](b.append)}a.unbind("focus",this._showDatepicker);b.trigger&&b.trigger.remove();c=this._get(b,"showOn");if(c=="focus"||c=="both")a.focus(this._showDatepicker);if(c=="button"||c=="both"){c=this._get(b,"buttonText");var f=this._get(b,"buttonImage");b.trigger=d(this._get(b,"buttonImageOnly")?d("<img/>").addClass(this._triggerClass).attr({src:f,alt:c,title:c}):d('<button type="button"></button>').addClass(this._triggerClass).html(f==
""?c:d("<img/>").attr({src:f,alt:c,title:c})));a[e?"before":"after"](b.trigger);b.trigger.click(function(){d.datepicker._datepickerShowing&&d.datepicker._lastInput==a[0]?d.datepicker._hideDatepicker():d.datepicker._showDatepicker(a[0]);return false})}},_autoSize:function(a){if(this._get(a,"autoSize")&&!a.inline){var b=new Date(2009,11,20),c=this._get(a,"dateFormat");if(c.match(/[DM]/)){var e=function(f){for(var h=0,i=0,g=0;g<f.length;g++)if(f[g].length>h){h=f[g].length;i=g}return i};b.setMonth(e(this._get(a,
c.match(/MM/)?"monthNames":"monthNamesShort")));b.setDate(e(this._get(a,c.match(/DD/)?"dayNames":"dayNamesShort"))+20-b.getDay())}a.input.attr("size",this._formatDate(a,b).length)}},_inlineDatepicker:function(a,b){var c=d(a);if(!c.hasClass(this.markerClassName)){c.addClass(this.markerClassName).append(b.dpDiv).bind("setData.datepicker",function(e,f,h){b.settings[f]=h}).bind("getData.datepicker",function(e,f){return this._get(b,f)});d.data(a,"datepicker",b);this._setDate(b,this._getDefaultDate(b),
true);this._updateDatepicker(b);this._updateAlternate(b)}},_dialogDatepicker:function(a,b,c,e,f){a=this._dialogInst;if(!a){this.uuid+=1;this._dialogInput=d('<input type="text" id="'+("dp"+this.uuid)+'" style="position: absolute; top: -100px; width: 0px; z-index: -10;"/>');this._dialogInput.keydown(this._doKeyDown);d("body").append(this._dialogInput);a=this._dialogInst=this._newInst(this._dialogInput,false);a.settings={};d.data(this._dialogInput[0],"datepicker",a)}E(a.settings,e||{});b=b&&b.constructor==
Date?this._formatDate(a,b):b;this._dialogInput.val(b);this._pos=f?f.length?f:[f.pageX,f.pageY]:null;if(!this._pos)this._pos=[document.documentElement.clientWidth/2-100+(document.documentElement.scrollLeft||document.body.scrollLeft),document.documentElement.clientHeight/2-150+(document.documentElement.scrollTop||document.body.scrollTop)];this._dialogInput.css("left",this._pos[0]+20+"px").css("top",this._pos[1]+"px");a.settings.onSelect=c;this._inDialog=true;this.dpDiv.addClass(this._dialogClass);this._showDatepicker(this._dialogInput[0]);
d.blockUI&&d.blockUI(this.dpDiv);d.data(this._dialogInput[0],"datepicker",a);return this},_destroyDatepicker:function(a){var b=d(a),c=d.data(a,"datepicker");if(b.hasClass(this.markerClassName)){var e=a.nodeName.toLowerCase();d.removeData(a,"datepicker");if(e=="input"){c.append.remove();c.trigger.remove();b.removeClass(this.markerClassName).unbind("focus",this._showDatepicker).unbind("keydown",this._doKeyDown).unbind("keypress",this._doKeyPress).unbind("keyup",this._doKeyUp)}else if(e=="div"||e=="span")b.removeClass(this.markerClassName).empty()}},
_enableDatepicker:function(a){var b=d(a),c=d.data(a,"datepicker");if(b.hasClass(this.markerClassName)){var e=a.nodeName.toLowerCase();if(e=="input"){a.disabled=false;c.trigger.filter("button").each(function(){this.disabled=false}).end().filter("img").css({opacity:"1.0",cursor:""})}else if(e=="div"||e=="span")b.children("."+this._inlineClass).children().removeClass("ui-state-disabled");this._disabledInputs=d.map(this._disabledInputs,function(f){return f==a?null:f})}},_disableDatepicker:function(a){var b=
d(a),c=d.data(a,"datepicker");if(b.hasClass(this.markerClassName)){var e=a.nodeName.toLowerCase();if(e=="input"){a.disabled=true;c.trigger.filter("button").each(function(){this.disabled=true}).end().filter("img").css({opacity:"0.5",cursor:"default"})}else if(e=="div"||e=="span")b.children("."+this._inlineClass).children().addClass("ui-state-disabled");this._disabledInputs=d.map(this._disabledInputs,function(f){return f==a?null:f});this._disabledInputs[this._disabledInputs.length]=a}},_isDisabledDatepicker:function(a){if(!a)return false;
for(var b=0;b<this._disabledInputs.length;b++)if(this._disabledInputs[b]==a)return true;return false},_getInst:function(a){try{return d.data(a,"datepicker")}catch(b){throw"Missing instance data for this datepicker";}},_optionDatepicker:function(a,b,c){var e=this._getInst(a);if(arguments.length==2&&typeof b=="string")return b=="defaults"?d.extend({},d.datepicker._defaults):e?b=="all"?d.extend({},e.settings):this._get(e,b):null;var f=b||{};if(typeof b=="string"){f={};f[b]=c}if(e){this._curInst==e&&
this._hideDatepicker();var h=this._getDateDatepicker(a,true);E(e.settings,f);this._attachments(d(a),e);this._autoSize(e);this._setDateDatepicker(a,h);this._updateDatepicker(e)}},_changeDatepicker:function(a,b,c){this._optionDatepicker(a,b,c)},_refreshDatepicker:function(a){(a=this._getInst(a))&&this._updateDatepicker(a)},_setDateDatepicker:function(a,b){if(a=this._getInst(a)){this._setDate(a,b);this._updateDatepicker(a);this._updateAlternate(a)}},_getDateDatepicker:function(a,b){(a=this._getInst(a))&&
!a.inline&&this._setDateFromField(a,b);return a?this._getDate(a):null},_doKeyDown:function(a){var b=d.datepicker._getInst(a.target),c=true,e=b.dpDiv.is(".ui-datepicker-rtl");b._keyEvent=true;if(d.datepicker._datepickerShowing)switch(a.keyCode){case 9:d.datepicker._hideDatepicker();c=false;break;case 13:c=d("td."+d.datepicker._dayOverClass,b.dpDiv).add(d("td."+d.datepicker._currentClass,b.dpDiv));c[0]?d.datepicker._selectDay(a.target,b.selectedMonth,b.selectedYear,c[0]):d.datepicker._hideDatepicker();
return false;case 27:d.datepicker._hideDatepicker();break;case 33:d.datepicker._adjustDate(a.target,a.ctrlKey?-d.datepicker._get(b,"stepBigMonths"):-d.datepicker._get(b,"stepMonths"),"M");break;case 34:d.datepicker._adjustDate(a.target,a.ctrlKey?+d.datepicker._get(b,"stepBigMonths"):+d.datepicker._get(b,"stepMonths"),"M");break;case 35:if(a.ctrlKey||a.metaKey)d.datepicker._clearDate(a.target);c=a.ctrlKey||a.metaKey;break;case 36:if(a.ctrlKey||a.metaKey)d.datepicker._gotoToday(a.target);c=a.ctrlKey||
a.metaKey;break;case 37:if(a.ctrlKey||a.metaKey)d.datepicker._adjustDate(a.target,e?+1:-1,"D");c=a.ctrlKey||a.metaKey;if(a.originalEvent.altKey)d.datepicker._adjustDate(a.target,a.ctrlKey?-d.datepicker._get(b,"stepBigMonths"):-d.datepicker._get(b,"stepMonths"),"M");break;case 38:if(a.ctrlKey||a.metaKey)d.datepicker._adjustDate(a.target,-7,"D");c=a.ctrlKey||a.metaKey;break;case 39:if(a.ctrlKey||a.metaKey)d.datepicker._adjustDate(a.target,e?-1:+1,"D");c=a.ctrlKey||a.metaKey;if(a.originalEvent.altKey)d.datepicker._adjustDate(a.target,
a.ctrlKey?+d.datepicker._get(b,"stepBigMonths"):+d.datepicker._get(b,"stepMonths"),"M");break;case 40:if(a.ctrlKey||a.metaKey)d.datepicker._adjustDate(a.target,+7,"D");c=a.ctrlKey||a.metaKey;break;default:c=false}else if(a.keyCode==36&&a.ctrlKey)d.datepicker._showDatepicker(this);else c=false;if(c){a.preventDefault();a.stopPropagation()}},_doKeyPress:function(a){var b=d.datepicker._getInst(a.target);if(d.datepicker._get(b,"constrainInput")){b=d.datepicker._possibleChars(d.datepicker._get(b,"dateFormat"));
var c=String.fromCharCode(a.charCode==G?a.keyCode:a.charCode);return a.ctrlKey||c<" "||!b||b.indexOf(c)>-1}},_doKeyUp:function(a){a=d.datepicker._getInst(a.target);if(a.input.val()!=a.lastVal)try{if(d.datepicker.parseDate(d.datepicker._get(a,"dateFormat"),a.input?a.input.val():null,d.datepicker._getFormatConfig(a))){d.datepicker._setDateFromField(a);d.datepicker._updateAlternate(a);d.datepicker._updateDatepicker(a)}}catch(b){d.datepicker.log(b)}return true},_showDatepicker:function(a){a=a.target||
a;if(a.nodeName.toLowerCase()!="input")a=d("input",a.parentNode)[0];if(!(d.datepicker._isDisabledDatepicker(a)||d.datepicker._lastInput==a)){var b=d.datepicker._getInst(a);d.datepicker._curInst&&d.datepicker._curInst!=b&&d.datepicker._curInst.dpDiv.stop(true,true);var c=d.datepicker._get(b,"beforeShow");E(b.settings,c?c.apply(a,[a,b]):{});b.lastVal=null;d.datepicker._lastInput=a;d.datepicker._setDateFromField(b);if(d.datepicker._inDialog)a.value="";if(!d.datepicker._pos){d.datepicker._pos=d.datepicker._findPos(a);
d.datepicker._pos[1]+=a.offsetHeight}var e=false;d(a).parents().each(function(){e|=d(this).css("position")=="fixed";return!e});if(e&&d.browser.opera){d.datepicker._pos[0]-=document.documentElement.scrollLeft;d.datepicker._pos[1]-=document.documentElement.scrollTop}c={left:d.datepicker._pos[0],top:d.datepicker._pos[1]};d.datepicker._pos=null;b.dpDiv.css({position:"absolute",display:"block",top:"-1000px"});d.datepicker._updateDatepicker(b);c=d.datepicker._checkOffset(b,c,e);b.dpDiv.css({position:d.datepicker._inDialog&&
d.blockUI?"static":e?"fixed":"absolute",display:"none",left:c.left+"px",top:c.top+"px"});if(!b.inline){c=d.datepicker._get(b,"showAnim");var f=d.datepicker._get(b,"duration"),h=function(){d.datepicker._datepickerShowing=true;var i=d.datepicker._getBorders(b.dpDiv);b.dpDiv.find("iframe.ui-datepicker-cover").css({left:-i[0],top:-i[1],width:b.dpDiv.outerWidth(),height:b.dpDiv.outerHeight()})};b.dpDiv.zIndex(d(a).zIndex()+1);d.effects&&d.effects[c]?b.dpDiv.show(c,d.datepicker._get(b,"showOptions"),f,
h):b.dpDiv[c||"show"](c?f:null,h);if(!c||!f)h();b.input.is(":visible")&&!b.input.is(":disabled")&&b.input.focus();d.datepicker._curInst=b}}},_updateDatepicker:function(a){var b=this,c=d.datepicker._getBorders(a.dpDiv);a.dpDiv.empty().append(this._generateHTML(a)).find("iframe.ui-datepicker-cover").css({left:-c[0],top:-c[1],width:a.dpDiv.outerWidth(),height:a.dpDiv.outerHeight()}).end().find("button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a").bind("mouseout",function(){d(this).removeClass("ui-state-hover");
this.className.indexOf("ui-datepicker-prev")!=-1&&d(this).removeClass("ui-datepicker-prev-hover");this.className.indexOf("ui-datepicker-next")!=-1&&d(this).removeClass("ui-datepicker-next-hover")}).bind("mouseover",function(){if(!b._isDisabledDatepicker(a.inline?a.dpDiv.parent()[0]:a.input[0])){d(this).parents(".ui-datepicker-calendar").find("a").removeClass("ui-state-hover");d(this).addClass("ui-state-hover");this.className.indexOf("ui-datepicker-prev")!=-1&&d(this).addClass("ui-datepicker-prev-hover");
this.className.indexOf("ui-datepicker-next")!=-1&&d(this).addClass("ui-datepicker-next-hover")}}).end().find("."+this._dayOverClass+" a").trigger("mouseover").end();c=this._getNumberOfMonths(a);var e=c[1];e>1?a.dpDiv.addClass("ui-datepicker-multi-"+e).css("width",17*e+"em"):a.dpDiv.removeClass("ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4").width("");a.dpDiv[(c[0]!=1||c[1]!=1?"add":"remove")+"Class"]("ui-datepicker-multi");a.dpDiv[(this._get(a,"isRTL")?"add":"remove")+"Class"]("ui-datepicker-rtl");
a==d.datepicker._curInst&&d.datepicker._datepickerShowing&&a.input&&a.input.is(":visible")&&!a.input.is(":disabled")&&a.input.focus()},_getBorders:function(a){var b=function(c){return{thin:1,medium:2,thick:3}[c]||c};return[parseFloat(b(a.css("border-left-width"))),parseFloat(b(a.css("border-top-width")))]},_checkOffset:function(a,b,c){var e=a.dpDiv.outerWidth(),f=a.dpDiv.outerHeight(),h=a.input?a.input.outerWidth():0,i=a.input?a.input.outerHeight():0,g=document.documentElement.clientWidth+d(document).scrollLeft(),
k=document.documentElement.clientHeight+d(document).scrollTop();b.left-=this._get(a,"isRTL")?e-h:0;b.left-=c&&b.left==a.input.offset().left?d(document).scrollLeft():0;b.top-=c&&b.top==a.input.offset().top+i?d(document).scrollTop():0;b.left-=Math.min(b.left,b.left+e>g&&g>e?Math.abs(b.left+e-g):0);b.top-=Math.min(b.top,b.top+f>k&&k>f?Math.abs(f+i):0);return b},_findPos:function(a){for(var b=this._get(this._getInst(a),"isRTL");a&&(a.type=="hidden"||a.nodeType!=1);)a=a[b?"previousSibling":"nextSibling"];
a=d(a).offset();return[a.left,a.top]},_hideDatepicker:function(a){var b=this._curInst;if(!(!b||a&&b!=d.data(a,"datepicker")))if(this._datepickerShowing){a=this._get(b,"showAnim");var c=this._get(b,"duration"),e=function(){d.datepicker._tidyDialog(b);this._curInst=null};d.effects&&d.effects[a]?b.dpDiv.hide(a,d.datepicker._get(b,"showOptions"),c,e):b.dpDiv[a=="slideDown"?"slideUp":a=="fadeIn"?"fadeOut":"hide"](a?c:null,e);a||e();if(a=this._get(b,"onClose"))a.apply(b.input?b.input[0]:null,[b.input?b.input.val():
"",b]);this._datepickerShowing=false;this._lastInput=null;if(this._inDialog){this._dialogInput.css({position:"absolute",left:"0",top:"-100px"});if(d.blockUI){d.unblockUI();d("body").append(this.dpDiv)}}this._inDialog=false}},_tidyDialog:function(a){a.dpDiv.removeClass(this._dialogClass).unbind(".ui-datepicker-calendar")},_checkExternalClick:function(a){if(d.datepicker._curInst){a=d(a.target);a[0].id!=d.datepicker._mainDivId&&a.parents("#"+d.datepicker._mainDivId).length==0&&!a.hasClass(d.datepicker.markerClassName)&&
!a.hasClass(d.datepicker._triggerClass)&&d.datepicker._datepickerShowing&&!(d.datepicker._inDialog&&d.blockUI)&&d.datepicker._hideDatepicker()}},_adjustDate:function(a,b,c){a=d(a);var e=this._getInst(a[0]);if(!this._isDisabledDatepicker(a[0])){this._adjustInstDate(e,b+(c=="M"?this._get(e,"showCurrentAtPos"):0),c);this._updateDatepicker(e)}},_gotoToday:function(a){a=d(a);var b=this._getInst(a[0]);if(this._get(b,"gotoCurrent")&&b.currentDay){b.selectedDay=b.currentDay;b.drawMonth=b.selectedMonth=b.currentMonth;
b.drawYear=b.selectedYear=b.currentYear}else{var c=new Date;b.selectedDay=c.getDate();b.drawMonth=b.selectedMonth=c.getMonth();b.drawYear=b.selectedYear=c.getFullYear()}this._notifyChange(b);this._adjustDate(a)},_selectMonthYear:function(a,b,c){a=d(a);var e=this._getInst(a[0]);e._selectingMonthYear=false;e["selected"+(c=="M"?"Month":"Year")]=e["draw"+(c=="M"?"Month":"Year")]=parseInt(b.options[b.selectedIndex].value,10);this._notifyChange(e);this._adjustDate(a)},_clickMonthYear:function(a){var b=
this._getInst(d(a)[0]);b.input&&b._selectingMonthYear&&setTimeout(function(){b.input.focus()},0);b._selectingMonthYear=!b._selectingMonthYear},_selectDay:function(a,b,c,e){var f=d(a);if(!(d(e).hasClass(this._unselectableClass)||this._isDisabledDatepicker(f[0]))){f=this._getInst(f[0]);f.selectedDay=f.currentDay=d("a",e).html();f.selectedMonth=f.currentMonth=b;f.selectedYear=f.currentYear=c;this._selectDate(a,this._formatDate(f,f.currentDay,f.currentMonth,f.currentYear))}},_clearDate:function(a){a=
d(a);this._getInst(a[0]);this._selectDate(a,"")},_selectDate:function(a,b){a=this._getInst(d(a)[0]);b=b!=null?b:this._formatDate(a);a.input&&a.input.val(b);this._updateAlternate(a);var c=this._get(a,"onSelect");if(c)c.apply(a.input?a.input[0]:null,[b,a]);else a.input&&a.input.trigger("change");if(a.inline)this._updateDatepicker(a);else{this._hideDatepicker();this._lastInput=a.input[0];typeof a.input[0]!="object"&&a.input.focus();this._lastInput=null}},_updateAlternate:function(a){var b=this._get(a,
"altField");if(b){var c=this._get(a,"altFormat")||this._get(a,"dateFormat"),e=this._getDate(a),f=this.formatDate(c,e,this._getFormatConfig(a));d(b).each(function(){d(this).val(f)})}},noWeekends:function(a){a=a.getDay();return[a>0&&a<6,""]},iso8601Week:function(a){a=new Date(a.getTime());a.setDate(a.getDate()+4-(a.getDay()||7));var b=a.getTime();a.setMonth(0);a.setDate(1);return Math.floor(Math.round((b-a)/864E5)/7)+1},parseDate:function(a,b,c){if(a==null||b==null)throw"Invalid arguments";b=typeof b==
"object"?b.toString():b+"";if(b=="")return null;for(var e=(c?c.shortYearCutoff:null)||this._defaults.shortYearCutoff,f=(c?c.dayNamesShort:null)||this._defaults.dayNamesShort,h=(c?c.dayNames:null)||this._defaults.dayNames,i=(c?c.monthNamesShort:null)||this._defaults.monthNamesShort,g=(c?c.monthNames:null)||this._defaults.monthNames,k=c=-1,l=-1,u=-1,j=false,o=function(p){(p=z+1<a.length&&a.charAt(z+1)==p)&&z++;return p},m=function(p){o(p);p=new RegExp("^\\d{1,"+(p=="@"?14:p=="!"?20:p=="y"?4:p=="o"?
3:2)+"}");p=b.substring(s).match(p);if(!p)throw"Missing number at position "+s;s+=p[0].length;return parseInt(p[0],10)},n=function(p,w,H){p=o(p)?H:w;for(w=0;w<p.length;w++)if(b.substr(s,p[w].length).toLowerCase()==p[w].toLowerCase()){s+=p[w].length;return w+1}throw"Unknown name at position "+s;},r=function(){if(b.charAt(s)!=a.charAt(z))throw"Unexpected literal at position "+s;s++},s=0,z=0;z<a.length;z++)if(j)if(a.charAt(z)=="'"&&!o("'"))j=false;else r();else switch(a.charAt(z)){case "d":l=m("d");
break;case "D":n("D",f,h);break;case "o":u=m("o");break;case "m":k=m("m");break;case "M":k=n("M",i,g);break;case "y":c=m("y");break;case "@":var v=new Date(m("@"));c=v.getFullYear();k=v.getMonth()+1;l=v.getDate();break;case "!":v=new Date((m("!")-this._ticksTo1970)/1E4);c=v.getFullYear();k=v.getMonth()+1;l=v.getDate();break;case "'":if(o("'"))r();else j=true;break;default:r()}if(c==-1)c=(new Date).getFullYear();else if(c<100)c+=(new Date).getFullYear()-(new Date).getFullYear()%100+(c<=e?0:-100);if(u>
-1){k=1;l=u;do{e=this._getDaysInMonth(c,k-1);if(l<=e)break;k++;l-=e}while(1)}v=this._daylightSavingAdjust(new Date(c,k-1,l));if(v.getFullYear()!=c||v.getMonth()+1!=k||v.getDate()!=l)throw"Invalid date";return v},ATOM:"yy-mm-dd",COOKIE:"D, dd M yy",ISO_8601:"yy-mm-dd",RFC_822:"D, d M y",RFC_850:"DD, dd-M-y",RFC_1036:"D, d M y",RFC_1123:"D, d M yy",RFC_2822:"D, d M yy",RSS:"D, d M y",TICKS:"!",TIMESTAMP:"@",W3C:"yy-mm-dd",_ticksTo1970:(718685+Math.floor(492.5)-Math.floor(19.7)+Math.floor(4.925))*24*
60*60*1E7,formatDate:function(a,b,c){if(!b)return"";var e=(c?c.dayNamesShort:null)||this._defaults.dayNamesShort,f=(c?c.dayNames:null)||this._defaults.dayNames,h=(c?c.monthNamesShort:null)||this._defaults.monthNamesShort;c=(c?c.monthNames:null)||this._defaults.monthNames;var i=function(o){(o=j+1<a.length&&a.charAt(j+1)==o)&&j++;return o},g=function(o,m,n){m=""+m;if(i(o))for(;m.length<n;)m="0"+m;return m},k=function(o,m,n,r){return i(o)?r[m]:n[m]},l="",u=false;if(b)for(var j=0;j<a.length;j++)if(u)if(a.charAt(j)==
"'"&&!i("'"))u=false;else l+=a.charAt(j);else switch(a.charAt(j)){case "d":l+=g("d",b.getDate(),2);break;case "D":l+=k("D",b.getDay(),e,f);break;case "o":l+=g("o",(b.getTime()-(new Date(b.getFullYear(),0,0)).getTime())/864E5,3);break;case "m":l+=g("m",b.getMonth()+1,2);break;case "M":l+=k("M",b.getMonth(),h,c);break;case "y":l+=i("y")?b.getFullYear():(b.getYear()%100<10?"0":"")+b.getYear()%100;break;case "@":l+=b.getTime();break;case "!":l+=b.getTime()*1E4+this._ticksTo1970;break;case "'":if(i("'"))l+=
"'";else u=true;break;default:l+=a.charAt(j)}return l},_possibleChars:function(a){for(var b="",c=false,e=function(h){(h=f+1<a.length&&a.charAt(f+1)==h)&&f++;return h},f=0;f<a.length;f++)if(c)if(a.charAt(f)=="'"&&!e("'"))c=false;else b+=a.charAt(f);else switch(a.charAt(f)){case "d":case "m":case "y":case "@":b+="0123456789";break;case "D":case "M":return null;case "'":if(e("'"))b+="'";else c=true;break;default:b+=a.charAt(f)}return b},_get:function(a,b){return a.settings[b]!==G?a.settings[b]:this._defaults[b]},
_setDateFromField:function(a,b){if(a.input.val()!=a.lastVal){var c=this._get(a,"dateFormat"),e=a.lastVal=a.input?a.input.val():null,f,h;f=h=this._getDefaultDate(a);var i=this._getFormatConfig(a);try{f=this.parseDate(c,e,i)||h}catch(g){this.log(g);e=b?"":e}a.selectedDay=f.getDate();a.drawMonth=a.selectedMonth=f.getMonth();a.drawYear=a.selectedYear=f.getFullYear();a.currentDay=e?f.getDate():0;a.currentMonth=e?f.getMonth():0;a.currentYear=e?f.getFullYear():0;this._adjustInstDate(a)}},_getDefaultDate:function(a){return this._restrictMinMax(a,
this._determineDate(a,this._get(a,"defaultDate"),new Date))},_determineDate:function(a,b,c){var e=function(h){var i=new Date;i.setDate(i.getDate()+h);return i},f=function(h){try{return d.datepicker.parseDate(d.datepicker._get(a,"dateFormat"),h,d.datepicker._getFormatConfig(a))}catch(i){}var g=(h.toLowerCase().match(/^c/)?d.datepicker._getDate(a):null)||new Date,k=g.getFullYear(),l=g.getMonth();g=g.getDate();for(var u=/([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g,j=u.exec(h);j;){switch(j[2]||"d"){case "d":case "D":g+=
parseInt(j[1],10);break;case "w":case "W":g+=parseInt(j[1],10)*7;break;case "m":case "M":l+=parseInt(j[1],10);g=Math.min(g,d.datepicker._getDaysInMonth(k,l));break;case "y":case "Y":k+=parseInt(j[1],10);g=Math.min(g,d.datepicker._getDaysInMonth(k,l));break}j=u.exec(h)}return new Date(k,l,g)};if(b=(b=b==null?c:typeof b=="string"?f(b):typeof b=="number"?isNaN(b)?c:e(b):b)&&b.toString()=="Invalid Date"?c:b){b.setHours(0);b.setMinutes(0);b.setSeconds(0);b.setMilliseconds(0)}return this._daylightSavingAdjust(b)},
_daylightSavingAdjust:function(a){if(!a)return null;a.setHours(a.getHours()>12?a.getHours()+2:0);return a},_setDate:function(a,b,c){var e=!b,f=a.selectedMonth,h=a.selectedYear;b=this._restrictMinMax(a,this._determineDate(a,b,new Date));a.selectedDay=a.currentDay=b.getDate();a.drawMonth=a.selectedMonth=a.currentMonth=b.getMonth();a.drawYear=a.selectedYear=a.currentYear=b.getFullYear();if((f!=a.selectedMonth||h!=a.selectedYear)&&!c)this._notifyChange(a);this._adjustInstDate(a);if(a.input)a.input.val(e?
"":this._formatDate(a))},_getDate:function(a){return!a.currentYear||a.input&&a.input.val()==""?null:this._daylightSavingAdjust(new Date(a.currentYear,a.currentMonth,a.currentDay))},_generateHTML:function(a){var b=new Date;b=this._daylightSavingAdjust(new Date(b.getFullYear(),b.getMonth(),b.getDate()));var c=this._get(a,"isRTL"),e=this._get(a,"showButtonPanel"),f=this._get(a,"hideIfNoPrevNext"),h=this._get(a,"navigationAsDateFormat"),i=this._getNumberOfMonths(a),g=this._get(a,"showCurrentAtPos"),k=
this._get(a,"stepMonths"),l=i[0]!=1||i[1]!=1,u=this._daylightSavingAdjust(!a.currentDay?new Date(9999,9,9):new Date(a.currentYear,a.currentMonth,a.currentDay)),j=this._getMinMaxDate(a,"min"),o=this._getMinMaxDate(a,"max");g=a.drawMonth-g;var m=a.drawYear;if(g<0){g+=12;m--}if(o){var n=this._daylightSavingAdjust(new Date(o.getFullYear(),o.getMonth()-i[0]*i[1]+1,o.getDate()));for(n=j&&n<j?j:n;this._daylightSavingAdjust(new Date(m,g,1))>n;){g--;if(g<0){g=11;m--}}}a.drawMonth=g;a.drawYear=m;n=this._get(a,
"prevText");n=!h?n:this.formatDate(n,this._daylightSavingAdjust(new Date(m,g-k,1)),this._getFormatConfig(a));n=this._canAdjustMonth(a,-1,m,g)?'<a class="ui-datepicker-prev ui-corner-all" onclick="DP_jQuery_'+y+".datepicker._adjustDate('#"+a.id+"', -"+k+", 'M');\" title=\""+n+'"><span class="ui-icon ui-icon-circle-triangle-'+(c?"e":"w")+'">'+n+"</span></a>":f?"":'<a class="ui-datepicker-prev ui-corner-all ui-state-disabled" title="'+n+'"><span class="ui-icon ui-icon-circle-triangle-'+(c?"e":"w")+'">'+
n+"</span></a>";var r=this._get(a,"nextText");r=!h?r:this.formatDate(r,this._daylightSavingAdjust(new Date(m,g+k,1)),this._getFormatConfig(a));f=this._canAdjustMonth(a,+1,m,g)?'<a class="ui-datepicker-next ui-corner-all" onclick="DP_jQuery_'+y+".datepicker._adjustDate('#"+a.id+"', +"+k+", 'M');\" title=\""+r+'"><span class="ui-icon ui-icon-circle-triangle-'+(c?"w":"e")+'">'+r+"</span></a>":f?"":'<a class="ui-datepicker-next ui-corner-all ui-state-disabled" title="'+r+'"><span class="ui-icon ui-icon-circle-triangle-'+
(c?"w":"e")+'">'+r+"</span></a>";k=this._get(a,"currentText");r=this._get(a,"gotoCurrent")&&a.currentDay?u:b;k=!h?k:this.formatDate(k,r,this._getFormatConfig(a));h=!a.inline?'<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" onclick="DP_jQuery_'+y+'.datepicker._hideDatepicker();">'+this._get(a,"closeText")+"</button>":"";e=e?'<div class="ui-datepicker-buttonpane ui-widget-content">'+(c?h:"")+(this._isInRange(a,r)?'<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" onclick="DP_jQuery_'+
y+".datepicker._gotoToday('#"+a.id+"');\">"+k+"</button>":"")+(c?"":h)+"</div>":"";h=parseInt(this._get(a,"firstDay"),10);h=isNaN(h)?0:h;k=this._get(a,"showWeek");r=this._get(a,"dayNames");this._get(a,"dayNamesShort");var s=this._get(a,"dayNamesMin"),z=this._get(a,"monthNames"),v=this._get(a,"monthNamesShort"),p=this._get(a,"beforeShowDay"),w=this._get(a,"showOtherMonths"),H=this._get(a,"selectOtherMonths");this._get(a,"calculateWeek");for(var L=this._getDefaultDate(a),I="",C=0;C<i[0];C++){for(var M=
"",D=0;D<i[1];D++){var N=this._daylightSavingAdjust(new Date(m,g,a.selectedDay)),t=" ui-corner-all",x="";if(l){x+='<div class="ui-datepicker-group';if(i[1]>1)switch(D){case 0:x+=" ui-datepicker-group-first";t=" ui-corner-"+(c?"right":"left");break;case i[1]-1:x+=" ui-datepicker-group-last";t=" ui-corner-"+(c?"left":"right");break;default:x+=" ui-datepicker-group-middle";t="";break}x+='">'}x+='<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix'+t+'">'+(/all|left/.test(t)&&C==0?c?
f:n:"")+(/all|right/.test(t)&&C==0?c?n:f:"")+this._generateMonthYearHeader(a,g,m,j,o,C>0||D>0,z,v)+'</div><table class="ui-datepicker-calendar"><thead><tr>';var A=k?'<th class="ui-datepicker-week-col">'+this._get(a,"weekHeader")+"</th>":"";for(t=0;t<7;t++){var q=(t+h)%7;A+="<th"+((t+h+6)%7>=5?' class="ui-datepicker-week-end"':"")+'><span title="'+r[q]+'">'+s[q]+"</span></th>"}x+=A+"</tr></thead><tbody>";A=this._getDaysInMonth(m,g);if(m==a.selectedYear&&g==a.selectedMonth)a.selectedDay=Math.min(a.selectedDay,
A);t=(this._getFirstDayOfMonth(m,g)-h+7)%7;A=l?6:Math.ceil((t+A)/7);q=this._daylightSavingAdjust(new Date(m,g,1-t));for(var O=0;O<A;O++){x+="<tr>";var P=!k?"":'<td class="ui-datepicker-week-col">'+this._get(a,"calculateWeek")(q)+"</td>";for(t=0;t<7;t++){var F=p?p.apply(a.input?a.input[0]:null,[q]):[true,""],B=q.getMonth()!=g,J=B&&!H||!F[0]||j&&q<j||o&&q>o;P+='<td class="'+((t+h+6)%7>=5?" ui-datepicker-week-end":"")+(B?" ui-datepicker-other-month":"")+(q.getTime()==N.getTime()&&g==a.selectedMonth&&
a._keyEvent||L.getTime()==q.getTime()&&L.getTime()==N.getTime()?" "+this._dayOverClass:"")+(J?" "+this._unselectableClass+" ui-state-disabled":"")+(B&&!w?"":" "+F[1]+(q.getTime()==u.getTime()?" "+this._currentClass:"")+(q.getTime()==b.getTime()?" ui-datepicker-today":""))+'"'+((!B||w)&&F[2]?' title="'+F[2]+'"':"")+(J?"":' onclick="DP_jQuery_'+y+".datepicker._selectDay('#"+a.id+"',"+q.getMonth()+","+q.getFullYear()+', this);return false;"')+">"+(B&&!w?"&#xa0;":J?'<span class="ui-state-default">'+q.getDate()+
"</span>":'<a class="ui-state-default'+(q.getTime()==b.getTime()?" ui-state-highlight":"")+(q.getTime()==u.getTime()?" ui-state-active":"")+(B?" ui-priority-secondary":"")+'" href="#">'+q.getDate()+"</a>")+"</td>";q.setDate(q.getDate()+1);q=this._daylightSavingAdjust(q)}x+=P+"</tr>"}g++;if(g>11){g=0;m++}x+="</tbody></table>"+(l?"</div>"+(i[0]>0&&D==i[1]-1?'<div class="ui-datepicker-row-break"></div>':""):"");M+=x}I+=M}I+=e+(d.browser.msie&&parseInt(d.browser.version,10)<7&&!a.inline?'<iframe src="javascript:false;" class="ui-datepicker-cover" frameborder="0"></iframe>':
"");a._keyEvent=false;return I},_generateMonthYearHeader:function(a,b,c,e,f,h,i,g){var k=this._get(a,"changeMonth"),l=this._get(a,"changeYear"),u=this._get(a,"showMonthAfterYear"),j='<div class="ui-datepicker-title">',o="";if(h||!k)o+='<span class="ui-datepicker-month">'+i[b]+"</span>";else{i=e&&e.getFullYear()==c;var m=f&&f.getFullYear()==c;o+='<select class="ui-datepicker-month" onchange="DP_jQuery_'+y+".datepicker._selectMonthYear('#"+a.id+"', this, 'M');\" onclick=\"DP_jQuery_"+y+".datepicker._clickMonthYear('#"+
a.id+"');\">";for(var n=0;n<12;n++)if((!i||n>=e.getMonth())&&(!m||n<=f.getMonth()))o+='<option value="'+n+'"'+(n==b?' selected="selected"':"")+">"+g[n]+"</option>";o+="</select>"}u||(j+=o+(h||!(k&&l)?"&#xa0;":""));if(h||!l)j+='<span class="ui-datepicker-year">'+c+"</span>";else{g=this._get(a,"yearRange").split(":");var r=(new Date).getFullYear();i=function(s){s=s.match(/c[+-].*/)?c+parseInt(s.substring(1),10):s.match(/[+-].*/)?r+parseInt(s,10):parseInt(s,10);return isNaN(s)?r:s};b=i(g[0]);g=Math.max(b,
i(g[1]||""));b=e?Math.max(b,e.getFullYear()):b;g=f?Math.min(g,f.getFullYear()):g;for(j+='<select class="ui-datepicker-year" onchange="DP_jQuery_'+y+".datepicker._selectMonthYear('#"+a.id+"', this, 'Y');\" onclick=\"DP_jQuery_"+y+".datepicker._clickMonthYear('#"+a.id+"');\">";b<=g;b++)j+='<option value="'+b+'"'+(b==c?' selected="selected"':"")+">"+b+"</option>";j+="</select>"}j+=this._get(a,"yearSuffix");if(u)j+=(h||!(k&&l)?"&#xa0;":"")+o;j+="</div>";return j},_adjustInstDate:function(a,b,c){var e=
a.drawYear+(c=="Y"?b:0),f=a.drawMonth+(c=="M"?b:0);b=Math.min(a.selectedDay,this._getDaysInMonth(e,f))+(c=="D"?b:0);e=this._restrictMinMax(a,this._daylightSavingAdjust(new Date(e,f,b)));a.selectedDay=e.getDate();a.drawMonth=a.selectedMonth=e.getMonth();a.drawYear=a.selectedYear=e.getFullYear();if(c=="M"||c=="Y")this._notifyChange(a)},_restrictMinMax:function(a,b){var c=this._getMinMaxDate(a,"min");a=this._getMinMaxDate(a,"max");b=c&&b<c?c:b;return b=a&&b>a?a:b},_notifyChange:function(a){var b=this._get(a,
"onChangeMonthYear");if(b)b.apply(a.input?a.input[0]:null,[a.selectedYear,a.selectedMonth+1,a])},_getNumberOfMonths:function(a){a=this._get(a,"numberOfMonths");return a==null?[1,1]:typeof a=="number"?[1,a]:a},_getMinMaxDate:function(a,b){return this._determineDate(a,this._get(a,b+"Date"),null)},_getDaysInMonth:function(a,b){return 32-(new Date(a,b,32)).getDate()},_getFirstDayOfMonth:function(a,b){return(new Date(a,b,1)).getDay()},_canAdjustMonth:function(a,b,c,e){var f=this._getNumberOfMonths(a);
c=this._daylightSavingAdjust(new Date(c,e+(b<0?b:f[0]*f[1]),1));b<0&&c.setDate(this._getDaysInMonth(c.getFullYear(),c.getMonth()));return this._isInRange(a,c)},_isInRange:function(a,b){var c=this._getMinMaxDate(a,"min");a=this._getMinMaxDate(a,"max");return(!c||b.getTime()>=c.getTime())&&(!a||b.getTime()<=a.getTime())},_getFormatConfig:function(a){var b=this._get(a,"shortYearCutoff");b=typeof b!="string"?b:(new Date).getFullYear()%100+parseInt(b,10);return{shortYearCutoff:b,dayNamesShort:this._get(a,
"dayNamesShort"),dayNames:this._get(a,"dayNames"),monthNamesShort:this._get(a,"monthNamesShort"),monthNames:this._get(a,"monthNames")}},_formatDate:function(a,b,c,e){if(!b){a.currentDay=a.selectedDay;a.currentMonth=a.selectedMonth;a.currentYear=a.selectedYear}b=b?typeof b=="object"?b:this._daylightSavingAdjust(new Date(e,c,b)):this._daylightSavingAdjust(new Date(a.currentYear,a.currentMonth,a.currentDay));return this.formatDate(this._get(a,"dateFormat"),b,this._getFormatConfig(a))}});d.fn.datepicker=
function(a){if(!d.datepicker.initialized){d(document).mousedown(d.datepicker._checkExternalClick).find("body").append(d.datepicker.dpDiv);d.datepicker.initialized=true}var b=Array.prototype.slice.call(arguments,1);if(typeof a=="string"&&(a=="isDisabled"||a=="getDate"||a=="widget"))return d.datepicker["_"+a+"Datepicker"].apply(d.datepicker,[this[0]].concat(b));if(a=="option"&&arguments.length==2&&typeof arguments[1]=="string")return d.datepicker["_"+a+"Datepicker"].apply(d.datepicker,[this[0]].concat(b));
return this.each(function(){typeof a=="string"?d.datepicker["_"+a+"Datepicker"].apply(d.datepicker,[this].concat(b)):d.datepicker._attachDatepicker(this,a)})};d.datepicker=new K;d.datepicker.initialized=false;d.datepicker.uuid=(new Date).getTime();d.datepicker.version="1.8.6";window["DP_jQuery_"+y]=d})(jQuery);
;

/* Polish initialisation for the jQuery UI date picker plugin. */
/* Written by Jacek Wysocki (jacek.wysocki@gmail.com). */
jQuery(function($){
	$.datepicker.regional['pl'] = {
		closeText: 'Zamknij',
		prevText: '&#x3c;Poprzedni',
		nextText: 'Nast\u0119pny&#x3e;',
		currentText: 'Dzi\u015b',
		monthNames: ['Stycze\u0144','Luty','Marzec','Kwiecie\u0144','Maj','Czerwiec','Lipiec','Sierpie\u0144','Wrzesie\u0144','Pa\u017adziernik','Listopad','Grudzie\u0144'],
		monthNamesShort: ['Sty','Lu','Mar','Kw','Maj','Cze','Lip','Sie','Wrz','Pa\u017a','Lis','Gru'],
		dayNames: ['Niedziela','Poniedzia\u0142ek','Wtorek','\u015aroda','Czwartek','Pi\u0105tek','Sobota'],
		dayNamesShort: ['Nie','Pn','Wt','\u015ar','Czw','Pt','So'],
		dayNamesMin: ['N','Pn','Wt','\u015ar','Cz','Pt','So'],
		weekHeader: 'Tydz',
		dateFormat: 'yy-mm-dd',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: false,
		yearSuffix: ''};
	$.datepicker.setDefaults($.datepicker.regional['pl']);
});

/*
 * TableSorter 2.0 - Client-side table sorting with ease!
 * Version 2.0.5b
 * @requires jQuery v1.2.3
 * 
 * Copyright (c) 2007 Christian Bach
 * Examples and docs at: http://tablesorter.com
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */
(function($){$.extend({tablesorter:new
function(){var parsers=[],widgets=[];this.defaults={cssHeader:"header",cssAsc:"headerSortUp",cssDesc:"headerSortDown",cssChildRow:"expand-child",sortInitialOrder:"asc",sortMultiSortKey:"shiftKey",sortForce:null,sortAppend:null,sortLocaleCompare:true,textExtraction:"simple",parsers:{},widgets:[],widgetZebra:{css:["even","odd"]},headers:{},widthFixed:false,cancelSelection:true,sortList:[],headerList:[],dateFormat:"us",decimal:'/\.|\,/g',onRenderHeader:null,selectorHeaders:'thead th',debug:false};function benchmark(s,d){log(s+","+(new Date().getTime()-d.getTime())+"ms");}this.benchmark=benchmark;function log(s){if(typeof console!="undefined"&&typeof console.debug!="undefined"){console.log(s);}else{alert(s);}}function buildParserCache(table,$headers){if(table.config.debug){var parsersDebug="";}if(table.tBodies.length==0)return;var rows=table.tBodies[0].rows;if(rows[0]){var list=[],cells=rows[0].cells,l=cells.length;for(var i=0;i<l;i++){var p=false;if($.metadata&&($($headers[i]).metadata()&&$($headers[i]).metadata().sorter)){p=getParserById($($headers[i]).metadata().sorter);}else if((table.config.headers[i]&&table.config.headers[i].sorter)){p=getParserById(table.config.headers[i].sorter);}if(!p){p=detectParserForColumn(table,rows,-1,i);}if(table.config.debug){parsersDebug+="column:"+i+" parser:"+p.id+"\n";}list.push(p);}}if(table.config.debug){log(parsersDebug);}return list;};function detectParserForColumn(table,rows,rowIndex,cellIndex){var l=parsers.length,node=false,nodeValue=false,keepLooking=true;while(nodeValue==''&&keepLooking){rowIndex++;if(rows[rowIndex]){node=getNodeFromRowAndCellIndex(rows,rowIndex,cellIndex);nodeValue=trimAndGetNodeText(table.config,node);if(table.config.debug){log('Checking if value was empty on row:'+rowIndex);}}else{keepLooking=false;}}for(var i=1;i<l;i++){if(parsers[i].is(nodeValue,table,node)){return parsers[i];}}return parsers[0];}function getNodeFromRowAndCellIndex(rows,rowIndex,cellIndex){return rows[rowIndex].cells[cellIndex];}function trimAndGetNodeText(config,node){return $.trim(getElementText(config,node));}function getParserById(name){var l=parsers.length;for(var i=0;i<l;i++){if(parsers[i].id.toLowerCase()==name.toLowerCase()){return parsers[i];}}return false;}function buildCache(table){if(table.config.debug){var cacheTime=new Date();}var totalRows=(table.tBodies[0]&&table.tBodies[0].rows.length)||0,totalCells=(table.tBodies[0].rows[0]&&table.tBodies[0].rows[0].cells.length)||0,parsers=table.config.parsers,cache={row:[],normalized:[]};for(var i=0;i<totalRows;++i){var c=$(table.tBodies[0].rows[i]),cols=[];if(c.hasClass(table.config.cssChildRow)){cache.row[cache.row.length-1]=cache.row[cache.row.length-1].add(c);continue;}cache.row.push(c);for(var j=0;j<totalCells;++j){cols.push(parsers[j].format(getElementText(table.config,c[0].cells[j]),table,c[0].cells[j]));}cols.push(cache.normalized.length);cache.normalized.push(cols);cols=null;};if(table.config.debug){benchmark("Building cache for "+totalRows+" rows:",cacheTime);}return cache;};function getElementText(config,node){var text="";if(!node)return"";if(!config.supportsTextContent)config.supportsTextContent=node.textContent||false;if(config.textExtraction=="simple"){if(config.supportsTextContent){text=node.textContent;}else{if(node.childNodes[0]&&node.childNodes[0].hasChildNodes()){text=node.childNodes[0].innerHTML;}else{text=node.innerHTML;}}}else{if(typeof(config.textExtraction)=="function"){text=config.textExtraction(node);}else{text=$(node).text();}}return text;}function appendToTable(table,cache){if(table.config.debug){var appendTime=new Date()}var c=cache,r=c.row,n=c.normalized,totalRows=n.length,checkCell=(n[0].length-1),tableBody=$(table.tBodies[0]),rows=[];for(var i=0;i<totalRows;i++){var pos=n[i][checkCell];rows.push(r[pos]);if(!table.config.appender){var l=r[pos].length;for(var j=0;j<l;j++){tableBody[0].appendChild(r[pos][j]);}}}if(table.config.appender){table.config.appender(table,rows);}rows=null;if(table.config.debug){benchmark("Rebuilt table:",appendTime);}applyWidget(table);setTimeout(function(){$(table).trigger("sortEnd");},0);};function buildHeaders(table){if(table.config.debug){var time=new Date();}var meta=($.metadata)?true:false;var header_index=computeTableHeaderCellIndexes(table);$tableHeaders=$(table.config.selectorHeaders,table).each(function(index){this.column=header_index[this.parentNode.rowIndex+"-"+this.cellIndex];this.order=formatSortingOrder(table.config.sortInitialOrder);this.count=this.order;if(checkHeaderMetadata(this)||checkHeaderOptions(table,index))this.sortDisabled=true;if(checkHeaderOptionsSortingLocked(table,index))this.order=this.lockedOrder=checkHeaderOptionsSortingLocked(table,index);if(!this.sortDisabled){var $th=$(this).addClass(table.config.cssHeader);if(table.config.onRenderHeader)table.config.onRenderHeader.apply($th);}table.config.headerList[index]=this;});if(table.config.debug){benchmark("Built headers:",time);log($tableHeaders);}return $tableHeaders;};function computeTableHeaderCellIndexes(t){var matrix=[];var lookup={};var thead=t.getElementsByTagName('THEAD')[0];var trs=thead.getElementsByTagName('TR');for(var i=0;i<trs.length;i++){var cells=trs[i].cells;for(var j=0;j<cells.length;j++){var c=cells[j];var rowIndex=c.parentNode.rowIndex;var cellId=rowIndex+"-"+c.cellIndex;var rowSpan=c.rowSpan||1;var colSpan=c.colSpan||1
var firstAvailCol;if(typeof(matrix[rowIndex])=="undefined"){matrix[rowIndex]=[];}for(var k=0;k<matrix[rowIndex].length+1;k++){if(typeof(matrix[rowIndex][k])=="undefined"){firstAvailCol=k;break;}}lookup[cellId]=firstAvailCol;for(var k=rowIndex;k<rowIndex+rowSpan;k++){if(typeof(matrix[k])=="undefined"){matrix[k]=[];}var matrixrow=matrix[k];for(var l=firstAvailCol;l<firstAvailCol+colSpan;l++){matrixrow[l]="x";}}}}return lookup;}function checkCellColSpan(table,rows,row){var arr=[],r=table.tHead.rows,c=r[row].cells;for(var i=0;i<c.length;i++){var cell=c[i];if(cell.colSpan>1){arr=arr.concat(checkCellColSpan(table,headerArr,row++));}else{if(table.tHead.length==1||(cell.rowSpan>1||!r[row+1])){arr.push(cell);}}}return arr;};function checkHeaderMetadata(cell){if(($.metadata)&&($(cell).metadata().sorter===false)){return true;};return false;}function checkHeaderOptions(table,i){if((table.config.headers[i])&&(table.config.headers[i].sorter===false)){return true;};return false;}function checkHeaderOptionsSortingLocked(table,i){if((table.config.headers[i])&&(table.config.headers[i].lockedOrder))return table.config.headers[i].lockedOrder;return false;}function applyWidget(table){var c=table.config.widgets;var l=c.length;for(var i=0;i<l;i++){getWidgetById(c[i]).format(table);}}function getWidgetById(name){var l=widgets.length;for(var i=0;i<l;i++){if(widgets[i].id.toLowerCase()==name.toLowerCase()){return widgets[i];}}};function formatSortingOrder(v){if(typeof(v)!="Number"){return(v.toLowerCase()=="desc")?1:0;}else{return(v==1)?1:0;}}function isValueInArray(v,a){var l=a.length;for(var i=0;i<l;i++){if(a[i][0]==v){return true;}}return false;}function setHeadersCss(table,$headers,list,css){$headers.removeClass(css[0]).removeClass(css[1]);var h=[];$headers.each(function(offset){if(!this.sortDisabled){h[this.column]=$(this);}});var l=list.length;for(var i=0;i<l;i++){h[list[i][0]].addClass(css[list[i][1]]);}}function fixColumnWidth(table,$headers){var c=table.config;if(c.widthFixed){var colgroup=$('<colgroup>');$("tr:first td",table.tBodies[0]).each(function(){colgroup.append($('<col>').css('width',$(this).width()));});$(table).prepend(colgroup);};}function updateHeaderSortCount(table,sortList){var c=table.config,l=sortList.length;for(var i=0;i<l;i++){var s=sortList[i],o=c.headerList[s[0]];o.count=s[1];o.count++;}}function multisort(table,sortList,cache){if(table.config.debug){var sortTime=new Date();}var dynamicExp="var sortWrapper = function(a,b) {",l=sortList.length;for(var i=0;i<l;i++){var c=sortList[i][0];var order=sortList[i][1];var s=(table.config.parsers[c].type=="text")?((order==0)?makeSortFunction("text","asc",c):makeSortFunction("text","desc",c)):((order==0)?makeSortFunction("numeric","asc",c):makeSortFunction("numeric","desc",c));var e="e"+i;dynamicExp+="var "+e+" = "+s;dynamicExp+="if("+e+") { return "+e+"; } ";dynamicExp+="else { ";}var orgOrderCol=cache.normalized[0].length-1;dynamicExp+="return a["+orgOrderCol+"]-b["+orgOrderCol+"];";for(var i=0;i<l;i++){dynamicExp+="}; ";}dynamicExp+="return 0; ";dynamicExp+="}; ";if(table.config.debug){benchmark("Evaling expression:"+dynamicExp,new Date());}eval(dynamicExp);cache.normalized.sort(sortWrapper);if(table.config.debug){benchmark("Sorting on "+sortList.toString()+" and dir "+order+" time:",sortTime);}return cache;};function makeSortFunction(type,direction,index){var a="a["+index+"]",b="b["+index+"]";if(type=='text'&&direction=='asc'){return"("+a+" == "+b+" ? 0 : ("+a+" === null ? Number.POSITIVE_INFINITY : ("+b+" === null ? Number.NEGATIVE_INFINITY : ("+a+" < "+b+") ? -1 : 1 )));";}else if(type=='text'&&direction=='desc'){return"("+a+" == "+b+" ? 0 : ("+a+" === null ? Number.POSITIVE_INFINITY : ("+b+" === null ? Number.NEGATIVE_INFINITY : ("+b+" < "+a+") ? -1 : 1 )));";}else if(type=='numeric'&&direction=='asc'){return"("+a+" === null && "+b+" === null) ? 0 :("+a+" === null ? Number.POSITIVE_INFINITY : ("+b+" === null ? Number.NEGATIVE_INFINITY : "+a+" - "+b+"));";}else if(type=='numeric'&&direction=='desc'){return"("+a+" === null && "+b+" === null) ? 0 :("+a+" === null ? Number.POSITIVE_INFINITY : ("+b+" === null ? Number.NEGATIVE_INFINITY : "+b+" - "+a+"));";}};function makeSortText(i){return"((a["+i+"] < b["+i+"]) ? -1 : ((a["+i+"] > b["+i+"]) ? 1 : 0));";};function makeSortTextDesc(i){return"((b["+i+"] < a["+i+"]) ? -1 : ((b["+i+"] > a["+i+"]) ? 1 : 0));";};function makeSortNumeric(i){return"a["+i+"]-b["+i+"];";};function makeSortNumericDesc(i){return"b["+i+"]-a["+i+"];";};function sortText(a,b){if(table.config.sortLocaleCompare)return a.localeCompare(b);return((a<b)?-1:((a>b)?1:0));};function sortTextDesc(a,b){if(table.config.sortLocaleCompare)return b.localeCompare(a);return((b<a)?-1:((b>a)?1:0));};function sortNumeric(a,b){return a-b;};function sortNumericDesc(a,b){return b-a;};function getCachedSortType(parsers,i){return parsers[i].type;};this.construct=function(settings){return this.each(function(){if(!this.tHead||!this.tBodies)return;var $this,$document,$headers,cache,config,shiftDown=0,sortOrder;this.config={};config=$.extend(this.config,$.tablesorter.defaults,settings);$this=$(this);$.data(this,"tablesorter",config);$headers=buildHeaders(this);this.config.parsers=buildParserCache(this,$headers);cache=buildCache(this);var sortCSS=[config.cssDesc,config.cssAsc];fixColumnWidth(this);$headers.click(function(e){var totalRows=($this[0].tBodies[0]&&$this[0].tBodies[0].rows.length)||0;if(!this.sortDisabled&&totalRows>0){$this.trigger("sortStart");var $cell=$(this);var i=this.column;this.order=this.count++%2;if(this.lockedOrder)this.order=this.lockedOrder;if(!e[config.sortMultiSortKey]){config.sortList=[];if(config.sortForce!=null){var a=config.sortForce;for(var j=0;j<a.length;j++){if(a[j][0]!=i){config.sortList.push(a[j]);}}}config.sortList.push([i,this.order]);}else{if(isValueInArray(i,config.sortList)){for(var j=0;j<config.sortList.length;j++){var s=config.sortList[j],o=config.headerList[s[0]];if(s[0]==i){o.count=s[1];o.count++;s[1]=o.count%2;}}}else{config.sortList.push([i,this.order]);}};setTimeout(function(){setHeadersCss($this[0],$headers,config.sortList,sortCSS);appendToTable($this[0],multisort($this[0],config.sortList,cache));},1);return false;}}).mousedown(function(){if(config.cancelSelection){this.onselectstart=function(){return false};return false;}});$this.bind("update",function(){var me=this;setTimeout(function(){me.config.parsers=buildParserCache(me,$headers);cache=buildCache(me);},1);}).bind("updateCell",function(e,cell){var config=this.config;var pos=[(cell.parentNode.rowIndex-1),cell.cellIndex];cache.normalized[pos[0]][pos[1]]=config.parsers[pos[1]].format(getElementText(config,cell),cell);}).bind("sorton",function(e,list){$(this).trigger("sortStart");config.sortList=list;var sortList=config.sortList;updateHeaderSortCount(this,sortList);setHeadersCss(this,$headers,sortList,sortCSS);appendToTable(this,multisort(this,sortList,cache));}).bind("appendCache",function(){appendToTable(this,cache);}).bind("applyWidgetId",function(e,id){getWidgetById(id).format(this);}).bind("applyWidgets",function(){applyWidget(this);});if($.metadata&&($(this).metadata()&&$(this).metadata().sortlist)){config.sortList=$(this).metadata().sortlist;}if(config.sortList.length>0){$this.trigger("sorton",[config.sortList]);}applyWidget(this);});};this.addParser=function(parser){var l=parsers.length,a=true;for(var i=0;i<l;i++){if(parsers[i].id.toLowerCase()==parser.id.toLowerCase()){a=false;}}if(a){parsers.push(parser);};};this.addWidget=function(widget){widgets.push(widget);};this.formatFloat=function(s){var i=parseFloat(s);return(isNaN(i))?0:i;};this.formatInt=function(s){var i=parseInt(s);return(isNaN(i))?0:i;};this.isDigit=function(s,config){return/^[-+]?\d*$/.test($.trim(s.replace(/[,.']/g,'')));};this.clearTableBody=function(table){if($.browser.msie){function empty(){while(this.firstChild)this.removeChild(this.firstChild);}empty.apply(table.tBodies[0]);}else{table.tBodies[0].innerHTML="";}};}});$.fn.extend({tablesorter:$.tablesorter.construct});var ts=$.tablesorter;ts.addParser({id:"text",is:function(s){return true;},format:function(s){return $.trim(s.toLocaleLowerCase());},type:"text"});ts.addParser({id:"digit",is:function(s,table){var c=table.config;return $.tablesorter.isDigit(s,c);},format:function(s){return $.tablesorter.formatFloat(s);},type:"numeric"});ts.addParser({id:"currency",is:function(s){return/^[?$????.]/.test(s);},format:function(s){return $.tablesorter.formatFloat(s.replace(new RegExp(/[?$???]/g),""));},type:"numeric"});ts.addParser({id:"ipAddress",is:function(s){return/^\d{2,3}[\.]\d{2,3}[\.]\d{2,3}[\.]\d{2,3}$/.test(s);},format:function(s){var a=s.split("."),r="",l=a.length;for(var i=0;i<l;i++){var item=a[i];if(item.length==2){r+="0"+item;}else{r+=item;}}return $.tablesorter.formatFloat(r);},type:"numeric"});ts.addParser({id:"url",is:function(s){return/^(https?|ftp|file):\/\/$/.test(s);},format:function(s){return jQuery.trim(s.replace(new RegExp(/(https?|ftp|file):\/\//),''));},type:"text"});ts.addParser({id:"isoDate",is:function(s){return/^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(s);},format:function(s){return $.tablesorter.formatFloat((s!="")?new Date(s.replace(new RegExp(/-/g),"/")).getTime():"0");},type:"numeric"});ts.addParser({id:"percent",is:function(s){return/\%$/.test($.trim(s));},format:function(s){return $.tablesorter.formatFloat(s.replace(new RegExp(/%/g),""));},type:"numeric"});ts.addParser({id:"usLongDate",is:function(s){return s.match(new RegExp(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/));},format:function(s){return $.tablesorter.formatFloat(new Date(s).getTime());},type:"numeric"});ts.addParser({id:"shortDate",is:function(s){return/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);},format:function(s,table){var c=table.config;s=s.replace(/\-/g,"/");if(c.dateFormat=="us"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$1/$2");}else if(c.dateFormat=="uk"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$2/$1");}else if(c.dateFormat=="dd/mm/yy"||c.dateFormat=="dd-mm-yy"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/,"$1/$2/$3");}return $.tablesorter.formatFloat(new Date(s).getTime());},type:"numeric"});ts.addParser({id:"time",is:function(s){return/^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/.test(s);},format:function(s){return $.tablesorter.formatFloat(new Date("2000/01/01 "+s).getTime());},type:"numeric"});ts.addParser({id:"metadata",is:function(s){return false;},format:function(s,table,cell){var c=table.config,p=(!c.parserMetadataName)?'sortValue':c.parserMetadataName;return $(cell).metadata()[p];},type:"numeric"});ts.addWidget({id:"zebra",format:function(table){if(table.config.debug){var time=new Date();}var $tr,row=-1,odd;$("tr:visible",table.tBodies[0]).each(function(i){$tr=$(this);if(!$tr.hasClass(table.config.cssChildRow))row++;odd=(row%2==0);$tr.removeClass(table.config.widgetZebra.css[odd?0:1]).addClass(table.config.widgetZebra.css[odd?1:0])});if(table.config.debug){$.tablesorter.benchmark("Applying Zebra widget",time);}}});})(jQuery);

/*
 Color animation jQuery-plugin
 http://www.bitstorm.org/jquery/color-animation/
 Copyright 2011 Edwin Martin <edwin@bitstorm.org>
 Released under the MIT and GPL licenses.
*/
(function(d){function i(){var b=d("script:first"),a=b.css("color"),c=false;if(/^rgba/.test(a))c=true;else try{c=a!=b.css("color","rgba(0, 0, 0, 0.5)").css("color");b.css("color",a)}catch(e){}return c}function g(b,a,c){var e="rgb"+(d.support.rgba?"a":"")+"("+parseInt(b[0]+c*(a[0]-b[0]),10)+","+parseInt(b[1]+c*(a[1]-b[1]),10)+","+parseInt(b[2]+c*(a[2]-b[2]),10);if(d.support.rgba)e+=","+(b&&a?parseFloat(b[3]+c*(a[3]-b[3])):1);e+=")";return e}function f(b){var a,c;if(a=/#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/.exec(b))c=
[parseInt(a[1],16),parseInt(a[2],16),parseInt(a[3],16),1];else if(a=/#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])/.exec(b))c=[parseInt(a[1],16)*17,parseInt(a[2],16)*17,parseInt(a[3],16)*17,1];else if(a=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(b))c=[parseInt(a[1]),parseInt(a[2]),parseInt(a[3]),1];else if(a=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9\.]*)\s*\)/.exec(b))c=[parseInt(a[1],10),parseInt(a[2],10),parseInt(a[3],10),parseFloat(a[4])];return c}
d.extend(true,d,{support:{rgba:i()}});var h=["color","backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","outlineColor"];d.each(h,function(b,a){d.fx.step[a]=function(c){if(!c.init){c.a=f(d(c.elem).css(a));c.end=f(c.end);c.init=true}c.elem.style[a]=g(c.a,c.end,c.pos)}});d.fx.step.borderColor=function(b){if(!b.init)b.end=f(b.end);var a=h.slice(2,6);d.each(a,function(c,e){b.init||(b[e]={a:f(d(b.elem).css(e))});b.elem.style[e]=g(b[e].a,b.end,b.pos)});b.init=true}})(jQuery);

var gazeta_pl = gazeta_pl || {};

gazeta_pl.biz = {
  init: function() {
    gazeta_pl.biz.nav.init();
    gazeta_pl.biz.switchbox.init();
    gazeta_pl.biz.gpw_switch.init();
    gazeta_pl.biz.currency_switch.init();
    gazeta_pl.biz.search.init();
    gazeta_pl.biz.article.init();
	gazeta_pl.biz.waluty.init();
	gazeta_pl.biz.gielda.init();

    $('.mod_zr_breaking_news .close_btn').click(function() {
      $('.mod_zr_breaking_news').hide();
      jQuery.cookie('hide_breaking_news', 'hide', { expires: 1/8, path: '/' });
    });
  },

  nav: {
    init: function(){
	  $('#navH li').gazeta(gfunc.nav);
	  $('#navH li.active').next().addClass('after');
	  if($('#navH li.active .p1').length > 0) $('#navH').addClass('lvl2');
	}
  },
  
  article: {
    count: 0,

    init: function() {
      var me = gazeta_pl.biz.article;
      if ($(document.body).attr('id').split(/_/).pop() != 'art') return;
      
      $('#art a.podmiot,#art a.spolka,#art a.waluta').each(function() {
        var el = $(this);
        $('#art').append('<div class="art_hintobj empty"><p class="wait">Proszę czekać</p></div>');
        var hintobj = $('.art_hintobj:last');
        hintobj.hide();
        el.css({ position: 'relative', zIndex: 500-me.count });
        hintobj.css({ zIndex: 499-me.count });
        me.count++;
        el.add(hintobj).hover(
          function() { me.show_hint(el, hintobj); },
          function() { me.hide_hint(el, hintobj); }
        );
      });
    },

    show_hint: function(el, hint) {
      var pos = el.offset();
      var posx = el.offsetParent().eq(0).offset();
      pos.left -= posx.left;
      pos.top -= posx.top;
      hint.css({ left: (pos.left-4)+'px', top: (pos.top+19)+'px' });
      if (hint.hasClass('empty')) {
        hint.removeClass('empty');
        var cln = el.attr('className').replace(/waluta/, '').replace(/spolka/, '').replace(/podmiot/, '');
        var uri = '/aliasy/gospo/';
        if (el.hasClass('waluta')) {
          uri += 'getDaneWaluty.jsp';
        } else {
          uri += 'getDanePodmiotu.jsp';
        }
        var data = 'k='+$.trim(cln)+'&t='+(new Date()).getTime();

        $.ajax({
          url: uri,
          data: data,
          success: function(msg) {
            hint.html(msg);
          }
        });
      }
      el.addClass('hover');
      hint.show();
    },

    hide_hint: function(el, hint) {
      el.removeClass('hover');
      hint.hide();
    }
  },

  gpw_switch: {
    chart: null,
    chart_title: null,

    init: function() {
      var me = gazeta_pl.biz.gpw_switch;
      me.chart = $('#gpw_img');
      me.chart_title = $('#gpw_charter');
      $('.notowania_GPW').each(function() {
         var el = $(this);
         el.find('li').hover(
           function() {
             var param = $(this).find('.param').html().split(/\*/).pop();
             me.set_data(param);
             $(this).addClass('hover');
           },
           function() {
             var param = $(this).find('.param').html().split(/\*/).shift();
             me.set_data(param);
             $(this).removeClass('hover');
           }
         );
      });
    },

    set_data: function(param) {
      var me = gazeta_pl.biz.gpw_switch;
      me.chart.attr('src', '/im/gospodarka/wykresy/'+param+'.gif');
      me.chart_title.html(param);
    }
  },

  currency_switch: {
    init: function() {
      var me = gazeta_pl.biz.currency_switch;
      $('.mod_currency_graph .notowania_waluta').each(function() {
        var elem = $(this);
        elem.find('li:not(.th)').hover(
          function() {
            var param = $(this).find('.param').html().split(/\*/).pop();
            var chart = elem.find('.W_chart');
            me.set_data(chart, param);
            $(this).addClass('hover');
          },
          function() {
            var param = $(this).find('.param').html().split(/\*/).shift();
            var chart = elem.find('.W_chart');
            me.set_data(chart, param);
            $(this).removeClass('hover');
          }
        );
      });
    },

    set_data: function(chart, param) {
      chart.find('img').attr('src', '/im/gospodarka/wykresy/'+param+'.gif');
      chart.find('.W_chart_title').html(param);
    }

  },

  switchbox: {
    tabs: null,
    elems: {},

    init: function() {
      var me = gazeta_pl.biz.switchbox;
      me.tabs = $('#columns_wrap .mod_zr_biz4');
      if (me.tabs.length == 0) return;
      me.tabs.eq(0).find('li.first').removeClass('first');
      me.tabs.find('a').each(function() {
        var name = $(this).attr('hash').replace(/#/, '');
        me.elems[name] = $('#columns_wrap .mod_'+name);
        $(this).click(function(e) {
          e.preventDefault();
          $(this).blur();
          me.switch_tab($(this));
        });
      }).eq(0).click();
    }, 

    switch_tab: function(el) {
      var me = gazeta_pl.biz.switchbox;
      var par = el.parents().filter('li');
      if (par.hasClass('first')) return;
      me.tabs.find('.first').removeClass('first');
      par.addClass('first');
      var name = el.attr('hash').replace(/#/, '');
      for (var i in me.elems) {
        if (name == i) {
          me.elems[i].show();
        } else {
          me.elems[i].hide();
        }
      }
    }
  },

  search: {
    current: 'serwis',

    init: function() {
      var me = gazeta_pl.biz.search;
      var xx = $('#searchH_param_dxx').val();
      var htm = '';
      htm += '<div id="search_top">';
      htm += '  <form id="search_top_serwis" action="http://szukaj.gazeta.pl/paramsCC" method="get">';
      htm += '    <fieldset>';
      htm += '      <div class="query"><input type="text" name="s.sm.query" id="search_top_serwis_q" /></div>';
      htm += '      <div class="dropdown">';
      htm += '        <div></div>';
      htm += '        <ul>';
      htm += '          <li class="serwis">w serwisie</li>';
      htm += '          <li class="spolki">sp\u00f3\u0142ek</li>';
      htm += '          <li class="internet">w internecie</li>';
      htm += '        </ul>';
      htm += '      </div>';
      htm += '      <div class="submit"><input type="submit" value="Szukaj" /></div>';
      htm += '      <input type="hidden" name="s.si(navigation).navigationEnabled" value="true" />';
      htm += '      <input type="hidden" name="search_r" value="serwis" />';
      htm += '      <input type="hidden" name="dxx" value="'+xx+'" />';
      htm += '      <input type="hidden" name="szuk" value="gazeta" />';
      htm += '      <input type="hidden" name="ile" value="10" />';
      htm += '      <input type="hidden" name="q" value="" />';
      htm += '      <input type="hidden" name="url" value="http://szukaj.gazeta.pl/portalSearch.do" />';
      htm += '    </fieldset>';
      htm += '  </form>';
      htm += '  <div class="hidden">';
      htm += '    <form id="search_top_spolki" action="http://gospodarka.gazeta.pl/Gielda/Szukaj" method="get">';
      htm += '      <fieldset>';
      htm += '        <input type="hidden" name="q" value="" id="search_top_spolki_q" />';
      htm += '        <input type="hidden" name="b" value="http://gospodarka.gazeta.pl/Gielda/0,83496,4635305.html" />';
      htm += '      </fieldset>';
      htm += '    </form>';
      htm += '    <form id="search_top_internet" action="http://szukaj.gazeta.pl/internet/0,0.html" method="get">';
      htm += '      <fieldset>';
      htm += '        <input type="hidden" value="" name="slowo" id="search_top_internet_q" />';
      htm += '      </fieldset>';
      htm += '    </form>';
      htm += '  </div>';
      htm += '</div>';

      $('#searchH').replaceWith(htm);

      $('#search_top .dropdown div').click(function() {
		if ($(this).hasClass('toggle')) {
          me.hide_list();
        } else {
          me.show_list();
        }
      });

      $('#search_top .dropdown li').hover(
        function() { $(this).addClass('hover'); },
        function() { $(this).removeClass('hover'); }
      );

      $('#search_top .dropdown li').click(function() {
        $(this).removeClass('hover');
        me.current = $(this).attr('className'); 
        me.hide_list();
      });

      $('#search_top_serwis').submit(function(e) {
        if (me.current == 'serwis') return true;
        e.preventDefault();
        $('#search_top_'+me.current+'_q').val($('#search_top_serwis_q').val());
        $('#search_top_'+me.current).submit();
        return false;
      });
    },

    hide_list: function() {
      $('#search_top .dropdown div').removeClass('toggle'); 
      $('#search_top .dropdown ul').hide();
    },

    show_list: function() {
      $('#search_top .dropdown div').addClass('toggle'); 
      $('#search_top .dropdown ul').show();
    }
  },
  
  waluty: {
    init: function(){
	  gazeta_pl.biz.waluty.datepickers.init();
	  gazeta_pl.biz.waluty.tables.init();
	  gazeta_pl.biz.waluty.forex.init();
	  gazeta_pl.biz.waluty.calendar.init();
	},
	datepickers: {
	  init: function(){
	    var refreshID = null;
		
		function customRange(input) {
          if (input.id == 'tableDateTo') {
            return {
              minDate: $('#tableDateFrom').datepicker("getDate"),
		      maxDate: '0'
            };
	      }
          if (input.id == 'tableDateFrom') {
            return {
              maxDate: ($('#tableDateTo').datepicker("getDate") ?  $('#tableDateTo').datepicker("getDate") : '0')
            };
          }
	      if (input.id == 'arch_to') {
            return {
              minDate: $('#arch_from').datepicker("getDate"),
		      maxDate: '0'
            };
	      }
          if (input.id == 'arch_from') {
            return {
              maxDate: ($('#arch_to').datepicker("getDate") ? $('#arch_to').datepicker("getDate") : '0')
            };
          }
        };
		function submitForm(){
		  $(this).parents('form').eq(0).submit();
		};
		
		function refresh_site(){
		  if($('#table_autorefresh').attr('checked')){
		    refreshID = setTimeout( function(){ 
			  document.location.href = document.location.href;
			}, 60 * 1000);
			$.cookie('refresh_site', 1)
		  }else{
		    if(refreshID){
			  clearTimeout(refreshID);
			  $.cookie('refresh_site', null);
			}
		  }
		}
				
        $( "#tableDate, #exc_day, #tableDateTop, #tableDateBottom" ).datepicker({
	      showOn: "both",
	      buttonImage: "http://bi.gazeta.pl/i/obrazki/wyborcza.biz/calendar-ico.png",
	      buttonImageOnly: true,
	      maxDate: '0',
		  onSelect: submitForm
        });
  
        $('#tableDateFrom, #tableDateTo, #arch_from, #arch_to').datepicker({
          showOn: "both",
	      buttonImage: "http://bi.gazeta.pl/i/obrazki/wyborcza.biz/calendar-ico.png",
	      buttonImageOnly: true,
          beforeShow: customRange,
		  onSelect: submitForm
        });
		$('#tableDuration').change(submitForm);
		
		if($('#table_autorefresh').length > 0){
		  if($.cookie('refresh_site')) $('#table_autorefresh').attr('checked','checked');
		  refresh_site();
		  $('#table_autorefresh').change(refresh_site);
		}
	  }
	},
	tables: {
	  init: function(){
	    $(".mod_waluty_table1 .show a").click(function(e){
          e.preventDefault();
		  var tr = $(this).parents('tr');
		  if(tr.hasClass('open')){
		    $(this).parents('tr').removeClass('open');
			$(this).parents('tr').next().fadeOut();
			$(this).attr('title','Rozwi\u0144');
		  }else{
		    $(this).parents('tr').addClass('open');
            $(this).parents('tr').next().fadeIn();
			$(this).attr('title','Zwi\u0144');
		  }
        });
  
        $(".mod_waluty_table1 .hide").click(function(e){
          e.preventDefault();
        });
  
        $(".mod_waluty_table1 .wykres").click(function(e){
          e.preventDefault();
          var _l = $(this).parent();
		  var period = $(this).attr('data-period');
          if((_l).hasClass('active')){
            return;
          };
          var _ll = _l.siblings();
          var _s = $(this).attr('href');
          _ll.removeClass('active');
          _l.addClass('active');
          $(this).parents('.c0').find('img').attr('src', _s);
		  if(period){
            $.cookie('exchange_active_chart', period, { path: '/' });
          }
        });
		
		$(".mod_waluty_chart .wykres").click(function(e){
          e.preventDefault();
          var _l = $(this).parent();
		  var period = $(this).attr('data-period');
          if((_l).hasClass('active')){
            return;
          };
          var _ll = _l.siblings();
          var _s = $(this).attr('href');
          _ll.removeClass('active');
          _l.addClass('active');
          $(this).parents('.chart').find('img').attr('src', _s);
		  if(period){
            $.cookie('exchange_active_chart', p, { path: '/' });
          }
        });
		
		var fthr = $(".table_forex_ohlc .body table thead tr");
		if(fthr.length > 0){
		  if(fthr.length === 1){
		    $(".table_forex_ohlc .body table").tablesorter({
              textExtraction: function(node){
                return ($(node).text().replace("+",'').replace("%",'').replace(",",'.'));
              },
              headers: { 0: { sorter: false}, 6: {sorter: false} },
              widgets: ['zebra']
            }); 
		  }
		  if(fthr.length === 2){
		    $(".table_forex_ohlc .body table").tablesorter({
              textExtraction: function(node){
                return ($(node).text().replace("+",'').replace("%",'').replace(",",'.'));
              },
              headers: { 0: { sorter: false}, 1: {sorter: false}, 2: {sorter: false} },
              widgets: ['zebra']
            }); 
		  }
		  $('.table_forex_ohlc .body table th.header').append('<small></small>');
		}
	  }
	},
	forex: {
	  init: function(){
	    var _defForexIm = $(".mod_waluty_table_forex_rate .im img").attr('src');
        $(".mod_waluty_table_forex_rate tbody tr").hover(
          function(){
	        $(".mod_waluty_table_forex_rate .im img").attr('src', $(this).attr('data-chart'))
          },function(){
            $(".mod_waluty_table_forex_rate .im img").attr('src', _defForexIm)
        });
	  }
	},
	calendar: {
      year: 0,
      month: 0,
      day: 0,
      city: '',
      names: 'stycze\u0144,luty,marzec,kwiecie\u0144,maj,czerwiec,lipiec,sierpie\u0144,wrzesie\u0144,pa\u017adziernik,listopad,grudzie\u0144'.split(/,/),

      init: function() {
        var cal = gazeta_pl.biz.waluty.calendar;
        if ($('#calendar_select').length == 0) return;
        var htm = '<div class="head"><a href="javascript:void(0)" id="calendar_month_prev">&laquo;</a><span id="calendar_month_name"></span><a href="javascript:void(0)" id="calendar_month_next">&raquo;</a></div><div class="body"><table><thead><tr><th>Pn</th><th>Wt</th><th>¦r</th><th>Czw</th><th>Pt</th><th>Sb</th><th>Ndz</th></tr></thead><tbody></tbody></table></div><div class="overlay"></div>';
        $('#calendar_select').html(htm);

        var uri = document.location.href;
        var d;
        if (d = uri.match(/_data=([0-9]{4})-([0-9]{2})(-([0-9]{2}))?/)) {
          cal.year = parseInt(d[1], 10);
          cal.month = parseInt(d[2], 10);
          cal.day = typeof d[4] == 'undefined' ? 0 : parseInt(d[4], 10);
        };
       
        if (cal.year == 0 || !cal.checkDate()) {
          d = new Date();
          cal.year = d.getFullYear();
          cal.month = d.getMonth() + 1;
          cal.day = d.getDate();
        };

        cal.getData();

        $('#calendar_month_prev').click(function() { cal.changeMonth(-1); });
        $('#calendar_month_next').click(function() { cal.changeMonth(1); });
      },

      changeMonth: function(n) {
        var cal = gazeta_pl.biz.waluty.calendar;
        cal.month += n;
        while (cal.month <= 0) {
          cal.year--;
          cal.month += 12;
        };
        while (cal.month >= 13) {
          cal.month -= 12;
          cal.year++;
        };

        cal.getData();
      },

      checkDate: function() {
        var y = this.year;
        var m = this.month+1;
        var d = this.day == 0 ? 1 : this.day;
    
        if (y < 2000 || y > 2200) return false;
        if (m < 1 || m > 12) return false;
        if (d < 1 || d > 31) return false;
        if (d == 31 && (m != 4 && m != 6 && m != 9 && m != 12)) return false;
        if (d > 29 && m == 2) return false;
        if (d == 29 && m == 2 && !(y % 4 == 0 && (y % 100 != 0 || y % 400 == 0))) return false;
    
        return true;
      },

      getData: function() {
        var cal = gazeta_pl.biz.waluty.calendar;
		
		var d = 'm='+cal.month+'&y='+cal.year+'&typ='+typProduktu;
		if(typeof ogrKolumna != 'undefined' && ogrKolumna != null ) d += '&ogr_kolumna='+ogrKolumna;
		if(typeof ogrWartosc != 'undefined' && ogrWartosc != null ) d += '&ogr_wartosc='+ogrWartosc;
		
        cal.showOverlay();
        $.ajax({
          url: '/Wydarzenia',
          data: d,
          success: function(msg) {
            msg = msg.replace(/,$/, '');
            msg = msg.split(/,/);
            for (var i = 0; i < msg.length; i++) msg[i] = parseInt(msg[i]);
            cal.hideOverlay();
            cal.generate(msg);
          },
          error: function() {
            cal.hideOverlay();
            cal.generate([]);
          }
        });
      },

      showOverlay: function() {
        var cb = $('#calendar_select');
        var ov = cb.find('.overlay');
        var w = cb.width();
        var h = cb.height();
        ov.css({opacity: 0.66, width: w+'px', height: h+'px', display: 'block'});
      },

      hideOverlay: function() {
        $('#calendar_select .overlay').hide();
      },

      generate: function(linkDay) {
        var cal = gazeta_pl.biz.waluty.calendar;
        var d = new Date(cal.year, cal.month-1, 1);

        var firstDay = d.getDay();
        firstDay = firstDay == 0 ? 6 : firstDay - 1;
    
        var rows = [];
        var row = '';
        var cnt = 0;

        while (firstDay > 0) {
          firstDay--;
          row += '<td class="blank">&nbsp;</td>';
          cnt++;
        };

        d.setMonth(d.getMonth() + 1);
        d.setDate(d.getDate() - 1);
        var days = d.getDate();

        for (var i = 1; i <= days; i++) {
          var cl = '';
          if (i == cal.day) cl = ' class="active"';
          var x = linkDay.indexOf(i) == -1 ? '<span>'+i+'</span>' : cal.makeDayLink(i);
          row += '<td'+cl+'>'+x+'</td>';
          cnt++;
          if (cnt == 7) {
            cnt = 0;
            rows.push(row);
            row = '';
          }
        };

        if (cnt != 0) {
          while (cnt++ < 7) row += '<td class="blank">&nbsp;</td>';
          rows.push(row);
        };
    
        rows = '<tr>'+rows.join('</tr><tr>')+'</tr>';
        $('#calendar_select tbody').html(rows);
        $('#calendar_month_name').html(cal.makeMonthLink());
      },

      makeMonthLink: function() {
        var cal = gazeta_pl.biz.waluty.calendar;
        var lz = cal.leadZero;
        return '<a href="?param=_data='+cal.year+'-'+lz(cal.month)+'">'+cal.names[cal.month-1]+' '+cal.year+'</a>';
      },
  
      makeDayLink: function(n) {
        var cal = gazeta_pl.biz.waluty.calendar;
        var lz = cal.leadZero;
        return '<a href="?param=_data='+cal.year+'-'+lz(cal.month)+'-'+lz(n)+'">'+n+'</a>';
      },

      leadZero: function(n) {
        return n < 10 ? '0'+n : n;
      }
    }
  },
  
  gielda : {
    init: function(){
      gazeta_pl.biz.gielda.markets.init();  
      gazeta_pl.biz.gielda.flashChart.init();
      gazeta_pl.biz.gielda.controls.init();  
      gazeta_pl.biz.gielda.staticChart.init();
      gazeta_pl.biz.gielda.biz_table.init();
      gazeta_pl.biz.gielda.catalog.init();
      gazeta_pl.biz.gielda.pie_chart.init();
      gazeta_pl.biz.gielda.walor_search.init();
      //gazeta_pl.biz.gielda.compare_search.init();
    },
    
    markets: {
      timeoutId : null,
      root: null,
      
      init: function() {
        var me = gazeta_pl.biz.gielda.markets;

        me.root = $('.mod_markets.with_charts');
        if (!me.root.length) return;

        me.root.find('tbody tr:not(.chart)').hover(		
          function() {
            var el = $(this);

            clearTimeout(me.timeoutId);
            me.timeoutId = setTimeout(function(){ me.onTimeout(el); }, 500);
          },
          function() {
            clearTimeout(me.timeoutId);
          }
        );
      },
      
      onTimeout: function(el) {
        var 
            me = gazeta_pl.biz.gielda.markets,
            old_row = null,
            old_chart = null,
            new_chart = null,
            h = 0;

        if (me.root.data('animating') || el.next().hasClass('active')) return;

        me.root.data('animating', true);
        old_row = me.root.find('.active');
        old_chart = old_row.find('.im');
        new_chart = el.next().find('.im');
        h = old_chart.height();

        old_chart.animate(
          { 'height': 0 },
          { duration: 500, 
            step: function(now, fx){ 
              new_chart.css({ 'height' : h - now });
            },
            complete: function(){ 
              old_row.removeClass('active');
              el.next().addClass('active');
              old_chart.removeAttr('style');
              new_chart.removeAttr('style');
              me.root.removeData('animating');
            }
          }
        );
      }
    },
    
    controls: {
      AUTO_REFRESH_INTERVAL : 60000,

      autoRefresh: {
        timeoutId: null,
        enabled: false,
        onChange: function(e){
          var me = gazeta_pl.biz.gielda.controls.autoRefresh;

          if ($(this).attr('checked')) {
            me.enabled = true;
            $.cookie('refresh_site', 1);

            if ($(this).attr('data-servlet')){
              gazeta_pl.biz.gielda.biz_table.updater.getUpdateData(); 
            } else if ($('#biz_flash_chart').length) {
              gazeta_pl.biz.gielda.flashChart.update();
            } else {
              me.timeoutId = setTimeout(function(){ document.location.href = document.location.href }, gazeta_pl.biz.gielda.controls.AUTO_REFRESH_INTERVAL);
            }
          } else {
            me.enabled = false;
            $.cookie('refresh_site', null);
            clearTimeout(me.timeoutId);
          }
        }
      },

      init: function(){
        var me = gazeta_pl.biz.gielda.controls;

        /* tools */
        $('.mod_biz .node_head .tools .save').click(function(){
          $(this).parent().toggleClass('open');
          return false;
        });

        /* datepickers */
        function customRange(input) {
          if (input.id == 'controlDateTo') {
            return {
              minDate: $('#controlDateFrom').datepicker("getDate"),
              maxDate: '0'
            };
          }

          if (input.id == 'controlDateFrom') {
            return {
              maxDate: ($('#controlDateTo').datepicker("getDate") ?  $('#controlDateTo').datepicker("getDate") : '0')
            };
          }
        };

        function submitForm(){
          $(this).parents('form').eq(0).submit();
        };

        $('#controlDateFrom, #controlDateTo').datepicker({
          showOn: "both",
          buttonImage: "http://bi.gazeta.pl/i/obrazki/wyborcza.biz/calendar-ico.png",
          buttonImageOnly: true,
          beforeShow: customRange,
          onSelect: submitForm
        });

        $( "#controlDateTop, #controlDateBottom" ).datepicker({
          showOn: "both",
          buttonImage: "http://bi.gazeta.pl/i/obrazki/wyborcza.biz/calendar-ico.png",
          buttonImageOnly: true,
          maxDate: '0',
          onSelect: submitForm
        });

        /* notowania */
        $('#controlIndex').change(function() {
          document.location.href = $(this).val();
        });

        /* espi */
        if (gazeta_pl.espiControlsServletUri) {
          $('#controlIndexes').change(function() {
            var index = $(this).val();
           
            $.ajax({
              url: gazeta_pl.espiControlsServletUri,
              data: { 'index' : index },
              dataType: 'json',
              success: function(data) {
                var
                    l = 0,
                    htm = '',
                    i = 0;

                if (data && (l = data.length)) {
                  htm += '<option value="">wszystkie sp\u00f3\u0142ki</option>';
                  for (i = 0; i < l; i++) {
                    htm += '<option value="'+data[i].ticker+'">'+data[i].name+'</option>';
                  }		  
                  $('#controlCompanies').html(htm);
                }
              }
            });
          });
        }

        /* refresh */
        $('.mod_biz .manual_refresh').click(function() {
          document.location.href = document.location.href;
          return false;
        });

        /* autorefresh */
        $('#auto_refresh').change(me.autoRefresh.onChange);
        if ($.cookie('refresh_site')) $('#auto_refresh').attr('checked','checked');
        $('#auto_refresh').change();
      }
    },
    flashChart: {
      flash: null,

      init: function() {
        window.amChartInited = function(chart_id) {
          gazeta_pl.biz.gielda.flashChart.flash = document.getElementById('biz_flash_chart');
        }
      },
      
      update: function() {
        if (!gazeta_pl.biz.gielda.controls.autoRefresh.enabled) return;
        if (gazeta_pl.biz.gielda.flashChart.flash) {
          gazeta_pl.biz.gielda.flashChart.flash.reloadData();
        }

        gazeta_pl.biz.gielda.controls.autoRefresh.timeoutId = setTimeout( function() {
          gazeta_pl.biz.gielda.flashChart.update();
        }, gazeta_pl.biz.gielda.controls.AUTO_REFRESH_INTERVAL);
      }
    },
    
    staticChart: {
      init: function() {
        $(".static_chart .plot").live('click',(function(e){
          var 
              li = $(this).parent(),
              lis = li.siblings(),
              period = $(this).attr('data-period'),
              src = $(this).attr('href');

          if (li.hasClass('active')) {
            return false;
          };

          lis.removeClass('active');
          li.addClass('active');
          $(this).parents('.static_chart').find('img').attr('src', src);
          if (period) {
            $.cookie('exchange_active_chart', period, { path: '/' });
          }

          return false;
        }));

      }
    },

    biz_table: {
      init: function(){
        /* rozwijanie */
        $(".mod_biz .show a").live('click',function(e) {
          var 
              servlet = $(this).parents('.biz_table').attr('data-rows-servlet'),
              tr = $(this).parents('tr'),
              id = tr.attr('id').replace('tr_','');
              me = $(this);

          e.preventDefault();

          if (tr.hasClass('open')) {
              tr.removeClass('open').addClass('working');
              me.attr('title','Rozwi\u0144');
              setTimeout(function() { tr.removeClass('working').next('.data').remove(); }, 1200);
          } else {
            if ( tr.hasClass('working') ) return;
            tr.addClass('working');
            $.ajax({
              url: ''+servlet+id,
              success: function(data) {
                gazeta_pl.biz.gielda.biz_table.showDataRow(id, data);
              },
              error: function(e) {  }
            });
          }
        });
      },

      showDataRow: function(id, data) {
        var tr = $('#tr_'+id), img = new Image();

        tr.after(data);     
        img.onload = function() {
            tr.addClass('open').removeClass('working').find('.show a').attr('title','Zwi\u0144');
        };
        img.src = tr.next().find('.active .plot').attr('href');
      },

      updater: {
        SERVLET_URI: '/fix/exchange/tables/ajax.jsp',
        ready: false,

        init: function() {
          var me = gazeta_pl.biz.gielda.biz_table.updater;

          me.SERVLET_URI = $('#auto_refresh').attr('data-servlet') || me.SERVLET_URI;
          me.SERVLET_URI = me.SERVLET_URI.replace(/&amp;/g, '&');
          
          me.ready = true;
        },
        
        checkChar: function( value ) {
          var val = parseFloat(value.replace(',','.'), 10);
          if (val > 0) return 'plus';
          if (val < 0) return 'minus';
          return 'nochange';
          //if (value.match(/^\s*\+/)) return 'plus';
          //if (value.match(/^\s*\-/)) return 'minus';
          //return 'nochange';
        },
        
        getUpdateData: function() {
          var me = gazeta_pl.biz.gielda.biz_table.updater;
         
          if (!me.ready) me.init();
          if (!gazeta_pl.biz.gielda.controls.autoRefresh.enabled) return;

          gazeta_pl.jsonp(me.SERVLET_URI, {}, 'gazeta_pl.biz.gielda.biz_table.updater.updateData');
        },
        
        updateData: function(data) {
          var me = gazeta_pl.biz.gielda.biz_table.updater;
          
          if (data.data.length == 0) {
            return;
          }
          me.updateDataPortion(data.data, 0);
        },
        
        updateDataPortion: function(data, index) {
          
          var 
              me = gazeta_pl.biz.gielda.biz_table.updater,
              i = index,
              j = 20,
              l = data.length,
              item = null,
              $tr = null,
              odd_color = '#ffffff',
              even_color = '#f9f9fb',
              highlight_color = '#faf6e2';

          while (j > 0 && i < l) {
            item = data[i];
            $tr = $('#tr_' + item.id);
            $tr.find(".open").html(item.value.open);
            $tr.find(".max").html(item.value.max);
            $tr.find(".min").html(item.value.min);
            $tr.find(".exchange").html(item.value.exchange);
            if (item.value.change) $tr.find(".change").html('<span class="' + me.checkChar(item.value.change) + '">' + item.value.change + '</span>');
            if (item.value.changeProportional) $tr.find(".changeProportional").html('<span class="' + me.checkChar(item.value.changeProportional) + '">' + item.value.changeProportional + '</span>');
            $tr.find(".volume").html(item.value.volume);
            $tr.find(".updated").html(item.value.updated);
            
            $tr.find(".bidExchange").html(item.value.bidExchange);
            if (item.value.bidChangeProcent) $tr.find(".bidChangeProcent").html('<span class="' + me.checkChar(item.value.bidChangeProcent) + '">' + item.value.bidChangeProcent + '</span>');
            if (item.value.bidChange) $tr.find(".bidChange").html('<span class="' + me.checkChar(item.value.bidChange) + '">' + item.value.bidChange + '</span>');
            $tr.find(".askExchange").html(item.value.askExchange);
            if (item.value.askChangeProcent) $tr.find(".askChangeProcent").html('<span class="' + me.checkChar(item.value.askChangeProcent) + '">' + item.value.askChangeProcent + '</span>');
            if (item.value.askChange) $tr.find(".askChange").html('<span class="' + me.checkChar(item.value.askChange) + '">' + item.value.askChange + '</span>');
            
            j--;
            i++;
            $tr.find('td').animate(
                { 
                    backgroundColor: highlight_color 
                }, 
                {
                    complete: function() {
                        var color = $tr.hasClass('even') ? even_color : odd_color;
                        $(this).animate({ backgroundColor: color }, { duration: 1500 });
                    }
                }
            );
          }
          
          if (j == 0) {
            setTimeout(function() {
              me.updateDataPortion( data, i );
            }, 10);
          }
          
          if (i == l) {
            gazeta_pl.biz.gielda.controls.autoRefresh.timeoutId = setTimeout( function() {
              me.getUpdateData();
            }, gazeta_pl.biz.gielda.controls.AUTO_REFRESH_INTERVAL);
          }
        }
      }
    },

    pie_chart : {
      init: function() {
        var
            k_ctr = $('#share_chart'),
            g_ctr = $('#votes_chart'),
            data_tr = $('.mod_shareholders table').eq(0).find('tbody tr:not(.summary)'),
            k_canvas = document.createElement('canvas'),
            g_canvas = document.createElement('canvas'),
            canvas_width = 220,
            canvas_height = 220,
            k_options = {},
            g_options = {};

        if (!$('.mod_shareholders').length) return;

        k_options.data = [];
        g_options.data = [];
        
        k_ctr[0].appendChild(k_canvas); 
        g_ctr[0].appendChild(g_canvas); 
        
        if (typeof G_vmlCanvasManager != 'undefined') {
          k_canvas = G_vmlCanvasManager.initElement(k_canvas); 
          g_canvas = G_vmlCanvasManager.initElement(g_canvas); 
        } 
        
        k_canvas.setAttribute("width", canvas_width);
        k_canvas.setAttribute("height", canvas_height);
        g_canvas.setAttribute("width", canvas_width);
        g_canvas.setAttribute("height", canvas_height);

        data_tr.each(function() {
          var
              name = $(this).find('.name span').text(),
              k_data = parseFloat($(this).find('.share_procent span').text().replace(/,/,".")),
              g_data = parseFloat($(this).find('.vote_procent span').text().replace(/,/,"."));
              
          k_options.data.push({ name: name, value: k_data, related: $(this) });
          g_options.data.push({ name: name, value: g_data, related: $(this) });
        });

        gazeta_pl.biz.gielda.pie_chart.draw(k_canvas, k_options);
        gazeta_pl.biz.gielda.pie_chart.draw(g_canvas, g_options);
      },

      draw: function(elem, options) {
        var 
            COLORS = options.colors || ['#dceaf5','#bcd0df','#487393','#244964','#143954'],
            HOVER_COLOR = options.hover_color || '#faf6e2',
            INNER_COLOR = options.inner_color || '#ffffff',
            LABEL_FONT = options.label_font || "bold 14px Arial, sans-serif",
            LABEL_COLOR = options.label_color || "#ffffff",
            LABEL_HOVER_COLOR = options.label_hover_color || "#000000",
            INNER_RADIUS = options.inner_radius || 45,
            START_ANGLE = options.start_range || -0.5 * Math.PI,
            
            ctx = elem.getContext('2d'),
            canvas_size = [elem.width, elem.height],
            radius = Math.min(canvas_size[0], canvas_size[1])/2,
            center = [canvas_size[0]/2, canvas_size[1]/2],
            hovered = -1,
            lastHovered = 0,
            total = 0,
            current = 0,
            dataLength = options.data.length,
            $tooltip = null;

        function drawChart() {
          var 
               startAngle = 0,
               endAngle = 0,
               midAngle = 0;
               
          ctx.clearRect(0, 0, canvas_size[0], canvas_size[1]);
          
          for (var i = 0; i < dataLength; i++) {
            startAngle = options.data[i]['startAngle'] + START_ANGLE;
            endAngle = options.data[i]['endAngle'] + START_ANGLE;
            midAngle = (startAngle + endAngle) / 2;

            ctx.beginPath();
            ctx.moveTo(center[0], center[1]); 
            ctx.arc(center[0], center[1], radius, startAngle, endAngle, false);
            ctx.lineTo(center[0], center[1]); 
            ctx.closePath();
            ctx.fillStyle = (i == hovered ? HOVER_COLOR : COLORS[i%COLORS.length]);    
            ctx.fill();
          }
          
          for (var i = 0; i < dataLength; i++) {
            startAngle = options.data[i]['startAngle'] + START_ANGLE;
            endAngle = options.data[i]['endAngle'] + START_ANGLE;
            midAngle = (startAngle + endAngle) / 2;

            ctx.fillStyle = (i == hovered ? LABEL_HOVER_COLOR : LABEL_COLOR);
            ctx.textAlign = "center";
            ctx.font = LABEL_FONT;
            ctx.fillText((100*options.data[i].value/total).toFixed(2) + '%', center[0] + Math.cos(midAngle) * ( 0.7 * radius ), center[1] + Math.sin(midAngle) * ( 0.7 * radius ));
          }
          
          ctx.beginPath();
          ctx.moveTo(center[0], center[1]); 
          ctx.arc(center[0], center[1], INNER_RADIUS, 0, Math.PI * 2, false);
          ctx.closePath();
          ctx.fillStyle = INNER_COLOR;
          ctx.fill();
        };
            
        if ($('#pie_chart_tooltip').length < 1) {
          $('body').append('<div id="pie_chart_tooltip"></div>');
        }
        $tooltip = $('#pie_chart_tooltip');

        for (var i = 0; i < dataLength; i++) {
          total += options.data[i].value;
          if (options.data[i].related) {
            (function(i) {
              $(options.data[i].related).hover(
                function() {
                  options.data[i].related.addClass('hovered');
                  hovered = i;
                  drawChart();
                },
                function() {
                  options.data[i].related.removeClass('hovered');
                  hovered = -1;
                  drawChart();
                }
              );
            })(i);
          }
        }

        for (var i = 0; i < dataLength; i++) {
          options.data[i]['startAngle'] = 2 * Math.PI * current;
          options.data[i]['endAngle'] = 2 * Math.PI * (current + (options.data[i].value / total));
          current += options.data[i].value / total;
        }

        $(elem).mousemove(function(e){
          var 
              mouseX = e.pageX,
              mouseY = e.pageY,
              offset = $(elem).offset(),
              relX = mouseX - offset.left,
              relY = mouseY - offset.top,
              xFromCentre = relX - center[0],
              yFromCentre = relY - center[1],
              distanceFromCentre = Math.sqrt( Math.pow( Math.abs( xFromCentre ), 2 ) + Math.pow( Math.abs( yFromCentre ), 2 ) ),
              clickAngle = 0;

          if (distanceFromCentre <= radius && distanceFromCentre > INNER_RADIUS) {
            clickAngle = Math.atan2( yFromCentre, xFromCentre ) - START_ANGLE;
            if (clickAngle < 0) clickAngle = 2 * Math.PI + clickAngle;
            
            for (var i = 0; i < dataLength; i++) {
              if (clickAngle >= options.data[i]['startAngle'] && clickAngle <= options.data[i]['endAngle']) {
                hovered = i;
                $tooltip.text(options.data[i].name);
                $tooltip.css({ left: mouseX - $tooltip.width()/2, top: mouseY - $tooltip.height() - 10 });
                $tooltip.css({ visibility: "visible" });
                if ($(options.data[i].related)) {
                  if (options.data[lastHovered].related) $(options.data[lastHovered].related).trigger('mouseout');
                  $(options.data[i].related).trigger('mouseover');
                  lastHovered = i;
                }
              }
            }
          } else {
            hovered = -1;
            $tooltip.css({ visibility: "hidden" });
            if (options.data[lastHovered].related) $(options.data[lastHovered].related).trigger('mouseout');
          }
          drawChart();
        });

        $(elem).mouseleave(function(e){
          hovered = -1;
          $tooltip.css({ visibility: "hidden" });
          if (options.data[lastHovered].related) $(options.data[lastHovered].related).trigger('mouseout');
          drawChart();
        });

        drawChart();
      }
    },

    catalog: {
      SPEED: 1,

      root: null,
      nav: null,
      list: null,
      elems: null,
      leftArrow: null,
      rightArrow: null,
      active: null,
      animateFlag: false,
      maxMargin: 0,

      init: function() {
        var me = gazeta_pl.biz.gielda.catalog;

        function move(dir) {
          var m = me.list.css('marginLeft'),
          l = parseInt(m,10) + (dir * me.SPEED);

          if (l > 0) l = 0;
          if (l < me.maxMargin) l = me.maxMargin;

          me.list.css('marginLeft', l);
          if (me.animateFlag) {
            setTimeout(function(){ move(dir) }, 1);
          }
        }

        me.root = $('.mod_company_catalog .index_filter');
        if (!me.root.length) return;

        me.nav = me.root.find('.nav');
        me.leftArrow = me.nav.find('.left');
        me.rightArrow = me.nav.find('.right');
        me.list = me.root.find('ul');
        me.elems = me.list.find('li');
        me.active = me.elems.find('span').parent();

        if (me.elems.index(me.active) > 0) {
          me.list.animate({ 'marginLeft': me.list.offset().left - me.active.offset().left + parseInt(me.active.css('marginLeft'), 10) }, 500);
        }
        me.maxMargin = me.list.offset().left - me.elems.last().offset().left + parseInt(me.elems.last().css('marginLeft'), 10);

        me.leftArrow.mousedown(function(){
          me.animateFlag = true;
          move(1);
        });

        me.rightArrow.mousedown(function(){
          me.animateFlag = true;
          move(-1);
        });

        me.rightArrow.mouseup(function(){
          me.animateFlag = false;
        });

        me.leftArrow.mouseup(function(){
          me.animateFlag = false;
        });
      }
    },

    walor_search: {
      $input: null,
      $root: null,
      $hints: null,
      servlet_uri: '/exchangeSearch.servlet',
      focused: false,
      cache: {},
      pos: -1,
      max: 0,
      last: '',
      working: false,
      categories: '',
      init: function() {
        var me = gazeta_pl.biz.gielda.walor_search;

        me.$root = $('#biz_walor_search');
        if (!me.$root.length) return;

        me.$input = me.$root.find('input[type="text"]');
        me.categories = $.trim(me.$root.find('input[name="categories"]').val());
        me.$hints = $('#biz_walor_search_hints').hide();

        if (!me.placeholder.support()) me.placeholder.make(me.$input);
        if (parseInt(me.$root.attr('data-max-hints'), 10) > 0) me.max = parseInt(me.$root.attr('data-max-hints'), 10);

        me.$input.focus(function(){ me.focused = true; });
        me.$input.blur(function(){ me.focused = false; setTimeout(function(){ me.$hints.hide(); }, 500); });
        me.$input.keydown(me.moveHint);

        me.$hints.find('li').live('mouseover', function(e) {
          me.pos = me.$hints.find('li').index($(this));
          me.$hints.find('li').removeClass('sel').eq(me.pos).addClass('sel');
        });

        me.$hints.find('a').live('click', function() {
          me.$input.val($(this).find('.c0').text());
        });

        me.$root.find('form').submit(function() {          
          var
              $li = me.$hints.find('li'),
              pos = 0;

          if (me.pos > -1) pos = me.pos;
          if ($li.length) {
            me.$input.val($li.eq(pos).find('.c0').text());
            document.location.href = $li.eq(pos).find('a').attr('href');
            me.$hints.hide();
          }

          return false;
        });

        setInterval(me.checkQuery, 10);
      },

      placeholder: {
        support: function() {
          var i = document.createElement('input');
          return 'placeholder' in i;
        },
        
        make: function($target) {
          if (!$.trim($target.val())) $target.val($target.attr('placeholder')).addClass('placeholder');

          $target.focus(function() {
            if ($target.val() == $target.attr('placeholder')) $target.val('').removeClass('placeholder');
          });

          $target.blur(function() {
            if (!$.trim($target.val())) $target.val($target.attr('placeholder')).addClass('placeholder');
          });
        }
      },

      checkQuery: function(e) {
        var 
            me = gazeta_pl.biz.gielda.walor_search,
            query = $.trim(me.$input.val());

        if (!me.focused) return;
        
        if (query == '') {
          me.$hints.hide();
          me.pos = -1;
          return;
        };
        
        if (query != me.last && !me.working) {
          me.last = query;
          if (me.cache[query]) {
            me.showHints(query, me.cache[query]);
          } else {
            $.ajax({
              url: me.servlet_uri,
              data: { 'query' : encodeURIComponent(query), 'categories' : me.categories },
              dataType: 'json',
              success: function(data) {
                me.cache[query] = data;
                me.showHints(query, me.cache[query]);
              }
            });
          }
        }
      },

      showHints: function(query, data) {
        var 
            me = gazeta_pl.biz.gielda.walor_search,
            i = 1,
            l = 0,
            html = '',
            p = new RegExp('('+query+')',"gi");

        if (!data || !data.data || !data.data.length || data.data.length - i == 0) {
          me.$hints.hide();
          me.pos = -1;
          return;
        };
        
        if (me.max) {
          l = (data.data.length > me.max + 1) ? me.max + 1 : data.data.length;
        } else {
          l = data.data.length;
        };

        for (;i < l;i++) {
          html += '<li><a href="'+data.data[i].instrument.url+'"><span class="c0">'+data.data[i].instrument.fullName.replace(p,'<strong>$1</strong>')+'</span><span class="c1">'+data.data[i].instrument.name.replace(p,'<strong>$1</strong>')+'</span><span class="c2">'+data.data[i].instrument.category+'</span></a></li>';
        }

        me.pos = -1;
        me.$hints.html(html).show();
      },

      moveHint: function(e) {
        var 
            me = gazeta_pl.biz.gielda.walor_search,
            $li = me.$hints.find('li'),
            l = $li.length;

        if (!l || !$('#biz_walor_search_hints:visible').length) return;

        switch (e.keyCode) {
          case 38: 
            me.pos -= 1;
            if (me.pos < 0) me.pos = l - 1;
            $li.removeClass('sel').eq(me.pos).addClass('sel');
            break;
          case 40: 
            me.pos += 1;
            if (me.pos > l - 1) me.pos = 0;
            $li.removeClass('sel').eq(me.pos).addClass('sel');
            break;
          case 13:
            me.$hints.hide();
            break;
        }
      }
    },
    
    compare_search: {
      $input: null,
      $root: null,
      $hints: null,
      servlet_uri: '/exchangeSearch.servlet',
      focused: false,
      cache: {},
      pos: -1,
      max: 0,
      last: '',
      working: false,
      categories: 'EXCHANGE CURRENCIES',
      wordCount: 0,
      wordIndex: 0,
      maxWords: 6,
      init: function() {
        var me = gazeta_pl.biz.gielda.compare_search;
        
        me.$root = $('#biz_walor_search_chart');
        if (!me.$root.length) return;

        me.$input = me.$root.find('input[type="text"]');
        me.$hints = $('#biz_walor_search_chart_hints').hide().css({ left: me.$input.offset().left - me.$root.offset().left });
        
        if (!me.placeholder.support()) me.placeholder.make(me.$input);
        if (parseInt(me.$root.attr('data-max-hints'), 10) > 0) me.max = parseInt(me.$root.attr('data-max-hints'), 10);

        me.$input.focus(function(){ me.focused = true; });
        me.$input.blur(function(){ me.focused = false; setTimeout(function(){ me.$hints.hide(); }, 500); });
        me.$input.keydown(me.moveHint);
        me.$input.keyup(me.checkQuery);

        me.$hints.find('li').live('mouseover', function(e) {
          me.pos = me.$hints.find('li').index($(this));
          me.$hints.find('li').removeClass('sel').eq(me.pos).addClass('sel');
        });

        me.$hints.find('li').live('click', me.setWord);

        me.$root.find('form').submit(function() {          
          var
              $li = me.$hints.find('li'),
              pos = 0;

          if (me.pos > -1) pos = me.pos;
          $li.eq(pos).trigger('click');

          return false;
        });
      },

      placeholder: {
        support: function() {
          var i = document.createElement('input');
          return 'placeholder' in i;
        },
        
        make: function($target) {
          if (!$.trim($target.val())) $target.val($target.attr('placeholder')).addClass('placeholder');

          $target.focus(function() {
            if ($target.val() == $target.attr('placeholder')) $target.val('').removeClass('placeholder');
          });

          $target.blur(function() {
            if (!$.trim($target.val())) $target.val($target.attr('placeholder')).addClass('placeholder');
          });
        }
      },

      checkQuery: function(e) {
        var 
            me = gazeta_pl.biz.gielda.compare_search,
            query = $.trim(me.$input.val()),
            word = '';

        if (!me.focused) return;
        
        word = me.extractWord(query, me.getSelectionStart(me.$input.get(0)));
        query = $.trim(word);
        
        if (word == '') {
          me.$hints.hide();
          me.pos = -1;
          return;
        };
        
        if (word != me.last && !me.working) {
          me.last = word;
          if (me.cache[word]) {
            me.showHints(word, me.cache[word]);
          } else {
            $.ajax({
              url: me.servlet_uri,
              data: { 'query' : encodeURIComponent(word), 'categories' : me.categories },
              dataType: 'json',
              success: function(data) {
                me.cache[word] = data;
                me.showHints(word, me.cache[word]);
              }
            });
          }
        }
      },

      showHints: function(query, data) {
        var 
            me = gazeta_pl.biz.gielda.compare_search,
            i = 1,
            l = 0,
            html = '',
            p = new RegExp('('+query+')',"gi");

        if (!data || !data.data || !data.data.length || data.data.length - i == 0) {
          me.$hints.hide();
          me.pos = -1;
          return;
        };
        
        if (me.max) {
          l = (data.data.length > me.max + 1) ? me.max + 1 : data.data.length;
        } else {
          l = data.data.length;
        };

        for (;i < l;i++) {
          html += '<li><span class="c0">'+data.data[i].instrument.fullName.replace(p,'<strong>$1</strong>')+'</span><span class="c1">'+data.data[i].instrument.name.replace(p,'<strong>$1</strong>')+'</span><span class="c2">'+data.data[i].instrument.category+'</span></li>';
        }

        me.pos = -1;
        me.$hints.html(html).show();
      },

      moveHint: function(e) {
        var 
            me = gazeta_pl.biz.gielda.compare_search,
            $li = me.$hints.find('li'),
            l = $li.length;
        
        if (e.keyCode == 188) {
          return false;
        }
        
        if (!l || !$('#biz_walor_search_chart_hints:visible').length) return;
        
        switch (e.keyCode) {
          case 38: 
            me.pos -= 1;
            if (me.pos < 0) me.pos = l - 1;
            $li.removeClass('sel').eq(me.pos).addClass('sel');
            break;
          case 40: 
            me.pos += 1;
            if (me.pos > l - 1) me.pos = 0;
            $li.removeClass('sel').eq(me.pos).addClass('sel');
            break;
          case 13:
            me.$hints.hide();
            break;
        }
      },
      
      setWord: function () {
        var 
            me = gazeta_pl.biz.gielda.compare_search,
            word = $(this).find('.c1').text(),
            list = [],
            p = 0;
        
        if (word) {
            list = me.$input.val().split(/,/);
            list[me.wordIndex] = word;
            me.wordCount = list.length;
            me.$input.val(list.join(','));
            me.$input.focus();
            p = me.endOfWord();
            if (me.wordCount < me.maxWords) {
                me.$input.val(me.$input.val()+',');
                p++;
            }
            me.setSelectionRange(me.$input.get(0), p, p); 
            me.$hints.hide();
        }
      },
      
      extractWord: function (v, p) {
        var 
            me = gazeta_pl.biz.gielda.compare_search,
            i = 0,
            w = '',
            c = '',
            m = false,
            l = v.length;
        
        me.wordIndex = 0;
        if (l == 0) return '';
        
        for (; i < l; i++) {   
            if (p == i) m = true;
            c = v[i];
            if (c == ',') {
                if (m) return w;
                me.wordIndex++;
                w = '';
            } else {
                w += c;
            }
        };
        
        return w;
      },

      endOfWord: function () {
        var 
            me = gazeta_pl.biz.gielda.compare_search,
            i = 0,
            wc = 0,
            m = me.wordIndex == 0,
            c = '',
            v = me.$input.val(),
            l = v.length;
            
        for (; i < l; i++) {
            c = v[i];
            if (c == ',') {
                if (m) return i;
                wc++;
                if (wc == me.wordIndex) m = true;
            }
        };
        
        return i;
      },

      getSelectionStart: function (o) {
        var r = null;
        
        if (o.createTextRange) {
            r = document.selection.createRange().duplicate();
            r.moveEnd('character', o.value.length);
            if (r.text == '') return o.value.length;
            return o.value.lastIndexOf(r.text);
        } else return o.selectionStart;
      },
      
      setSelectionRange: function (input, selectionStart, selectionEnd) {
        var range = null;
        
        if (input.createTextRange) {
            range = input.createTextRange();
            range.collapse(true);
            range.moveEnd('character', selectionEnd);
            range.moveStart('character', selectionStart);
            range.select();
        } else if (input.setSelectionRange) {
            input.focus();
            input.setSelectionRange(selectionStart, selectionEnd);
        }
      }
    }
  }	
};

var g_offers = {
  MAX_ELEMS: 6,
  ELEM_SIZE: 155,
  o_box: null,
  o_list: null,
  o_list_elem: null,
  o_left: null,
  o_right: null,
  o_left_s: null,
  o_right_s: null,
  position: 0,
  count: 0,
  init: function() {
    var me = g_offers;
    me.o_box = $('#mod_offer');
    if (me.o_box.length == 0) return;
    me.o_list = me.o_box.find('.list_holder ul');
    me.o_list_elem = me.o_list.find('li');
    me.count = me.o_list_elem.length;
    if (me.count > me.MAX_ELEMS) {
      me.o_list.parent().before('<span id="mod_offer_scroll_left"><span></span></span>');
      me.o_list.parent().after('<span id="mod_offer_scroll_right" class="active"><span class="active"></span></span>');
      $('#mod_offer').gazeta(gfunc.gslider, {
        selectors: {
          bodyOuter: '.list_holder',
          bodyInner: '.list_holder ul',
          bodyElems: '.list_holder li',
          buttonPrev: '#mod_offer_scroll_left',
          buttonNext: '#mod_offer_scroll_right'
        },
        fold: false,
        el_slide_time: 250
      });
    }
  }
};

var g_small_offers = {
  init: function() {
    var t = 0;
    var mod = $('#mod_offer_small');
    var pos = $('#mod_offer_small .list_holder > ul > li').index($('#mod_offer_small .permanent'));
    if (mod.length == 0) return;
    if ($.cookie('hp_small_offers_roll')) {
      t = 1 + parseInt($.cookie('hp_small_offers_roll'));
      var mod_ul = mod.find('.list_holder > ul');
      var mod_li = mod_ul.find('> li');
      if (t >= mod_li.length || t < 0) t = 0;
      var nt = t;
      while (nt-- > 0) mod_ul.append(mod_ul.find('> li:first'));
      mod_ul.find('> li.first').removeClass('first');
      mod_ul.find('> li:first').addClass('first');
    };
    $('#mod_offer_small .list_holder > ul > li').eq(pos).before($('#mod_offer_small .permanent'));
    $.cookie('hp_small_offers_roll', t, { expires: 1 });
    mod.css({ visibility: 'visible' });
  }
};

$(document).ready(function() {
  gazeta_pl.biz.init();
  g_offers.init();
  g_small_offers.init();
  window.setInterval(testDWF, 100);
  sietPCh.init();
  
  /* ukrycie pustych wierszy */
  $('#col_left .content_row').each(function() {
	if ($(this).gazeta(gfunc.emptyChild, '.holder_cl')) $(this).hide();
  });
  $('#holder_402, #holder_403').each(function() {
	if ($(this).gazeta(gfunc.emptyChild, '.wrap')) $(this).hide();
  });
  if ($('#bottom_wrap').gazeta(gfunc.emptyChild, '#holder_401')) $('#holder_401').hide();
  if ($('#bottom_wrap').gazeta(gfunc.emptyChild, '#holder_404')) $('#holder_404').hide();
  $('#top_wrap').find('.holder_top').each(function() {
    if ($.trim($(this).html().replace(/<!--.*?-->/g, '')) == '') $(this).hide();
  }); 
  if($('#holder_214').find('div').length > 0) $('#holder_214').addClass('hasContent');

});

function testDWF() {
  var s = $('#sitePath');
  var t = $('#dwf2');
  if (s.length == 0 || t.length == 0) return;
  var i = parseInt(t.css('top'));
  var j = s.offset().top - t.offset().top;
  if (j == 0) return;
  i += j;
  t.css({ top: (i+5)+'px' });
}

function check_ban43() {
  if (document.body) {
    if (!banXxByPoz[43] && !banXxByPoz[11]) document.body.className += ' noban43';
  } else {
    window.setTimeout(check_ban43, 100);
  }
}

check_ban43();

var sietPCh = {
	init: function(){
		if($('body').attr('class').indexOf('110627')>1){
			if($('.mod_percBase').length!=0){
				var new_p=$('#sitePath a:last-child').text();
				$('#sitePath a:last-child').remove();
				$('#sitePath').append('<span style="color: #000;">'+new_p+'</span>');
			}
		}
		if($('.mod_org')!=0){
			$('#sitePath a:last-child').attr({href: $('.mod_org .node_footer a').attr('href')});
		}
	}
}

gazeta_pl.pkbMapInfo = {
    'Austria': {
        'offset': { x: 213, y: 296 }
    },
    'Belgia': {
        'offset': { x: 165, y: 249 }
    },
    'Bulgaria': {
        'offset': { x: 326, y: 357 }
    },
    'Czechy': {
        'offset': { x: 242, y: 270 }
    },
    'Cypr': {
        'offset': { x: 433, y: 462 }
    },
    'Dania': {
        'offset': { x: 219, y: 179 }
    },
    'Estonia': {
        'offset': { x: 325, y: 158 }
    },
    'Finlandia': {
        'offset': { x: 305, y: 22 }
    },
    'Francja': {
        'offset': { x: 96, y: 253 }
    },
    'Grecja': {
        'offset': { x: 306, y: 387 }
    },
    'Hiszpania': {
        'offset': { x: 26, y: 315 }
    },
    'Holandia': {
        'offset': { x: 174, y: 230 }
    },
    'Irlandia': {
        'offset': { x: 70, y: 175 }
    },
    'Islandia': {
        'offset': { x: 74, y: 21 }
    },
    'Japonia': {
        'offset': { x: 863, y: 294 }
    },
    'Litwa': {
        'offset': { x: 312, y: 200 }
    },
    'Lotwa': {
        'offset': { x: 311, y: 180 }
    },
    'Luksemburg': {
        'offset': { x: 186, y: 269 }
    },
    'Malta': {
        'offset': { x: 241, y: 462 }
    },
    'Niemcy': {
        'offset': { x: 191, y: 213 }
    },
    'Norwegia': {
        'offset': { x: 209, y: 10 }
    },
    'Polska': {
        'offset': { x: 261, y: 221 }
    },
    'Portugalia': {
        'offset': { x: 11, y: 335 }
    },
    'Rumunia': {
        'offset': { x: 309, y: 303 }
    },
    'Slowacja': {
        'offset': { x: 280, y: 290 }
    },
    'Slowenia': {
        'offset': { x: 247, y: 325 }
    },
    'Szwajcaria': {
        'offset': { x: 180, y: 304 }
    },
    'Szwecja': {
        'offset': { x: 247, y: 39 }
    },
    'USA': {
        'offset': { x: 498, y: 27 }
    },
    'W_Brytania': {
        'offset': { x: 97, y: 141 }
    },
    'Wegry': {
        'offset': { x: 272, y: 303 }
    },
    'Wlochy': {
        'offset': { x: 182, y: 316 }
    }
};

gazeta_pl.pkbMapData = {
    'Belgia': {
        '2007/1': { pkb: 3.4 },
        '2007/2': { pkb: 3.3 },
        '2007/3': { pkb: 2.7 },
        '2007/4': { pkb: 1.8 },
        '2008/1': { pkb: 1.6 },
        '2008/2': { pkb: 1.9 },
        '2008/3': { pkb: 1.1 },
        '2008/4': { pkb: -1.3 },
        '2009/1': { pkb: -3.7 },
        '2009/2': { pkb: -4.1 },
        '2009/3': { pkb: -2.7 },
        '2009/4': { pkb: -0.1 },
        '2010/1': { pkb: 1.7 },
        '2010/2': { pkb: 2.7 },
        '2010/3': { pkb: 2.0 },
        '2010/4': { pkb: 2.1 },
        '2011/1': { pkb: 3.0 },
        '2011/2': { pkb: 2.5 }
    },
    
    'Bulgaria': {
        '2007/1': { pkb: 6.7 },
        '2007/2': { pkb: 6.9 },
        '2007/3': { pkb: 6.2 },
        '2007/4': { pkb: 6.8 },
        '2008/1': { pkb: 6.9 },
        '2008/2': { pkb: 6.5 },
        '2008/3': { pkb: 6.6 },
        '2008/4': { pkb: 4.7 },
        '2009/1': { pkb: -3.3 },
        '2009/2': { pkb: -4.6 },
        '2009/3': { pkb: -5.6 },
        '2009/4': { pkb: -8.9 },
        '2010/1': { pkb: -2.0 },
        '2010/2': { pkb: -0.4 },
        '2010/3': { pkb: 0.0 },
        '2010/4': { pkb: 3.8 },
        '2011/1': { pkb: 3.4 },
        '2011/2': { pkb: 2 }
    },
    
    'Czechy': {
        '2007/1': { pkb: 7.4 },
        '2007/2': { pkb: 6.1 },
        '2007/3': { pkb: 5.6 },
        '2007/4': { pkb: 5.4 },
        '2008/1': { pkb: 3.2 },
        '2008/2': { pkb: 3.4 },
        '2008/3': { pkb: 2.3 },
        '2008/4': { pkb: 0.4 },
        '2009/1': { pkb: -3.6 },
        '2009/2': { pkb: -4.8 },
        '2009/3': { pkb: -4.4 },
        '2009/4': { pkb: -3.2 },
        '2010/1': { pkb: 1.2 },
        '2010/2': { pkb: 2.3 },
        '2010/3': { pkb: 2.6 },
        '2010/4': { pkb: 2.7 },
        '2011/1': { pkb: 2.8 },
        '2011/2': { pkb: 2.4 }
    },
    
    'Dania': {
        '2007/1': { pkb: 3.1 },
        '2007/2': { pkb: -0.3 },
        '2007/3': { pkb: 1.5 },
        '2007/4': { pkb: 2.2 },
        '2008/1': { pkb: -0.3 },
        '2008/2': { pkb: 1.4 },
        '2008/3': { pkb: -1.2 },
        '2008/4': { pkb: -4.4 },
        '2009/1': { pkb: -4.3 },
        '2009/2': { pkb: -7.3 },
        '2009/3': { pkb: -6.1 },
        '2009/4': { pkb: -3.1 },
        '2010/1': { pkb: -1.1 },
        '2010/2': { pkb: 2.3 },
        '2010/3': { pkb: 3.3 },
        '2010/4': { pkb: 2.6 },
        '2011/1': { pkb: 1.9 },
        '2011/2': { pkb: 1.9 }
    },
    
    'Niemcy': {
        '2007/1': { pkb: 4.4 },
        '2007/2': { pkb: 3.5 },
        '2007/3': { pkb: 3.4 },
        '2007/4': { pkb: 2.4 },
        '2008/1': { pkb: 2.8 },
        '2008/2': { pkb: 1.8 },
        '2008/3': { pkb: 0.5 },
        '2008/4': { pkb: -1.9 },
        '2009/1': { pkb: -6.8 },
        '2009/2': { pkb: -6.2 },
        '2009/3': { pkb: -5.0 },
        '2009/4': { pkb: -2.2 },
        '2010/1': { pkb: 2.4 },
        '2010/2': { pkb: 4.1 },
        '2010/3': { pkb: 4.0 },
        '2010/4': { pkb: 3.8 },
        '2011/1': { pkb: 4.6 },
        '2011/2': { pkb: 2.8 }
    },
    
    'Estonia': {
        '2007/1': { pkb: 9.0 },
        '2007/2': { pkb: 7.9 },
        '2007/3': { pkb: 5.8 },
        '2007/4': { pkb: 5.2 },
        '2008/1': { pkb: -2.2 },
        '2008/2': { pkb: -2.6 },
        '2008/3': { pkb: -4.5 },
        '2008/4': { pkb: -10.7 },
        '2009/1': { pkb: -14.6 },
        '2009/2': { pkb: -16.6 },
        '2009/3': { pkb: -15.4 },
        '2009/4': { pkb: -8.8 },
        '2010/1': { pkb: -2.6 },
        '2010/2': { pkb: 3.1 },
        '2010/3': { pkb: 5.0 },
        '2010/4': { pkb: 6.7 },
        '2011/1': { pkb: 8.5 },
        '2011/2': { pkb: 8.4 }
    },
    
    'Irlandia': {
        '2007/1': { pkb: 6.7 },
        '2007/2': { pkb: 4.6 },
        '2007/3': { pkb: 2.7 },
        '2007/4': { pkb: 6.7 },
        '2008/1': { pkb: -1.2 },
        '2008/2': { pkb: -1.6 },
        '2008/3': { pkb: -1.1 },
        '2008/4': { pkb: -7.9 },
        '2009/1': { pkb: -8.4 },
        '2009/2': { pkb: -6.9 },
        '2009/3': { pkb: -7.5 },
        '2009/4': { pkb: -5.2 },
        '2010/1': { pkb: -1.1 },
        '2010/2': { pkb: -0.8 },
        '2010/3': { pkb: 0.1 },
        '2010/4': { pkb: 0.0 },
        '2011/1': { pkb: 0.0 },
        '2011/2': { pkb: null }
    },
    
    'Grecja': {
        '2007/1': { pkb: 5.4 },
        '2007/2': { pkb: 4.2 },
        '2007/3': { pkb: 3.9 },
        '2007/4': { pkb: 3.6 },
        '2008/1': { pkb: 1.6 },
        '2008/2': { pkb: 1.5 },
        '2008/3': { pkb: 1.0 },
        '2008/4': { pkb: 0.1 },
        '2009/1': { pkb: -1.1 },
        '2009/2': { pkb: -2.7 },
        '2009/3': { pkb: -3.5 },
        '2009/4': { pkb: -2.1 },
        '2010/1': { pkb: -2.8 },
        '2010/2': { pkb: -3.1 },
        '2010/3': { pkb: -4.1 },
        '2010/4': { pkb: -7.4 },
        '2011/1': { pkb: -5.5 },
        '2011/2': { pkb: null }
    },
    
    'Hiszpania': {
        '2007/1': { pkb: 3.9 },
        '2007/2': { pkb: 3.7 },
        '2007/3': { pkb: 3.5 },
        '2007/4': { pkb: 3.2 },
        '2008/1': { pkb: 2.7 },
        '2008/2': { pkb: 1.9 },
        '2008/3': { pkb: 0.3 },
        '2008/4': { pkb: -1.4 },
        '2009/1': { pkb: -3.5 },
        '2009/2': { pkb: -4.4 },
        '2009/3': { pkb: -3.9 },
        '2009/4': { pkb: -3.0 },
        '2010/1': { pkb: -1.4 },
        '2010/2': { pkb: 0.0 },
        '2010/3': { pkb: 0.2 },
        '2010/4': { pkb: 0.6 },
        '2011/1': { pkb: 0.9 },
        '2011/2': { pkb: 0.7 }
    },
    
    'Francja': {
        '2007/1': { pkb: 2.7 },
        '2007/2': { pkb: 2.1 },
        '2007/3': { pkb: 2.4 },
        '2007/4': { pkb: 1.7 },
        '2008/1': { pkb: 1.5 },
        '2008/2': { pkb: 0.3 },
        '2008/3': { pkb: -0.5 },
        '2008/4': { pkb: -2.1 },
        '2009/1': { pkb: -3.9 },
        '2009/2': { pkb: -3.2 },
        '2009/3': { pkb: -2.7 },
        '2009/4': { pkb: -0.6 },
        '2010/1': { pkb: 1.1 },
        '2010/2': { pkb: 1.5 },
        '2010/3': { pkb: 1.6 },
        '2010/4': { pkb: 1.4 },
        '2011/1': { pkb: 2.1 },
        '2011/2': { pkb: 1.6 }
    },
    
    'Wlochy': {
        '2007/1': { pkb: 2.2 },
        '2007/2': { pkb: 1.7 },
        '2007/3': { pkb: 1.5 },
        '2007/4': { pkb: 0.1 },
        '2008/1': { pkb: 0.3 },
        '2008/2': { pkb: -0.4 },
        '2008/3': { pkb: -1.8 },
        '2008/4': { pkb: -3.4 },
        '2009/1': { pkb: -6.7 },
        '2009/2': { pkb: -6.3 },
        '2009/3': { pkb: -4.9 },
        '2009/4': { pkb: -3.0 },
        '2010/1': { pkb: 0.7 },
        '2010/2': { pkb: 1.4 },
        '2010/3': { pkb: 1.4 },
        '2010/4': { pkb: 1.5 },
        '2011/1': { pkb: 1.0 },
        '2011/2': { pkb: 0.8 }
    },
    
    'Lotwa': {
        '2007/1': { pkb: 10.2 },
        '2007/2': { pkb: 9.6 },
        '2007/3': { pkb: 10.2 },
        '2007/4': { pkb: 9.5 },
        '2008/1': { pkb: 2.9 },
        '2008/2': { pkb: -2.2 },
        '2008/3': { pkb: -5.5 },
        '2008/4': { pkb: -10.2 },
        '2009/1': { pkb: -18.0 },
        '2009/2': { pkb: -17.4 },
        '2009/3': { pkb: -19.5 },
        '2009/4': { pkb: -16.9 },
        '2010/1': { pkb: -5.1 },
        '2010/2': { pkb: -3.0 },
        '2010/3': { pkb: 2.6 },
        '2010/4': { pkb: 3.5 },
        '2011/1': { pkb: 3.4 },
        '2011/2': { pkb: 5.7 }
    },
    
    'Litwa': {
        '2007/1': { pkb: 9.2 },
        '2007/2': { pkb: 10.0 },
        '2007/3': { pkb: 10.9 },
        '2007/4': { pkb: 8.3 },
        '2008/1': { pkb: 8.4 },
        '2008/2': { pkb: 5.2 },
        '2008/3': { pkb: -0.1 },
        '2008/4': { pkb: -1.7 },
        '2009/1': { pkb: -13.9 },
        '2009/2': { pkb: -16.0 },
        '2009/3': { pkb: -14.5 },
        '2009/4': { pkb: -14.4 },
        '2010/1': { pkb: -1.9 },
        '2010/2': { pkb: 1.2 },
        '2010/3': { pkb: 1.6 },
        '2010/4': { pkb: 4.6 },
        '2011/1': { pkb: 6.8 },
        '2011/2': { pkb: 5.9 }
    },
    
    'Wegry': {
        '2007/1': { pkb: 1.7 },
        '2007/2': { pkb: 0.6 },
        '2007/3': { pkb: 0.5 },
        '2007/4': { pkb: 0.4 },
        '2008/1': { pkb: 2.1 },
        '2008/2': { pkb: 1.9 },
        '2008/3': { pkb: 0.5 },
        '2008/4': { pkb: -2.2 },
        '2009/1': { pkb: -6.4 },
        '2009/2': { pkb: -7.4 },
        '2009/3': { pkb: -7.3 },
        '2009/4': { pkb: -5.1 },
        '2010/1': { pkb: -0.9 },
        '2010/2': { pkb: 0.7 },
        '2010/3': { pkb: 2.4 },
        '2010/4': { pkb: 2.4 },
        '2011/1': { pkb: 1.6 },
        '2011/2': { pkb: 1.2 }
    },
    
    'Holandia': {
        '2007/1': { pkb: 3.2 },
        '2007/2': { pkb: 3.1 },
        '2007/3': { pkb: 4.5 },
        '2007/4': { pkb: 4.8 },
        '2008/1': { pkb: 3.5 },
        '2008/2': { pkb: 3.0 },
        '2008/3': { pkb: 1.7 },
        '2008/4': { pkb: -0.9 },
        '2009/1': { pkb: -4.1 },
        '2009/2': { pkb: -4.8 },
        '2009/3': { pkb: -3.3 },
        '2009/4': { pkb: -2.0 },
        '2010/1': { pkb: 0.5 },
        '2010/2': { pkb: 2.1 },
        '2010/3': { pkb: 1.8 },
        '2010/4': { pkb: 2.3 },
        '2011/1': { pkb: 2.8 },
        '2011/2': { pkb: 1.5 }
    },
    
    'Austria': {
        '2007/1': { pkb: 4.3 },
        '2007/2': { pkb: 4.1 },
        '2007/3': { pkb: 3.3 },
        '2007/4': { pkb: 2.9 },
        '2008/1': { pkb: 3.3 },
        '2008/2': { pkb: 3.2 },
        '2008/3': { pkb: 2.0 },
        '2008/4': { pkb: -0.7 },
        '2009/1': { pkb: -3.9 },
        '2009/2': { pkb: -4.9 },
        '2009/3': { pkb: -3.5 },
        '2009/4': { pkb: -1.4 },
        '2010/1': { pkb: 0.5 },
        '2010/2': { pkb: 2.1 },
        '2010/3': { pkb: 2.8 },
        '2010/4': { pkb: 3.3 },
        '2011/1': { pkb: 3.9 },
        '2011/2': { pkb: 4.1 }
    },
    
    'Polska': {
        '2007/1': { pkb: 7.0 },
        '2007/2': { pkb: 7.0 },
        '2007/3': { pkb: 6.3 },
        '2007/4': { pkb: 7.1 },
        '2008/1': { pkb: 6.7 },
        '2008/2': { pkb: 5.7 },
        '2008/3': { pkb: 5.2 },
        '2008/4': { pkb: 2.5 },
        '2009/1': { pkb: 1.5 },
        '2009/2': { pkb: 1.3 },
        '2009/3': { pkb: 0.9 },
        '2009/4': { pkb: 2.8 },
        '2010/1': { pkb: 3.1 },
        '2010/2': { pkb: 3.6 },
        '2010/3': { pkb: 4.6 },
        '2010/4': { pkb: 3.9 },
        '2011/1': { pkb: 4.3 },
        '2011/2': { pkb: 4.5 }
    },
    
    'Portugalia': {
        '2007/1': { pkb: 2.6 },
        '2007/2': { pkb: 2.2 },
        '2007/3': { pkb: 2.2 },
        '2007/4': { pkb: 2.4 },
        '2008/1': { pkb: 0.9 },
        '2008/2': { pkb: 0.7 },
        '2008/3': { pkb: 0.3 },
        '2008/4': { pkb: -2.0 },
        '2009/1': { pkb: -3.9 },
        '2009/2': { pkb: -3.0 },
        '2009/3': { pkb: -2.0 },
        '2009/4': { pkb: -1.1 },
        '2010/1': { pkb: 1.8 },
        '2010/2': { pkb: 1.4 },
        '2010/3': { pkb: 1.2 },
        '2010/4': { pkb: 1.0 },
        '2011/1': { pkb: -0.6 },
        '2011/2': { pkb: -0.9 }
    },
    
    'Rumunia': {
        '2007/1': { pkb: 6.5 },
        '2007/2': { pkb: 6.1 },
        '2007/3': { pkb: 5.6 },
        '2007/4': { pkb: 6.7 },
        '2008/1': { pkb: 9.2 },
        '2008/2': { pkb: 9.6 },
        '2008/3': { pkb: 8.6 },
        '2008/4': { pkb: 2.9 },
        '2009/1': { pkb: -5.5 },
        '2009/2': { pkb: -8.3 },
        '2009/3': { pkb: -7.4 },
        '2009/4': { pkb: -6.6 },
        '2010/1': { pkb: -2.1 },
        '2010/2': { pkb: -0.5 },
        '2010/3': { pkb: -2.1 },
        '2010/4': { pkb: -0.6 },
        '2011/1': { pkb: 0.3 },
        '2011/2': { pkb: 0.3 }
    },
    
    'Slowenia': {
        '2007/1': { pkb: 7.7 },
        '2007/2': { pkb: 7.0 },
        '2007/3': { pkb: 7.3 },
        '2007/4': { pkb: 5.7 },
        '2008/1': { pkb: 5.3 },
        '2008/2': { pkb: 5.2 },
        '2008/3': { pkb: 3.4 },
        '2008/4': { pkb: -1.0 },
        '2009/1': { pkb: -7.7 },
        '2009/2': { pkb: -9.4 },
        '2009/3': { pkb: -9.4 },
        '2009/4': { pkb: -6.0 },
        '2010/1': { pkb: -0.3 },
        '2010/2': { pkb: 1.3 },
        '2010/3': { pkb: 1.4 },
        '2010/4': { pkb: 1.9 },
        '2011/1': { pkb: 2.1 },
        '2011/2': { pkb: null }
    },
    
    'Slowacja': {
        '2007/1': { pkb: 9.3 },
        '2007/2': { pkb: 9.5 },
        '2007/3': { pkb: 10.5 },
        '2007/4': { pkb: 12.6 },
        '2008/1': { pkb: 9.1 },
        '2008/2': { pkb: 7.4 },
        '2008/3': { pkb: 6.0 },
        '2008/4': { pkb: 1.3 },
        '2009/1': { pkb: -5.0 },
        '2009/2': { pkb: -5.0 },
        '2009/3': { pkb: -5.0 },
        '2009/4': { pkb: -4.2 },
        '2010/1': { pkb: 4.5 },
        '2010/2': { pkb: 4.4 },
        '2010/3': { pkb: 4.0 },
        '2010/4': { pkb: 3.3 },
        '2011/1': { pkb: 3.5 },
        '2011/2': { pkb: 3.4 }
    },
    
    'Finlandia': {
        '2007/1': { pkb: 5.0 },
        '2007/2': { pkb: 5.6 },
        '2007/3': { pkb: 5.5 },
        '2007/4': { pkb: 5.3 },
        '2008/1': { pkb: 3.4 },
        '2008/2': { pkb: 2.4 },
        '2008/3': { pkb: 1.1 },
        '2008/4': { pkb: -2.9 },
        '2009/1': { pkb: -8.7 },
        '2009/2': { pkb: -9.9 },
        '2009/3': { pkb: -8.3 },
        '2009/4': { pkb: -5.8 },
        '2010/1': { pkb: 1.0 },
        '2010/2': { pkb: 4.6 },
        '2010/3': { pkb: 3.5 },
        '2010/4': { pkb: 5.5 },
        '2011/1': { pkb: 5.1 },
        '2011/2': { pkb: 3.7 }
    },
    
    'Szwecja': {
        '2007/1': { pkb: 4.3 },
        '2007/2': { pkb: 3.4 },
        '2007/3': { pkb: 2.6 },
        '2007/4': { pkb: 3.6 },
        '2008/1': { pkb: 1.3 },
        '2008/2': { pkb: 0.7 },
        '2008/3': { pkb: 0.1 },
        '2008/4': { pkb: -5.1 },
        '2009/1': { pkb: -6.6 },
        '2009/2': { pkb: -6.3 },
        '2009/3': { pkb: -6.4 },
        '2009/4': { pkb: -1.7 },
        '2010/1': { pkb: 2.9 },
        '2010/2': { pkb: 4.5 },
        '2010/3': { pkb: 6.6 },
        '2010/4': { pkb: 7.6 },
        '2011/1': { pkb: 6.4 },
        '2011/2': { pkb: 5.3 }
    },
    
    'W_Brytania': {
        '2007/1': { pkb: 2.6 },
        '2007/2': { pkb: 2.9 },
        '2007/3': { pkb: 2.9 },
        '2007/4': { pkb: 2.4 },
        '2008/1': { pkb: 1.9 },
        '2008/2': { pkb: 1.0 },
        '2008/3': { pkb: -0.4 },
        '2008/4': { pkb: -2.7 },
        '2009/1': { pkb: -5.4 },
        '2009/2': { pkb: -5.9 },
        '2009/3': { pkb: -5.3 },
        '2009/4': { pkb: -2.8 },
        '2010/1': { pkb: -0.3 },
        '2010/2': { pkb: 1.6 },
        '2010/3': { pkb: 2.5 },
        '2010/4': { pkb: 1.5 },
        '2011/1': { pkb: 1.6 },
        '2011/2': { pkb: 0.7 }
    },
    
    'Islandia': {
        '2007/1': { pkb: 2.2 },
        '2007/2': { pkb: 7.2 },
        '2007/3': { pkb: 8.5 },
        '2007/4': { pkb: 5.8 },
        '2008/1': { pkb: 7.3 },
        '2008/2': { pkb: 1.0 },
        '2008/3': { pkb: -1.5 },
        '2008/4': { pkb: -0.9 },
        '2009/1': { pkb: -6.0 },
        '2009/2': { pkb: -4.2 },
        '2009/3': { pkb: -9.0 },
        '2009/4': { pkb: -8.3 },
        '2010/1': { pkb: -5.9 },
        '2010/2': { pkb: -6.4 },
        '2010/3': { pkb: -1.4 },
        '2010/4': { pkb: 0.1 },
        '2011/1': { pkb: 2.2 },
        '2011/2': { pkb: null }
    },
    
    'Norwegia': {
        '2007/1': { pkb: 3.7 },
        '2007/2': { pkb: 2.0 },
        '2007/3': { pkb: 2.8 },
        '2007/4': { pkb: 2.4 },
        '2008/1': { pkb: 1.7 },
        '2008/2': { pkb: 2.0 },
        '2008/3': { pkb: -0.3 },
        '2008/4': { pkb: -1.1 },
        '2009/1': { pkb: -1.1 },
        '2009/2': { pkb: -2.5 },
        '2009/3': { pkb: -1.4 },
        '2009/4': { pkb: -1.3 },
        '2010/1': { pkb: 0.0 },
        '2010/2': { pkb: 1.1 },
        '2010/3': { pkb: -1.2 },
        '2010/4': { pkb: 1.2 },
        '2011/1': { pkb: -0.1 },
        '2011/2': { pkb: 0.3 }
    },
    
    'Szwajcaria': {
        '2007/1': { pkb: 3.2 },
        '2007/2': { pkb: 3.7 },
        '2007/3': { pkb: 3.7 },
        '2007/4': { pkb: 4.0 },
        '2008/1': { pkb: 3.8 },
        '2008/2': { pkb: 3.3 },
        '2008/3': { pkb: 1.7 },
        '2008/4': { pkb: -0.3 },
        '2009/1': { pkb: -2.2 },
        '2009/2': { pkb: -3.2 },
        '2009/3': { pkb: -1.9 },
        '2009/4': { pkb: -0.3 },
        '2010/1': { pkb: 1.5 },
        '2010/2': { pkb: 2.8 },
        '2010/3': { pkb: 2.8 },
        '2010/4': { pkb: 3.1 },
        '2011/1': { pkb: 2.5 },
        '2011/2': { pkb: 2.3 }
    },
    
    'USA': {
        '2007/1': { pkb: 1.2 },
        '2007/2': { pkb: 1.7 },
        '2007/3': { pkb: 2.5 },
        '2007/4': { pkb: 2.2 },
        '2008/1': { pkb: 1.6 },
        '2008/2': { pkb: 1.0 },
        '2008/3': { pkb: -0.6 },
        '2008/4': { pkb: -3.3 },
        '2009/1': { pkb: -4.5 },
        '2009/2': { pkb: -5.0 },
        '2009/3': { pkb: -3.7 },
        '2009/4': { pkb: -0.5 },
        '2010/1': { pkb: 2.2 },
        '2010/2': { pkb: 3.3 },
        '2010/3': { pkb: 3.5 },
        '2010/4': { pkb: 3.1 },
        '2011/1': { pkb: 2.2 },
        '2011/2': { pkb: 1.5 }
    },
    
    'Cypr': {
        '2007/1': { pkb: 5.0 },
        '2007/2': { pkb: 4.9 },
        '2007/3': { pkb: 5.1 },
        '2007/4': { pkb: 5.6 },
        '2008/1': { pkb: 4.5 },
        '2008/2': { pkb: 4.4 },
        '2008/3': { pkb: 3.4 },
        '2008/4': { pkb: 2.3 },
        '2009/1': { pkb: 0.5 },
        '2009/2': { pkb: -1.7 },
        '2009/3': { pkb: -2.6 },
        '2009/4': { pkb: -2.8 },
        '2010/1': { pkb: -0.9 },
        '2010/2': { pkb: 0.7 },
        '2010/3': { pkb: 2.0 },
        '2010/4': { pkb: 2.5 },
        '2011/1': { pkb: 1.6 },
        '2011/2': { pkb: 1.4 }
    },
    
    'Luksemburg': {
        '2007/1': { pkb: 6.8 },
        '2007/2': { pkb: 8.3 },
        '2007/3': { pkb: 7.3 },
        '2007/4': { pkb: 4.2 },
        '2008/1': { pkb: 5.5 },
        '2008/2': { pkb: 3.4 },
        '2008/3': { pkb: 1.1 },
        '2008/4': { pkb: -4.1 },
        '2009/1': { pkb: -5.2 },
        '2009/2': { pkb: -7.3 },
        '2009/3': { pkb: -2.9 },
        '2009/4': { pkb: 1.1 },
        '2010/1': { pkb: 1.2 },
        '2010/2': { pkb: 5.0 },
        '2010/3': { pkb: 2.3 },
        '2010/4': { pkb: 5.7 },
        '2011/1': { pkb: 4.9 },
        '2011/2': { pkb: null }
    },
    
    'Malta': {
        '2007/1': { pkb: 5.7 },
        '2007/2': { pkb: 4.5 },
        '2007/3': { pkb: 4.6 },
        '2007/4': { pkb: 3.4 },
        '2008/1': { pkb: 5.7 },
        '2008/2': { pkb: 6.2 },
        '2008/3': { pkb: 5.5 },
        '2008/4': { pkb: 4.1 },
        '2009/1': { pkb: -4.1 },
        '2009/2': { pkb: -4.4 },
        '2009/3': { pkb: -2.9 },
        '2009/4': { pkb: -1.6 },
        '2010/1': { pkb: 3.4 },
        '2010/2': { pkb: 3.0 },
        '2010/3': { pkb: 2.5 },
        '2010/4': { pkb: 3.6 },
        '2011/1': { pkb: 2.2 },
        '2011/2': { pkb: null }
    },
    
    'USA': {
        '2007/1': { pkb: 1.2 },
        '2007/2': { pkb: 1.7 },
        '2007/3': { pkb: 2.5 },
        '2007/4': { pkb: 2.2 },
        '2008/1': { pkb: 1.6 },
        '2008/2': { pkb: 1.0 },
        '2008/3': { pkb: -0.6 },
        '2008/4': { pkb: -3.3 },
        '2009/1': { pkb: -4.5 },
        '2009/2': { pkb: -5.0 },
        '2009/3': { pkb: -3.7 },
        '2009/4': { pkb: -0.5 },
        '2010/1': { pkb: 2.2 },
        '2010/2': { pkb: 3.3 },
        '2010/3': { pkb: 3.5 },
        '2010/4': { pkb: 3.1 },
        '2011/1': { pkb: 2.2 },
        '2011/2': { pkb: 1.5 }
    },
    
    'Japonia': {
        '2007/1': { pkb: 3.3 },
        '2007/2': { pkb: 2.4 },
        '2007/3': { pkb: 1.8 },
        '2007/4': { pkb: 1.8 },
        '2008/1': { pkb: 1.3 },
        '2008/2': { pkb: -0.1 },
        '2008/3': { pkb: -1.2 },
        '2008/4': { pkb: -4.7 },
        '2009/1': { pkb: -9.9 },
        '2009/2': { pkb: -7.0 },
        '2009/3': { pkb: -6.2 },
        '2009/4': { pkb: -1.8 },
        '2010/1': { pkb: 5.5 },
        '2010/2': { pkb: 3.3 },
        '2010/3': { pkb: 4.8 },
        '2010/4': { pkb: 2.5 },
        '2011/1': { pkb: -0.7 },
        '2011/2': { pkb: -0.9 }
    }
}

gazeta_pl.pkbMapDebt = {
    'Belgia': [ 130.4, 127.3, 122.7, 117.4, 113.7, 107.9, 106.6, 103.5, 98.5, 94.2, 92.1, 88.1, 84.2, 89.6, 96.2, 96.8 ],
    'Bulgaria': [ null, null, 108.3, 77.6, 77.6, 72.5, 66, 52.4, 44.4, 37, 27.5, 21.6, 17.2, 13.7, 14.6, 16.2 ],
    'Czechy': [ 14.6, 12.5, 13.1, 15, 16.4, 18.5, 24.9, 28.2, 29.8, 30.1, 29.7, 29.4, 29, 30, 35.3, 38.5 ],
    'Dania': [ 72.6, 69.4, 65.4, 61.4, 58.1, 52.4, 49.6, 49.5, 47.2, 45.1, 37.8, 32.1, 27.5, 34.5, 41.8, 43.6 ],
    'Niemcy': [ 55.6, 58.4, 59.7, 60.3, 60.9, 59.7, 58.8, 60.4, 63.9, 65.8, 68, 67.6, 64.9, 66.3, 73.5, 83.2 ],
    'Estonia': [ 8.2, 7.6, 7, 6, 6.5, 5.1, 4.8, 5.7, 5.6, 5, 4.6, 4.4, 3.7, 4.6, 7.2, 6.6 ],
    'Irlandia': [ 82, 73.4, 64.3, 53.6, 48.5, 37.8, 35.5, 32.1, 30.9, 29.6, 27.4, 24.8, 25, 44.4, 65.6, 96.2 ],
    'Grecja': [ 97, 99.4, 96.6, 94.5, 94, 103.4, 103.7, 101.7, 97.4, 98.6, 100, 106.1, 105.4, 110.7, 127.1, 142.8 ],
    'Hiszpania': [ 63.3, 67.4, 66.1, 64.1, 62.3, 59.3, 55.5, 52.5, 48.7, 46.2, 43, 39.6, 36.1, 39.8, 53.3, 60.1 ],
    'Francja': [ 55.5, 58, 59.2, 59.4, 58.9, 57.3, 56.9, 58.8, 62.9, 64.9, 66.4, 63.7, 63.9, 67.7, 78.3, 81.7 ],
    'Wlochy': [ 121.5, 120.9, 118.1, 114.9, 113.7, 109.2, 108.8, 105.7, 104.4, 103.9, 105.9, 106.6, 103.6, 106.3, 116.1, 119 ],
    'Cypr': [ 51.4, 52.6, 56.9, 58.6, 58.9, 58.8, 60.7, 64.6, 68.9, 70.2, 69.1, 64.6, 58.3, 48.3, 58, 60.8 ],
    'Lotwa': [ 15.1, 13.9, 11.1, 9.6, 12.5, 12.3, 14, 13.5, 14.6, 14.9, 12.4, 10.7, 9, 19.7, 36.7, 44.7 ],
    'Litwa': [ 11.5, 13.8, 15.4, 16.5, 22.7, 23.7, 23.1, 22.3, 21.1, 19.4, 18.4, 18, 16.9, 15.6, 29.5, 38.2 ],
    'Luksemburg': [ 7.4, 7.4, 7.4, 7.1, 6.4, 6.2, 6.3, 6.3, 6.1, 6.3, 6.1, 6.7, 6.7, 13.6, 14.6, 18.4 ],
    'Wegry': [ 85.4, 71.4, 62, 59.9, 59.8, 54.9, 52, 55.6, 58.3, 59.1, 61.8, 65.7, 66.1, 72.3, 78.4, 80.2 ],
    'Malta': [ 35.3, 40.1, 48.4, 53.4, 57.1, 55.9, 62.1, 60.1, 69.3, 72.4, 69.6, 64.2, 62, 61.5, 67.6, 68 ],
    'Holandia': [ 76.1, 74.1, 68.2, 65.7, 61.1, 53.8, 50.7, 50.5, 52, 52.4, 51.8, 47.4, 45.3, 58.2, 60.8, 62.7 ],
    'Austria': [ 68.3, 68.3, 64.4, 64.8, 67.3, 66.5, 67.3, 66.7, 65.8, 65.2, 64.6, 62.8, 60.7, 63.8, 69.6, 72.3 ],
    'Polska': [ 49, 43.4, 42.9, 38.9, 39.6, 36.8, 37.6, 42.2, 47.1, 45.7, 47.1, 47.7, 45, 47.1, 50.9, 55 ],
    'Portugalia': [ 59.2, 58.3, 54.4, 50.4, 49.6, 48.5, 51.2, 53.8, 55.9, 57.6, 62.8, 63.9, 68.3, 71.6, 83, 93 ],
    'Rumunia': [ 6.6, 10.6, 15, 16.8, 21.7, 22.5, 25.7, 24.9, 21.5, 18.7, 15.8, 12.4, 12.6, 13.4, 23.6, 30.8 ],
    'Slowenia': [ null, null, null, null, null, null, 26.7, 27.9, 27.3, 27.4, 26.7, 26.4, 23.1, 21.9, 35.2, 38 ],
    'Slowacja': [ 22.1, 31.1, 33.8, 34.5, 47.9, 50.3, 48.9, 43.4, 42.4, 41.5, 34.2, 30.5, 29.6, 27.8, 35.4, 41 ],
    'Finlandia': [ 56.6, 57, 53.9, 48.4, 45.7, 43.8, 42.5, 41.5, 44.5, 44.4, 41.7, 39.7, 35.2, 34.1, 43.8, 48.4 ],
    'Szwecja': [ 72.8, 73.3, 71.2, 69.9, 64.3, 53.9, 54.7, 52.5, 51.7, 50.3, 50.4, 45, 40.2, 38.8, 42.8, 39.8 ],
    'W_Brytania': [ 51.2, 51.3, 49.8, 46.7, 43.7, 41, 37.7, 37.5, 39, 40.9, 42.5, 43.4, 44.5, 54.4, 69.6, 80 ],
    'USA': [ 71.1, 70.3, 67.8, 64.6, 60.8, 54.8, 54.7, 57.1, 60.4, 61.4, 61.7, 61.1, 62.2, 71.2, 84.6, 91.6 ],
    'Japonia': [ 92.4, 100.3, 107.1, 120.1, 133.8, 142.1, 151.7, 160.9, 167.2, 178.1, 191.6, 191.3, 187.7, 195.0, 216.3, 220.3 ],
    'Norwegia': [ null, null, null, null, null, null, 45.9, 42.1, 40.8, 34.5, 25.4, 30.1, 28.6, 69.7, 91.7, 96.6 ],
    'Szwajcaria': [ null, null, null, null, null, null, 29.2, 36.1, 44.3, 45.6, 44.5, 55.4, 51.5, 49.1, 43.1, 44.7 ],
    'Islandia': [ null, null, null, null, null, null, 61.0, 68.0, 67.5, 71.9, 72.2, 64.4, 57.2, 54.9, 54.9, 55.0 ]
}



gazeta_pl.pkbMap = {

    BASE_PATH: 'http://bi.gazeta.pl/i/obrazki/wyborcza.biz/mapa/',

    OFFSET: -23,

    SCALE_MIN: -20,
    SCALE_MAX: 15,

    TIMELINE_START: {
        year: 2007,
        quarter: 1
    },

    TIMELINE_END: {
        year: 2011,
        quarter: 2
    },

    lastC: '',
    graphDisplayed: false,

    json: { data: [] },

    dom: {
        scale: null,
        overlay: null,
        base: null,
        nav: null,
        hover: null,
        tlButtons: null,
        sliderButtons: null
    },

    images: {},

    addEvent: function(obj, type, fn) {

        if (obj.addEventListener) {
            obj.addEventListener(type, fn, false);
        } else if (obj.attachEvent) {
            obj['e' + type + fn] = fn;
            obj[type + fn] = function() { obj['e' + type + fn] (window.event); }
            obj.attachEvent('on' + type, obj[type + fn]);
        }

    },

    findPos: function(obj) {
      var curleft = 0, curtop = 0;
      if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
          curleft += obj.offsetLeft
          curtop += obj.offsetTop
        }
      }
      return [curleft,curtop];
    },

    copyProps: function(e) {
      var i = null, t = {};
      for (i in e) t[i] = e[i];
      return t;
    },

    roman: function(i) {
        switch (i) {
        case 1: return 'I';
        case 2: return 'II';
        case 3: return 'III';
        case 4: return 'IV';
        }
    },

    wrap: function(a) {

        var
            trim = function(s) {
                return s.replace(/^\s+|\s+$/g,'');
            };

        a.each = function(fn) {
            for (var i = 0, l = a.length; i < l; i++) fn.call(a[i], i);
        }

        a.addEvent = function(e, fn, c) {
            a.each(function(i) {
                gazeta_pl.pkbMap.addEvent(this, e, function(ev) {
                    ev.index = i;
                    if (fn.apply(c, arguments) === false) {
                        ev.preventDefault && ev.preventDefault();
                        ev.returnValue = false;
                    }
                    if (this.blur) this.blur();
                });
            });
        }

        a.addClass = function(cl, i) {
            if (typeof i == 'undefined') {
                a.each(function() {
                    if (!(' ' + this.className + ' ').match(' ' + cl + ' ')) {
                        this.className += ' ' + cl;
                    }
                });
            } else {
               if (!(' ' + a[i].className + ' ').match(' ' + cl + ' ')) {
                   a[i].className += ' ' + cl;
               }
            }
        }

        a.removeClass = function(cl, i) {
            if (typeof i == 'undefined') {
                a.each(function() {
                    this.className = trim((' ' + this.className + ' ').replace(' ' + cl + ' ', ''));
                });
            } else {
                a[i].className = trim((' ' + a[i].className + ' ').replace(' ' + cl + ' ', ''));
            }
        }

        a.hasClass = function(cl, i) {
            if (typeof i == 'undefined') return false;
            return !!((' ' + a[i].className + ' ').match(' ' + cl + ' '));
        }

        return a;

    },

    init: function() {

        var
            i = 0,
            htm = '',
            tlEnd = null,
            sliderButtons = this.wrap([]),
            tlButtons = this.wrap([]),
            links = null;

        this.dom.scale = document.getElementById('pkbMapScale');
        this.dom.overlay = document.getElementById('pkbMapOverlay');
        this.dom.base = document.getElementById('pkbMapBase');
        this.dom.nav = document.getElementById('pkbMapNav');
        this.dom.hover = document.getElementById('pkbMapHover');

        this.initOverlay();

        htm = '<ul>';
        for (i = this.SCALE_MIN; i <= this.SCALE_MAX; i++) htm += '<li>' + i + '</li>';
        htm += '</ul>';
        this.dom.scale.innerHTML = htm;

        tlEnd = this.TIMELINE_END;
        htm = '<span class="prev"><a data-action="slideLeft" href="#"></a></span>';
        htm += '<div><ul>';
        i = this.copyProps(this.TIMELINE_START);
        while (1) {
            htm += 
                '<li><a data-action="set" data-time="' + 
                i.year + ',' + i.quarter + '" href="#">' + 
                this.roman(i.quarter) + ' kw. ' + i.year + '</a></li>';

            i.quarter++;
            if (i.quarter > 4) {
                i.quarter = 1;
                i.year++;
            }
            if (i.year > tlEnd.year || (i.year == tlEnd.year && i.quarter > tlEnd.quarter)) break;
        }
        htm += '</ul></div>';
        htm += '<span class="next"><a data-action="slideRight" href="#"></a></span>';
        this.dom.nav.innerHTML = htm;

        links = this.wrap(this.dom.nav.getElementsByTagName('a'));
        links.each(function() {
            if (this.getAttribute('data-action') == 'set') {
                tlButtons.push(this);
            } else {
                sliderButtons.push(this);
            }
        });

        tlButtons.addEvent('click', this.onTimelineClick, this);
        sliderButtons.addEvent('click', this.onSliderClick, this);

        tlButtons.addClass('active', 0);

        this.dom.tlButtons = tlButtons;
        this.dom.sliderButtons = sliderButtons;

        this.loadData();
        this.draw(2007, 1);

        this.addEvent(document, 'click', function(e) {
            if (gazeta_pl.pkbMap.graphDisplayed) {
                gazeta_pl.pkbMap.hideGraph();
                e.preventDefault && e.preventDefault();
                e.returnValue = false;
            }
        });

    },

    initOverlay: function() {

        var scr = document.createElement('script');
        scr.src = '/info/wyborcza.biz/map-data.js';
        document.getElementsByTagName('head')[0].appendChild(scr);

    },

    draw: function(year, quarter) {

        var
            base = this.dom.base,
            data = gazeta_pl.pkbMapData,
            info = gazeta_pl.pkbMapInfo,
            img = null,
            time = year + '/' + quarter,
            country = '',
            htm = '';

        while ((img = base.getElementsByTagName('img')).length) {
            base.removeChild(img[0]);
        }

        for (country in data) {
            img = this.images[country + '/' + time];
            if (img) {
                base.appendChild(img);
                img.style.left = info[country].offset.x + 'px';
                img.style.top = info[country].offset.y + 'px';
            } else {
                gazeta_pl.trace('missing: ' + country + '/' + time);
            }
        }

        if (year == this.TIMELINE_START.year && quarter == this.TIMELINE_START.quarter) {
            this.dom.sliderButtons.removeClass('active', 0);
        } else {
            this.dom.sliderButtons.addClass('active', 0);
        }

        if (year == this.TIMELINE_END.year && quarter == this.TIMELINE_END.quarter) {
            this.dom.sliderButtons.removeClass('active', 1);
        } else {
            this.dom.sliderButtons.addClass('active', 1);
        }

        this.currentYear = year;
        this.currentQuarter = quarter;

    },

    loadData: function() {

        var
            data = gazeta_pl.pkbMapData,
            img = null,
            base = this.BASE_PATH,
            ntime = null,
            ndata = null,
            country = '',
            time = '',
            pkb = 0;

        for (country in data) {
           for (time in data[country]) {

             ntime = time.split('/').map(function(x) { return parseInt(x, 10); });
             ndata = data[country][time];
             if (ndata.pkb === null) continue;
             pkb = Math.min(this.SCALE_MAX, Math.max(this.SCALE_MIN, Math.floor(ndata.pkb, 10))) - this.OFFSET;
             img = new Image();
             img.src = base + pkb + '/' + country.toUpperCase() + '.png';

             this.images[country + '/' + time] = img;

           }

           img = new Image();
           img.src = base + 'hover/' + country.toUpperCase() + '_k.png';
           this.images['hover/' + country] = img;
        }

    },

    getCountry: function(c) {

        return ({

            '1': 'Portugalia',
            '2': 'Hiszpania',
            '3': 'Francja',
            '4': 'Wlochy',
            '5': 'Szwajcaria',
            '6': 'Rumunia',
            '7': 'Bulgaria',
            '8': 'Grecja',
            '9': 'Litwa',
            'a': 'Lotwa',
            'b': 'Belgia',
            'c': 'Holandia',
            'd': 'Niemcy',
            'e': 'Dania',
            'f': 'Austria',
            'g': 'Estonia',
            'h': 'Finlandia',
            'i': 'Szwecja',
            'j': 'Norwegia',
            'k': 'W_Brytania',
            'l': 'Irlandia',
            'm': 'Islandia',
            'n': 'USA',
            'o': 'Japonia',
            'p': 'Luksemburg',
            'q': 'Czechy',
            'r': 'Slowacja',
            's': 'Polska',
            't': 'Wegry',
            'u': 'Slowenia',
            'v': 'Cypr',
            'w': 'Malta'

        })[c];

    },

    getCountryName: function(c) {

        return ({

            '1': 'Portugalia',
            '2': 'Hiszpania',
            '3': 'Francja',
            '4': 'W\u0142ochy',
            '5': 'Szwajcaria',
            '6': 'Rumunia',
            '7': 'Bu\u0142garia',
            '8': 'Grecja',
            '9': 'Litwa',
            'a': '\u0141otwa',
            'b': 'Belgia',
            'c': 'Holandia',
            'd': 'Niemcy',
            'e': 'Dania',
            'f': 'Austria',
            'g': 'Estonia',
            'h': 'Finlandia',
            'i': 'Szwecja',
            'j': 'Norwegia',
            'k': 'Wielka Brytania',
            'l': 'Irlandia',
            'm': 'Islandia',
            'n': 'USA',
            'o': 'Japonia',
            'p': 'Luksemburg',
            'q': 'Czechy',
            'r': 'S\u0142owacja',
            's': 'Polska',
            't': 'W\u0119gry',
            'u': 'S\u0142owenia',
            'v': 'Cypr',
            'w': 'Malta'

        })[c];

    },

    onTimelineClick: function(e) {
        var 
            i = e.index,
            bs = this.dom.tlButtons,
            time = [];

        if (bs.hasClass('active', i)) return false;
        bs.removeClass('active');
        bs.addClass('active', i);

        time = bs[i].getAttribute('data-time')
            .split(',')
            .map(function(x) { return parseInt(x, 10); });

        this.draw(time[0], time[1]);
        return false;
    },

    onSliderClick: function(e) {

        var y = 0, q = 0, tl = null;

        if (!this.dom.sliderButtons.hasClass('active', e.index)) return false;
        if (this.dom.sliderButtons[e.index].parentNode.className.match(/prev/)) {
            this.currentQuarter--;   
            if (this.currentQuarter < 1) {
                this.currentQuarter = 4;
                this.currentYear--;
            }
        } else {
            this.currentQuarter++;   
            if (this.currentQuarter > 4) {
                this.currentQuarter = 1;
                this.currentYear++;
            }
        }

        y = this.currentYear;
        q = this.currentQuarter;
        tl = this.dom.tlButtons;

        tl.removeClass('active');
        tl.each(function(i) {

          if (this.getAttribute('data-time') == y + ',' + q) {
              tl.addClass('active', i);
          }

        });

        this.draw(y, q);

        return false;
    },

    onData: function(json) {

        var loader = document.getElementById('pkbMapLoader');

        json.data = json.data.map(function(x) { return x.split(''); });
        this.json = json;

        this.addEvent(this.dom.overlay, 'mousemove', this.onMouseMove); 

        this.addEvent(this.dom.overlay, 'mouseout', function(e) {
            gazeta_pl.pkbMap.hideHover();
        });

        this.addEvent(this.dom.overlay, 'click', this.onOvClick);

        loader.parentNode.removeChild(loader);
    },

    onOvClick: function(e) {

        var
            ov = document.createElement('div'),
            main = document.getElementById('pkbMapMain'),
            btnClose = null,
            graphPKB = null,
            graphDebt = null,
            me = gazeta_pl.pkbMap,
            country = me.getCountry(me.lastC),
            countryName = me.getCountryName(me.lastC),
            layer = null,
            htm = '';

        if (me.lastC == '.' || !country || !countryName) {
            me.onMouseMove(e);
            country = me.getCountry(me.lastC);
            countrlyName = me.getCountryName(me.lastC);
            if (me.lastC == '.' || !country || !countryName) return;
        }

        htm += '<div id="pkbMapGraph">';
        htm += '<h1>' + countryName + '</h1>';
        htm += '<div class="pkb"><h2>Wzrost PKB <span>(dane w proc.)</span></h2><div id="pkbGraphPKB"></div></div>';
        htm += '<div class="debt"><h2>D\u0142ug publiczny <span>(dane w proc. PKB)</span></h2><div id="pkbGraphDebt"></div></div>';
        htm += '<a href="#" id="pkbGraphClose"></a>';
        htm += '</div>';

        layer = document.createElement('div');
        layer.setAttribute('id', 'pkbMapGraphLayer');
    
        ov.innerHTML = htm;
        ov.setAttribute('id', 'pkbMapGraphWindow');
        main.appendChild(layer);
        main.appendChild(ov);

        btnClose = document.getElementById('pkbGraphClose');
        graphPKB = document.getElementById('pkbGraphPKB');
        graphDebt = document.getElementById('pkbGraphDebt');

        me.drawGraph(country, graphPKB, graphDebt);

        setTimeout(function() {
            me.graphDisplayed = true;
        }, 100);
    },

    onMouseMove: function(e) {

        var 
            mx = e.pageX || e.clientX + document.documentElement.scrollLeft,
            my = e.pageY || e.clientY + document.documentElement.scrollTop,
            me = gazeta_pl.pkbMap,
            json = me.json,
            pos = me.findPos(me.dom.overlay),
            cx = mx - pos[0],
            cy = my - pos[1],
            mw = json.data[0].length,
            mh = json.data.length;

        cx = Math.floor(cx / 6);
        cy = Math.floor(cy / 6);

        if (cy >= 0 && cy < json.data.length && cx >= 0 && cx < json.data[0].length) {
        
            if (me.lastC != json.data[cy][cx]) {
                me.lastC = json.data[cy][cx];

                me.showHover(me.getCountry(me.lastC));

            }

        }

    },

    drawGraph: function(country, pkb, debt) {

        var
            pkbData = gazeta_pl.pkbMapData[country],
            debtData = gazeta_pl.pkbMapDebt[country],

            i = null,
            s = null,
            f = true,

            div = null,

            year = 1995,
            syear = 2001,

            cl = '',
            
            htm = '';

        for (i in pkbData) {
            if (!i.match(/^[0-9]{4}\/[0-9]{1}$/)) continue;
            cl = (i == this.currentYear + '/' + this.currentQuarter) ? ' active' : '';
            htm += '<div class="holder' + cl + '"><div class="t' + Math.max(-21, Math.min(15, Math.floor(pkbData[i].pkb))) + '" data-value="' + pkbData[i].pkb + '"></div></div>';
        }

        div = document.createElement('div');
        div.innerHTML = htm;
        pkb.appendChild(div);
        this.arrangeGraph(div, true);

        htm = '';
        for (i = 0; i < debtData.length; i++) {
            cl = (year == this.currentYear) ? ' active' : '';
            if (year >= syear) htm += '<div class="holder' + cl + '"><div data-value="' + debtData[i] + '"></div></div>';
            year++;
        }
        div = document.createElement('div');
        div.innerHTML = htm;
        debt.appendChild(div);

        this.arrangeGraph(div, false);
    },

    hideGraph: function() {
        var ov = document.getElementById('pkbMapGraphWindow');
        ov.parentNode.removeChild(ov);
        ov = document.getElementById('pkbMapGraphLayer');
        ov.parentNode.removeChild(ov);
        this.graphDisplayed = false;
    },

    arrangeGraph: function(target, istop) {

        var
            divs = target.getElementsByTagName('div'),
            max = 1.0,
            min = -1.0,
            i = 0,
            l = divs.length,
            d = null,
            m = 0,
            mf = 0,
            off = 0,
            area = 0,
            defArea = istop ? 76 : 90,
            caption = null;

        for (; i < l; i++) {
            d = divs[i];
            if (d.getAttribute('data-value')) {

                m = parseFloat(d.getAttribute('data-value'));
                if (isNaN(m)) continue;
                mf = Math.floor(m);
                
                max = Math.max(m, max);
                min = Math.min(m, min);
            }
        }

        area = max - min;
        ratio = defArea / area;
        above = max * ratio;
        below = min * ratio;

        for (i = 0; i < l; i++) {
            d = divs[i];
            if (!(divs[i].parentNode && divs[i].parentNode.className.match(/holder/))) continue;
            if (d.getAttribute('data-value')) {
                m = parseFloat(d.getAttribute('data-value'));

                caption = document.createElement('span');

                off = d.parentNode.className.match(/active/) ? -1 : 0;

                if (isNaN(m)) {
                    caption.innerHTML = 'b/d';
                    caption.style.top = '18px';
                } else {
                    caption.innerHTML = ((m * 10) + '').replace(/([0-9])$/, ',$1').replace(/^(-?),/, '$1' + '0,');
                    m *= ratio;
                    d.style.height = Math.round(Math.abs(m)) + 'px';

                    if (m < 0) {
                        d.style.top = off + (Math.round(above) + 1) + 'px';
                        caption.style.bottom = '-18px';
                    } else {
                        d.style.top = off + Math.round(above) - Math.round(m) + 'px';
                        caption.style.top = '-18px';
                    }
                }

                d.appendChild(caption);
                d.parentNode.style.height = Math.round(above) + 'px';
                d.parentNode.style.marginBottom = -Math.round(below) + 'px';

            }
        }

    },

    showHover: function(country) {

        this.hideHover();

        if (!country) return;

        img = new Image();
        this.dom.hover.appendChild(img);

        img.src = this.images['hover/' + country].src;
        img.style.left = gazeta_pl.pkbMapInfo[country].offset.x + 'px';
        img.style.top = gazeta_pl.pkbMapInfo[country].offset.y + 'px';
        
        this.dom.overlay.style.cursor = 'pointer';

    },

    hideHover: function() {

        var img = this.dom.hover.getElementsByTagName('img');
        if (img.length) this.dom.hover.removeChild(img[0]);

        this.dom.overlay.style.cursor = 'default';

    }

}

gazeta_pl.pkbMap.addEvent(window, 'load', function() {

    if (document.getElementById('pkbMap')) gazeta_pl.pkbMap.init();

});

