// JavaScript Document

var jsonData = null;

$(document).ready(function() {
						   
//	Pagina resize

	
	$(window).bind("resize", function(){
		var scrollHeight = parseInt($(window).height())-122;
		$("#scroller").css('height',scrollHeight+'px');
	}).trigger("resize");

	$("#scroller").trigger("resize");
	//$("#scroller").jScrollPane();
				 


// PNG FIX 

						   
	$.pngfix('/style/imres/images/common/pixel.gif');
	$('.login IMG, #submenu ul li a.active').pngfix();

	$('.content HR').each(function() {
		$(this).prev().css('margin-bottom','0');							   
	});


	$(".products-list TBODY TR").hover(function() {
		$(this).children().css('background-color', '#EAEDF3');
	},
	function() {
		$(this).children().css('background-color', '');	
	});


// HOOFDMENU

	$("#menu UL LI:not(.menu-split)").hover(function() {

			var $prev = $(this).prev();
			var $next = $(this).next();
			
			if ($prev) {
				$prev.removeClass('menu-split').addClass('menu-split-left');
			}
			if ($next) {
				$next.removeClass('menu-split').addClass('menu-split-right');
			}		
	},
	function() {
			var $prev = $(this).prev();
			var $next = $(this).next();
			
			if ($prev) {
				$prev.removeClass('menu-split-left').addClass('menu-split');
			}
			if ($next) {
				$next.removeClass('menu-split-right').addClass('menu-split');
			}			
	});
	
	$("#menu UL LI:last A").addClass('menu-last');
	
	
// SUBMENU

	$('#content-default-submenu ul li:last:not(.active)').css('background','none');
	$('#content-default-submenu ul li.active').prev().css('background','none');


// SEARCH

	$("#search-input").focus(function() {
		if( $(this).val() == $("#search-check").val() ){
			$(this).val('');
		}
	});

	$("#search-form").submit(function() {
		var searchVal = $("#search-input").val();
		if (searchVal > '' && searchVal != 'web & product search') {
			location = '/web/show/search/web/'+searchVal;
		}
		return false;
	});

	
	
// WEBSHOP MENU

	$('.content-categorie-content ul li[class=""]').hover(
		function(){
			$(this).addClass('active');
		}, function(){
			$(this).removeClass('active');
		}
	);
	


	
	
// Print pagina
	
	$(".print-page").click(function() {
		openWin($(this).attr('href'),600,400);
		return false;
	});

	
});


function openWin(url, wi, he) {
  var win = window.open(url,'popup_win','width='+wi+',height='+he+',resizable=yes,status=no,toolbar=no,menubar=no, scrollbars=yes');
 
  var b = screen.width;
  var h = screen.height;
 
  b = (b - wi) / 2;
  h = (h - he) / 2;
 
  win.moveTo(b,h);
  
  return false;
}

function menuItemLength() {
	$("#menu UL LI:last").addClass('menu-last');
	var qtyItems = $("#menu UL LI:not(.menu-split)").length;
	var qtySplit = qtyItems-1;
	var splitLength = qtySplit*2;
	var totalLength = 585-splitLength;
	var itemLength = Math.floor(totalLength / qtyItems);
	
	var leftOver = totalLength % qtyItems;
	var lastWidth = itemLength+leftOver;
					
	$("#menu UL LI").each(function() {
		if (!$(this).hasClass("menu-split") ) {
			$(this).css('width', itemLength+'px');
		}
	});
	$("#menu UL LI:last").css('width', lastWidth+'px');
	
}


function number_format (number, decimals, dec_point, thousands_sep)
{
  var exponent = "";
  var numberstr = number.toString ();
  var eindex = numberstr.indexOf ("e");
  if (eindex > -1)
  {
    exponent = numberstr.substring (eindex);
    number = parseFloat (numberstr.substring (0, eindex));
  }
  
  if (decimals != null)
  {
    var temp = Math.pow (10, decimals);
    number = Math.round (number * temp) / temp;
  }
  var sign = number < 0 ? "-" : "";
  var integer = (number > 0 ? 
      Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
  
  var fractional = number.toString ().substring (integer.length + sign.length);
  dec_point = dec_point != null ? dec_point : ".";
  fractional = decimals != null && decimals > 0 || fractional.length > 1 ? 
               (dec_point + fractional.substring (1)) : "";
  if (decimals != null && decimals > 0)
  {
    for (i = fractional.length - 1, z = decimals; i < z; ++i)
      fractional += "0";
  }
  
  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? 
                  thousands_sep : null;
  if (thousands_sep != null && thousands_sep != "")
  {
	for (i = integer.length - 3; i > 0; i -= 3)
      integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  }
  
  return sign + integer + fractional + exponent;
}

