var oImage = new Image;
oImage.src = 'data/themes/pietys/images/phone_car.jpg';
oImage.src = 'data/themes/pietys/images/cgroup.jpg';
oImage.src = 'data/themes/pietys/images/mousetrap.jpg';
oImage.src = 'data/themes/pietys/images/news.jpg';
oImage.src = 'data/themes/pietys/images/two.jpg';

var crewTitles = {
		crew1: "Rytis Saladžius. Aktorius",
		crew2: "Aneta Bublytė. Prodiuserė",
		crew3: "Stefanija Jokštytė. Prodiuserė",
		crew4: "Sigitas Šidlauskas. Aktorius",
		crew5: "Dovilė Šarunytė. Režisieriaus asistentė",
		crew6: "Jurga Jutaitė. Prodiuserė",
		crew7: "Rūta Papartytė. Aktorė",
		crew8: "MONOKLIS. Platintojas",
		crew9: "Julius Zubavičius. Garso režisierius, kompozitorius",
		crew10: "Sigitas Šidlauskas. Aktorius",
		crew11: "Audrius Zelenius. Operatorius",
		crew12: "",
		crew13: "Julius Syčius. Kameros asistentas",
		crew14: "Jonas Tertelis. Režisieriaus aistentas",
		crew15: "Ieva Veiverytė. Scenarijaus tęstinumas",
		crew16: "",
		crew17: "Ona Kvintaitė. Dailininkė",
		crew18: "Jurgita Globytė. Grimerė",
		crew19: "Lukas Dainys. Vykdantysis prodiuseris",
		crew20: "Tomas Smulkis. Režisierius",
		crew21: "Karolis Stankus. Operatrorius",
		crew22: "Gerda Matazinskaitė. Grimerė",
		crew23: "Jurgita Petrulytė. Kostiumų dailininkė"
}



var PageEngine = {

	active: '',
	activeEl: $('#menu-title')[0],
	video1: '<object width="766" height="490"><param name="movie" value="http://www.youtube.com/v/OQEN29dd6Vc&hl=en_US&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/OQEN29dd6Vc&hl=en_US&fs=1&rel=0&showinfo=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="766" height="490"></embed></object>',
	video2: '<object width="766" height="490"><param name="movie" value="http://www.youtube.com/v/ytesN68XLWE&hl=en_US&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ytesN68XLWE&hl=en_US&fs=1&rel=0&showinfo=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="766" height="490"></embed></object>',
	video3: '<object width="766" height="490"><param name="movie" value="http://www.youtube.com/v/mzWLnqHWVVo&hl=en_US&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/mzWLnqHWVVo&hl=en_US&fs=1&rel=0&showinfo=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="766" height="490"></embed></object>',
	video: '',
	videoName: 'video1',
	changeTitle: function(el) {
		if ((el.id == 'begining1') || (el.id == 'menu-title') || (el.id == 'begining2') || (el.id == 'home') || (el.id == 'home1') || (el.id == 'next-video') || (el.id == 'prev-video')) {
			 this.active = '';
			 PageEngine.uNmarkActive();
			 return;
		}
		this.activeEl = el;
		this.active = el.id;
		PageEngine.markActive();
	},

	markActive: function () {
		$('#menu-title')[0].style.color = '#FFFFFF';
		$('.menu-item').css({'color':'#FFFFFF'});
		PageEngine.activeEl.style.color = '#000000';
	},

	uNmarkActive: function () {
		$('.menu-button').css({'color':'#FFFFFF'});
	},
	
		
	changePage: function (id) {
		if (this.active == id) return;
		switch(id) {
			case 'filmo-aprasymas':
				PageEngine.gotoAboutMovie();
				break;
			case 'platintojas':
				PageEngine.gotoMonoklis();
				break;
			case 'kurybine-grupe':
				PageEngine.gotoAboutTeam();
				break;
			case 'foto':
				PageEngine.showGallery();
				break;
			case 'video':
				PageEngine.showVideo();
				break;
			case 'media':
				PageEngine.changeToThirdMenu();
				break;
			case 'menu-title':
				PageEngine.changeToSecondMenu();
				break;
			case 'home':
				PageEngine.goToHomeFromGallery();
				break;
			case 'home1':
				PageEngine.goToHomeFromVideo();
				break;
			case 'news':
				PageEngine.goToNews();
				break;
			case 'begining1':
				PageEngine.goToBegining();
				break;
			case 'begining2':
				PageEngine.goToBegining();
				break;
			case 'prev-video':
				PageEngine.handleVideoNav();
				break;
			case 'next-video':
				PageEngine.handleVideoNav();
				break;
		}
	},
	
	handleVideoNav:function() {
		if (PageEngine.videoName == 'video1') {
			PageEngine.videoName = 'video2';
			PageEngine.video = PageEngine.video2;
		} else if (PageEngine.videoName == 'video2') {
			PageEngine.videoName = 'video3';
			PageEngine.video = PageEngine.video3;
		} else {
      PageEngine.videoName = 'video1';
			PageEngine.video = PageEngine.video1;
    }
		PageEngine.generateVideo();
	},
	
	showVideo: function() {
		$('#text-container').slideUp('fast');
		$('#bg-foto').fadeOut('normal', PageEngine.changeBgToVideo);
		$('#menu-wrapper').animate({top:'-15px'}, 800);
	},
	
	changeBgToVideo: function() {
		$('#bg-foto').css({'background-image':'url(data/themes/pietys/images/empty.jpg)'}).fadeIn('normal', PageEngine.generateVideo);
		$('#third-menu').css({'display':'none'});
		$('#nav-menu').fadeIn('slow');
	},
	
	generateVideo: function() {
		if (PageEngine.video == '') {
			PageEngine.video = PageEngine.video1;
		}
		$('#video-container')[0].innerHTML = PageEngine.video;
		$('#video-container').fadeIn('fast');
	},
	
	changeToSecondMenu: function() {
		$('#text-container').slideUp('fast');
		$('#first-menu').css({'display':'none'});
		$('#bg-foto').fadeOut('normal', PageEngine.changeBgToSecondMenu).fadeIn('normal');
		$('#second-menu').fadeIn('slow');
		$('#menu-wrapper').animate({top:'-335px'}, 800);
	},

	changeToThirdMenu: function() {
		$('#text-container').slideUp('fast');
		$('#first-menu').css({'display':'none'});
		$('#bg-foto').fadeOut('normal', PageEngine.changeBgToThirdMenu).fadeIn('normal');
		$('#third-menu').fadeIn('slow');
		$('#menu-wrapper').animate({top:'-440px'}, 800);
	},

	gotoAboutTeam: function() {
		$('#text-container').slideUp('fast');
		$('#bg-foto').fadeOut('normal', PageEngine.changeBgToEmpty);
		$('#menu-wrapper').animate({top:'-261px'}, 800);
	},
	
	goToBegining: function() {
		$('#text-container').slideUp('fast');
		$('#video-container').hide();
		$('#crew_board').fadeOut('normal');
		$('#second-menu').css({'display':'none'});
		$('#third-menu').css({'display':'none'});
		$('#bg-foto').fadeOut('normal', PageEngine.changeBgToHome).fadeIn('normal');
		$('#menu-wrapper').animate({top:'-192px'}, 800);
		$('#first-menu').fadeIn('slow');
	},

	gotoAboutMovie: function() {
		$('#text-container').slideUp('fast');
		$('#crew_board').fadeOut('normal');
		$('#bg-foto').fadeOut('normal', PageEngine.changeBgToAboutMovie).fadeIn('normal');
		$('#menu-wrapper').fadeIn('slow').animate({top:'-500px'}, 800, '', PageEngine.bringInTextForAboutMovie);
	},

	goToNews: function() {
		$('#text-container').slideUp('fast');
		$('#bg-foto').fadeOut('normal', PageEngine.changeBgToNews).fadeIn('normal');
		$('#menu-wrapper').animate({top:'-500px'}, 800, '', PageEngine.bringInNewsText);
	},

	changeBgToNews: function() {
		$('#bg-foto').css({'background-image':'url(data/themes/pietys/images/news.jpg)'});
	},

	changeBgToEmpty: function() {
		$('#crew_board img').tooltip({
			delay: 0,
			track: true,
			bodyHandler: function() {
				var title = new Array();
				title = this.src.split('/');
				title = title[title.length-1];
				title = title.split('.')[0];
				title = crewTitles[title];
				if (title) {
					var arr = title.split('.');
					return arr[0] +'. <b> '+arr[1]+'</b>';
				}  
	    	},
	    	showURL: false
		});
		$('#bg-foto').css({'background-image':'url(data/themes/pietys/images/empty.jpg)'}).fadeIn('normal');
		$('#crew_board').fadeIn('normal');
	},
	
	changeBgToAboutMovie: function() {
		$('#bg-foto').css({'background-image':'url(data/themes/pietys/images/phone_car.jpg)'});
	},

	changeBgToSecondMenu: function() {
		$('#bg-foto').css({'background-image':'url(data/themes/pietys/images/mousetrap.jpg)'});
	},

	changeBgToThirdMenu: function() {
		$('#bg-foto').css({'background-image':'url(data/themes/pietys/images/two.jpg)'});
	},
		
	bringInNewsText: function() {
		$('#text-container').css({'top':'-440px', 'left':'-188px', 'width':'370px', 'height':'400px', 'color':'#FFFFFF'});
		$('#text-container')[0].innerHTML = $('#content-naujienos')[0].innerHTML;
		$('#text-container').slideDown('normal');
	},

	bringInTextForAboutMovie: function() {
		$('#text-container').css({'top':'-410px', 'left':'-5px', 'width':'300px', 'height':'240px', 'color':'#000000'});
		$('#text-container')[0].innerHTML = $('#content-'+PageEngine.active)[0].innerHTML;
		$('#text-container').slideDown('normal');
	},

	gotoMonoklis: function() {
		$('#text-container').slideUp('fast');
		$('#crew_board').fadeOut('normal');
		$('#bg-foto').fadeOut('normal', PageEngine.changeBgToMonoklis).fadeIn('normal');
		$('#menu-wrapper').fadeIn('slow').animate({top:'-17px'}, 800, '', PageEngine.bringInTextForMonoklis);
	},

	changeBgToMonoklis: function() {
		$('#bg-foto').css({'background-image':'url(data/themes/pietys/images/cgroup.jpg)'});
	},

	bringInTextForMonoklis: function() {
		$('#text-container').css({'top':'-528px', 'left':'220px', 'width':'292px', 'height':'400px', 'color':'#FFFFFF'});
		$('#text-container')[0].innerHTML = $('#content-'+PageEngine.active)[0].innerHTML;
		$('#text-container').slideDown('normal');
	},

	goToHome: function () {
		$('#text-container').slideUp('fast');
		$('#crew_board').fadeOut('normal');
		$('#bg-foto').fadeOut('normal', PageEngine.changeBgToHome).fadeIn('normal');
		$('#menu-wrapper').fadeIn('slow').animate({top:'-192px'}, 800);
	},

	changeBgToHome: function() {
		$('#bg-foto').css({'background-image':'url(data/themes/pietys/images/first.jpg)'});	
	},
	changeBgForGallery: function() {
		$('#bg-foto').fadeOut('slow', function () {
			$('#bg-foto').css({'background-image':''});
			if ($('.nav-controls').length == 0) {
				PageEngine.initGalleriffic();
			}
			$('#controls').fadeIn('slow');
			$('#slideshow_holder').fadeIn('slow');
		});
	},
	showGallery: function() {
		$('#text-container').slideUp('fast');
		$('#video-container').hide();
		$('#menu-wrapper').animate({'top':'-17'}, 800, '', PageEngine.changeBgForGallery).fadeOut('slow');
	},

	initGalleriffic: function() {
		var gallery = $('#thumbs').galleriffic({
	        imageContainerSel:         '#slideshow', // The CSS selector for the element within which the main slideshow image should be rendered
	        controlsContainerSel:      '#controls', // The CSS selector for the element within which the slideshow controls should be rendered
	        prevLinkText:              'Atgal',
	        nextLinkText:              'Pirmyn'
	    });
	},

	goToHomeFromGallery: function() {
		$('#third-menu').css({'display':'none'});
		$('#first-menu').fadeIn('slow');
		$('#menu-wrapper').css({'top':'-17px'});
		$('#slideshow_holder').fadeOut('slow', PageEngine.changeBgToHome);
		$('#controls').fadeOut('slow', PageEngine.fadeInHome);
		
	},
	
	goToHomeFromVideo: function() {
		$('#nav-menu').css({'display':'none'});
		$('#first-menu').fadeIn('slow');
		$('#menu-wrapper').css({'top':'-17px'});
		$('#video-container').hide();
		$('#bg-foto').fadeOut('slow', PageEngine.changeBgToHome);
		$('#menu-wrapper').fadeIn('slow').animate({'top':'-192px'},800);
		$('#bg-foto').fadeIn('slow');
	},

	fadeInHome: function() {
		$('#menu-wrapper').fadeIn('slow').animate({'top':'-192px'},800);
		$('#bg-foto').fadeIn('slow');
	}
	 
}

function clickHandler(el) {
	PageEngine.changePage(el.id);
	PageEngine.changeTitle(el);
}


$(document).ready(function() {
		$('#bg-foto').fadeIn('slow');
		$('#first-menu').fadeIn('slow');
});
