﻿
window.addEvent('domready', function() {

var listImages = function(id, znak) {

		if (Browser.Engine.trident4) {
			
			iSet = 'gallery'; 
			iNext = 'gallery';
		}
		else 
		{
			iSet = 'imageSet';
			iNext = id;
		}
		if (znak == '+')
		{
			if ($('pageNumber').get('text') == $('pages').get('text'))
			{
				var fnBreak = 1;
			}
		}
		if (znak == '-')
		{
			if ($('pageNumber').get('text') == '1')
			{
				var fnBreak = 1;
			}
		}

		if (fnBreak != 1)
		{
			if (!Browser.Engine.trident4) $(id).set('html', $(iSet).get('html'));
			pN = $('pageNumber').get('text');
			if (znak == '+' ) pN++; else pN--;
			$('pageNumber').set('text', pN);
			$$('#'+ iNext +' img').each(function(item) {
				tempSrc = new String();
				tempSrc = item.get('src');

				tempSrc = tempSrc.replace(/[a-z:_./]+/i, '');
				tempSrc = tempSrc.replace(/[a-z:_./]+/i, '');
				tempSrc = tempSrc.toInt();
				if (znak == '+' ) tempSrc = tempSrc + 25; else tempSrc = tempSrc - 25;
				if (tempSrc < 10) tempSrc = '0' + tempSrc.toString();
				if (tempSrc < 100) tempSrc = '0' + tempSrc.toString();
				item.set('src', 'venice_carnival/design/inspire/' + tempSrc + '.jpg');
				item.getParent().set('href', 'venice_carnival/design/inspire/big/' + tempSrc + '.jpg');
				
			});
			if (!Browser.Engine.trident4)
			{
				myFuture.toElement($(id)).chain(function() {
					$('imageSet').set('html', $(id).get('html'));
					$$("#imageSet a").slimbox();
					mySet.toElement($('imageSet'));
			
				});
			}
			else
			{
				$$("#gallery a").slimbox();
			}
	}
		};
		
		
		var reset = false;

      var menuFx = new Fx.Tween($('menu'),{
         duration: 500,
         link: 'cancel',
         onComplete:function() {
            if(reset) {
               $('menu').setStyle('background-position','0 0');
            }
         }
      });
 

		var myFx = new Fx.Scroll($('centerIn'), {
			duration: 8000,
		    offset: {
		        'x': 0,
		        'y': 0
		    }
		});
		
		var myFuture = new Fx.Scroll($('gallery'), {
		    offset: {
		        'x': 0,
		        'y': 0
		    }
		});


		var mySet = new Fx.Scroll($('gallery'), {
			duration : 0,
		    offset: {
		        'x': 0,
		        'y': 0
		    }
		});

		
		var windowFx = new Fx.Scroll(window, {
		    offset: {
		        'x': 0,
		        'y': 0
		    }
		});

		
		$('downStih').addEvent('mouseenter', function() { 
			//event = new Event(event).stop();
			myFx.toBottom(); 
			$('upStih').setStyle('z-index', '1');
		});
			
		
		$('upStih').addEvent('mouseenter', function() { 
			//event = new Event(event).stop();
			myFx.toTop(); 
		});
		
		$('menu-music').addEvent('mouseenter', function(e) {
			e.stop();
            menuFx.start('background-position','-50px 0');
            reset = false;		
		}).addEvent('click', function() {
			windowFx.toElement('main-music');
			return false;
		});
		
		$('menu-prog').addEvent('mouseenter', function(e) {
			$('menu').setStyle('background-position', '83px 70px');	
			e.stop();
            menuFx.start('background-position','53px 0');
            reset = false;		
	
		}).addEvent('click', function() {
			windowFx.toElement('main-prog');
			return false;
		});



		$('menu-art').addEvent('mouseenter', function(e) {
			$('menu').setStyle('background-position', '188px 70px');	
			e.stop();
            menuFx.start('background-position','208px 0');
            reset = false;	
		}).addEvent('click', function() {
			windowFx.toElement('main-art');
			return false;
		});

		
		$('menu-photo').addEvent('mouseenter', function(e) {
			$('menu').setStyle('background-position', '380px 70px');	
			e.stop();
            menuFx.start('background-position','370px 0');
            reset = false;	
		}).addEvent('click', function() {
			windowFx.toElement('photo');
			return false;
		});
		
		$('menu-video').addEvent('mouseenter', function(e) {
			$('menu').setStyle('background-position', '470px 70px');	
			e.stop();
            menuFx.start('background-position','480px 0');
            reset = false;	
		}).addEvent('click', function() {
			alert('Видео пока не готово, заходите позднее ;)');
			//windowFx.toElement('video');
			return false;
		});
		
		
		$('down-menu-music').addEvent('click', function() {
			windowFx.toElement('main-music');
			return false;
		});
		
		$('down-menu-prog').addEvent('click', function() {
			windowFx.toElement('main-prog');
			return false;
		});



		$('down-menu-art').addEvent('click', function() {
			windowFx.toElement('main-art');
			return false;
		});

		
		$('down-menu-inspire').addEvent('click', function() {
			windowFx.toElement('main-inspire');
			return false;
		});

		
		
		$('toInspire').addEvent('click', function() {
			windowFx.toElement('main-inspire');
			return false;
		});

		$('a_where_tickets').addEvent('click', function() {
			windowFx.toElement('predp');
			return false;
		});

		$('menu-org').addEvent('mouseenter', function(e) {
			$('menu').setStyle('background-position', '547px 70px');	
			e.stop();
            menuFx.start('background-position','587px 0');
            reset = false;	
		});

		$('menu-kont').addEvent('mouseenter', function(e) {
			$('menu').setStyle('background-position', '728px 70px');	
			e.stop();
            menuFx.start('background-position','748px 0');
            reset = false;	
		});


		
		$$('#menu li').addEvent('mouseleave', function(e) {
			e.stop();
			menuFx.start('background-position','0px 70px');

		});
		
		$('gallery_back').addEvent('mouseenter', function() {
			this.src = 'venice_carnival/design/left_arrow_active.gif';
		})
		.addEvent('mouseleave', function() {
			this.src = 'venice_carnival/design/left_arrow.gif';
		})
		.addEvent('click', function() { listImages('imagePast', '-'); });


		$('gallery_next').addEvent('mouseenter', function() {
			this.src = 'venice_carnival/design/right_arrow_active.gif';
		})
		.addEvent('mouseleave', function() {
			this.src = 'venice_carnival/design/right_arrow.gif';
		})
		.addEvent('click', function() { listImages('imageFuture', '+'); });

		mySet.toElement($('imageSet'));

		if (Browser.Engine.trident4)
		{
			$('gallery').set('html', $('imageSet').get('html'));
		}
		

});


