$(document).ready(function(){
    var temp=null;
    var media='';
	var chefID=0;
	var galleryID=0;
	var slide_width = $(document).width();
 	var pag=0;
 	var speed=1500;
 	
 	var w = 1024;
 	var h = 683;

    var slides = $('.slide.index').show();
 	var mask = $('.mask');
 	
    mask.css('width',slide_width*slides.length);
    slides.css('left', slide_width);
 	
 	slides.eq(0).css('left',0);
 	
 	var sld_index = 0;
 	var sld_prev = -1
	$('.video-container').hide().css('opacity',0);
	$('.slide p').hide();
	$('#hover').show();
	
	initialize();
	
	function initialize(){ 	
    		$('h1').fadeIn(1000);
     		slides.eq(0).find('.img').replaceWith('<img src="'+slides.eq(0).find('.img').attr('id')+'" />');
     		slides.eq(0).addClass('loader');
     		slides.eq(0).find('img').hide().load(function(){
     			slides.eq(0).removeClass('loader').find('img').fadeIn(1000,function(){
     				$('#background img.normal').show();
     			});
     			resizeme();
 				$('#hover').hide();
     			
     			showMainMenu();
     	
     			
  				$('#progress div').animate({width:slide_width/slides.length*(sld_index+1)},speed);
     		});
		
			$(document).mousemove(function(){
	            clearInterval(temp);
	     		//temp = setInterval(autoplay,15000);
	     	});
	     	$(document).click(function(){
	     		clearInterval(temp);
	     		//temp = setInterval(autoplay,15000);
	     	});
			
			$('#controls').fadeOut()
		//});
     	

	}
    
 	function showMainMenu(){
 		$('#menu')
 			  .animate({left:0},300)
 			  .animate({left:-10},100);
 		$('#main-menu>li').each(function(idx){
 			$(this).delay((idx+1)*150).animate({left:30},250);
 		});
 		$('#show-menu').animate({left:-36},300);
 	}	
 	function hideMainMenu(){
 			$('#menu').animate({left:-210},300);
 			$('#main-menu>li').css('left',-200);
 			$('#show-menu').animate({left:0},300);
 			$('.contact').slideUp();
 	}
 	function showEventsMenu(){
 		var count=1;
 		$('#events-menu li').each(function(){
 			if($(this).parent().hasClass('submenu')){
 				$(this).css('left',0);
 			}else{
 				$(this).delay(count*150).animate({left:30},250);
 				count++;
 			}
 		});
 	}
 	function hideEventsMenu(){
 		$('#events-menu li').stop(true,true);
 		$('#events-menu li').css('left',-200);
 	}
 	var menu=true;

 	var ua = navigator.userAgent;
    var event = (ua.match(/iPad/i)) ? "click" : "mousemove";
 	
 	$(document).bind(event, function(e){
 		
 			if(e.pageX<60 && !menu){
 				showMainMenu();
 				if($('#main-menu #events').hasClass('selected')){
 					setTimeout(showEventsMenu,2000);
 				}
				menu=true; 		
 			}else if(e.pageX>210 && menu){
	 			hideMainMenu();
 				hideEventsMenu();
 				menu=false;
 			}
 		
 	});
 	
	$('#show-menu').click(function(e){
		$(document).trigger('click');
		e.preventDefault();
	});
	
 	$('#controls #next').live('click',function(e){

 		if(slides.queue().length==0){
 			next();
 		}
 	});
 	$('#controls #prev').live('click',function(e){
 		if(slides.queue().length==0){
 			prev();
 		}
 	});
 	
 	$('.slide.index .view-films').click(function(e){
 		$('#main-menu a#road').trigger('click');
 		hideMainMenu();
 		e.preventDefault();
 	});
             	/*Main menu actions*/
             	$('#main-menu>li>a').click(function(e){
             		if(slides.eq(sld_index).hasClass($(this).attr('id'))){
             			return false;
             		}
             		if($(this).attr('id')!='contact')
             			$('.contact').slideUp();
             		hideEventsMenu();
             		$('#next').show();
             		switch ($(this).attr('id')){
             			case 'contact':
             			if(slides.queue().length==0){
             				hideVideo();
             				hideGallery();
             				hideChefs();
             				hideDishes();
             				$('#hover').show();
             				$('.slide.contactus').eq(0).find('.img').replaceWith('<img src="'+$('.slide.contactus').eq(0).find('.img').attr('id')+'" />');
     						slides.eq(sld_index).addClass('loader').find('img:not(.logos),p').hide();
     						$('.slide.contactus').eq(0).find('img').load(function(){
			     				slides.eq(sld_index).removeClass('loader').find('img:not(.logos),p').show();		
             					resizeme();
             					$('#controls').hide();
             					slides.hide();
             					slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
             						$(this).hide();
             						$(this).find('p').show();
             						slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');

             					});
             				$('.slide.contactus').eq(0).show().css('left', slide_width).animate({left:0},speed,function(){
             					slides = $('.slide.contactus');
             					slides.show().css('left', slide_width);
             					slides.eq(0).css('left', 0);
             					mask.css('width',slide_width*slides.length);
             					$('#progress div').animate({width:slide_width/slides.length*(sld_index+1)},speed);
             					$(this).find('p').fadeIn(1000);
             					$('#hover').hide();
             				});
             			});
             				$('#menu a').removeClass('selected');
             				$(this).addClass('selected');
             			}
             			break;
             			case 'manifesto':
             			if(slides.queue().length==0){
             				hideVideo();
             				hideGallery();
             				hideChefs();
             				hideDishes();
             				$('#hover').show();
             				$('.slide.manifesto').eq(0).find('.img').replaceWith('<img src="'+$('.slide.manifesto').eq(0).find('.img').attr('id')+'" />');
     						slides.eq(sld_index).addClass('loader').find('img:not(.logos),p').hide();
     						$('.slide.manifesto').eq(0).find('img').load(function(){
			     				slides.eq(sld_index).removeClass('loader').find('img:not(.logos),p').show();				
             					resizeme();
             					$('#controls').fadeIn();
             					slides.hide();
             					slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
             						$(this).hide();
             						$(this).find('p').show();
             						slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');

             					});
             				$('.slide.manifesto').eq(0).show().css('left', slide_width).animate({left:0},speed,function(){
             					slides = $('.slide.manifesto');
             					slides.show().css('left', slide_width);
             					slides.eq(0).css('left', 0);
             					mask.css('width',slide_width*slides.length);
             					sld_index=0;
             					sld_prev=-1;
             					$('#progress div').animate({width:slide_width/slides.length*(sld_index+1)},speed);
             					$(this).find('p').fadeIn(1000);
             					$('#hover').hide();
             				});
             			});
             				$('#menu a').removeClass('selected');
             				$(this).addClass('selected');
             			}
             			
             			break;
             			case 'brotherhood':
             			if(slides.queue().length==0){
             				hideVideo();
             				hideGallery();
             				hideChefs();
             				hideDishes();
             				$('#hover').show()
             				$('.slide.brotherhood').eq(0).find('.img').replaceWith('<img src="'+$('.slide.brotherhood').eq(0).find('.img').attr('id')+'" />');
             				slides.eq(sld_index).addClass('loader').find('img:not(.logos),p').hide();
     						$('.slide.brotherhood').eq(0).find('img').load(function(){
	             				slides.eq(sld_index).removeClass('loader').find('img:not(.logos),p').show();
             					resizeme();
             					$('#controls').fadeIn();
             					slides.hide();
             					$(this).find('p').hide();
             					slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
             						$(this).hide();
             						slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
             					
             					});
	             				$('.slide.brotherhood').eq(0).css('left', slide_width).show().animate({left:0},speed,function(){
	             					slides = $('.slide.brotherhood');
	             					slides.show().css('left', slide_width);
	             					slides.eq(0).css('left', 0);
	             					mask.css('width',slide_width*slides.length);
	             					sld_index=0;
	             					sld_prev=-1;
	             					$('#progress div').animate({width:slide_width/slides.length*(sld_index+1)},speed);
	             					$('#hover').hide();
	             					$(this).find('p').fadeIn(1000);
	             				});
             				});
             				$('#menu a').removeClass('selected');
             				$(this).addClass('selected');
             			}	
             			break;
             			case 'japan':
             			if(slides.queue().length==0){
             				hideVideo();
             				hideGallery();
             				hideChefs();
             				hideDishes();
             				$('#hover').show()
             				$('.slide.japan').eq(0).find('.img').replaceWith('<img src="'+$('.slide.japan').eq(0).find('.img').attr('id')+'" />');
             				slides.eq(sld_index).addClass('loader').find('img:not(.logos),p').hide();
     						$('.slide.japan').eq(0).find('img').load(function(){
	             				slides.eq(sld_index).removeClass('loader').find('img:not(.logos),p').show();
             					resizeme();
             					$('#controls').fadeIn();
             					slides.hide();
             					$(this).find('p').hide();
             					slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
             						$(this).hide();
             						slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
             					
             					});
	             				$('.slide.japan').eq(0).css('left', slide_width).show().animate({left:0},speed,function(){
	             					slides = $('.slide.japan');
	             					slides.show().css('left', slide_width);
	             					slides.eq(0).css('left', 0);
	             					mask.css('width',slide_width*slides.length);
	             					sld_index=0;
	             					sld_prev=-1;
	             					$('#progress div').animate({width:slide_width/slides.length*(sld_index+1)},speed);
	             					$('#hover').hide();
	             					$(this).find('p').fadeIn(1000);
	             				});
             				});
             				$('#menu a').removeClass('selected');
             				$(this).addClass('selected');
             			}	
             			break;
             			case 'sponsors':
             			if(slides.queue().length==0){
             				hideVideo();
             				hideGallery();
             				hideChefs();
             				hideDishes();
             				$('#hover').show()
             				$('.slide.sponsors').eq(0).find('.img').replaceWith('<img src="'+$('.slide.sponsors').eq(0).find('.img').attr('id')+'" />');
             				slides.eq(sld_index).addClass('loader').find('img:not(.logos),p').hide();
     						$('.slide.sponsors').eq(0).find('img:not(.logos)').load(function(){
	             				slides.eq(sld_index).removeClass('loader').find('img:not(.logos),p').show();
             					$('#controls').fadeOut();
             					slides.hide();
             					$(this).find('p').hide();
             					slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
             						$(this).hide();
             						slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
             					
             					});
	             				$('.slide.sponsors').eq(0).css('left', slide_width).show().animate({left:0},speed,function(){
	             					slides = $('.slide.sponsors');
	             					slides.show().css('left', slide_width);
	             					slides.eq(0).css('left', 0);
	             					mask.css('width',slide_width*slides.length);
	             					sld_index=0;
	             					sld_prev=-1;
	             					$('#progress div').animate({width:slide_width/slides.length*(sld_index+1)},speed);						
	             					$('#content-sponsors').fadeIn(1000);
	             				    $('.sponsors-container').fadeIn(1000);
	             					$('#hover').hide();
	             				});
	             				resizeme();
             				});
             				$('#menu a').removeClass('selected');
             				$(this).addClass('selected');
             			}	
             			break;
             			case 'road':
	             		if(slides.queue().length==0){
             				hideVideo();
             				hideGallery();
             				hideChefs();
             				hideDishes();
             				$('#hover').show()

             					$('#controls').hide();
             					slides.hide();
             					$(this).find('p').hide();
             					$('#background img').hide();
             					$('#background img.road').fadeIn(1000);
             					resizeme();
             					slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
             						$(this).hide();
             						slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
             					
             					});
	             				$('.slide.road').eq(0).css('left', slide_width).show().animate({left:0},speed,function(){
	             					slides = $('.slide.road');
	             					slides.show().css('left', slide_width);
	             					slides.eq(0).css('left', 0);
	             					mask.css('width',slide_width*slides.length);
	             					sld_index=0;
	             					sld_prev=-1;
	             					$('#progress div').animate({width:slide_width/slides.length*(sld_index+1)},speed);
	             					$('#hover').hide();
	             					$(this).find('p').fadeIn(1000);
	             					$('#content-index').css('width',slide_width).fadeIn(1000);
	             				    $('.logo-container').fadeIn(1000);
	             				});
             				
             				$('#menu a').removeClass('selected');
             				$(this).addClass('selected');
             			}	
             			break;
             			case 'events':
             				
             				hideVideo();
         					showEventsMenu();
         					hideGallery();
         					hideChefs();
         					hideDishes();
         					$('#controls').fadeIn();
         					slides.hide();
         					$('#background img').hide();
         					$('.play').hide();
         					$('#background img.events').fadeIn(1000);
         					slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
         						$(this).hide();
         						$(this).find('p').hide();
         						slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
         					});
         					$('.slide.background').eq(0).css('left', slide_width).show().animate({left:0},speed,function(){
             					slides = $('.slide.background');
             					slides.show().css('left', slide_width);
             					slides.eq(0).css('left', 0);
             					mask.css('width',slide_width*slides.length);
             					sld_index=0;
             					sld_prev=-1;
             					$('#progress div').css('width',0);
             				});
             					
         					$('.submenu:visible').slideUp();
             				$('#menu a').removeClass('selected');
             				$(this).addClass('selected');
             			
             			break;
             			case 'chefs':
             				hideVideo();
             				hideGallery();
             				hideDishes();
             				$('#controls').fadeOut();
             				slides.hide();
             				$('#background img').hide();
             				$('#background img.chefs').fadeIn(1000);
             				slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
             					$(this).hide();
             					$(this).find('p').hide();
             					slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
             				});
             				$('.slide.chefs').eq(0).css('left', slide_width).show().animate({left:0},speed,function(){
             					slides = $('.slide.chefs');
             					slides.show().css('left', slide_width);
             					slides.eq(0).css('left', 0);
             					mask.css('width',slide_width*slides.length);
             					sld_index=0;
             					sld_prev=-1;
             					$('#progress div').css('width',0);
             					$(this).find('p').fadeIn();
             					
             				});
             				$('#menu a').removeClass('selected');
             				$(this).addClass('selected');

             					$('#chef-list .chef').find('.img').each(function(){
             						$(this).replaceWith('<img src="'+$(this).attr('id')+'" />');
             					});
             					$('#chef-list .chef').eq(0).find('img').load(function(){
             						pag=0;
             						var chefsbyrow = $('#chef-list .chef').length /2;
             						var wi = ($(document).width()/chefsbyrow<200)?$(document).width()/chefsbyrow:200;
             						$('#chef-list .chef img').width(wi).height('auto');	
             						
             						var itemsrow = Math.floor(slide_width/wi);
             						var rows = Math.ceil($('#chef-list .chef').length / itemsrow);
             						var rest_width = slide_width%wi;

             						var position = (Math.floor($('#chef-list .chef').eq(0).find('img').height())*(rows-pag-2)) + (Math.floor(rest_width/itemsrow)*(rows-pag-2));
             						
             						$('#super-chefs').height(($('#chef-list .chef').eq(0).find('img').height()*2) + (rest_width/itemsrow*2));	
             						$('#chef-mask').height(($('#chef-list .chef').eq(0).find('img').height()*2) + (rest_width/itemsrow*2)).css('bottom',0);
             						$('#chef-list .chef').css({'padding-left':rest_width/itemsrow,'padding-top':rest_width/itemsrow});
             						$('#chef-list').delay(300).animate({bottom:-position-10},700).animate({bottom:-position},100,function(){
             						$('#super-chefs .pageup').fadeIn()});	
             						resizeme();
             					});
           
             			break;
             			case 'gallery':
             				hideVideo();
             				hideGallery();
             				hideChefs();
             				hideDishes();
             				$('#controls').fadeOut();
             				slides.hide();
             				$('#background img').hide();
             				$('#background img.gallery').fadeIn(1000);
             				slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
             					$(this).hide();
             					$(this).find('p').hide();
             					slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
             				});
             				$('.slide.gallery').eq(0).css('left', slide_width).show().animate({left:0},speed,function(){
             					slides = $('.slide.gallery');
             					slides.show().css('left', slide_width);
             					slides.eq(0).css('left', 0);
             					mask.css('width',slide_width*slides.length);
             					sld_index=0;
             					sld_prev=-1;
             					$('#progress div').css('width',0);
             					$(this).find('p').fadeIn();
             					
             					
             				});
             				$('#menu a').removeClass('selected');
             				$(this).addClass('selected');
								
             					$('#gallery-list .gallery').eq(0).find('.img').replaceWith('<img src="'+$('#gallery-list .gallery').eq(0).find('.img').attr('id')+'" />');
             					
             					$('#gallery-list .gallery').eq(0).find('img').load(function(){
             						$('#gallery-list .gallery').find('.img').each(function(){
             							$(this).replaceWith('<img src="'+$(this).attr('id')+'" />');
             						});
             						pag=0;
             						var chefsbyrow = $('#gallery-list .gallery').length /10;
             						var wi = ($(document).width()/chefsbyrow<200)?$(document).width()/chefsbyrow:200;
             						$('#gallery-list .gallery img').width(wi).height('auto');	
             						
             						var itemsrow = Math.floor(slide_width/wi);
             						var rows = Math.ceil($('#gallery-list .gallery').length / itemsrow);
             						var rest_width = slide_width%wi;

             						var position = (Math.floor($('#gallery-list .gallery').eq(0).find('img').height())*(rows-pag-2)) + (Math.floor(rest_width/itemsrow)*(rows-pag-2));
             						
             						$('#super-gallery').height(($('#gallery-list .gallery').eq(0).find('img').height()*2) + (rest_width/itemsrow*2));	
             						$('#gallery-mask').height(($('#gallery-list .gallery').eq(0).find('img').height()*2) + (rest_width/itemsrow*2)).css('bottom',0);
             						$('#gallery-list .gallery').css({'padding-left':rest_width/itemsrow,'padding-top':rest_width/itemsrow});
             						$('#gallery-list').delay(300).animate({bottom:-position-10},700).animate({bottom:-position},100,function(){
             						$('#super-gallery .pageup').fadeIn();
             						resizeme();
             						
             					});	
             				});
             			break;
             			case 'press':
             				hideVideo();
							hideGallery();
             				hideChefs();
             				hideDishes();
             				$('#controls').fadeOut();
             				slides.hide();
             				slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
             					$(this).hide();
             					$(this).find('p').hide();
             					slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
             				});
             				$('.slide.press').eq(0).css('left', slide_width).show().animate({left:0},speed,function(){
             					slides = $('.slide.press');
             					slides.show().css('left', slide_width);
             					slides.eq(0).css('left', 0);
             					mask.css('width',slide_width*slides.length);
             					sld_index=0;
             					sld_prev=-1;
             					$('#progress div').css('width',0);
             				});
             				$('#menu a').removeClass('selected');
             				$(this).addClass('selected');
             			break;
             		}
             		e.preventDefault();
             	});
				var eventID='';
             	/*Events menu first level actions*/
             	$('#events-menu .event>a').click(function(e){

             		var event = $(this).parent(); 
             		eventID = event.attr('id');
     				if(slides.eq(sld_index).hasClass(eventID)){
     					return false;
     				}
     				if(slides.queue().length==0){
     					$('#hover').show();
             		    hideChefs();
             			$('.slide.'+eventID).eq(0).find('.img').replaceWith('<img src="'+$('.slide.'+eventID).eq(0).find('.img').attr('id')+'" />');
     					slides.eq(sld_index).addClass('loader').find('img,p').hide();
     					$('.slide.'+eventID).eq(0).find('img').load(function(){
     						slides.eq(sld_index).removeClass('loader').find('img,p').show();
     						resizeme();
	     					slides.hide();
	     					slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
	     						$(this).hide();
	     						$(this).find('p').hide();
	     						slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
	     					});
	     					$('.slide.'+eventID).eq(0).show().css('left', slide_width).animate({left:0},speed,function(){
	     						slides = $('.slide.'+eventID);
	     						slides.show().css('left', slide_width);
	     						slides.eq(0).css('left', 0);
	     						mask.css('width',slide_width*slides.length);
	     						sld_index=0;
	     						sld_prev=-1;
	     						$('#progress div').css('width',0);
	     						$('#hover').hide();
	     						$(this).find('p').fadeIn(1000);
	     					});
	     				});
	     				$('#events-menu a').removeClass('selected');
	     				$(this).addClass('selected');
	     				/*Acordion effect*/
	     				$('.submenu:visible').slideUp();
	     				event.find('.submenu').slideDown();
     				}


             		e.preventDefault();
             	});

             	/*Events menu second level actions*/
             	$('#events-menu .submenu a').live('click',function(e){
             		switch($(this).attr('class')){
             			case 'dishes':
             				hideChefs();
             				$('#controls').fadeOut();
             				slides.hide();
             				slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
             					$(this).hide();
             					$(this).find('p').hide();
             					slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
             				});
             				$('.slide.background').eq(0).css('left', slide_width).show().animate({left:0},speed,function(){
             					slides = $('.slide.background');
             					slides.show().css('left', slide_width);
             					slides.eq(0).css('left', 0);
             					mask.css('width',slide_width*slides.length);
             					sld_index=0;
             					sld_prev=-1;
             					$('#progress div').animate({width:slide_width/slides.length*(sld_index+1)},speed);
             					$(this).find('p').fadeIn(1000);
             				});
             				
             				$('#dishes-list .dish').parent().hide().find('.dish.'+eventID).parent().show();
             				$('.submenu a').removeClass('selected');
             				$(this).addClass('selected');
             				
             				$('#dishes-list .dish').find('.img').each(function(){
             					$(this).replaceWith('<img src="'+$(this).attr('id')+'" />');
             				});
             				$('#dishes-list .dish').eq(0).find('img').load(function(){
             					$('#dishes-list').delay(300).animate({bottom:10},700).animate({bottom:0},100);	
             				});
             				
             			break;
             			default:
             				hideDishes();
             				var index = $(this);
             				var event = $(this).parent().index();
             				var prev = $('#events-menu .submenu a.selected').parent().index();  
             				if($(this).hasClass('selected')){
             					return false;
             				}
             						
             				slides.promise().done(function(){
             					if(slides.hasClass('background')){
             						$('#hover').show();
             						$('.slide.'+eventID).eq(event+1).find('.img').replaceWith('<img src="'+$('.slide.'+eventID).eq(event+1).find('.img').attr('id')+'" />');
     								slides.eq(sld_index).addClass('loader').find('img,p').hide();
     								$('.slide.'+eventID).eq(event+1).find('img').load(function(){
	             						slides.eq(sld_index).removeClass('loader').find('img,p').show();
	             						resizeme();
	             						slides.hide();
				     					slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
				     						$(this).hide();
				     						$(this).find('p').hide();
				     						slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
				     					});
				     					$('.slide.'+eventID).eq(event+1).show().css('left', slide_width).animate({left:0},speed,function(){
				     						slides = $('.slide.'+eventID);
				     						slides.show().css('left', slide_width);
				     						slides.eq(event+1).css('left', 0);
				     						mask.css('width',slide_width*slides.length);
				     						sld_index=event+1;
				     						sld_prev=event;
				     						$('#progress div').css('width',0);
				     						$('#hover').hide();
				     					});
				     				});
             					}else{
             						sld_prev = prev+1;
             						sld_index = event+1;
             						set_current_slide('left');
             					}
             					$('#events-menu .submenu a').removeClass('selected');
             					index.addClass('selected');
             				});
             			break;
             		}		
             		e.preventDefault();
             	});

             	/*Launch video*/
             	$('#content-index .button:not(.disabled)').click(function(e){
            
             			switch ($(this).attr('id')){
             				case 'video1':
             					media='<iframe src="http://player.vimeo.com/video/31264533?byline=0&amp;portrait=0&amp;color=c9ff23" width="640" height="360" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>';
             				break;
             				case 'video2':
             					media='<iframe src="http://player.vimeo.com/video/31266742?byline=0&amp;portrait=0&amp;color=c9ff23" width="640" height="360" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>';
             				break;
             				case 'video3':
             					media='<iframe src="http://player.vimeo.com/video/31442858?byline=0&amp;portrait=0&amp;color=c9ff23" width="640" height="360" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>';
             				break;
             				case 'video4':
             					media='<iframe src="http://player.vimeo.com/video/31364926?byline=0&amp;portrait=0&amp;color=c9ff23" width="640" height="360" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>';
             				break;
					case 'video5':
             					media='<iframe src="http://player.vimeo.com/video/31968953?byline=0&amp;portrait=0&amp;color=c9ff23" width="640" height="360" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>';
             				break;
             			}
             			
             			$('.video-container').dialog({
						 	closeOnEscape: true,
						 	autoOpen: false,
							modal: true,
							closeText:'',
						 	height: 480,
						 	width:710,
							open:function(){
									$('.video-container').animate({opacity:1},1000);
									$('.video-container .video').append(media);
									$('.ui-dialog').css('top',$(document).height()/2 - ($(this).height()+70)/2);
									$('.ui-dialog').css('left',$(document).width()/2 - ($(this).width()+70)/2);
									$('.ui-dialog').height($(this).height()+15);
									$('.ui-dialog-content').height($(this).height());
								},
							close:function(e){	
									$('.video-container .video').empty();
								}
				 			});
             			
             			$('.video-container').dialog('open');
             			e.preventDefault();
             	});
             	$('.video-container .close a').click(function(e){
             		$('.video-container').animate({opacity:0},1000,function(){
             			$('.video-container').dialog('close');	
             		});
             		
             		e.preventDefault();
             	});
             	function hideVideo(){
             		$('.video-container').dialog('close');
             		$('.logo-container').fadeOut(1000);
             	}
             	


             	/*Controls img resizing and recalculate mask width*/
             	function resizeme(){

             		var docH = $(window).height();
				 	var docW = $(window).width()
				 	var rw = w/docW; 	
				 	var rh = h/docH;
				 	
				 	
				 	
				 	if(rw>rh){
				 		$('.slide>img, #background>img').height(h/rh);
				 		$('.slide>img, #background>img').width(w/rh);

				 			
				 	}else{
				 		$('.slide>img, #background>img').height(h/rw);
				 		$('.slide>img, #background>img').width(w/rw);

				 	
				 	}
				 	$('.slide>img:not(.logos), #background>img').center();
				 	
				 	if(docW<1024){
				 		hideMainMenu();
				 		hideEventsMenu()
				 	}
				 	
             	
             	}
             	$(window).resize(function() {
             		resizeme();
             	    slide_width = $(document).width();				                 	
             		mask.css('width',slide_width*slides.length);
             		$('#progress div').css('width',slide_width/slides.length*(sld_index+1));
             		$('#content-index').css('width',slide_width); 
             		
	             	var chefsbyrow = $('#chef-list .chef').length /2;
					var wi = ($(document).width()/chefsbyrow<200)?$(document).width()/chefsbyrow:200;
					$('#chef-list .chef img').width(wi).height('auto');	
					
					var itemsrow = Math.floor(slide_width/wi);
					var rows = Math.ceil($('#chef-list .chef').length / itemsrow);
					var rest_width = slide_width%wi;

					var position = (Math.floor($('#chef-list .chef').eq(0).find('img').height())*(rows-pag-2)) + (Math.floor(rest_width/itemsrow)*(rows-pag-2));
					
					$('#super-chefs').height(($('#chef-list .chef').eq(0).find('img').height()*2) + (rest_width/itemsrow*2));	
					$('#chef-mask').height(($('#chef-list .chef').eq(0).find('img').height()*2) + (rest_width/itemsrow*2)).css('bottom',0);
					$('#chef-list .chef').css({'padding-left':rest_width/itemsrow,'padding-top':rest_width/itemsrow});
					$('#chef-list').css('bottom',-position);
					
					var chefsbyrow = $('#gallery-list .gallery').length /10;
					var wi = ($(document).width()/chefsbyrow<200)?$(document).width()/chefsbyrow:200;
					$('#gallery-list .gallery img').width(wi).height('auto');	
					
					var itemsrow = Math.floor(slide_width/wi);
					var rows = Math.ceil($('#gallery-list .gallery').length / itemsrow);
					var rest_width = slide_width%wi;

					var position = (Math.floor($('#gallery-list .gallery').eq(0).find('img').height())*(rows-pag-2)) + (Math.floor(rest_width/itemsrow)*(rows-pag-2));
					
					$('#super-gallery').height(($('#gallery-list .gallery').eq(0).find('img').height()*2) + (rest_width/itemsrow*2));	
					$('#gallery-mask').height(($('#gallery-list .gallery').eq(0).find('img').height()*2) + (rest_width/itemsrow*2)).css('bottom',0);
					$('#gallery-list .gallery').css({'padding-left':rest_width/itemsrow,'padding-top':rest_width/itemsrow});
					$('#gallery-list').css('bottom',-position);
					
             		
             		      		
             	});

            
             	function next(){
             		if(slides.hasClass('background')){
             			return false;
             		}
             		
             		if(slides.hasClass('chefs')){
             			chefID=(chefID==$('#chef-list .chef').length-1)?-1:chefID;
             			$('#chef-list .chef').eq(chefID+1).trigger('click');
             			return false;
             		}
             		
             		if(slides.hasClass('gallery')){
             			galleryID=(galleryID==$('#gallery-list .gallery').length-1)?-1:galleryID;
             			$('#gallery-list .gallery').eq(galleryID+1).trigger('click');
             			return false;
             		}
             		
             		if(sld_index==slides.length-2){
             			if(slides.hasClass('manifesto') || slides.hasClass('brotherhood')){
	            			$('#next').fadeOut();
        	     		}
             		}else{
             			$('#next').fadeIn();
             		}
             		sld_prev=sld_index;
             	    sld_index++;
             		if(sld_index==slides.length){
             			sld_index=0;
             			sld_prev=-1;
             		}
             		set_current_slide('left');
             	}

             	function prev(){
             		if(slides.hasClass('background')){
             			return false;
             		}
             		
             		if(slides.hasClass('chefs')){
             			chefID=(chefID==0)?$('#chef-list .chef').length:chefID;
             			$('#chef-list .chef').eq(chefID-1).trigger('click');
             			return false;
             		}
             		
             		if(slides.hasClass('gallery')){
             			galleryID=(galleryID==0)?$('#gallery-list .gallery').length:galleryID;
             			$('#gallery-list .gallery').eq(galleryID-1).trigger('click');
             			return false;
             		}
             		if(slides.hasClass('manifesto') || slides.hasClass('brotherhood')){

	            		$('#next').fadeIn();
        	     	}
             		sld_prev=sld_index;
             		sld_index--;
             		if(sld_index==-1){
             			sld_index=slides.length-1;
             			sld_prev=0;
             		}
             		set_current_slide('right');
             	}

             	function autoplay(){
         			if(slides.length>1){
         				sld_prev=sld_index;
         				sld_index++;
         				if(sld_index==slides.length){
         					sld_index=0;
         					sld_prev=-1;
         				}
         				set_current_slide('left');
         			}
             	}

             	function set_current_slide(direction) {
					
					
					if(slides.eq(sld_index).hasClass('road')){
					
						/*Slides direction move control*/
	             		if(direction=='left'){
	             			/* Forward */
	             			slides.eq(sld_index).css('left',slide_width);
	     			
	             				slides.eq(sld_index).animate({left:0},speed,function(){
	             					$(this).find('p').fadeIn(1000);
	             				});
	             				$('#progress div').animate({width:slide_width/slides.length*(sld_index+1)},speed);
	             				slides.eq(sld_prev).animate({left:-slide_width},speed).delay(500).promise().done(function(){
	             					$('#hover').hide();
	             					$(this).find('p').hide();
	             			
	             				});
	             	
	             		}else{
	             			slides.eq(sld_index).css('left',-slide_width);

	     						slides.eq(sld_prev).removeClass('loader').find('img,p').show();
	     						resizeme();
	             				slides.eq(sld_index).animate({left:0},speed,function(){
	             					$(this).find('p').fadeIn(1000);
	             				});
	             				$('#progress div').animate({width:slide_width/slides.length*(sld_index+1)},speed);
	             				slides.eq(sld_prev).animate({left:slide_width},speed).delay(500).promise().done(function(){
	             					$('#hover').hide();
	             					$(this).find('p').hide();
	             					
	             				});
	             			
	             		}

					}else{
					
             			$('#hover').show();
					
					
	             		/*Slides direction move control*/
	             		if(direction=='left'){
	             			/* Forward */
	             			slides.eq(sld_index).css('left',slide_width);
	             			slides.eq(sld_index).find('.img').replaceWith('<img src="'+slides.eq(sld_index).find('.img').attr('id')+'" />');
	     					slides.eq(sld_prev).addClass('loader').find('img,p').hide();
	     					slides.eq(sld_index).find('img:not(.logos)').load(function(){
	     						slides.eq(sld_prev).removeClass('loader').find('img,p').show();
	     						resizeme();
	             				slides.eq(sld_index).animate({left:0},speed,function(){
	             					$(this).find('p').fadeIn(1000);
	             				});
	             				$('#progress div').animate({width:slide_width/slides.length*(sld_index+1)},speed);
	             				slides.eq(sld_prev).animate({left:-slide_width},speed).delay(500).promise().done(function(){
	             					$('#hover').hide();
	             					$(this).find('p').hide();
	             					slides.eq(sld_prev).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_prev).find('img:not(.logos)').attr('src')+'" />');
	             				});
	             			});
	             		}else{
	             			slides.eq(sld_index).css('left',-slide_width);
	             			slides.eq(sld_index).find('.img').replaceWith('<img src="'+slides.eq(sld_index).find('.img').attr('id')+'" />');
	     					slides.eq(sld_prev).addClass('loader').find('img,p').hide();
	     					slides.eq(sld_index).find('img:not(.logos)').load(function(){
	     						slides.eq(sld_prev).removeClass('loader').find('img,p').show();
	     						resizeme();
	             				slides.eq(sld_index).animate({left:0},speed,function(){
	             					$(this).find('p').fadeIn(1000);
	             				});
	             				$('#progress div').animate({width:slide_width/slides.length*(sld_index+1)},speed);
	             				slides.eq(sld_prev).animate({left:slide_width},speed).delay(500).promise().done(function(){
	             					$('#hover').hide();
	             					$(this).find('p').hide();
	             					slides.eq(sld_prev).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_prev).find('img:not(.logos)').attr('src')+'" />');
	             				});
	             			});
	             		}
             		
             		}
             		
             		
             		/* Controls submenu selected item */
             		$('#events-menu a.selected').parents('.event').find('.submenu a').removeClass('selected');
             		if($('#events-menu a').hasClass('selected') && sld_index>0){
             			$('#events-menu a.selected').parents('.event').find('.submenu a').eq(sld_index-1).addClass('selected');
             		}
             	}

             	/* Chefs list and data*/

             	$('#chef-list .chef').click(function(e){

             		var chef = $(this);
       				var id = ($('#chef-list .chef').index(chef));
             		
             		chefID = id;
             		
             		if(slides.eq(sld_index).attr('class')=='slide chefs chef'+id){
             			return false;
             		}
             			
           
             		$('#chef-list .data').animate({top:$('#chef-list').height()},1000,function(){
             			$('#chef-list .data .hidden').hide();
             			$('#chef-list .more').show();
             			$('#super-chef').height($('#super-chef').height()+$(this).height()+35);
             			$('#chef-mask').height($('#chef-mask').height()+$(this).height()+35);
             		});		
             		$('#chef-list').delay(300)
             				       .animate({bottom:-$(this).parent().parent().height()+40},1000,function(){
             							$('#show-chefs').css('bottom',53).show('fast').delay(1000).animate({top:-41});
             							chef.next('.data').css('width',slide_width)
             												 .animate({top:-chef.next('.data').height()-40,opacity:.7},1000);					 
             						});

     				$('#hover').show();
             		$('.slide.chefs.chef'+id).eq(0).find('.img').replaceWith('<img src="'+$('.slide.chefs.chef'+id).eq(0).find('.img').attr('id')+'" />');
     				slides.eq(sld_index).addClass('loader').find('img,p').hide();
     				$('.slide.chefs.chef'+id).eq(0).find('img').load(function(){
     					$('#super-chefs .pageup').fadeOut();
	     				$('#super-chefs .pagedown').fadeOut();	
     					slides.eq(sld_index).removeClass('loader').find('img,p').show();
     					resizeme();
     					slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
     						$(this).hide();
     						slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
     					});
	     				$('.slide.chefs.chef'+id).eq(0).css('left', slide_width).show().animate({left:0},speed,function(){
	     					slides = $('.slide.chefs.chef'+id);
	     					slides.show().css('left', slide_width);
	     					slides.eq(0).css('left', 0);
	     					mask.css('width',slide_width*slides.length);
	     					sld_index=0;
	     					sld_prev=-1;
	     					$('#progress div').css('width',0);
	     					$('#hover').hide();
	     					$('#controls').fadeIn();     					
	     				});
     				});
             		e.preventDefault();
             	});
             	function hideChefs(){
             		$('#chef-list .data .hidden').hide();
             		$('#chef-list .data').animate({top:$('#chef-list').height(),opacity:1},{queue:false,duration:1000});
             		$('#chef-list .more').show();
             		$('#chef-list').delay(300)
             				       .animate({bottom:-600},1000,function(){
             							$('#show-chefs').css('bottom',53);		 
             						});
             		$('#chef-list .chef').find('img').each(function(){
             			$(this).replaceWith('<div class="img" id="'+$(this).attr('src')+'"></div>');
             		});
             		$('#super-chefs>a').hide();
             	}
             	$('#show-chefs').mouseenter(function(){
             		if($(this).queue()==0){
             			$(this).animate({top:-51});	   
             		}
             	});
             	$('#show-chefs').mouseleave(function(){
             		if($(this).queue()==0){
             			$(this).animate({top:-41});	   
             		}	   
             	});
             	$('#show-chefs').click(function(e){
             		$(this).hide().css('bottom',53);
             		$('#chef-list .data').animate({top:$('#chef-list').height()},1000,function(){
             			$('#chef-list .data .hidden').hide();
             			$('#chef-list .more').show();
             			$('#controls').fadeOut();
             		});
					pag=0;
             		var chefsbyrow = $('#chef-list .chef').length /2;
					var wi = ($(document).width()/chefsbyrow<200)?$(document).width()/chefsbyrow:200;
					$('#chef-list .chef img').width(wi).height('auto');	
					
					var itemsrow = Math.floor(slide_width/wi);
					var rows = Math.ceil($('#chef-list .chef').length / itemsrow);
					var rest_width = slide_width%wi;

					var position = (Math.floor($('#chef-list .chef').eq(0).find('img').height())*(rows-pag-2)) + (Math.floor(rest_width/itemsrow)*(rows-pag-2));
					
					$('#super-chefs').height(($('#chef-list .chef').eq(0).find('img').height()*2) + (rest_width/itemsrow*2));	
					$('#chef-mask').height(($('#chef-list .chef').eq(0).find('img').height()*2) + (rest_width/itemsrow*2)).css('bottom',0);
					$('#chef-list .chef').css({'padding-left':rest_width/itemsrow,'padding-top':rest_width/itemsrow});
					$('#chef-list').delay(300).animate({bottom:-position-10},700).animate({bottom:-position},100,function(){
					$('#super-chefs .pageup').fadeIn()});
             		
     				slides.hide();
     				slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
     					$(this).hide();
     					slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
     				});
     				$('.slide.background').eq(0).css('left', slide_width).show().animate({left:0},speed,function(){
     					slides = $('.slide.background');
     					slides.show().css('left', slide_width);
     					slides.eq(0).css('left', 0);
     					mask.css('width',slide_width*slides.length);
     					sld_index=0;
     					sld_prev=-1;
     					$('#progress div').css('width',0);
     				});
     		

             		
             		e.preventDefault();
             	});
             	$('.more a').click(function(e){
             		$(this).parent().hide();
             		$(this).parent().parent().find('.hidden:not(.list)').fadeIn();
             		$(this).parents('.data').animate({top:-$(this).parents('.data').innerHeight()},1000);
             		e.preventDefault();
             	});
             	$('.data .cop').click(function(e){
             		hideChefs();
             		slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
             		$('#main-menu a').removeClass('selected');
             		$('#main-menu #events').addClass('selected');
             		$('#events-menu .event#copenhagen>a').trigger('click');
             		e.preventDefault();
             	});
             	$('.data .col').click(function(e){
             		hideChefs();
             		slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
             		$('#main-menu a').removeClass('selected');
             		$('#main-menu #events').addClass('selected');
             		$('#events-menu .event#collio>a').trigger('click');
             		e.preventDefault();
             	});
             	$('.data .lap').click(function(e){
             		hideChefs();
             		slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
             		$('#main-menu a').removeClass('selected');
             		$('#main-menu #events').addClass('selected');
             		$('#events-menu .event#lapland>a').trigger('click');
             		e.preventDefault();
             	});
             	$('#chef-list .list a').click(function(e){
					
					var link = $(this);
					$(this).find('.img').replaceWith('<img class="hidden" src="'+$(this).find('.img').attr('id')+'" />');
   					
   					$(this).find('img').load(function(){
	   					$('.video-container').dialog({
	   						closeOnEscape: false,
	   						autoOpen: false,
							modal: true,
							closeText:'',
							width: link.find('img').width()+70,
	   						open:function(){
									$('.video-container').animate({opacity:1},1000);
									link.find('img').clone().appendTo($('.video-container .video'));
									$('.video-container .video img').show();
									$('.ui-dialog').css('top',$(document).height()/2 - (link.find('img').height()+70)/2);
									$('.ui-dialog').css('left',$(document).width()/2 - (link.find('img').width()+70)/2);
									$('.ui-dialog').height(link.find('img').height()+70);
									$('.ui-dialog-content').height(link.find('img').height()+70);
								},
							close:function(){
									$('.video-container .video').empty();
									link.find('img').replaceWith('<div class="img hidden" id="'+link.find('img').attr('src')+'" />');
								}
	   						
	   					});
	   					$('.video-container').dialog('open');
 					});
   					
   					e.preventDefault();
   				});
   				$('#super-chefs .pageup').click(function(e) {
             	    
					pag++;
					var chefsbyrow = $('#chef-list .chef').length /2;
					var wi = ($(document).width()/chefsbyrow<200)?$(document).width()/chefsbyrow:200;
					$('#chef-list .chef img').width(wi).height('auto');	
					
					var itemsrow = Math.floor(slide_width/wi);
					var rows = Math.ceil($('#chef-list .chef').length / itemsrow);
					var rest_width = slide_width%wi;

					var position = (Math.floor($('#chef-list .chef').eq(0).find('img').height())*(rows-pag-2)) + (Math.floor(rest_width/itemsrow)*(rows-pag-2));
						
	    			$('#chef-list .chef').css({'padding-left':rest_width/itemsrow,'padding-top':rest_width/itemsrow});
					$('#chef-list').delay(300).animate({bottom:-position-10},700).animate({bottom:-position},100);	             		
             		if(pag==0){
             			$('#super-chefs .pagedown').fadeOut();
             			$('#super-chefs .pageup').fadeIn();
             		}else if(pag==rows-2){
             			$('#super-chefs .pageup').fadeOut();
             			$('#super-chefs .pagedown').fadeIn();
             		}else{
             			$('#super-chefs .pageup').fadeIn();
             			$('#super-chefs .pagedown').fadeIn();
             		}
             		e.preventDefault();
             		      		
             	});
             	$('#super-chefs .pagedown').click(function(e) {
             	    
					pag--;
					var chefsbyrow = $('#chef-list .chef').length /2;
					var wi = ($(document).width()/chefsbyrow<200)?$(document).width()/chefsbyrow:200;
					$('#chef-list .chef img').width(wi).height('auto');	
					
					var itemsrow = Math.floor(slide_width/wi);
					var rows = Math.ceil($('#chef-list .chef').length / itemsrow);
					var rest_width = slide_width%wi;

					var position = (Math.floor($('#chef-list .chef').eq(0).find('img').height())*(rows-pag-2)) + (Math.floor(rest_width/itemsrow)*(rows-pag-2));
						
	    			$('#chef-list .chef').css({'padding-left':rest_width/itemsrow,'padding-top':rest_width/itemsrow});
					$('#chef-list').delay(300).animate({bottom:-position-10},700).animate({bottom:-position},100);	             		
             		if(pag==0){
             			$('#super-chefs .pagedown').fadeOut();
             			$('#super-chefs .pageup').fadeIn();
             		}else if(pag==rows-2){
             			$('#super-chefs .pageup').fadeOut();
             			$('#super-chefs .pagedown').fadeIn();
             		}else{
             			$('#super-chefs .pageup').fadeIn();
             			$('#super-chefs .pagedown').fadeIn();
             		}
             		e.preventDefault();
             		      		
             	});
             	
             	
             	/* Gallery list*/

             	$('#gallery-list .gallery').click(function(e){

             		var gallery = $(this);
       				var id = ($('#gallery-list .gallery').index(gallery));
             		
             		galleryID = id;
             		
             		if(slides.eq(sld_index).attr('class')=='slide gallery gallery'+id){
             			return false;
             		}
             			
           
             		
             		$('#gallery-list').delay(300)
             				       .animate({bottom:-$(this).parent().parent().height()+40},1000,function(){
             							$('#show-gallery').css('bottom',53).show('fast').delay(1000).animate({top:-41})					 
             						});

     				$('#hover').show();
     				$('#controls').fadeIn();
             		$('.slide.gallery.gallery'+id).eq(0).find('.img').replaceWith('<img src="'+$('.slide.gallery.gallery'+id).eq(0).find('.img').attr('id')+'" />');
     				slides.eq(sld_index).addClass('loader').find('img,p').hide();
     				$('.slide.gallery.gallery'+id).eq(0).find('img').load(function(){
     					$('#super-gallery .pageup').fadeOut();
	     				$('#super-gallery .pagedown').fadeOut();	
     					slides.eq(sld_index).removeClass('loader').find('img,p').show();
     					resizeme();
     					slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
     						$(this).hide();
     						slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
     					});
	     				$('.slide.gallery.gallery'+id).eq(0).css('left', slide_width).show().animate({left:0},speed,function(){
	     					slides = $('.slide.gallery.gallery'+id);
	     					slides.show().css('left', slide_width);
	     					slides.eq(0).css('left', 0);
	     					mask.css('width',slide_width*slides.length);
	     					sld_index=0;
	     					sld_prev=-1;
	     					$('#progress div').css('width',0);
	     					$('#hover').hide();     					
	     				});
     				});
             		e.preventDefault();
             	});
             	function hideGallery(){
             		$('#gallery-list').delay(300)
             				       .animate({bottom:-2000},1000,function(){
             							$('#show-gallery').css('bottom',53);		 
             						});
             		$('#gallery-list .gallery').find('img').each(function(){
             			$(this).replaceWith('<div class="img" id="'+$(this).attr('src')+'"></div>');
             		});
             		$('#super-gallery>a').hide();
             	}
             	$('#show-gallery').mouseenter(function(){
             		if($(this).queue()==0){
             			$(this).animate({top:-51});	   
             		}
             	});
             	$('#show-gallery').mouseleave(function(){
             		if($(this).queue()==0){
             			$(this).animate({top:-41});	   
             		}	   
             	});
             	$('#show-gallery').click(function(e){
             		$(this).hide().css('bottom',53);
             		$('#controls').fadeOut();
             		var chefsbyrow = $('#gallery-list .gallery').length /10;
					var wi = ($(document).width()/chefsbyrow<200)?$(document).width()/chefsbyrow:200;
					$('#gallery-list .gallery img').width(wi).height('auto');	
					
					var itemsrow = Math.floor(slide_width/wi);
					var rows = Math.ceil($('#gallery-list .gallery').length / itemsrow);
					var rest_width = slide_width%wi;

					var position = (Math.floor($('#gallery-list .gallery').eq(0).find('img').height())*(rows-pag-2)) + (Math.floor(rest_width/itemsrow)*(rows-pag-2));
					
					$('#super-gallery').height(($('#gallery-list .gallery').eq(0).find('img').height()*2) + (rest_width/itemsrow*2));	
					$('#gallery-mask').height(($('#gallery-list .gallery').eq(0).find('img').height()*2) + (rest_width/itemsrow*2)).css('bottom',0);
					$('#gallery-list .gallery').css({'padding-left':rest_width/itemsrow,'padding-top':rest_width/itemsrow});
					$('#gallery-list').delay(300).animate({bottom:-position-10},700).animate({bottom:-position},100,function(){
						if(pag==0){
	             			$('#super-gallery .pagedown').fadeOut();
	             			$('#super-gallery .pageup').fadeIn();
	             		}else if(pag==rows-2){
	             			$('#super-gallery .pageup').fadeOut();
	             			$('#super-gallery .pagedown').fadeIn();
	             		}else{
	             			$('#super-gallery .pageup').fadeIn();
	             			$('#super-gallery .pagedown').fadeIn();
	             		 }
					
					});
             		
     				slides.hide();
     				slides.eq(sld_index).show().animate({left:-slide_width},speed,function(){
     					$(this).hide();
     					slides.eq(sld_index).find('img:not(.logos)').replaceWith('<div class="img" id="'+slides.eq(sld_index).find('img:not(.logos)').attr('src')+'" />');
     				});
     				$('.slide.background').eq(0).css('left', slide_width).show().animate({left:0},speed,function(){
     					slides = $('.slide.background');
     					slides.show().css('left', slide_width);
     					slides.eq(0).css('left', 0);
     					mask.css('width',slide_width*slides.length);
     					sld_index=0;
     					sld_prev=-1;
     					$('#progress div').css('width',0);
     				});
     		

             		
             		e.preventDefault();
             	});
             	
             	
   				$('#super-gallery .pageup').click(function(e) {
             	    
					pag++;
					var chefsbyrow = $('#gallery-list .gallery').length /10;
					var wi = ($(document).width()/chefsbyrow<200)?$(document).width()/chefsbyrow:200;
					$('#gallery-list .gallery img').width(wi).height('auto');	
					
					var itemsrow = Math.floor(slide_width/wi);
					var rows = Math.ceil($('#gallery-list .gallery').length / itemsrow);
					var rest_width = slide_width%wi;

					var position = (Math.floor($('#gallery-list .gallery').eq(0).find('img').height())*(rows-pag-2)) + (Math.floor(rest_width/itemsrow)*(rows-pag-2));
						
	    			$('#gallery-list .gallery').css({'padding-left':rest_width/itemsrow,'padding-top':rest_width/itemsrow});
					$('#gallery-list').delay(300).animate({bottom:-position-10},700).animate({bottom:-position},100);	             		
             		if(pag==0){
             			$('#super-gallery .pagedown').fadeOut();
             			$('#super-gallery .pageup').fadeIn();
             		}else if(pag==rows-2){
             			$('#super-gallery .pageup').fadeOut();
             			$('#super-gallery .pagedown').fadeIn();
             		}else{
             			$('#super-gallery .pageup').fadeIn();
             			$('#super-gallery .pagedown').fadeIn();
             		}
             		e.preventDefault();
             		      		
             	});
             	$('#super-gallery .pagedown').click(function(e) {
             	    
					pag--;
					var chefsbyrow = $('#gallery-list .gallery').length /10;
					var wi = ($(document).width()/chefsbyrow<200)?$(document).width()/chefsbyrow:200;
					$('#gallery-list .gallery img').width(wi).height('auto');	
					
					var itemsrow = Math.floor(slide_width/wi);
					var rows = Math.ceil($('#gallery-list .gallery').length / itemsrow);
					var rest_width = slide_width%wi;

					var position = (Math.floor($('#gallery-list .gallery').eq(0).find('img').height())*(rows-pag-2)) + (Math.floor(rest_width/itemsrow)*(rows-pag-2));
						
	    			$('#gallery-list .gallery').css({'padding-left':rest_width/itemsrow,'padding-top':rest_width/itemsrow});
					$('#gallery-list').delay(300).animate({bottom:-position-10},700).animate({bottom:-position},100);	             		
             		if(pag==0){
             			$('#super-gallery .pagedown').fadeOut();
             			$('#super-gallery .pageup').fadeIn();
             		}else if(pag==rows-2){
             			$('#super-gallery .pageup').fadeOut();
             			$('#super-gallery .pagedown').fadeIn();
             		}else{
             			$('#super-gallery .pageup').fadeIn();
             			$('#super-gallery .pagedown').fadeIn();
             		}
             		e.preventDefault();
             		      		
             	});

             	/* Dishes list*/

             	$('#dishes-list .dish').click(function(e){
             		$('#dishes-list').delay(300).animate({bottom:-$(this).parent().parent().height()+40},1000);
   					var link = $(this);
					$(this).siblings().eq(0).replaceWith('<img class="hidden" src="'+$(this).siblings().eq(0).attr('id')+'" />');
					$(this).siblings(0).eq(0).load(function(){
	   					$('.video-container').dialog({
	   						closeOnEscape: false,
	   						autoOpen: false,
							modal: true,
							closeText:'',
							width: link.siblings(0).eq(0).width()+70,
	   						open:function(){
									$('.video-container').animate({opacity:1},1000);
									link.siblings(0).eq(0).clone().appendTo($('.video-container .video'));
									$('.video-container .video img').show();
									$('.ui-dialog').css('top',$(document).height()/2 - (link.siblings(0).eq(0).height()+70)/2);
									$('.ui-dialog').css('left',$(document).width()/2 - (link.siblings(0).eq(0).width()+70)/2);
									$('.ui-dialog').height(link.siblings(0).eq(0).height()+70);
									$('.ui-dialog-content').height(link.siblings(0).eq(0).height()+70);
								},
							close:function(){
									$('.video-container .video').empty();
									link.siblings(0).eq(0).replaceWith('<div class="img hidden" id="'+link.siblings(0).eq(0).attr('src')+'" />');
									$('#dishes-list').delay(300).animate({bottom:10},700).animate({bottom:0},100);
								}
	   						
	   					});
	   					$('.video-container').dialog('open');
   					});
             		e.preventDefault();
             	});
             	function hideDishes(){
             		$('#dishes-list').delay(300).animate({bottom:-600},1000);
             		$('#dishes-list .dish').find('img').each(function(){
             			$(this).replaceWith('<div class="img" id="'+$(this).attr('src')+'"></div>');
             		});
             	}
});
