/* ****************************************************************************************** *
 * Das Script kann frei verwendet werden, dieser Kommentar sowie die Nennung des Nicks
 * muss jedoch erhalten bleiben.
 *
 *                                                                           (c) Quaese, 2009
 * ****************************************************************************************** */

function qpReflexion(objAttr){this.IDName="reflexion";this.AttrName="class";this.ReflWidth=0.8;this.StartOpac=0.7;this.EndOpac=0.0;this.isFilterIE=false;this.isIE7=false;if(typeof objAttr=="object")
this.setAttributes(objAttr);this.init();};qpReflexion.prototype.checkAttr=function(){if(this.AttrName=="class")
this.AttrName="className";};qpReflexion.prototype.init=function(){this.isFilterIE=(/MSIE/.test(navigator.userAgent)&&!window.opera&&(Number(navigator.userAgent.split(";")[1].substr(navigator.userAgent.split(";")[1].search(/\d/)))>=5.5))?true:false;this.isIE7=(/MSIE/.test(navigator.userAgent)&&!window.opera&&(Number(navigator.userAgent.split(";")[1].substr(navigator.userAgent.split(";")[1].search(/\d/)))>=7))?true:false;this.setAttributes({len:this.ReflWidth,start:this.StartOpac,end:this.EndOpac});var arrHelp=document.getElementsByTagName("img");this.checkAttr();for(var i=arrHelp.length-1;i>=0;i--){var strHelp=(this.AttrName!="className"&&(typeof arrHelp[i].getAttribute(this.AttrName)=="string"))?arrHelp[i].getAttribute(this.AttrName):((this.AttrName=="className")?arrHelp[i].className:"");var strPattern=eval("/\\b"+this.IDName+"\\b/");if(strHelp.search(strPattern)!=-1){this.setReflection(arrHelp[i]);}}};qpReflexion.prototype.Reflect=function(objArg){try{if(objArg.length>0){for(var i=objArg.length-1;i>=0;i--){this.setReflection(objArg[i]);}}else{this.setReflection(objArg);}}catch(objException){this.setReflection(objArg);}};qpReflexion.prototype.setAttributes=function(objAttr){if(typeof objAttr=="object"){for(var strEntry in objAttr){switch(strEntry.toLowerCase()){case"len":this.ReflWidth=((Number(objAttr[strEntry])>=0)&&(Number(objAttr[strEntry])<=1))?Number(objAttr[strEntry]):1.0;break;case"start":this.StartOpac=((Number(objAttr[strEntry])>=0)&&(Number(objAttr[strEntry])<=1))?Number(objAttr[strEntry]):0.8;this.StartOpacIE=parseInt(100*this.StartOpac);break;case"end":this.EndOpac=((Number(objAttr[strEntry])>=0)&&(Number(objAttr[strEntry])<=1))?Number(objAttr[strEntry]):0.0;this.EndOpacIE=parseInt(100*this.EndOpac);break;}}}};qpReflexion.prototype.setReflection=function(objImg){try{objImg.src;}catch(objExc){return;}
var blnHide=(this.GetStyle(objImg,'display','display')=="none")?true:false;if(blnHide)
objImg.style.display="block";var intWidth=parseInt(this.GetStyle(objImg,"width","width"));var intHeight=parseInt(this.GetStyle(objImg,"height","height"));if(blnHide)
objImg.style.display="none";if(document.createElement("canvas").getContext){var objCanvas=document.createElement("canvas");objCanvas.className="refl-class";objCanvas.style.cssText=objImg.style.cssText;if(blnHide)
objCanvas.style.display="";objCanvas.width=intWidth;objCanvas.height=(blnHide)?intHeight:2*intHeight;objCanvas.style.width=intWidth+"px";objCanvas.style.height=(blnHide)?(intHeight+"px"):(2*intHeight+"px");var objContext=objCanvas.getContext('2d');objContext.save();var intMove=(blnHide)?(intHeight-1):(2*intHeight-1);objContext.translate(0,intMove);objContext.scale(1,-1);objContext.drawImage(objImg,0,0,intWidth,intHeight);objContext.restore();objContext.save();intMove=(blnHide)?0:intHeight;objContext.translate(0,intMove);objContext.globalCompositeOperation="destination-in";var objGradient=objContext.createLinearGradient(0,0,0,intHeight);objGradient.addColorStop(0,"rgba(0,0,0,"+this.StartOpac+")");objGradient.addColorStop(this.ReflWidth,"rgba(0,0,0,"+this.EndOpac+")");objContext.fillStyle=objGradient;objContext.fillRect(0,0,intWidth,intHeight);objContext.restore();if(!blnHide)
objContext.drawImage(objImg,0,0,intWidth,intHeight);objImg.parentNode.replaceChild(objCanvas,objImg);}else{if(this.isFilterIE){var objOuter=document.createElement("span");objOuter.className="refl-class";if(objImg.style.position=="absolute"||objImg.style.position=="relative"){objOuter.style.position=objImg.style.position;objOuter.style.top=(objImg.style.top!="")?objImg.style.top:"0px";objOuter.style.left=(objImg.style.left!="")?objImg.style.left:"0px";objOuter.style.zIndex=(objImg.style.zIndex!="")?objImg.style.zIndex:"";}
objOuter.style.styleFloat=(objImg.style.styleFloat!="")?objImg.style.styleFloat:"";objOuter.style.paddingTop=objImg.style.marginTop;objOuter.style.paddingRight=objImg.style.marginRight;objOuter.style.paddingBottom=objImg.style.marginBottom;objOuter.style.paddingLeft=objImg.style.marginLeft;objOuter.style.display="inline-block";var objInner=document.createElement("span");objInner.style.position="relative";objInner.style.border=objImg.style.border;objInner.style.background=objImg.style.background;if(this.isIE7)
objInner.style.display="inline-block";var intHelpW=intHelpH=0;var arrCSS=new Array();arrCSS[0]=new Array("paddingLeft","paddingRight");arrCSS[1]=new Array("paddingTop","paddingBottom","borderTopWidth","borderBottomWidth");for(var j=0;j<arrCSS[0].length;j++){intHelpW+=(objImg.style[arrCSS[0][j]]!="")?parseInt(objImg.style[arrCSS[0][j]]):0;intHelpH+=(objImg.style[arrCSS[1][j]]!="")?parseInt(objImg.style[arrCSS[1][j]]):0;}
var objSpacer=document.createElement("iframe");objSpacer.style.width=(intHelpW+intWidth)+"px";if(blnHide){objSpacer.style.height=(intHelpH+intHeight)+"px";}else{objSpacer.style.height=(intHelpH+2*intHeight)+"px";}
objSpacer.style.visibility="hidden";objInner.appendChild(objSpacer);intHelpW=(objImg.style.paddingLeft!="")?parseInt(objImg.style.paddingLeft):0;intHelpH=(objImg.style.paddingTop!="")?parseInt(objImg.style.paddingTop):0;var objBild=document.createElement("img");objBild.src=objImg.src;objBild.style.width=intWidth+"px";objBild.style.height=intHeight+"px";objBild.style.position="absolute";if(blnHide){objBild.style.display="none";}
if(this.isIE7&&(window.document.compatMode=="CSS1Compat")){var intBorderTop=intBorderLeft=0;}else{var intBorderTop=(objImg.style.borderTopWidth!="")?parseInt(objImg.style.borderTopWidth):0;var intBorderLeft=(objImg.style.borderLeftWidth!="")?parseInt(objImg.style.borderLeftWidth):0;}
objBild.style.top=(intHelpH+intBorderTop)+"px";objBild.style.left=(intHelpW+intBorderLeft)+"px";objInner.appendChild(objBild);var objBild=document.createElement("img");objBild.src=objImg.src;objBild.style.width=intWidth+"px";objBild.style.height=intHeight+"px";objBild.style.position="absolute";if(blnHide){objBild.style.top=(intHelpH+intBorderTop)+"px";}else{objBild.style.top=(intHelpH+intHeight+intBorderTop)+"px";}
objBild.style.left=(intHelpW+intBorderLeft)+"px";objBild.style.filter="flipv progid:DXImageTransform.Microsoft.Alpha(opacity="+this.StartOpacIE+", style=1, finishOpacity="+this.EndOpacIE+", startx=0, starty=0, finishx=0, finishy="+parseInt(this.ReflWidth*intHeight)+")";objInner.appendChild(objBild);objOuter.appendChild(objInner);var objParent=objImg.parentNode;objParent.replaceChild(objOuter,objImg);}}};qpReflexion.prototype.GetStyle=function(objElem,strCSS,strCSSjs){if(window.getComputedStyle){strStyle=window.getComputedStyle(objElem,null).getPropertyValue(strCSS);}else if(objElem.currentStyle){strStyle=objElem.currentStyle[strCSSjs];}
return strStyle;};

