Cufon.replace('h2');
Cufon.replace('h1.title');
Cufon.replace('div#tagline');
// Cufon.replace('ul.submenu');

// CYCLE PLUGIN //
//---------------------------------------------------//

$.fn.cycle.defaults = {
	    speed:  '2000'
	
}


$(function(){
	
$('#slider').cycle({ 
    fx:     'fade', 
    timeout: 0, 
    next:   '#nextBtn', 
    prev:   '#prevBtn' 
});

//$('div#rope').stop(true, false).animate({top: "-120px"}, 200, "easeOutQuad");
$("#balloon").stop().css("top", "-500px");
$('div.promo').height('0');

$("#balloon:not(.level2)").stop().css("top", "-500px");
$("#balloon:not(.level2)").delay(500).animate({top: "100px"}, 3000, "easeOutQuint", openPromo);
//$(".welcome").stop().css("background-position","0px 100px").animate({backgroundPosition: "0px 0px"}, 4000, "easeOutQuint");

// $("#balloon").click(function() { $(this).stop().delay(200).animate({top: "-500px"}, 5000, "easeOutExpo"});

function openPromo() {
	//$('div.promo').show("slow");
	$('div.promo').delay(100).animate({height: "180px"}, 2000, "easeOutQuint");
	$('div#curtain').css("margin-top", "-100px").animate({marginTop: "0px"}, 2000, "easeOutQuint");
//	alert ("open promo");
}

$('div#curtain').click(function() {
    window.location = $(this).find('a:first').attr("href");
    return false;
});

$('#balloon.level2').click(function(){
	$(this).stop(true, false).animate({top: "-500px"}, 2000, "easeInExpo");
	//	$('div#rope').stop(true, false).animate({top: "0px"}, 500, "easeOutElastic");

	
//	alert ("balloon!");
});


// SET BODY CLASS //
//---------------------------------------------------//

var currentclass = $("body").attr('class').split(' ').slice(-1);
//alert (currentclass);

	if (currentclass=='banket'||currentclass=='kino'||currentclass=='lunch'||currentclass=='clients') {
		currentclass='catering';
		
	}
	if (currentclass=='ostrovitianova'||currentclass=='tupoleva') {
		currentclass='cafe';
		
	}
 $('ul#mainmenu a').each(function(i) {
	if ($(this).attr("name")==currentclass) {
		$(this).addClass("active");
	}
	
	
	
 });
	
	
// SIDEBAR FOLLOW SCROLL //
//---------------------------------------------------//

// var $sidebar   = $("ul.submenu"),
//         $window    = $(window),
//         offset     = $sidebar.offset(),
//         topPadding = 72;
// 
//     $window.scroll(function() {
//         if ($window.scrollTop() > offset.top) {
//             $sidebar.stop().animate({
//                 marginTop: $window.scrollTop() - offset.top + topPadding
//             }, 300);
//         } else {
//             $sidebar.stop().animate({
//                 marginTop: 0
//             }, 300);
//         }
//     });


// MENU PAGE ROLLOVERS //
//---------------------------------------------------//

$('div.menuline').mouseover(function(){
	$(this).addClass("hovering");
	
	if ($(this).find("a").length!=0) {
		var pos = $(this).offset(); 
		var top = pos.top + "px";
		var pic = "url(" + $(this).find("div.cell a:first").attr('rel') + ")";
		$('#menuinfopic').css("background-image", pic);
		$('#menuinfobox').css( {top: top});
		$('#menuinfobox').show();
	}
});

$('div.menuline').mouseout(function(){
	$(this).removeClass("hovering");
	$('#menuinfobox').hide();
});


$('div.menuline:even').addClass("evenline");

// BALLOON ON L2 PAGES //
//---------------------------------------------------//

$('div#rope').toggle(function(){
	$("#balloon").stop().css("left", screen.width/2-250).animate({top: "150px"}, 4000, "easeOutQuint");
}, 
function(){
	$("#balloon").stop(true, false).animate({top: "-500px"}, 2000, "easeInExpo");
});

// TOP MENU ANIMATION //
//---------------------------------------------------//

$("ul#mainmenu li a:not(.active)").hover(function(){
	$(this).stop().css("background-position","0px -80px").animate({backgroundPosition: "0px -40px"}, 400, "easeOutExpo");
},
function(){
  	$(this).stop().animate({backgroundPosition: "0px -80px"}, 400, "easeOutExpo");
});


// SUBMENU PAGE LOGIC //
//---------------------------------------------------//
$("ul.submenu.showhide li a").click(function() {
	var menuid = $(this).attr('id');
	menuid = menuid.substring(5);
	$(this).parent().parent().find('li').removeClass('active');
	$(this).parent().addClass('active');
	
//	alert (menuid);
	
	//alert(menuid);
	if (menuid=="all") {
		$('div.contentsection').show();
	}
	else {
		$('div.contentsection').hide();
		$('div.contentsection#' + menuid).show();
	}
	return false;
	
});







// SMOOTH SCROLL ON INTERNAL LINKS //
//---------------------------------------------------//

$('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 500);
                return false;
            }
        }
    });


});

//modified by Wooya to W3C standards
function show_hide(msg_id) {
   document.getElementById(msg_id).style.display = document.getElementById(msg_id).style.display == 'none' ? 'block' : 'none';
}
