window.addEvent('load',function(){
	if (Browser.Engine.trident){$$('div.footer')[0].innerHTML+='';}
	if ($$('.accordion')[1]){
		$$('h3.accordion').each(function(el){
			el.innerHTML='<span>'+el.innerHTML+'</span>';
			el.getElements('span')[0].addEvents({
				'mouseenter': function(){
					this.addClass('hover');
				},
				'mouseleave': function(){
					this.removeClass('hover');
				}
			});
		});
		var cAccordion = new Accordion('h3.accordion', 'div.accordion', {
			display: ($$('h3.accordion')[0].hasClass('sh'))? 1: 0,
			onComplete: function(){
				$$('.footer')[0].innerHTML+='';
			},
			onActive: function(toggler){
				toggler.addClass('active');
			},
			onBackground: function(toggler){
				toggler.removeClass('active');
			}
		});
	}
});
window.addEvent('domready',function(){
	var ind = location.href.indexOf('#');
	if (ind != -1){var l = location.href.substring(ind+1);}

	if (l=='text' && $$('p.filter')[0]){
		$$('p.filter')[0].getElements('a')[0].removeClass('active');
		$$('p.filter')[0].getElements('a')[1].addClass('active');
		$$('div.logos').removeClass('active');
		$$('div.clients').addClass('active');
	}

	if ($$('p.filter')[0]){
		$$('p.filter')[0].getElements('a')[0].addEvent('click',function(){
			this.getNext().removeClass('active');
			this.addClass('active');
			$$('div.logos').addClass('active');
			$$('div.clients').removeClass('active');
			if (Browser.Engine.trident){$$('div.footer').innerHTML+='';}
		});
		$$('p.filter')[0].getElements('a')[1].addEvent('click',function(){
			this.getPrevious().removeClass('active');
			this.addClass('active');
			$$('div.logos').removeClass('active');
			$$('div.clients').addClass('active');
			if (Browser.Engine.trident){$$('div.footer').innerHTML+='';}
		});
	}
	$$('div.logos a').each(function(el){
		el.addEvent('click',function(event){
			event.stop();
			window.open(this.href,'new');
		});
	});
	if ($$('a[rel=photo]')[0]){
		var gallery = new Element('div', {
			'id': 'gallery',
			'html': '<div id="gallery_bg"></div><div id="gallery_cnt"></div>',
			'styles': {
				'width':'100%',
				'height':'100%',
				'position':'absolute',
				'top':0,
				'left':0,
				'display': 'none',
				'z-index':2000
			}
		}).inject(document.body);

		$('gallery').addEvent('click',function(){
			$('gallery').setStyles({'display': 'none'});
			$('gallery_cnt').empty();
			$('gallery_cnt').setStyles({
				'height': 0,
				'width': 0,
				'margin-left': 0,
				'margin-bottom': 0
			});
		});
		$('gallery_bg').setStyles({
			'width':'100%',
			'height':'100%',
			'position':'absolute',
			'top':0,
			'left':0,
			'opacity': '0.2',
			'background': '#000'
		});

		function iebg(){
			if (Browser.Engine.trident){
				$('gallery_bg').setStyle('height',document.body.offsetHeight);
			}
		}
		window.onresize = iebg;
		iebg();
		$('gallery_cnt').setStyles({
			'padding':'10px 10px 10px 10px',
			'position':'absolute',
			'top':'0',
			'left':'50%',
			'background': '#fff'
		});
	}
	$$('a[rel=photo]').each(function(element){
		element.addEvent('click',function(event){
			event.stop();
			gallery.getElement('#gallery_cnt').empty();
			$('gallery').setStyles({'display': 'block'});
			var img = new Asset.image(this.href, {
				onload: function(){
					var effect = new Fx.Morph(gallery.getElement('#gallery_cnt'), {duration: 500, transition: Fx.Transitions.Sine.easeOut}).start({
					    'height': img.height,
					    'width': img.width,
					    'margin-left': (img.width.toInt()/2+5)*(-1),
					    'margin-top': document.getScroll().y+100
					}).chain(function(){
						img.inject($('gallery_cnt'));
						effect.start({
						 	'height': img.height+40
						}).chain(function(){
							var title = new Element('span', {
								'html': element.getElements('img')[0].alt,
								'styles':{
									'display': 'block',
									'margin-top': '0.6em',
									'font-size': '1.2em',
									'color': '#000'
								}
							}).inject($('gallery_cnt'));
						});
					});
				}
			});
		});
	});

	if ($$('#gallery ul.preview')[0]){
		$$('#gallery ul.preview')[0].setStyles({'width': '2500%'});
    if($('smallpic') != null){
      $('gallery').setStyles({'width': '100%'});
    }else{
      $('gallery').setStyles({'overflow': 'hidden', 'width': '100%'});
    }
		var gallery = new Fx.Morph($$('#gallery ul.preview')[0], {duration: 200});
		gallery.start({'margin-left':'0'});
		var active = $$('#gallery ul.preview')[0].getElements('a')[0];

		var counter = $$('#gallery ul.preview')[0].getElements('a').length;
		activenumber = 0;

		k_elem = window;
		if (Browser.Engine.trident){
			k_elem = $$('.container')[0];
		}
		k_elem.addEvent('keydown',function(event){
			if (event.key=='left'){
				if (activenumber>0){
					activenumber--;
					gallery.start({'margin-left':activenumber*(-130)+($('gallery').getSize().x/2)-60});
					$$('#gallery ul.preview')[0].getElements('a').each(function(el){
						if (el!=active){
							el.getParent().removeClass('active');
						}
					});
					if ($$('#gallery ul.preview')[0].getElements('a')[activenumber]!=active){
						$$('#gallery ul.preview')[0].getElements('a')[activenumber].getParent().addClass('active');
					}
				}
			}
			if (event.key=='right'){
				if (activenumber<counter-1){
					activenumber++;
					gallery.start({'margin-left':activenumber*(-130)+($('gallery').getSize().x/2)-60});
					$$('#gallery ul.preview')[0].getElements('a').each(function(el){
						if (el!=active){
							el.getParent().removeClass('active');
						}
					});
					if ($$('#gallery ul.preview')[0].getElements('a')[activenumber]!=active){
						$$('#gallery ul.preview')[0].getElements('a')[activenumber].getParent().addClass('active');
					}
				}
			}
			if (event.key == 'enter'){
				el = $$('#gallery ul.preview')[0].getElements('a')[activenumber];
				active = el;
				el.removeEvents('');
				el.getParent().addClass('active');
				$('active').empty().addClass('load');
				var Img = new Asset.image(el.href, {
					'title': el.getElements('img')[0].title,
					'alt': el.getElements('img')[0].alt,
					onload: function(){
						$('active').empty();
						$('active').removeClass('load');
						Img.inject($('active'));
						preview();
					}
				});
			}
			event.stop();
		});

		function preview(){
			$$('#gallery ul.preview')[0].getElements('a').each(function(el){
				if (el!=active){
					el.removeEvents('');
					el.getParent().removeClass('active');
					el.addEvent('click', function(event){
						activenumber = $$('#gallery ul.preview')[0].getElements('a').indexOf(this);
						gallery.start({'margin-left':activenumber*(-130)+($('gallery').getSize().x/2)-60});
						active = el;
						event.stop();
						el.removeEvents('');
						this.getParent().addClass('active');
						var flag = false;
						if (this.getParent().hasClass('vert')) {
							flag = true;
						}
						$('active').empty().addClass('load');
						var Img = new Asset.image(el.href, {
							'title': el.getElements('img')[0].title,
							'alt': el.getElements('img')[0].alt,
							onload: function(){
								var ititle = el.getElements('img')[0].title;
								$('active').removeClass('load');
								$('active').empty();
								if (flag) {
									$('active').addClass('vert');
								} else {
									$('active').removeClass('vert');
								}
								if (ititle!=''){
									$('active').innerHTML = '<cite>'+ititle+'</cite>';
								}
								Img.inject($('active'));
								
								preview();
							}
						});
					});
				}else{
					el.addEvent('click', function(event){event.stop();});
				}
			});
		}
		preview();
	}



	if(Browser.Engine.trident4){
		if ($$('a.logo img')[0]){
			$$('a.logo img')[0].src='/assets/templates/mp/i/blank.gif';
			$$('a.logo img')[0].setStyles({'filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="scale", src="/assets/templates/mp/i/logo.png")'});
		}
		if ($$('img.logo')[0]){
			$$('img.logo')[0].src='/assets/templates/mp/i/blank.gif';
			$$('img.logo')[0].setStyles({'filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="scale", src="/assets/templates/mp/i/logo.png")'});
		}
		if ($$('.cnt-footer-auth img')[0]){
			$$('.cnt-footer-auth img')[0].src='/assets/templates/mp/i/blank.gif';
			$$('.cnt-footer-auth img')[0].setStyles({'filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="scale", src="/assets/templates/mp/i/imm-logo.png")'});
		}

		if ($$('#s1 img')[0]){
			$$('#s1 img')[0].src='/assets/templates/mp/i/blank.gif';
			$$('#s1 img')[0].setStyles({'filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="scale", src="/assets/templates/mp/i/1.png")'});

			$$('#s2 img')[0].src='/assets/templates/mp/i/blank.gif';
			$$('#s2 img')[0].setStyles({'filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="scale", src="/assets/templates/mp/i/2.png")'});

			$$('#s3 img')[0].src='/assets/templates/mp/i/blank.gif';
			$$('#s3 img')[0].setStyles({'filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="scale", src="/assets/templates/mp/i/3.png")'});

			$$('#s4 img')[0].src='/assets/templates/mp/i/blank.gif';
			$$('#s4 img')[0].setStyles({'filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="scale", src="/assets/templates/mp/i/4.png")'});

			$$('#s5 img')[0].src='/assets/templates/mp/i/blank.gif';
			$$('#s5 img')[0].setStyles({'filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="scale", src="/assets/templates/mp/i/5.png")'});

			$$('#s6 img')[0].src='/assets/templates/mp/i/blank.gif';
			$$('#s6 img')[0].setStyles({'filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="scale", src="/assets/templates/mp/i/6.png")'});

			$$('#s7 img')[0].src='/assets/templates/mp/i/blank.gif';
			$$('#s7 img')[0].setStyles({'filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="scale", src="/assets/templates/mp/i/7.png")'});
		}
	}
	if ($('scontainer')){
		$('scontainer').setStyles({'overflow':'hidden'});


		var ef = new Fx.Morph('services', {duration:500});
		var sleft = -800;

		var active = $('s4');
		var activehint = active.getElements('p.hint')[0];

		active.setStyle('z-index',1000);
		var sf = new Fx.Morph(active, {duration:500}).start({
			'margin-left': -50,
			'margin-top': -80,
			'width': 300,
			'height': 462
		}).chain(function(){
			activehint.setStyles({'display': 'block'});
		});

		var sff = '';
		function zoom(element,index,resize){
			if (element!=active){
				if (sff){
					sff.cancel();
				}
				if (sf){
					sf.cancel();
				}
				sf.start({
					'margin-left': 0,
					'margin-top': 0,
					'width': 200,
					'height': 308
				});
				active.setStyle('z-index',0);
				active = element;
				active.setStyle('z-index',1000);
				activehint.setStyles({'display': 'none'});
				activehint = active.getElements('p.hint')[0];
				sleft = (index+1)*(-200);
				ef.start({'left': sleft}).chain(function(){
					sf = new Fx.Morph(active, {duration:500}).start({
						'margin-left': -50,
						'margin-top': -80,
						'width': 300,
						'height': 462
					}).chain(function(){
						activehint.setStyles({'display': 'block'});
					});
				});
			}else{
				if (!resize){
					window.location = element.getElements('a')[0].href;
				}
			}
		}

		function resize(){
			zoom(active,0,true);
		}
		window.onresize = resize;

		$$('#services>div').each(function(element,index){
			element.getElements('a')[0].addEvent('click',function(event){
				event.stop();
				zoom(element,index,0);
			});
			element.addEvents({
				'mouseenter':function(){
					if (this!=active){
						var sff = new Fx.Morph(this, {duration:100}).start({
							'margin-left': -10,
							'margin-top': -15,
							'width': 220,
							'height': 338
						});
					}
				},
				'mouseleave':function(){
					if (this!=active){
						var sff = new Fx.Morph(this, {duration:100}).start({
							'margin-left': 0,
							'margin-top': 0,
							'width': 200,
							'height': 308
						});
					}
				}
			});
		});
	}
});



