$(document).ready(function() {	

$(".price .new").each(function(){  
    var price = $(this).html();
    $(this).html(prettifyPrice(price));
});

$(".price .old").each(function(){  
    var price = $(this).html();
    $(this).html(prettifyPrice(price));
});

$(".newprice").each(function(){  
    var price = $(this).html();
    $(this).html(prettifyPrice(price));
});

$(".subprice").each(function(){  
    var price = $(this).html();
    $(this).html(prettifyPrice(price));
});

$(".priceprice .striked").each(function(){  
    var price = $(this).html();
    if (price.indexOf(",00") != -1) {
      price = price.replace(",00",",-");
       $(this).html(price);
    }   
});

$(function(){
    $('input').keydown(function(e){    
    	if($(this).attr('id') != "startpoint") {
	        if (e.keyCode == 13) { 
	        	 if($(this).parents('form').attr('id') != "checkoutdelivery") {
	        		 $(this).parents('form').submit().wait(100);
	        	 }
	            return false;
	        }
    	}
    });
});

function prettifyPrice(price) {
  if (price.indexOf(",00") != -1) {
      price = price.replace(",00",",-");
    }
    else {
      var euro = price.split(",")[0];
      var cents = price.split(",")[1];
      if(!isNaN(cents)){
        price = euro + "," + "<sup>" + cents + "</sup>";
      }
    }
  return price;
}

$("#shopping_basket a").mouseover(function(){
    $("#popout").show();  
});

$("#shopping_basket").mouseleave( function(){  
    var timeout = setTimeout(function(){
          $("#popout").hide();
    },2000);      
    $("#popout").mouseover(function(){
      if(timeout) clearTimeout(timeout);
      $("#popout").show();  
    });
    $("#popout").mouseleave(function(){
      $("#popout").hide();  
    });
});

$("ul#topnav .current a.category-menu").hover(function(){
   // $(this).css("color","black");
   // $(this).css("-ms-filter","progid:DXImageTransform.Microsoft.dropshadow(OffX=0px, OffY=0px, Color='#00ccff')");
});

$("ul#topnav .current a.category-menu").mouseleave(function(){
  //  $(this).css("color","white");
});

  function megaHoverOver(){
    var sub = $(this).find(".sub");
    sub.stop().fadeTo('fast', 1).show();
  }
  function megaHoverOut(){ 
  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
  $(this).hide(); 		  
  });
  }
  var config = {    
  sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
  interval: 500, // number = milliseconds for onMouseOver polling interval    
  over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
  timeout: 500, // number = milliseconds delay before onMouseOut    
  out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
  };
  $("ul#topnav li .sub").css({'opacity':'0'});
  $("ul#topnav li").hoverIntent(config);

  //modal window
  jQuery(function ($) {
    // Load dialog on click
    $('.modal').click(function (e) {
      $('#modal-' + e.target.rel).modal();
      return false;
    });
  });
});
