$(window).load(function() {
				jQuery("#main_loading").fadeOut(100);
});

var keys= new Array();
keys['fr']=new Array();
keys['fr'][0]='Cabaret a Paris';
keys['fr'][1]='Divertisment a Paris';
keys['fr'][3]='Cusine russe restaurant';
keys['fr'][4]='Le restaurant a Paris';
keys['ru']=new Array();
keys['ru'][0]='Кабаре в Париже';
keys['ru'][1]='Развлечения в Париже';
keys['ru'][3]='Ресторан русской кухни';
keys['ru'][4]='Ресторан в Париже';

jQuery(document).ready(function($){
	//var BaseUrl= "http://localhost:8888/villagerusse/site";
	var BaseUrl= "http://www.villagerusse.com/v1/";
	var isLaunched= false;

	$.fn.slideLeftHide = function( speed, callback ) { this.animate( { width: "hide", paddingLeft: "hide", paddingRight: "hide", marginLeft: "hide", marginRight: "hide" }, speed, callback ); }
$.fn.slideLeftShow = function( speed, callback ) { this.animate( { width: "show", paddingLeft: "show", paddingRight: "show", marginLeft: "show", marginRight: "show" }, speed, callback ); }

	$('#navigation_wrapper').animate({top: '0'}, 500, 'easeOutQuart');

	$('#main_navigation a').click(function(){
		var lang='';
		var href = $(this).attr('href');
		lang=href.substring(28,30);
		if(lang!='ru' && lang!='en')
			lang='fr';
		pos=$('#main_navigation a').index(this);
		var linkTarget= $(this).attr('target');
		if(lang!='en'){
			if(keys[lang][pos])
				document.title=keys[lang][pos];
			else
				document.title=$(this).text();
		}else{
			document.title=$(this).text();
		}
		if (linkTarget == "_blank"){
			return
		} else {
		$.bbq.pushState({ url: href });
		return false;
		}
	});

	$('#copyright a').click(function(){
		var href = $(this).attr('href');
		var linkTarget= $(this).attr('target');
		if (linkTarget == "_blank"){
			return
		} else {
		$.bbq.pushState({ url: href });
		return false;
		}
	});


	function LaunchPage(currentPageLink,href){
		$('#main_navigation a').removeClass('selected');
		currentPageLink.addClass('selected');
		switchLogo(currentPageLink.text());
		if(isLaunched){
			$('.slide').hide('slide', {direction: 'left'} ,500, function(){
				$('#superbg').stopSlideShow();
				my_slideshowActive = false;
				$("#main_loading").fadeIn(100);
				$('.slide').load(href, function(){
					$("#main_loading").fadeOut(100);
					$('.slide').show('slide',{direction: 'left'} ,300, function(){
				            Cufon.replace('.page_title', { fontFamily: 'redoctober' });
						if ($('.mainpagegallery', this).length){
							var theMainGalleryContent = $('.mainpagegallery', this).html();
							$('#superbgimage img.activeslide').hide('slide',{direction: 'up'} ,1000, function(){
								$('#superbg').html(theMainGalleryContent);
								$('#superbg').superbgimage({ reload: true }).show().removeClass('hidden');
							});
						/*	$('#superbgimage').hide('slide',{direction: 'up'} ,500, function(){
							$('#superbg').html(theMainGalleryContent);
							$('#superbg').superbgimage({ reload: true }).show(500, function(){$('#superbgimage').show('slide',{direction: 'down'} ,500);});
							*/

						}
					});
					isLaunched=true;
				});
			});
		} else {
				$('#superbg').stopSlideShow();
				my_slideshowActive = false;
				$("#main_loading").fadeIn(100);
				$('.slide').load(href, function(){
					$("#main_loading").fadeOut(100);
					$('.slide').show('slide',{direction: 'left'} ,300, function(){
				            Cufon.replace('.page_title', { fontFamily: 'eurcntrc' });
						if ($('.mainpagegallery', this).length){
							var theMainGalleryContent = $('.mainpagegallery', this).html();
							$('#superbgimage img.activeslide').hide('slide',{direction: 'up'} ,1000, function(){
								$('#superbg').html(theMainGalleryContent);
								$('#superbg').superbgimage({ reload: true }).show().removeClass('hidden');
							});
						/*	$('#superbgimage').hide('slide',{direction: 'up'} ,500, function(){
							$('#superbg').html(theMainGalleryContent);
							$('#superbg').superbgimage({ reload: true }).show(500, function(){$('#superbgimage').show('slide',{direction: 'down'} ,500);});
							*/

						}
					isLaunched=true;
				});
			});
			}
	}


	////SUBPAGES LINKS


	$("a.subpages_title").live("mouseover", function() {
				$(this).animate({paddingLeft: '20'}, 300);
	});
	$("a.subpages_title:not(.selected)").live("mouseout", function() {
			$(this).animate({paddingLeft: '0'}, 200);
	});

	function LaunchSubPage(currentSubPageLink,href){
			currentSubPageLink.animate({paddingLeft: '20'}, 500, 'easeOutQuart');
			$('a.subpages_title').removeClass('selected');
			currentSubPageLink.addClass('selected');
			$("a.subpages_title:not(.selected)").animate({paddingLeft: '0'}, 200);
			$('.subpage_content').slideUp();
			currentSubPageLink.parent().children('.subpage_content').slideDown();
			var theGalleryContent = currentSubPageLink.parent().children().children('.gallery').html();
			if (currentSubPageLink.parent().children().children('.gallery').length){

		$('#superbg').stopSlideShow();
		my_slideshowActive = false;
		$('#superbg').html(theGalleryContent);
		$('#superbg').superbgimage({ reload: true }).show().removeClass('hidden');
}

	}

	$('a.subpages_title').live('click',function(){
		var href = $(this).attr('href');
		$.bbq.pushState({ url: href });
		return false;
	});


	////CLOSE

	$('a.close').live('click',function(){
		var href = "close";
		$.bbq.pushState({ url: href });
		return false;
	});

	////SWITCH LOGO

	function switchLogo(place){
		if (place == "Les Nuits Blanches" || place == "Blog" || place == "Cigare Club" || place == "Contact"){
		$('a#logo').css("background-position-x", "0px");
		} else if (place == "Bar Gorinitch"){
		$('a#logo').css("background-position-x", "-324px");
		} else if (place == "La Banya"){
		$('a#logo').css("background-position-x", "-216px");
		} else if (place == "Gastronomie Russe"){
		$('a#logo').css("background-position-x", "-108px");
		}

	}


///HISTORY BBQ
$(window).bind( "hashchange", function(e) {
    // In jQuery 1.4, use e.getState( "url" );
    var url = $.bbq.getState( "url" );

    $("#main_navigation a").each(function(){
		$(this).click(function(e){
			if($(e.target).is('a')) return;
		});
		var currentPageLink = $(this);
		var href = $(this).attr( "href" );
      if ( href === url ) {
		 LaunchPage(currentPageLink,href);
      }
    });

    $("#copyright a").each(function(){
		$(this).click(function(e){
			if($(e.target).is('a')) return;
		});
		var currentPageLink = $(this);
		var href = $(this).attr( "href" );
      if ( href === url ) {
		 LaunchPage(currentPageLink,href);
      }
    });


    $(".close").each(function(){
		$(this).click(function(e){
			if($(e.target).is('a')) return;
		});
		var href = "close";
      if ( href === url ) {
		$('.slide').hide('slide',{direction: 'left'},300);
		isLaunched=false;
      }
    });


    $("a.subpages_title").each(function(){
		$(this).click(function(e){
			if($(e.target).is('a')) return;
		});
		var currentSubPageLink = $(this);
		var href = $(this).attr( "href" );
      if ( href === url ) {
		 LaunchSubPage(currentSubPageLink,href);
      }
    });



  });


$(window).trigger( "hashchange" );

});

