
/**funcs*/

if(console=='undefined'||Object.isUndefined(console)){
	var console = {};
	console.log = function(mess){
		alert(mess);
	};
}


function $_GET(q,s) {
    s = (s) ? s : window.location.search;
    var re = new RegExp('&'+q+'=([^&]*)','i');
    return (s=s.replace(/^\?/,'&').match(re)) ? s=s[1] : s='';
}

function activeMenu() {
try{
	['tv','tablo','butplay','butpause','preloader','contentContainer','pageMenu'].each(function(el){
		$(el).hide();
	});
	
	galleryMode =false;
	overed=false;
	
	Try.these(function(){
		flash = !supportsVideo();
		
		var playVideo= function(element){
			if(flash){
				$(element).tocPlay();
				$(element).paused=false;
				}
			else $(element).play();
		};
		
		var pauseVideo= function(element){
			if(flash){
				$(element).tocPause();
				$(element).paused=true;
				}
			else $(element).pause();
		};
		
		$('banner').observe("ended",function(event){
			Try.these(function(){$('repl').parentNode.removeChild($('repl'));});
		$('banner').parentNode.insert("<img id='repl' src='images/main/play.png' class='banner_control_button'/>");
		overed=true;
		$('repl').onclick=function(){
			overed=false;
			playVideo($('banner'));
			$('repl').fade({duration:0.2});
			setTimeout(function(){$('repl').parentNode.removeChild($('repl'));},200);
		}.bind(this);
	}.bind(this));
	
	
		$('banner').observe("mouseover",function(event){
			if(!overed){
				if(!$('banner').ended){
					if(!$('banner').paused){
						$('banner').parentNode.insert("<img id='repl' src='images/main/stop.png' style='z-index:10;' class='banner_control_button'/>");
						$('repl').onclick=function(){
							pauseVideo($('banner'));
							$('repl').fade({duration:0.2});
							setTimeout(function(){
								overed=false;
								Try.these(function(){$('repl').parentNode.removeChild($('repl'));});
								},200);
						}.bind(this);
					}
					else{
						$('banner').parentNode.insert("<img id='repl' src='images/main/play.png' style='z-index:10;' class='banner_control_button'/>");
						$('repl').onclick=function(){
							playVideo($('banner'));
						
						$('repl').fade({duration:0.2});
						setTimeout(function(){
							overed=false;
							Try.these(function(){$('repl').parentNode.removeChild($('repl'));});
							},200);
						}.bind(this);
					}
				}
				else{
					Try.these(function(){$('repl').parentNode.removeChild($('repl'));});
					$('banner').parentNode.insert("<img id='repl' src='images/main/play.png' style='z-index:10;' class='banner_control_button'/>");
					$('repl').onclick=function(){
						playVideo($('banner'));
						$('repl').fade({duration:0.2});
						setTimeout(function(){
							overed=false;
							Try.these(function(){$('repl').parentNode.removeChild($('repl'));});
							},200);
					}.bind(this);
				}
			}
		}.bind(this));
	
		$('banner').observe("mouseout",function(event){
			if(!Object.isUndefined(event)&&Object.isElement($('repl'))){
				if(event.pointerY()>$('repl').cumulativeOffset().top&&event.pointerY()<($('repl').cumulativeOffset().top+115)&&event.pointerX()>(document.viewport.getWidth()/2 - 60)&&event.pointerX()<(document.viewport.getWidth()/2 + 45)){
					event.stop();
					overed=true;
				}
				else{
					overed=false;
					Try.these(function(){$('repl').parentNode.removeChild($('repl'));});
				}
			}
		});
		
		$('banner').paused=false;
		
	}.bind(this));
	
    }
    catch(err){
    console.log(err);
    }
}

/**EOF funcs*/

var startGallery = Class.create({
	initialize: function(options) {
		try{
			this.options = {
					images:		Array(),
					contents: 	Array(),
					duration:	1.0,
			    	text:   	Array(),
			    	imagesText:	Array(),
			    	imgContainer: {},
			    	contentContainer:{}
			};
			    Object.extend(this.options, options || { });
			    
			    this.state.imgContainer = {};
			    var offset = this.options.imgContainer.cumulativeOffset();
			    this.state.imgContainer.top = offset.top; 
			    this.state.imgContainer.left = offset.left;
			    this.state.animating = 0;
			    if($_GET('gallery')){
			    	  this.contentInjection('1');
						this.deactivate('1');
						this.showLoading('1.mov');
						this.activeElement = 'img1';
						$('imagesText').hide();
						setTimeout(function(){
							this.iconOverAnimation($('img1'),true);
							}.bind(this),900);
			    	
			    }
			    
			    $('gallerySwitcher').observe("click",
				    function(){
			    	window.location = "kp3d_3dgallery.html";
					}.bind(this));
			    setTimeout(function(){
			    	this.startGalleryRun();
			    }.bind(this),500);
			   setTimeout(function(){ $('loader').fade();},2000);
		}
		catch(err){
			console.log(err);
		}
	},
	
	imageElements:Array(),
	
	state: {},
	
	activeTextInterval: false,
	
	updateTime: false,
	
	activeElement: false,
	
	playVideo: function(element){
		if(flash) {
        setTimeout(function(){
			$(element).tocPlay();
			$(element).paused=false;
            }.bind(this),200);
		}
		else $(element).play();
	},
	
	pauseVideo: function(element){
		if(flash){
        setTimeout(function(){
			$(element).tocPause();
			$(element).paused=true;
             }.bind(this),200);
			}
		else $(element).pause();
	},
	
	returnCanplayEvent: function(){
		if(flash) return "player:canplay";
		else return "canplay";
	},
	
	createImages: function(){
		try{
		var i = 1;
		
		this.options.images.each(function(img){
			
			var right = 0;
			var top = 0;
			switch(i){
			/**	from Max:
			 * 	1: 2 px right, 6 px down
				2: 4 px down
				3: 1 px down, 1 px right 
				4: 1 px down, 1 px right 
				5:  3 px left
				6:  2 px right*/
				case 1:
					
					right = 2;
					top= 6;
				break;
				
				case 2:
					
					right =0;
					top = 4;
				break;
				
				case 3:
					right = 1;
					top = 1;
					break;
					
				case 4:
					right = 1;
					top = 1;
					break;
					
				case 5:
					right = -3;
					top = 0;
					break;
					
				case 6:
					right = 2;
					top = 0;
					break;
					
				case 7:
					right = 0;
					top = -8;
					break;
					
				case 8:
					right = 0;
					top = 2;
					break;
				default:
					right = 0;
					top = 0;
					break;
						
			}
			
			var image = new Element('img', {src:img, id:'img'+i,
											style:"cursor:pointer;position:relative;z-index:9999999;" +
													"top:15px;"+
													"left:5px;"+
													"width:66px;" +
													"height:59px;" +
													"margin-top:"+top+"px;" +
													"margin-left:"+right+"px;"});
			this.state[image.id]={};
			this.imageElements.push(image);
			i++;
		}.bind(this));
		return this.imageElements;
		}
		catch(err){
			console.log(err);
		}
	},
	
	createEmbed: function(id){
		if(!flash){
		var video = new Element("video",{
										preload: "auto",
										controls:false,
										id:id+'.mov',
										style:	"position:absolute;z-index:1;" +
												"background-color:transparent;" +
												"overflow:hidden;"+
												"margin-top:69px;" +
												"margin-left:256px;" +
												"width:405px;" +
												"height:282px;"});
		var sources = new Array({src:"http://www.mackiev.net/kidpix/video/index_"+id+".mov",type:"video/quicktime"},
								{src:"http://www.mackiev.net/kidpix/video/index_"+id+".ogg",type:"video/ogg"});
		sources.each(function(el){
				video.insert('<source src="'+el.src+'" type="'+el.type+'"></source>');
			}.bind(this));
		}
		else{
			
								/*var video = new Element("OBJECT",{	name:id + ".mov",
														type: "application/x-shockwave-flash",
														data: "flash/player.swf",
														id: id+'.mov',
														style: "position:absolute;z-index:1; background-color:transparent;overflow:hidden;margin-top:70px;margin-left:256px;width:405px;height:282px;"
														
														});
								video.innerHTML = '<param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><param name="wmode" value="transparent"><param name="movie" value="flash/player.swf"><param name="flashvars" value="src=../video/index_'+id+'.mov&id='+id+'.mov">';*/
								
								
			var video = '<object width="242" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="'+id+'.mov"  type="application/x-shockwave-flash" data="flash/player.swf?'+ new Date().getTime() +'" id="'+id+'.mov"'+ 
						'style="position:absolute;z-index:1; background-color:transparent;overflow:hidden;margin-top:70px;margin-left:256px;width:405px;height:282px;">'+
						'<param name="allowFullScreen" value="true"/>'+
						'<param name="allowScriptAccess" value="always"/>'+ 
						'<param name="wmode" value="transparent"/>'+
						'<param name="movie" value="flash/player.swf?'+ new Date().getTime() +'"/>'+
						'<param name="flashvars" value="src=../video/index_'+id+'.mov&id='+id+'.mov"/>'+
						'</object>';
			
		}
		
		this.currentVideo =id;
		return video;	

	},
	
	addObservers: function(element){
		$(element).observe("mouseenter",function(){this.iconOverAnimation(element);}.bind(this));
		$(element).observe("mouseleave",function(){this.iconOutAnimation(element);}.bind(this));
		$(element).observe("click",function(){
			if(!$("contentC"+(element.id.substr(3,element.id.length)-1))){
				
				if(this.updateTime) clearInterval(this.updateTime);
			 
				this.contentInjection(element.id.substr(3,element.id.length));
				this.deactivate(element.id.substr(3,element.id.length));
				this.showLoading(element.id.substr(3,element.id.length)+'.mov');
				this.activeElement = element.id;
			}
			}.bind(this));
	},
	
	showLoading: function(id){
		try{
		$('tablo').style.textAlign = 'center';
		$('tablo').update('--:-- / --:--');
		if(!galleryMode){
			/***/
			
			if(!flash&&Object.isElement($('banner')))setTimeout(function(){$('banner').pause();},500);
			else setTimeout(function(){
				$('zaglushka').parentNode.removeChild($('zaglushka'));
				},2000);
			$("zaglushka").fade({duration:0.2});
			$('tablo').appear();
			$('butplay').appear();
			$('butpause').appear();
			$("tv").appear();
			$("contentContainer").appear();
			$('pageMenu').appear();
			
			setTimeout(function(){
				
				var offset = this.options.imgContainer.cumulativeOffset();
			    this.state.imgContainer.top = offset.top; 
			    this.state.imgContainer.left = offset.left;
			    this.state.animating = 0;
			}.bind(this),1000);
			/***/
			galleryMode = true;
			setTimeout(function(){$('preloader').appear({duration:1.2});},500);
		}
		else{
			$('preloader').show();
		}
		$('preloader').style.zIndex=90;
			$(id).observe(this.returnCanplayEvent(),function(event){
            setTimeout(function(){
					this.canPlayFunc(id);
                    }.bind(this),1000);
			}.bind(this));
		}
		catch(err){
			console.log(err);
		}
	},
	
	canPlayFunc: function(id){
		this.animatingButton = false;
		
		$('preloader').fade();
		
		setTimeout(function(){
			if(!this.animatingButton){
				$('butpause').appear({duration:0.1});
				$('butplay').fade({duration:0.1});
				(!flash)?$(id).play():setTimeout(function(){Prototype.emptyFunction();},10);
			}
			}.bind(this),1200);
		
		$('butplay').onclick = function(){
			if(!this.animatingButton){
				this.animatingButton = true;
				this.pauseAppearAnimation();
				setTimeout(function(){this.playVideo($(id));}.bind(this),200);
				setTimeout(function(){this.animatingButton = false;}.bind(this),2000);
			}
			}.bind(this);
		
		$('butpause').onclick = function(){
			if(!this.animatingButton){
				this.animatingButton = true;
				this.playAppearAnimation();
				setTimeout(function(){this.pauseVideo($(id));}.bind(this),200);  
				
				setTimeout(function(){this.animatingButton = false;}.bind(this),2000);
			}
		}.bind(this);
		
		this.updateTime = setInterval(function(){
			if(!Object.isElement($(id))||$(id).isNull)clearInterval(self);
			else{
				/**GETTING duration and current time*/
				if(flash){
					if(Object.isFunction($(id).duration)) var duration = $(id).duration();
					else var duration = 0;
					if(Object.isFunction($(id).currentTime)) var currentTime = $(id).currentTime();
					else var currentTime = 0;
				}
				else{
					var duration = $(id).duration;
					var currentTime = $(id).currentTime;
				}
				/**EOF*/
				$('tablo').update(this.parseTime(currentTime) + '/' + this.parseTime(duration));
				
				if($(id).ended){
					$('butpause').hide();//fade({duration:0.2});
					$('butplay').appear({duration:0.2});
					
				}
			}
			}.bind(this),300);
	},
	
	pauseAppearAnimation: function(){
		if(flash){
			$('butplay').hide();
			$('butpause').show();
		}
		else{
			$('butplay').fade({duration:0.1});
			$('butpause').appear({duration:0.1});
		}
		
	},
	
	playAppearAnimation: function(){
		if(flash){
			$('butplay').show();
			$('butpause').hide();
		}
		else{
			$('butplay').appear({duration:0.1});
			$('butpause').fade({duration:0.1});
		}
		
	},
	
	parseTime: function(time){
			if(!Object.isNumber(time)) time =0;
			var secondsVal = Math.round(time);
			var minutes = Math.floor(secondsVal/60);
			var seconds = secondsVal - minutes *60;
			if(minutes.toString().length <2) minutes = "0"+minutes;
			if(seconds.toString().length <2) seconds = "0"+seconds;
			return minutes + ":" + seconds;	
		},
		
	deactivate: function(id){
			try{
        $('imagesText').update(this.options.imagesText[id-1]);
     
        if(this.activeElement&&!Object.isUndefined($(this.activeElement))){
			if(this.activeElement.substr(3,this.activeElement.length)!=id){
				var element = $(this.activeElement);	
				new Effect.Morph(element.id, { 
					queue:{ scope:'iconsMorph'+element.id,position:'end'},
					style: "width:66px;height:59px;", 
					duration: 0.1  
			}); 
		
			new Effect.Move(element,{x:5,y:15,mode:'absolute',
				duration:0.1,
				queue:{ scope:'icons'+element.id,position:'end'},
				afterFinish: function(effect) {this.state[element.id].animating =0;
					this.state[element.id].outAnimating=0;
				}.bind(this)});
			
		}
		}
	}
			catch(err){
				
				console.log(err);
			}
	},
	
	iconOverAnimation: function(element,outerCall){
		
		if(Object.isUndefined(outerCall)) outerCall=false;
		if('img'+this.currentVideo != element.id || outerCall){
			var timestamp = new Date().getTime();
        	this.timestamp = timestamp;
			setTimeout(
				function(){
					if(this.timestamp - new Date().getTime()<=81){
						this.timestamp = timestamp;
						var offset = element.cumulativeOffset();
		
						if(offset.top >= this.state.imgContainer.top&&element.style.width == '66px'){
							if(this.state[element.id].overAnimating!=1&&this.state[element.id].outAnimating!=1){
								this.state[element.id].animating=1;
								this.state[element.id].overAnimating=1;
								function morph(){
                					/*Adding title*/
                    				$('imagesText').hide();
                       				// $('imagesText').style.top = this.state.imgContainer.top + 50 +'px';
                       				$('imagesText').style.left = (offset.left -65 - $("body_player").cumulativeOffset()[0]) +'px';
                        			$('imagesText').update(this.options.imagesText[element.id.substr(3,element.id.length)-1]);
                       				if(!flash) 	$('imagesText').appear({duration:0.5});
                       				else 		$('imagesText').show();
                
									new Effect.Morph(element.id, { 
										queue:{ scope:'iconsMorph'+element.id,position:'end'},
										style: "width:80px;height:72px;", 
										duration: 0.1 
									});
								} 
								morph.bind(this).defer();
								if(element.id.substr(3)==5){moveX=-7;}
								else moveX = -5;
			
				
								new Effect.Move(element,{
									x:moveX,
									y:-15,
									mode:'relative',
									duration:0.1,
									queue:{ 
										scope:'icons'+element.id,
										position:'end'
									},
									afterFinish: function(effect) {
										this.state[element.id].animating =0;
										this.state[element.id].overAnimating=0;
									}.bind(this)
								});
							}
						}
					}
				}.bind(this),80);
		}else{
            setTimeout(
				function(){
                    if(this.timestamp - new Date().getTime()<=81){
						this.timestamp = timestamp;
		            	var offset = element.cumulativeOffset();
		            	$('imagesText').hide();
		           		//$('imagesText').style.top = this.state.imgContainer.top + 50 +'px';
		            	$('imagesText').style.left = (offset.left - 58 - $("body_player").cumulativeOffset()[0]) +'px';
		            	$('imagesText').update(this.options.imagesText[element.id.substr(3,element.id.length)-1]);
		            	if(!flash) 	$('imagesText').appear({duration:0.5});
                    	else 		$('imagesText').show();

                    }
				}.bind(this),80);
        }
	},
	
	iconOutAnimation: function(element){
		if(this.currentVideo != element.id.substr(3)){
        	$('imagesText').update();
			if(this.timestamp - new Date().getTime()<=82){
				var offset = element.cumulativeOffset();
				this.state[element.id].animating=1;
				this.state[element.id].outAnimating=1;
				$('imagesText').update();
				setTimeout(
					function(){
						new Effect.Morph(element.id, { 
							queue:{ scope:'iconsMorph'+element.id,position:'end'},
							style: "width:66px;height:59px;", 
							duration: 0.1  
						}); 
						new Effect.Move(element,{
							x:5,
							y:15,
							mode:'absolute',
							duration:0.1,
							queue:{ 
								scope:'icons'+element.id,
								position:'end'
							},
							afterFinish: function(effect) {
								this.state[element.id].animating =0;
								this.state[element.id].outAnimating=0;
							}.bind(this)
						});
			
					
					}.bind(this),
				33);
				/**Active element title must appear again*/ 	
				this.showActiveTitle();
		     	/**EOF*/
			}else{
        		this.timestamp = new Date().getTime();
        		this.showActiveTitle();
        	}
		}
	},
	
	showActiveTitle: function(){
		if(this.activeElement){
			 var offset = $(this.activeElement).cumulativeOffset();
	            $('imagesText').hide();
	         //   $('imagesText').style.top = this.state.imgContainer.top + 50 +'px';
	            $('imagesText').style.left = (offset.left - 58 - $("body_player").cumulativeOffset()[0]) +'px';
	            $('imagesText').update(this.options.imagesText[this.activeElement.substr(3,this.activeElement.length)-1]);
	            if(!flash) 	$('imagesText').appear({duration:0.5});
               else 		$('imagesText').show();
		}
	},
	
	contentInjection: function(id){
		var obj =  this.createEmbed(id); 
		this.inject(obj,id);
		
	},
	
	
	inject: function(obj,id){
		var swf =  this.options.contents[id];
		var cont = new Element('div', {id:"contentC"+(id-1)
							});
		var textContainer = new Element('div', {id:"contentC"+(id-1)+"text",
												className:"text_container"
												
												});
		textContainer.insert(this.options.text[(id-1)]);
		cont.insert(textContainer);
		cont.insert(new Element("div",{style:	"position:absolute;z-index:1;" +
												"background-color:#000;" +
												"overflow:hidden;"+
												"margin-top:80px;" +
												"margin-left:255px;" +
												"width:405px;" +
												"height:282px;"}));
		cont.insert(obj);
		cont.hide();
		$(this.options.contentContainer).insert(cont);
		this.contentTransition(cont);
	},
		
	contentTransition: function(cont){
		$($(this.options.contentContainer).firstDescendant().id).fade({duration:0.5});
		setTimeout(function(){
			$($(cont.id).firstDescendant().id).appear({duration:0.2});
			$(cont.id).show();
		}.bind(this),500);
	
		
		setTimeout(function(){
			$(this.options.contentContainer).removeChild($(this.options.contentContainer).firstDescendant());
			}.bind(this),500);
		
	},
	
	startGalleryRun: function(){
		var images = this.createImages();
		
		images.each(function(img){
						var imgWrapper = new Element('div',{'class':'imgBlock'});	
						
						imgWrapper.insert(img);
						$(this.options.imgContainer).insert(imgWrapper);
						setTimeout(function(){this.state[img.id].realWidth = img.getWidth();
						this.state[img.id].outAnimating = 0;
						this.state[img.id].overAnimating = 0;
						this.state[img.id].animating = 0;
						}.bind(this),33);
	
						this.addObservers(img);
						
					}.bind(this));
	}
});




var startNewVideoGallery = Class.create({
	
	initialize: function(options) {
		try{
			this.options = {
					images:		Array(),
					contents: 	Array(),
					duration:	1.0,
			    	text:   	Array(),
			    	imagesText:	Array(),
			    	imgContainer: {},
			    	contentContainer:{}
			};

			    Object.extend(this.options, options || { });
			    this.flash = !this.supportsVideo();
			    this.currentVideo =1;
			    this.images = Array();
			    this.startGalleryRun();
			    setTimeout(function(){ $('loader').fade();},1500);
			 
		}
		catch(err){
			console.log(err);
		}
	},
	
	supportsVideo: function() {
			  if(!!document.createElement('video').canPlayType == false) return false;
			  else if(document.createElement('video').canPlayType('video/ogg') ==''&&document.createElement('video').canPlayType('video/quicktime') =='') return false;
			  else return true;
	},
	
	timestamp: false,
	
	firstLoaded: true,
	
	activeElement: 1,
	
	currentVideo: 1,
	
	state: {},
	
	startGalleryRun: function(){
		try{
			var i = 1;
			$(this.options.imgContainer).setStyle(
					"width:500px;" +
					"margin-top:-100px;" +
					"position:relative;" +
					"z-index:5;");
			
			Element.prototype.smallSize = function (id){
				if(this.id!=id){
					this.style.width = '83px';
					this.style.height = '63px';
					this.style.marginTop = '5px';
					this.style.marginLeft = '5px';
				}
			};
			
			this.options.images.each(function(el){
				var img = new Element("img",{src:el,
					width:83,
					id:i,
					alt:'',
					border:0,
					align:'left',
					style:"margin:5px;" +
							"position:absolute;" +
							"left:"+ (20+(98*i)-120) +"px;"
							});
				this.images.push(img);
				$(this.options.imgContainer).insert(img);
				this.imgObserve(img);
				i++;
			}.bind(this));

			this.state['imgContainer'] = $(this.options.imgContainer).cumulativeOffset();
			
			var video = this.createEmbed(this.currentVideo);
			var videoContainer = new Element("div",{
											id: 	"videoContainer",
											className:	"video_container"
			});
			videoContainer.insert(video);
			videoContainer.insert("<div id='loading' style='position: absolute;top:0px; z-index: 997;'>" +
					"<img src='images/main/bg-noise.png' width='594' height='450'>" +
					"<img src='images/main/preloader.gif' class='gal_preloader'></div>");
			$('newTV').insert(videoContainer);
			
			
			if(this.flash){
				document.observe("player:canplay",function(event){
						setTimeout(function(){if(Object.isElement($('loading')))$('loading').fade();},2000);
					});
			}
			else{
				$(video).observe("canplay",function(event){
					setTimeout(function(){$(video).play();}.bind(this),1500);
					$('loading').fade();
				}.bind(this));
			}
			
			setTimeout(function(){
				this.setClickTransitions('1');
				this.updateText('1');
			}.bind(this),1500);
		}
		catch(err){
			console.log(err);
		}
	},
	
	imgObserve: function(img){
		$(img).observe("click",function(){
			if(!this.inProgress&&this.currentVideo!=$(img).id){
			this.setClickTransitions($(img).id);
			this.setVideo($(img).id);
			}
		}.bind(this));
		
		$(img).observe("mouseover",function(){
			this.setOverTransitions($(img).id);
		}.bind(this));
		
		$(img).observe("mouseout",function(){
			this.setOutTransitions($(img).id);
		}.bind(this));
	},
	
	setClickTransitions: function(id){
		if(!this.firstLoaded&&!this.flash){
			$(this.currentVideo+'.mov').innerHTML="<source/>";
			$(this.currentVideo+'.mov').load();
			$(this.currentVideo+'.mov').stopObserving();
		}
		this.inProgress = true;
		this.activeElement=id;
		
		this.makeSmallImages(id);
		
		if($(id).style.width !='100px'){
			new Effect.Morph($(id), { 
				queue:{ scope:'iconsMorph'+id,position:'end'},
				style: "width:94px;height:71px;margin-top:-5px;margin-left:0px", 
				duration: 0.3 
			});
		}
		
		new Effect.Move($('shadowContainer').firstDescendant(),{
			x:((98*id)-107),
			mode:'absolute',
			duration:0.6,
			queue:{ scope:'icons'+id,position:'end'},
			afterFinish: function(effect) {
				this.inProgress =false;
						}.bind(this)
			});
		
		this.firstLoaded =false;
	},
	
	setOverTransitions: function(id){
			try{
			if(this.currentVideo != id){
				this.Morph = new Effect.Morph($(id), { 
							queue:{ scope:'iconsMorph'+id,position:'end'},
							style: "width:94px;height:71px;margin-top:-5px;margin-Left:0px;", 
							duration: 0.132 
						});
				
				
			}
			this.activeElement = id;
			/**Showing Title*/
			 this.updateText(id);
	        /**EOF*/
			}
			catch(err){
				console.log(err);
			}
	},
	
	setOutTransitions: function(id){
		if(!Object.isUndefined(this.Morph)) this.Morph.cancel();
		if(this.currentVideo != id){
			this.makeSmallImages(this.currentVideo);
		}
		
		this.updateText(this.currentVideo);
	},
	
	
	updateText: function(id){
		try{
			
		var offset = $(id.toString()).cumulativeOffset();
        $('imagesText').hide();
        //$('imagesText').style.top = this.state.imgContainer.top + 50 +'px';
        $('imagesText').style.left = (offset.left - $("newTV").cumulativeOffset()[0] - 55) +'px';
        $('imagesText').update(this.options.imagesText[id-1]);
        if(!this.flash)	$('imagesText').appear({duration:0.5});
        else			$('imagesText').show();
		}
		catch(err){
			console.log(err);
		}
	},
	
	setVideo: function(id){
		this.currentVideo = id;
		var vid = this.createEmbed(id);
		$('videoContainer').firstDescendant().fade({duration:0.9});
		setTimeout(function(){
			$('videoContainer').update(vid);
			$('videoContainer').insert("<div id='loading' style='position: absolute;top:0px; z-index: 997;'>" +
					"<div class='loading'>Loading</div>" +
					"<img src='images/main/bg-noise.png' width='594' height='450'>" +
					"<img src='images/main/preloader.gif' class='preloader'></div>");
			$('videoContainer').firstDescendant().appear({duration:0.5});
			
			if(!this.flash){
				$(vid).observe("canplay",function(event){
					$(vid).pause();
					setTimeout(function(){
						if(!Object.isUndefined(vid)&&Object.isElement($(vid)))
							$(vid).play();
					}.bind(this),1500);
					$('loading').fade();
				}.bind(this));
			}
			
		}.bind(this),500);
	},
	
	createEmbed: function(id){
		if(!this.flash){
			var video = new Element("video",{
				preload: "auto",
				controls:true,
				id:id+'.mov',
				style:	"position:relative;" +
						"background-color:transparent;" +
						"width:594px;" +
						"height:450px;"+
						"-moz-border-radius:5px;" +
						"-webkit-border-radius:5px;" });
			var sources = new Array("http://www.mackiev.net/kidpix/video/"+id+".mov",
									"http://www.mackiev.net/kidpix/video/"+id+".ogg");
			sources.each(function(el){
			video.insert("<source src='"+el+"'>");
			}.bind(this));
		}
		else{
			var video = '<object width="242" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" type="application/x-shockwave-flash" data="flash/player.swf" id="'+id+'.mov"'+ 
						'style="position:relative;background-color:transparent;width:594px;height:450px;">'+
						'<param name="allowFullScreen" value="true">'+
						'<param name="allowScriptAccess" value="always">'+
						'<param name="wmode" value="transparent">'+
						'<param name="movie" value="flash/player.swf">'+
						'<param name="flashvars" value="src=http://www.mackiev.net/kidpix/video/'+id+'.mov&id='+id+'.mov&controls=true">'+
						'</object>';
		}
		return video;
	},
	
	makeSmallImages: function(id){
		if(Object.isFunction(this.images[0].smallSize)){
				this.images.invoke('smallSize',id);
				}
			
			else{
				this.images.each(function(el){
					if(el.id!=id){
						el.style.width = '83px';
						el.style.height = '63px';
						el.style.marginTop = '5px';
						el.style.marginLeft = '5px';
					}
				}.bind(this));
			}
	}

});

