
// function setHashPath(path) {
// 	if(path!=undefined && path!="undefined") location.hash = "path="+path;
// 	//window.manualChange = true;
// }

// function getHashPath() {
// 	if(location.hash.split("path=").length>1) {
// 		var hash = location.hash.split("path=")[1];
// 		return hash;
// 	} else {
// 		return "undefined";
// 	}
	
// }


var lightboxSettings = {
    overlayBgColor: '#000',
    overlayOpacity: 0.5,
    imageLoading: '/js/jquery/lightbox/images/lightbox-ico-loading.gif',
    imageBtnClose: '/js/jquery/lightbox/images/lightbox-btn-close.gif',
    imageBtnPrev: '/js/jquery/lightbox/images/lightbox-btn-prev.gif',
    imageBtnNext: '/js/jquery/lightbox/images/lightbox-btn-next.gif',
    imageBlank: '/js/jquery/lightbox/images/lightbox-blank.gif',
    containerResizeSpeed: 350,
    txtImage: 'Изображение',
    txtOf: 'из·'
};

$(document).ready(function()
{

    $('a.lightbox').lightBox(lightboxSettings);
    $(".menu-effect").live('click', function() {
        $(this).parent().next().show('fast');
        $("#menu > ul > li").removeClass('active');
        $(this).parent().addClass('active');
        //return false;
    });

    var setCategoryLoading = function() {
    	$("#right-column-container").addClass("ajax-loading");
    }
    
    var setCategoryLoaded = function() {
    	$("#right-column-container").removeClass("ajax-loading");
    }

    // var updateMenu = function(path) {
    //     $("#menu > ul > li").removeClass('active');
    //     $("#menu > ul > li.shop-index").addClass('active');
    // 	var element = $(".shop-ajax-link[href=\""+path+"\"]");
    //     var isRoot = element.hasClass('is-root');

    //     if (isRoot) {
    //         $("#menu li.shop a.opened[href!=\""+path+"\"]").each(function(){
    //             if($(this).parent().next().hasClass('submenu')) {
    //                 $(this).parent().next().hide('slow');
    //                 $(this).removeClass('opened');
    //                 $(this).addClass('closed');
    //             }
    //          });
    //         if(element.hasClass('closed')) {
    //             if (element.parent().next().hasClass('submenu')) {
    //                 element.parent().next().show('slow');
    //                 element.removeClass('closed');
    //                 element.addClass('opened');
    //             }
    //             //break;
    //         } else {
    //             if (element.parent().next().hasClass('submenu')) {
    //                 element.parent().next().hide('slow');
    //                 element.removeClass('opened');
    //                 element.addClass('closed');
    //             }
    //         }
    //     } else {
    //         var element = element.parents('li.submenu').show('slow');
    //         element.removeClass('closed');
    //         element.addClass('opened');
    //     }
    // }

    // window.manualChange = false;       

    // $(".shop-ajax-link").live("click", function(){
    // 	setCategoryLoading();
    // 	var href = $(this).attr("href");

    // 	updateMenu(href);
    // 	$("#ajax-content").load(href, function(){
    // 		setHashPath(href);
    // 		window.manualChange = true;
    // 		setCategoryLoaded();
    // 	});
    // 	return false;
    // });
    
	// $(window).hashchange(function(){
	// 	if(window.manualChange) {
	// 		window.manualChange = false;
	// 		return false;
	// 	}
	// 	var path = getHashPath();
	// 	if(path==location.pathname || path=="undefined") {
	// 		return false;
	// 	}
		
	// 	setCategoryLoading();
 //    	updateMenu(path);
 //    	$("#ajax-content").load(path, function(){
 //    		setHashPath(path);
 //    		setCategoryLoaded();
 //    	});
 //    	return false;
	// });
	
	//  $(window).hashchange();

     $("#item-small-images a").live('click', function(){
         setCategoryLoading();
            $("#item-big-image > img").attr('src', $(this).attr('href').split('::')[0]);
            $("#zoom").attr('href', $(this).attr('href').split('::')[1]);
            $("#item-small-images > div").removeClass('active');
            $(this).parent('div').addClass('active');
         setCategoryLoaded();
         return false;
     });

     $("a.add-to-cart").live('click',function(){
        $("#overlay").show();
        $("#popup").show();
        
        $("#popup").load($(this).attr('href'));
        return false; 
     });
     $('#popup input[name="quantity"], .position form input[name="quantity"]').live("keyup", function(){
        var input = parseInt($(this).attr("value"));
        if($(this).val().length > 0) {
            if (isNaN(input) || input < 1) {
                $(this).val(1);
            } else {
                $(this).val(input);
            }
        }
     });
    $('#popup input[name="quantity"]').live("focusout", function(){
        if($(this).val().length == 0) $(this).val(1);
    });

     $("#popup .cancel").live('click', function(){
        $("#overlay").hide();
        $("#popup").hide();
        $("#popup").html('');
        return false;
     });
     $("#popup .continue").live('click', function(){
        $(this).parents('form').ajaxSubmit({
                success: function(text) { 
			$("#cart-info").replaceWith(text); 
			$("#overlay").hide();
			$("#popup").hide();
		        $("#popup").html('');
		}
	    });
	return false;
     });
     $("#popup .go").live('click', function(){
        $(this).parents('form').ajaxSubmit({
                success: function() { 
			window.location.href = "/cart";
			$("#overlay").hide();
		        $("#popup").hide();
		        $("#popup").html('');
		}
            });
        return false;
     });
     $("#popup .action").live('click', function(){
        var quantity = $(this).parents("form").find('input[name="quantity"]');
        if($(this).hasClass('up')) {
            quantity.attr('value', parseInt(quantity.attr('value'))+1);
        } else if ($(this).hasClass('down') && parseInt(quantity.attr('value'))>1) {
            quantity.attr('value', parseInt(quantity.attr('value'))-1);
        }
        return false;
     });

     $(".position a.action").live('click', function(){
        var form = $(this).parents('form');
        form.find('input').val($(this).attr('href'));
        form.submit();
        return false;
     });

     $(".position form input").live('focusout', function(){
        if($(this).val().length == 0) $(this).val(1);
        $(this).parents('form').submit();
     });
     $(".position form").live("submit", function(){
        $(this).ajaxSubmit({
            success: function(text){ 
                $("#cart-info").replaceWith(text);
                $("#ajax-content").load("/cart");
            }
        });
        return false;
     });

     $("a.cart-delete").live('click', function(){
        var url = $(this).attr('href');
        $.ajax({
            url:url,
            success: function(text){ 
                $("#cart-info").replaceWith(text);
                $("#ajax-content").load("/cart");
            }
        });
        return false;
     });

});

