// JavaScript Document

$(function(){

	$(".mainlinks .item").hover(function(){
		$(this).addClass("hover");
		$(this).find(".hoverlist").show();
	},function(){
		$(this).removeClass("hover")		
		$(this).find(".hoverlist").hide();
	});
	
	$(".catelogs .opencate").click(function(){
		
		
		if(0 == $("body.cms-home").size()){
			$(".catelogs").find(".holderlist").toggle();
			$(this).toggleClass("open");		
		}
		
		return false;
	});
	$(document).click(function(){
		if(0 == $("body.cms-home").size()){
			$(".catelogs").find(".holderlist").hide();	
			$(".catelogs .opencate").addClass("open");
		}
	});
	$(document).trigger('click');
		
	$(".catelogs .hoverlist dl, .mini_prolist dl, .headcart, .products-grid li").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover")
	});
	
	
});

function SelectStyle(on,option){
	on = "." + on;
	option = "." + option;
	var currentSort = $(on).attr('id');
	var currentText = $(option+" li."+currentSort + " a").html();
	$(on + " .text").addClass(currentSort).html(currentText);
	
	$(".selectbox").hover(function(){
		$(option).show()
	},function(){		
		$(option).hide()
		
	})
}

function decorateDataList(el, option){
	//option; // ['odd','even','first','last']
	$(el).find('>:last-child').addClass('last');
	$(el).find('>:first-child').addClass('first');
	$(el).find('>:nth-child(even)').addClass('even');
	$(el).find('>:nth-child(odd)').addClass('odd');
	
}
function decorateList(el,hover){
	el = '#' + el;
	$(el).find('>:last-child').addClass('last');
	$(el).find('>:first-child').addClass('first');
	$(el).find('>:nth-child(even)').addClass('even');
	$(el).find('>:nth-child(odd)').addClass('odd');
	if(hover){
		$(el).find('>*').hover(function(){
			$(this).addClass('hover');
		},
		function(){
			$(this).removeClass('hover');
		});
		}
}
function decorateTable(el){
	el = '#' + el;
	$(el).find('tbody tr:nth-child(even)').addClass('even');
	$(el).find('tbody tr:nth-child(odd)').addClass('odd');
	$(el).find('tr:last-child').addClass('last');
	$(el).find('tr:first-child').addClass('first');
}


function popWin(url,win,para) {
    var win = window.open(url,win,para);
    win.focus();
}
function setLocation(url){
    window.location.href = url;
}

function hoverdiv(mc,oper){
	$(mc).hover(function(){
		$(this).addClass("hoverbg");
		$(this).find(oper).show()
	},
	function(){
		$(this).find(oper).hide();
		$(this).removeClass("hoverbg");
	});
	
}

function formatNumber(number) {
	var parts = number.toString().split('.');
	var integer = parts[0].split('');
	var decimal = parts[1];
	var start = integer.length % 3;
	var length = integer.length;
	if(start == 0) {
		start = 3;
	}
	while(start < integer.length) {
		integer.splice(start, 0, ',');
		start += 4;
	}
	return [integer.join(''), decimal].join('.');
}



