var JUS = JUS || {};
JUS.navigation = {
	init:function(){
		if(jQuery(".wpsc-breadcrumbs").length>0){
			JUS.navigation.open(jQuery("#wpsc-crumb-"),true);
		}
		if(jQuery("#cart").length>0){
			console.log(jQuery("nav a[href='http://jus/?wpsc_product_category=webshop']").next("ul").append("<li><a href='#cart'>Cart</a></li>"));
		}
		jQuery(".menu-item").each(function(index) {
			if(JUS.navigation.hasChildren(jQuery(this))){
				jQuery(this).addClass("has-children");
			}
		});
		jQuery(".menu-item-object-wpsc-product").closest(".has-children").removeClass("has-children");
	},
	hasChildren:function(elem){
		return !!elem.find("ul").length;
	},
	open:function(elem,root){
		jQuery("nav a[href='"+elem.attr("href")+"']").parent().addClass("current-menu-ancestor");
		if(elem.next().is("a")){
			JUS.navigation.open(elem.next(),false);
		}
	}
}
jQuery(function () {
	JUS.navigation.init();
});
