var locationhref = location.href.toLowerCase();
var currentcat = null;

if (locationhref.indexOf('product.php') != -1)
{
 if (document.referrer.indexOf('category.php') != -1)
     locationhref = document.referrer;
 else
     locationhref = location.href.toLowerCase().substring(0, location.href.lastIndexOf('/')) + '/category.php?id_category=';

 if (locationhref.indexOf('&') != -1)
     locationhref = locationhref.substring(0, locationhref.indexOf('&'));

 currentcat = locationhref.substring(locationhref.indexOf('id_category') + 12);
}

$('a#cat' + currentcat).css({color: '#00f'});

function containsChild(child)
{
 var foundChild = false;
 var UL = child;

 while ((UL = UL.nextSibling) != null)
     if (UL.nodeName == 'UL')
         break;

 if (UL != null)
 {
     var nextLI = null;

     if (UL.childNodes != null)
         nextLI = UL.childNodes[0];

     while (nextLI != null)
     {
         if (nextLI.nodeName == 'LI')
         {
             var nextA = null;

             if (nextLI.childNodes != null)
                 nextA = nextLI.childNodes[0];

             while (nextA != null)
             {
                 if (nextA.nodeName == 'A')
                     foundChild = (foundChild || containsChild(nextA));

                 nextA = nextA.nextSibling;
             }
         }

         nextLI = nextLI.nextSibling;
     }
 }  

 return (foundChild || locationhref.indexOf(child.href.toLowerCase())>=0);
	console.log(currentcat);
}


   $(function(){
	
	
    	$('.drawers-wrapper-inner ul#menu').accordion({
	    	header: 'a.drawer-handle',
			navigation: true,
	    	active: 0,
	    	autoheight: false,
	    	event:'click',
	        navigationFilter: function() { return containsChild(this); } 
	    });
	   
       

        $('.drawers-wrapper-inner ul#menu ul').accordion({
                header: 'a.drawer-handle',
                navigation: true,
                active: false,
                autoheight: false,
                event:'click',
                navigationFilter: function() { return containsChild(this); } 
            });
           


    	$('.drawer-handle:first').addClass('first-cat'); 
     	$('.drawer-handle:last').addClass('last-cat'); 
        




   });



$(document).ready(function () {         
   
   $('#stores-accordion').accordion({
    	header: '.stores-accordion-header ',
    	active: false,
    	autoheight: false,
    	event:'click'
    });
     
   
        
   $(document).ready(function() {
    
    $('.drawers-wrapper-inner a:last').addClass('last');
    $('.stores-accordion-content:last').addClass('last');
    $('.stores-accordion-header:last').addClass('last-stores'); 

    $('.stores-accordion-header last-stores').click(function(){
       $(this).removeClass().addClass('stores-accordion-header');
     });
   });    
              
});  
  
    
$(function() {
   $('#product-image a').fancybox({
     'hideOnContentClick': true,
     'overlayShow': false,
     'zoomOpacity'  : true,
     'zoomSpeedIn'  : 250,
     'zoomSpeedOut' : 250
   });
   
   $('.fancybox').fancybox({
      'hideOnContentClick': true,
     'overlayShow': false,
     'zoomOpacity'  : true,
     'frameWidth'   : 700,
     'frameHeight'  : 278

   });
   
});     
  



$(document).ready(function(){
$('<div class="tr"></div><div class="tl"></div><div class="br"></div><div class="bl"></div>').appendTo(".rounded");
});      

 
 

