 $().ready(function() {

     /*ie fixes*/
     if ($.browser.msie) {
        $('.page-links ul li:last-child').add('.page-links-bottom ul li:last-child').css({'border-right' : 'none'});
     }

     /* sidemenu animation */
     $('li ul', '.sidemenu').hide();
     $('li.current', '.sidemenu').parents('ul').show();     
     $('.sidemenu li a').click(function(){
         var ul = $(this).parents('li').find('ul:first');
         $('.sidemenu>li>ul').not(ul).hide();
         $('.sidemenu>li>ul').not(ul).data({'opened' : 0});
         if ($(ul).size() > 0) {
             if ($(ul).data('opened')) {
                $(ul).data({'opened' : 0});
                $(ul).first().hide();
             } else {
                 $(ul).data({'opened' : 1});
                 $(ul).first().show();
             }
             if ($(this).siblings().size() > 0) {
                return false;
             }
         }
     });

     /* current recipe management */
     $('ul.giant li a:first').addClass('active');
     $('ul.giant li a').click(function(){
         $('ul.giant li a').removeClass('active');
         $(this).addClass('active');
     });

	var bg_height = 26;
	$('.main-menu ul li').not('.active').css( {backgroundPosition: "0px -"+bg_height+"px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:100})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0px -"+bg_height+"px)"}, {duration:100, complete:function(){
				$(this).css({backgroundPosition: "0px -"+bg_height+"px"})
			}})
		})

	// sitemap bar animation fly out and in
    var colWidth = 248;
    var openSitemap = function(elem) {
		$(elem).animate({bottom : "512px"},  300)
			.animate({width : colWidth+"px"}, 100, function(){
                            $('.white-dinamic-bg').animate({height : "512px"}, 300, function(){
                                $('.white-bg-inner').fadeIn(500, function() {
                                    $('.sitemap-bar span').removeClass('red-arrow-right-icon').addClass('red-arrow-down-icon');
                                });
                            } );
                        } )
			.addClass('opened');
    }

    var SiteMapURL = "/assets/snippets/utils/sm.php";
    if (document.sitemapIsOpened) {
        openSitemap($('.sitemap-bar'));
    }
	$('.sitemap-bar').click(function(){
		if (!$(this).hasClass('opened')) {
        $.post(SiteMapURL, {opened : 1});
        openSitemap($(this));
		} else {
                    $('.white-bg-inner').fadeOut(300, function(){
                        $('.white-dinamic-bg').animate({height : "0"},  300, function() {
                            $('.sitemap-bar').animate({width : "100px"}, 100)
                                    .animate({bottom : "0px"}, 300, function(){
                                        $('.sitemap-bar span').removeClass('red-arrow-down-icon').addClass('red-arrow-right-icon');
                                    })
                                    .removeClass('opened');
                        });
                    });
            $.post(SiteMapURL, {opened : 0});
		}
	});

        // .login animation
        var loginHeight = 130;
        $('.login-bar').mouseover(function(){
            if (!$('.login-bar').hasClass('opened')) {
                $('.login-body').animate({height: loginHeight + "px"}, 200, function(){
                    $('.login-body-inner').fadeIn(200);
                    $('.login-bar span').removeClass('red-arrow-right-icon').addClass('red-arrow-down-icon');
                    $('.login-bar').animate({bottom: loginHeight + "px"}, 200).addClass('opened');
                });
            }
        })

        $('.login-bar').mouseover(function(){
            if ($('.login-bar').hasClass('opened')) {
                $('.login-body-inner').fadeOut(200, function(){
                    $('.login-body').animate({height: "0px"}, 200, function(){
                        $('.login-bar span').removeClass('red-arrow-down-icon').addClass('red-arrow-right-icon');
                        $('.login-bar').animate({bottom: "0px"}, 200).removeClass('opened');
                    });
                });
            }
        })

        // .shopping-cart animation
        var SCHeight = 350;
        $('.shopping-cart', '.rightcol').click(function(){
            if (!$('.shopping-cart', '.rightcol').hasClass('opened')) {
                $('.shopping-cart', '.rightcol').animate({bottom: SCHeight + "px"}, 200).addClass('opened');
                $('.shopping-cart-body', '.rightcol').animate({height: SCHeight + "px"}, 200, function(){
                    $('.shopping-cart-body-inner', '.rightcol').fadeIn(200);
                    $('.shopping-cart span', '.rightcol').removeClass('red-arrow-right-icon').addClass('red-arrow-down-icon');
                });
            } else {
                $('.shopping-cart-body-inner', '.rightcol').fadeOut(200, function(){
                    $('.shopping-cart', '.rightcol').animate({bottom: "0px"}, 200).removeClass('opened');
                    $('.shopping-cart-body', '.rightcol').animate({height: "0px"}, 200, function(){
                        $('.shopping-cart span', '.rightcol').removeClass('red-arrow-down-icon').addClass('red-arrow-right-icon');
                    });
                });
            }
        })

        // language animation
        var langHeight = 70;
        $('.language-bar').mouseover(function(){
            if (!$('.language-bar').hasClass('opened')) {
                $('.language-body').animate({height: langHeight + "px"}, 200, function(){
                    $('.language-body-inner').fadeIn(200);
                    $('.language-bar span').removeClass('red-arrow-right-icon').addClass('red-arrow-down-icon');
                    $('.language-bar').animate({bottom: langHeight + "px"}, 200).addClass('opened');
                });
            }
        })

        $('.language-bar').mouseover(function(){
            if ($('.language-bar').hasClass('opened')) {
                $('.language-body-inner').fadeOut(200, function(){
                    $('.language-body').animate({height: "0px"}, 200, function(){
                        $('.language-bar span').removeClass('red-arrow-down-icon').addClass('red-arrow-right-icon');
                        $('.language-bar').animate({bottom: "0px"}, 200).removeClass('opened');
                    });
                });
            }
        });

        /* product and services sections  */
       $('.ps-image-block').hover(function(){
           $(this).find('img').stop().animate({"margin-left": "-94px"}, 100);
       }, function(){
           $(this).find('img').stop().animate({"margin-left": "0px"}, 150);
       });

       /* gifts sections */
       $('.gift-image-block').hover(function(){
           $('.main-area-full-holster').css({"overflow": "visible"});
           $(this).find('img').stop().animate({'width' : '147px', 'height' : '152px', 'margin-left' : '-15px', 'margin-bottom' : '-15px', 'opacity' : '1'}, 100);
           $(this).css({"z-index": "10"});
       }, function(){
           $(this).css({"z-index": "1"});
           $(this).find('img').stop().animate({'width' : '113px', 'height' : '117px', 'margin-left' : '0px', 'margin-bottom' : '0px', 'opacity' : '.8'}, 100);
           $('.main-area-full-holster').css({"overflow": "hidden"});
       });

       $('#send-order').click(function(){
           sc.send($('#comment-text'));            
           return false;
       })


       // lang path detection
       var path = window.location.pathname;
       $('.language-body-inner li:first a').attr('href', path.replace('/ru/', '/en/'));
       $('.language-body-inner li:last a').attr('href', path.replace('/en/', '/ru/'));       

       $('#subscribe-link').click(function(){
           var SubscibeCartUrl = "/assets/snippets/utils/newsletter.php"
           if ($(this).hasClass('subscribe')){
               $.post(SubscibeCartUrl, {subscribe : 1}, function(data){
                   $('#subscribe-link').removeClass('subscribe').addClass('unsubscribe').html('Unsubscribe');
               });
           } else {
               $.post(SubscibeCartUrl, {subscribe : 0}, function(data){
                   $('#subscribe-link').removeClass('unsubscribe').addClass('subscribe').html('Subscribe');
               });
           }
           return false;
       });

});