//////////////////////////////////////////////////////////////////////////////////

// CloudCarousel V1.0.4
// (c) 2010 by R Cecco. <http://www.professorcloud.com>
// MIT License
//
// Reflection code based on plugin by Christophe Beyls <http://www.digitalia.be>
//
// Please retain this copyright header in all versions of the software

//////////////////////////////////////////////////////////////////////////////////
 
(function($){
	function Reflection(a,b,c){
		var d,cntx,imageWidth=a.width,imageHeight=a.width,gradient,parent;parent=$(a.parentNode);
		if($.browser.msie){
			this.element=d=parent.append("<img class='reflection' style='position:absolute'/>").find(':last')[0];
			d.src=a.src;
			d.style.filter="flipv progid:DXImageTransform.Microsoft.Alpha(opacity="+(c*100)+", style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy="+(b/imageHeight*100)+")"}else{this.element=d=parent.append("<canvas class='reflection' style='position:absolute'/>").find(':last')[0];
			if(!d.getContext){
				return
			}
			cntx=d.getContext("2d");
			try{
				$(d).attr({width:imageWidth,height:b});
				cntx.save();
				cntx.translate(0,imageHeight-1);cntx.scale(1,-1);
				cntx.drawImage(a,0,0,imageWidth,imageHeight);cntx.restore();cntx.globalCompositeOperation="destination-out";gradient=cntx.createLinearGradient(0,0,0,b);
				gradient.addColorStop(0,"rgba(255, 255, 255, "+(1-c)+")");
				gradient.addColorStop(1,"rgba(255, 255, 255, 1.0)");
				cntx.fillStyle=gradient;cntx.fillRect(0,0,imageWidth,b)
			}catch(e){
				return
			}
		}
		$(d).attr({'alt':$(a).attr('alt'),title:$(a).attr('title')})
	}
	var s=function(a,b){
		this.orgWidth=a.width;
		this.orgHeight=a.height;
		this.image=a;
		this.reflection=null;
		this.alt=a.alt;
		this.title=a.title;
		this.imageOK=false;
		this.options=b;
		this.imageOK=true;
		if(this.options.reflHeight>0){
			this.reflection=new Reflection(this.image,this.options.reflHeight,this.options.reflOpacity)
		}
		$(this.image).css('position','absolute')
	};
	var t=function(o,p,q){
		var r=[],funcSin=Math.sin,funcCos=Math.cos,ctx=this;
		this.controlTimer=0;
		this.stopped=false;
		this.container=o;
		this.xRadius=q.xRadius;
		this.yRadius=q.yRadius;
		this.showFrontTextTimer=0;
		this.autoRotateTimer=0;
		if(q.xRadius===0){
			this.xRadius=($(o).width()/2.3)
		}
		if(q.yRadius===0){
			this.yRadius=($(o).height()/6)
		}
		this.xCentre=q.xPos;
		this.yCentre=q.yPos;
		this.frontIndex=0;
		this.rotation=this.destRotation=Math.PI/2;
		this.timeDelay=1000/q.FPS;
		if(q.altBox!==null){
			$(q.altBox).css('display','block');
			$(q.titleBox).css('display','block')}$(o).css({position:'relative',overflow:'hidden'});
			$(q.buttonLeft).css('display','inline');
			$(q.buttonRight).css('display','inline');
			$(q.buttonLeft).bind('mouseup',this,function(a){
				a.data.rotate(1);
				return false
			});
			$(q.buttonRight).bind('mouseup',this,function(a){ 
				// alert("Button geklickt");
				a.data.rotate(1);
				return false
			});
			if(q.mouseWheel){
				$(o).bind('mousewheel',this,function(a){
					a.data.rotate(1); 
					return false
				})
			}
			// $(o).bind('mouseover click',this,function(a){
			$(o).bind('click',this,function(a){
				clearInterval(a.data.autoRotateTimer);
				var b=$(a.target).attr('alt');
				if(b !== undefined && b !== null){
					clearTimeout(a.data.showFrontTextTimer);
					$(q.altBox).html(($(a.target).attr('alt')));
					$(q.titleBox).html(($(a.target).attr('title')));
					if(q.bringToFront&&a.type=='click'){
						var c=$(a.target).data('itemIndex');
						var d=a.data.frontIndex;
						var e=c-d;
					}
				}
			});
		/* $(o).bind('mouseout',this,function(a){
			var b=a.data;
			clearTimeout(b.showFrontTextTimer);
			b.showFrontTextTimer=setTimeout(function(){b.showFrontText()},1000);
			b.autoRotate()
		}); 
		$(o).bind('mousedown',this,function(a){ 
			var c=$(a.target).data('itemIndex');
			var d=a.data.frontIndex;	
			// alert(d);
			// document.getElementById('imagecarousel_c133-title').title = "hjkjk";
			return false
		}); */
		o.onselectstart=function(){
			return false
		};
		this.innerWrapper=$(o).wrapInner('<div style="position:absolute;width:100%;height:100%;"/>').children()[0];
		this.showFrontText=function(){
			// alert(this.frontIndex);
			var title_arr = new Array();
			var alt_arr = new Array();
			alt_arr[0] = "DALTON MEDICAL";
			title_arr[0] = "Lernen Sie uns kennen";
			alt_arr[1] = "UNSER STANDORT";
			title_arr[1] = "***";
			alt_arr[2] = "UNSER STANDORT";
			title_arr[2] = "Dalton Medical GmbH<br/>Wilhelm-Theodor-Römheld-Straße 14<br/>55130 Mainz - Deutschland<br/>Tel.: +49 (0) 6131 / 21 20 6-0<br/>Fax : +49 (0) 6131 / 21 20 6-10<br/>E-Mail: <a href=\"mailto:info@dalton-medical.de\">info@dalton-medical.de</a>";
			alt_arr[3] = "UNSERE VERTRIEBSMARKEN";
			title_arr[3] = "***";
			alt_arr[4] = "UNSERE VERTRIEBSMARKEN";
			title_arr[4] = "Ellipse, UltraShape, Applisonix";
			alt_arr[5] = "PRODUKTE";
			title_arr[5] = "***";
			alt_arr[6] = "Ellipse-MultiFlex I<sup>2</sup>PL + NdYAG";
			title_arr[6] = "&quot;Das neue Workhorse der ästhetischen Medizin&quot;";
			alt_arr[7] = "Ellipse I<sup>2</sup>PL <sup>plus</sup>";
			title_arr[7] = "Sicher, flexibel, schnell - die ideale Kombination aus Effektivität und Wirtschaftlichkeit, für den medizinisch-ästhetischen Profi.";
			alt_arr[8] = "Ultrashape Contour I, Ver. 3<br/>Focussed Ultrasound + RF";
			title_arr[8] = "Der Goldstandard und Erfolgsgarant im Wachstumsmarkt<br/>&quot;nicht-invasiver Fettabbau & Body Controuring&quot;.";
			alt_arr[9] = "Applisonix Selectif <sup>pro</sup>";
			title_arr[9] = "***";
			alt_arr[10] = "KOOPERATIONSPARTNER";
			title_arr[10] = "***";
			alt_arr[11] = "Peak-Service GmbH";
			title_arr[11] = "Technischer Service und Dienstleistungen rund um unsere Vertriebsprodukte, in Deutschland und Österreich.<br/><br/>PEAK-System Technik GmbH<br/>Hauptgeschäftsstelle Darmstadt<br/>Im Tiefen See 62<br/>64293 Darmstadt<br/>Tel.: 06151 / 82 87 0<br/>Fax: 06151 / 82 87 59<br/>E-Mail: <a href=\"mailto:info@peak-system.com\">info@peak-system.com</a>";
			alt_arr[12] = "HI-TEC-SUPPORT";
			title_arr[12] = "Technischer Service und Dienstleistungen rund um unsere Vertriebsprodukte, in der Schweiz.<br/><br/>Hi-Tec-Support GmbH<br/>Wanistrasse 7<br/>8422 Pfungen/Winterthur<br/>Tel.: +41 52 214 33 00<br/>Fax: +41 52 214 33 05<br/>Internet: <a href=\"http://www.hi-tec-support.com\" target=\"_blank\">www.hi-tec-support.com</a>";
			alt_arr[13] = "MMV LEASING";
			title_arr[13] = "Finanzierungs-Dienstleistungen rund um unsere Vertriebsprodukte, in Deutschland.<br/><br/>MMV Leasing GmbH<br/>Ferdinand-Sauerbruch-Straße 7<br/>56073 Koblenz<br/>Telefon 0261 9433-0<br/>Telefax 0261 9433-555<br/>Internet: <a href=\"http://www.mmv-leasing.de\" target=\"_blank\">www.mmv-leasing.de</a><br/>E-Mail: <a href=\"mailto:info@mmv-leasing.de\">info@mmv-leasing.de</a>";
			alt_arr[14] = "MEDICO PARTNER";
			title_arr[14] = "Vermietungsservice für Ellipse-Systeme in Deutschland und Österreich und der Schweiz.<br/><br/>MEDICO PARTNER<br/>Hirtenstraße 12<br/>46145 Oberhausen<br/>Tel: +49 208 / 9407290<br/>Fax: +49 208 / 9407291<br/>Internet: <a href=\"http://www.medico-partner.de\" target=\"_blank\">www.medico-partner.de</a><br/>E-Mail: <a href=\"mailto:m.neumann@medico-partner.de\">m.neumann@medico-partner.de</a>";
			alt_arr[15] = "ECOS OFFICE CENTER MAINZ";
			title_arr[15] = "ecos office center mainz<br/>BBC Büroservice & Business-Center GmbH<br/>Wilhelm-Theodor-Roemheld-Str. 14<br/>D-55130 Mainz<br/>Tel.: +49.(0) 6131.921-0<br/>Fax: +49.(0) 6131.921-100<br/>Internet: <a href=\"http://www.ecos-office.de/mainz\" target=\"_blank\">www.ecos-office.de/mainz</a><br/>E-Mail: <a href=\"mailto:mainz@ecos-office.de\">mainz@ecos-office.de</a><br/>Amtsgericht Mainz HRB 6048 - GF Dipl.Betr.wirt (FH) Harald Kastor";
			// alert(title_arr[Math.abs(this.frontIndex)]);
			$(q.titleBox).html(title_arr[Math.abs(this.frontIndex)]);
			$(q.altBox).html(alt_arr[Math.abs(this.frontIndex)]);
			/* 
			if(r[this.frontIndex]===undefined){
				return
			}
			$(q.titleBox).html($(r[this.frontIndex].image).attr('title'));
			$(q.altBox).html($(r[this.frontIndex].image).attr('alt'));
			*/
		};
		
		
		
		/* this.showFrontText = function() {
			var fIndex = this.frontIndex;
			if(fIndex < 0) fIndex += items.length;
			if ( items[fIndex] === undefined ) { return; } // Images might not have loaded yet.
			$(options.titleBox).html( $(items[fIndex].image).attr('title'));
			$(options.altBox).html( $(items[fIndex].image).attr('alt'));
		}; */



		this.go=function(){
			if(this.controlTimer!==0){
				return
			}
			var a=this;
			this.controlTimer=setTimeout(function(){a.updateAll()},this.timeDelay)};
			this.stop=function(){
				clearTimeout(this.controlTimer);
				this.controlTimer=0
			};
			this.rotate=function(a){
				this.frontIndex-=a;
				this.frontIndex%=r.length;
				this.destRotation+=(Math.PI/r.length)*(2*a);
				this.showFrontText();
				this.go()};
				this.autoRotate=function(){
					if(q.autoRotate!=='no'){
						var a=(q.autoRotate==='right')?1:-1;
						this.autoRotateTimer=setInterval(function(){ctx.rotate(a)},q.autoRotateDelay)}};
						this.updateAll=function(){
							var a=q.minScale;
							var b=(1-a)*0.5;var w,h,x,y,scale,item,sinVal;
							var c=(this.destRotation-this.rotation);
							var d=Math.abs(c);
							this.rotation+=c*q.speed;
							if(d<0.001){
								this.rotation=this.destRotation
							}
							var e=r.length;
							var f=(Math.PI/e)*2;
							var g=this.rotation;
							var j=$.browser.msie;
							this.innerWrapper.style.display='none';
							var k;
							var l='px',reflHeight;
							var m=this;
							for(var i=0;i<e;i++){
								item=r[i];
								sinVal=funcSin(g);
								scale=((sinVal+1)*b)+a;
								x=this.xCentre+(((funcCos(g)*this.xRadius)-(item.orgWidth*0.5))*scale);
								y=this.yCentre+(((sinVal*this.yRadius))*scale);
								if(item.imageOK){
									var n=item.image;w=n.width=item.orgWidth*scale;h=n.height=item.orgHeight*scale;n.style.left=x+l;
									n.style.top=y+l;n.style.zIndex=""+(scale*100)>>0;
									if(item.reflection!==null){
										reflHeight=q.reflHeight*scale;
										k=item.reflection.element.style;
										k.left=x+l;
										k.top=y+h+q.reflGap*scale+l;
										k.width=w+l;
										if(j){
											k.filter.finishy=(reflHeight/h*100)
										}else{
											k.height=reflHeight+l
										}
									}
								}
								g+=f
							}
							this.innerWrapper.style.display='block';
							if(d>=0.001){
								this.controlTimer=setTimeout(function(){m.updateAll()},this.timeDelay)}else{this.stop()}};
								this.checkImagesLoaded=function(){
									var i;
									for(i=0;i<p.length;i++){
										if((p[i].width===undefined)||((p[i].complete!==undefined)&&(!p[i].complete))){
											return
										}
									}
									for(i=0;i<p.length;i++){
										r.push(new s(p[i],q));
										$(p[i]).data('itemIndex',i)}clearInterval(this.tt);
										this.showFrontText();
										this.autoRotate();
										this.updateAll()
									};
									this.tt=setInterval(function(){ctx.checkImagesLoaded()},50)};
									$.fn.CloudCarousel=function(a){
										this.each(function(){
											a=$.extend({},{reflHeight:0,reflOpacity:0.5,reflGap:0,minScale:0.5,xPos:0,yPos:0,xRadius:0,yRadius:0,altBox:null,titleBox:null,FPS:30,autoRotate:'no',autoRotateDelay:1500,speed:0.2,mouseWheel:false,bringToFront:false},a);
										$(this).data('cloudcarousel',new t(this,$('.cloudcarousel',$(this)),a))
									});
									return this
								}
							})(jQuery);
