$().ready(
    function()
    {
    	$('a').focus(
    		function()
    		{
    			$(this).blur();
    		}
    	);
    	$('img.hover-active').hover(
    		function()
    		{
    			$(this).attr('src', $(this).attr('src').replace('.jpg', '_active.jpg'));
    		},
    		function()
    		{
    			$(this).attr('src', $(this).attr('src').replace('_active.jpg', '.jpg'));
    		}
    	);
    	$('img.hover-active-p').hover(
    		function()
    		{
    			$(this).attr('src', $(this).attr('src').replace('.png', '_active.png'));
    		},
    		function()
    		{
    			$(this).attr('src', $(this).attr('src').replace('_active.png', '.png'));
    		}
    	);
    	
    	$('table#product-variations a.add-product').click(
    		function()
    		{
    			$.post('/order/', 'action=add_product&product_id=' + $(this).attr('id'),
    				function()
    				{
    					$.fancybox({
    						'href': '/order/?modal=1'
    					});
    				}
    			);
    			$(this).removeClass('add-product').addClass('in-cart');
    			$(this).children('img').attr('src', '/images/in_cart_active.png');
    			$('div#header div.cart').html('<a href="/order/" rel="nofollow"><img src="/images/cart.png" alt="" class="hover-active-p" title="Оформить заказ" /></a>');
    			return false;
    		}
    	);
    	
    	$('div#accessories-container div.accessory').hover(
    		function()
    		{
    			var class_name = ($(this).hasClass('added')) ? '.remove' : '.add';
    			$(this).children(class_name).fadeIn('fast');
    		},
    		function()
    		{
    			var class_name = ($(this).hasClass('added')) ? '.remove' : '.add';
    			$(this).children(class_name).fadeOut('fast');
    		}
    	);
    	$('div#accessories-container div.accessory div.add a').click(
    		function()
    		{
    			$.post('/order/', 'action=add_accessory&accessory_id=' + $(this).attr('id').replace('add-', ''));
    			$(this).parent().parent().mouseleave().addClass('added').mouseenter();
    			$('div#header div.cart').html('<a href="/order/" rel="nofollow"><img src="/images/cart.png" alt="" class="hover-active-p" title="Оформить заказ" /></a>');
    			return false;
    		}
    	);
    	$('div#accessories-container div.accessory div.remove a.remove').click(
    		function()
    		{
    			$.post('/order/', 'action=remove_accessory&accessory_id=' + $(this).attr('id').replace('remove-', ''));
    			$(this).parent().parent().mouseleave().removeClass('added').mouseenter();
    			return false;
    		}
    	);
    	
        $('div#header div.cart a, table#product-variations a.in-cart, a.buy-accessories, a.pages').click(
        	function()
        	{
        		if ($(this).attr('href').search('modal=1') == -1)
        		{
        			$(this).attr('href', $(this).attr('href') + '?modal=1');
        		}
        	}
        ).fancybox();
        
        var ll = new google.maps.LatLng(55.755, 37.620);
        var map_options = {
            'zoom': 17,
            'center': ll,
            'mapTypeId': google.maps.MapTypeId.ROADMAP,
            'mapTypeControl': false
        };
        var map = new google.maps.Map(document.getElementById('map'), map_options);
        
    	var src = ['accessories_bg_active.png', 'accessories_hover_bg.png',
    	           'buy_active.png',
    	           'cart.png', 'cart_active.png',
    	           'in_cart.png', 'in_cart_active.png',
    	           'order_input_active.jpg', 'order_textarea_active.jpg', 'order_submit_active.png'],
    		img = [];
    	for (var i = 0; i < src.length; i++)
    	{
    		img[i] = $('<img/>').attr('src', '/images/' + src[i]);
    	}
    }
);
