SMSlideshow = new Class({
	initialize: function(thumbnails, slideshow_image, props) {
		this.props = Object.extend({
			images: [],
			poststampWidth: 86,
			poststampHeight: 88,
			poststampSize: 159,
			thumbnailsCountVisible: 3,
			leftArrowId: 'slideshow_left',
			rightArrowId: 'slideshow_right',
			poststampClass: 'poststamp_big'
		}, props || {});

		if (this.props.images.length < 1) { return; }

		var galleryImgs = $$('#'+slideshow_image+' img');
		if (galleryImgs.length > 0) galleryImgs.each(function(image) {	image.remove();	});

		this.thumbnails = $(thumbnails);
		this.slideshow_image = $(slideshow_image);

		if (this.thumbnails && this.slideshow_image)
		{
			this.currentPosition = 0;
			this.maxZIndex = 0;
			this.currentIndex = 0;
			this.leftArrow = $(this.props.leftArrowId);
			this.rightArrow = $(this.props.rightArrowId);

			if (this.props.images.length > this.props.thumbnailsCountVisible) {
				if (window.ie)
				{
					this.leftArrow.setStyle('cursor', 'hand');
					this.rightArrow.setStyle('cursor', 'hand');
				}
				else
				{
					this.leftArrow.setStyle('cursor', 'pointer');
					this.rightArrow.setStyle('cursor', 'pointer');
				}
				
				this.leftArrow.setStyle('opacity', 0.25);
		
				if (this.props.images.length<=this.props.thumbnailsCountVisible)
				{
					this.rightArrow.setStyle('opacity', 0.25);
				}
				else
				{
					this.rightArrow.setStyle('opacity', 1);
				}
			}
	
			this.fx = new Fx.Styles(this.thumbnails, {duration: 500, wait: false, transition: Fx.Transitions["Cubic"]["easeOut"]});
			this.fxLeftArrow = new Fx.Styles(this.leftArrow, {duration: 250, wait: false, transition: Fx.Transitions.linear});
			this.fxRightArrow = new Fx.Styles(this.rightArrow, {duration: 250, wait: false, transition: Fx.Transitions.linear});
			this.fxSlideshowImage = new Fx.Styles(this.slideshow_image, {duration: 1000, wait: false, transition: Fx.Transitions["Cubic"]["easeOut"]});
			this.pendingEffects = [];
			this.previousIndex = -1;
			this.busy = false;
			this.start();
		}
	},
	cleanQueue: function(){
			var smSlideshow = this;
			var testAgain = false;
			if (smSlideshow.pendingEffects.length>=2)
			{
				if (smSlideshow.pendingEffects[0][0]==smSlideshow.pendingEffects[1][0] && 
						smSlideshow.pendingEffects[0][2]+smSlideshow.pendingEffects[1][2]==1)
				{
					smSlideshow.pendingEffects.shift();
					smSlideshow.pendingEffects.shift();
					testAgain = true;
				}
			}
			if (smSlideshow.pendingEffects.length>2)
			{
				if (smSlideshow.pendingEffects[0][1]==1 && 
						smSlideshow.pendingEffects[1][1]==0)
				{
					smSlideshow.pendingEffects.shift();
					smSlideshow.pendingEffects.shift();
					testAgain = true;
				}
			}
			if (smSlideshow.pendingEffects.length>3)
			{
				if (smSlideshow.pendingEffects[1][1]==1 && 
						smSlideshow.pendingEffects[2][1]==0)
				{
					t = smSlideshow.pendingEffects.shift();
					smSlideshow.pendingEffects.shift();
					smSlideshow.pendingEffects.shift();
					smSlideshow.pendingEffects.unshift(t);
					testAgain = true;
				}
			}
			
			if (testAgain) {smSlideshow.cleanQueue();}
	},
	runQueue: function(force){
		if (!this.busy || force)
		{
			var smSlideshow = this;
			smSlideshow.cleanQueue();
			
			if (smSlideshow.pendingEffects.length>0)
			{
				smSlideshow.busy = true;
				t = smSlideshow.pendingEffects.shift();
				if (t[2]==1)
					t[0].setStyle('z-index', ++smSlideshow.maxZIndex);
				t[0].effect('opacity', {duration: t[1]}).start(t[2]).chain(function() {smSlideshow.runQueue(true)});
			}
			else
			{
				smSlideshow.busy = false;
			}
		}
	},
	start: function(){
		
		var images = [];
		var smSlideshow = this;
		
		for (j = 0; j < this.props.images.length; j++) {
			var span = new Element('span');
			var img = new Element('img');

			span.addClass(this.props.poststampClass);
			
			images[j] = this.props.images[j][1];
			
			img.setProperty('src', this.props.images[j][0]);
			img.setProperty('width', this.props.poststampWidth);
			img.setProperty('height', this.props.poststampHeight);
			img.addEvent('click',function(){

				for (k = 0; k < smSlideshow.props.images.length; k++) {
					if (smSlideshow.props.images[k][0]==this.getProperty('src'))
					{
						nextIndex = k;
						break;
					}
				}
				if (smSlideshow.currentIndex != nextIndex)
				{
					smSlideshow.previousIndex = smSlideshow.currentIndex;
					smSlideshow.currentIndex = nextIndex;
					var firstEffect = [];
					var secondEffect = [];
					smSlideshow.loadedImages.each(function(image, i) {
						if (image.getProperty('src')==images[smSlideshow.currentIndex])
						{
							secondEffect = [image, 500, 1];
						}
						else if (image.getProperty('src')==images[smSlideshow.previousIndex])
						{
							firstEffect = [image, 500, 0];
						}
					});
					if (firstEffect.length>0)
						smSlideshow.pendingEffects.push(firstEffect);
					if (secondEffect.length>0)
						smSlideshow.pendingEffects.push(secondEffect);
					smSlideshow.runQueue(false);
				}
			});
			img.injectInside(span);
			span.injectInside(this.thumbnails);
		}
		
		smSlideshow.loadedImages = [];
		
		new Asset.images(images, {
			onProgress: function(i) {
				this.setStyles({
					'position': 'absolute',
					'z-index': i,
					'opacity': 0,
					'left': (smSlideshow.slideshow_image.getCoordinates().width / 2) - (this.width / 2),
					'top': (smSlideshow.slideshow_image.getCoordinates().height / 2) - (this.height / 2)
				});
				smSlideshow.maxZIndex=(i>smSlideshow.maxZIndex)?i:smSlideshow.maxZIndex;
				smSlideshow.loadedImages[i] = this;
				this.inject(smSlideshow.slideshow_image);
				if (this.getProperty('src')==images[smSlideshow.currentIndex] &&
						smSlideshow.previousIndex != smSlideshow.currentIndex)
				{
					smSlideshow.previousIndex = smSlideshow.currentIndex;
					smSlideshow.pendingEffects.push([this, 1500, 1]);
					smSlideshow.runQueue(false);
				}
			},
			onComplete: function() {
			}
		});

		if (this.props.images.length > this.props.thumbnailsCountVisible) {

			/*
			 * right arrow func
			 */
			this.rightArrow.addEvent('click',function(){
				if (this.currentPosition<this.props.images.length-this.props.thumbnailsCountVisible)
				{
					this.thumbnails.setStyle('width', this.thumbnails.getStyle('width').replace('px', '').toInt() + this.props.poststampSize);
					this.currentPosition++;
					this.fx.start({'left':-this.currentPosition*this.props.poststampSize});
				}
				
				if (this.currentPosition>=this.props.images.length-this.props.thumbnailsCountVisible)
				{
					this.fxRightArrow.start({'opacity':0.25});
				}
	
				if (this.currentPosition>0)
				{
					this.fxLeftArrow.start({'opacity':1});
				}
			}.bind(this));
	
			/*
			 * left arrow func
			 */
			this.leftArrow.addEvent('click',function(){
				if (this.currentPosition>0)
				{
					this.thumbnails.setStyle('width', this.thumbnails.getStyle('width').replace('px', '').toInt() - this.props.poststampSize);
					this.currentPosition--;
					this.fx.start({'left':-this.currentPosition*this.props.poststampSize});
				}
	
				if (this.currentPosition==0)
				{
					this.fxLeftArrow.start({'opacity':0.25});
				}
	
				if (this.props.images.length>this.props.thumbnailsCountVisible)
				{
					this.fxRightArrow.start({'opacity':1});
				}
			}.bind(this));
		}
	}
});

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		}
	]			
};

BrowserDetect.init();

var Site = {
	
	start: function(){
		
		if(typeof sIFR == "function"){
			sIFR.replaceElement(named({sSelector:"div.home_page_action h1", sFlashSrc:"fileadmin/swf/calibri_bold.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#b4eac4", sWmode:"transparent", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=0"}));
			sIFR.replaceElement(named({sSelector:"div.linked_back_top h6", sFlashSrc:"fileadmin/swf/calibri_bold.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#ebe2af", sWmode:"transparent", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=0"}));
			sIFR.replaceElement(named({sSelector:"div.content_page_action h1", sFlashSrc:"fileadmin/swf/calibri_bold.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#b7d8eb", sWmode:"transparent", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=0"}));
			sIFR.replaceElement(named({sSelector:"div.container_back_middle h1", sFlashSrc:"fileadmin/swf/calibri_bold.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#fafcfe", sWmode:"transparent", sHoverColor:"#888888", nPaddingTop:2, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
			sIFR.replaceElement(named({sSelector:"div.home_page_latest h1", sFlashSrc:"fileadmin/swf/calibri_bold.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#ffe875", sWmode:"transparent", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=0"}));
			sIFR.replaceElement(named({sSelector:"div.home_page_call_us h1", sFlashSrc:"fileadmin/swf/calibri_bold.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#73b9df", sWmode:"transparent", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=0"}));
		};
		
		/*
		if ($('smGallery')!=null)
			myShow = new Slideshow('smGallery', {hu: 'fileadmin/images/', images: ['slideshow_1.jpg','slideshow_2.jpg','slideshow_3.jpg','slideshow_4.jpg'], duration: [1500, 3000]});
		*/
		
		var Tips2 = new Tips($$('a.location'), {
			initialize:function(){
				this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
			},
			fixed:(BrowserDetect.browser == "Explorer" && BrowserDetect.version<7),
			className: 'custom',
			onShow: function(toolTip) {
				this.fx.start(1);
			},
			onHide: function(toolTip) {
				this.fx.start(0);
			}
		});
		
		/*
		var smSlideshow2 = new SMSlideshow('thumbnails', 'slideshow_image',
										{images: [
												['fileadmin/images/image_01.gif', 'fileadmin/images/slide_1.jpg'],
												['fileadmin/images/image_02.gif', 'fileadmin/images/slide_2.jpg'],
												['fileadmin/images/image_03.gif', 'fileadmin/images/slide_3.jpg'],
												['fileadmin/images/image_04.gif', 'fileadmin/images/slide_4.jpg'],
												['fileadmin/images/image_05.gif', 'fileadmin/images/slide_5.jpg'],
												['fileadmin/images/image_06.gif', 'fileadmin/images/slide_6.jpg'],
												['fileadmin/images/image_07.gif', 'fileadmin/images/slide_7.jpg']
										 ],
										 poststampClass: 'poststamp_big',
										 poststampWidth: 86,
										 poststampHeight: 88,
										 poststampSize: 141,
										 thumbnailsCountVisible: 4,
										 leftArrowId: 'slideshow_left',
										 rightArrowId: 'slideshow_right'
										 });*/

		if ($('kwick')) Site.parseKwicks();
	},
	
	parseKwicks: function(){
		var kwicks = $$('a.kwick');
		var fx = new Fx.Elements(kwicks, {wait: false, duration: 200, transition: Fx.Transitions.quadOut});
		kwicks.each(function(kwick, i){
			kwick.addEvent('mouseenter', function(e){
				var obj = {};
				obj[i] = {
					'width': [kwick.getStyle('width').toInt(), 198]
				};
				kwicks.each(function(other, j){
					if (other != kwick){
						var w = other.getStyle('width').toInt();
						if (w != 96) obj[j] = {'width': [w, 96]};
					}
				});
				fx.start(obj);
			});
		});
		
		$('kwick').addEvent('mouseleave', function(e){
			var obj = {};
			kwicks.each(function(other, j){
				obj[j] = {'width': [other.getStyle('width').toInt(), 113]};
			});
			fx.start(obj);
		});
	}	
};

window.addEvent('domready', Site.start);