Cufon.set('fontFamily', 'MetaPro-Normal').replace('.content .content-wrap h1')
Cufon.set('fontFamily', 'MetaPro-Normal').replace('.content .content-wrap h2')
('.form h1')
('.header .absoluting .head-phone ul li span')
('.content .content-wrap .products .conteiner .inner .for-whom')
('.orderdetails .ttitle')
('#totalPrice')
('.cpt_product_related_products h2')
('.comments h2')
('.cpt_product_related_products .product-name')
('.pretty-red span');

$(document).ready(function() {
	var activeAccordionIndex = 0;
	
	$('.sub-categories li .parents li.active').parent().parent().addClass('active');
	activeAccordionIndex = $('.sub-categories li.active').index();
	
	$("#accordion").accordion({ 
		animated: 'slide',
		active: (activeAccordionIndex > 0 ? activeAccordionIndex : 0),
		autoHeight: false
	});
	
	var comboboxValueContainerClass = 'comboboxValueContainerWB';
	var comboboxDropDownButtonClass = 'comboboxDropDownButtonWB';
	var comboboxContainerClass = 'comboboxContainerWB';
	var comboboxDropDownClass = 'comboboxDropDownContainerWB';
	var width = '147px';

	$(".combobox").each(function(i){

		if($(this).hasClass('with-button')){
			comboboxValueContainerClass = 'comboboxValueContainer';
			comboboxDropDownButtonClass = 'comboboxDropDownButton';
			comboboxContainerClass = 'comboboxContainer';
			comboboxDropDownClass = 'comboboxDropDownContainer';
			width = '130px';
		}

		$(this).combobox({ 
			comboboxContainerClass: comboboxContainerClass, 
			comboboxValueContainerClass: comboboxValueContainerClass, 
			comboboxValueContentClass: "comboboxValueContent", 
			comboboxDropDownClass: comboboxDropDownClass, 
			comboboxDropDownButtonClass: comboboxDropDownButtonClass, 
			comboboxDropDownItemClass: "comboboxItem", 
			comboboxDropDownItemHoverClass: "comboboxItemHover",
			width: width
		});
	});
	
	$('input[type=checkbox]').ezMark({
		checkboxCls: 'box' ,
		checkedCls: 'box-checked'
	});
	
	$("#myController").jFlow({
		controller: ".jFlowControl", // must be class, use . sign
		//slideWrapper : "#jFlowSlider", // must be id, use # sign
		slides: "#slides", // the div where all your sliding divs are nested in
		selectedWrapper: "jFlowSelected", // just pure text, no sign
		width: "1002px", // this is the width for the content-slider
		height: "155px", // this is the height for the content-slider
		duration: 400, // time in miliseconds to transition one slide
		auto: true
	});
	
	
	var searchMinValue = parseInt($('input[name=search_price_from]').val());
	var searchMaxValue = parseInt($('input[name=search_price_to]').val());
	var sliderMin = $('#slider').slider({
		animate: true,
		range: true,
		min: searchMinValue,
		max: searchMaxValue,
		values: [searchMinValue, searchMaxValue],
		slide: function(e, ui) {
			$('input[name=search_price_from]').val(ui.values[0]);
			$('input[name=search_price_to]').val(ui.values[1]);
		}
	});
	
	var defaultSearchText = $('#searchstring').val();
	$('#searchstring').focus(function(){
		if ($(this).val() == defaultSearchText) {
			$(this).val('');
		}
	});
	$('#searchstring').blur(function(){
		if ($(this).val() == '') {
			$(this).val(defaultSearchText);
		}
	});
	
	var timer = null;
	$('#slides').hover(
		function() {
			clearInterval(timer);
		},
		function() {
			if ($('#slides div').length > 1) dotimer();
		}
	);
	
	var dotimer = function (x){
		if(timer != null) clearInterval(timer);
		timer = setInterval(function() {
			if ($('.jFlowControl.jFlowSelected').next().length) {
				$('.jFlowControl.jFlowSelected').next().click();
			} else {
				$('.jFlowControl:eq(0)').click();
			}
		}, 7000);
	}
	if ($('#slides div').length > 1) dotimer();
	
	$('.cloud-zoom').jqzoom({
		preloadText: 'Загружаю...',
		zoomWidth: 305,
		zoomHeight: 305,
		showEffect: 'show',
		hideEffect: 'hide',
		xOffset: 35
	});
	
	//popups
	$('.header .absoluting .head-log a.login').colorbox({iframe:true, innerWidth: 280, innerHeight: 280});
	$('.header .absoluting .head-phone ul li.not-phoned .cant-reach').colorbox({iframe:true, innerWidth: 280, innerHeight: 365});
	$('.content .content-wrap .products .conteiner .extras-block .empty a.addtowatch').colorbox({iframe:true, innerWidth: 280, innerHeight: 365});
	$('.content .content-wrap .block-product-detailed-info .extras-block .empty a.addtowatch').colorbox({iframe:true, innerWidth: 280, innerHeight: 365});
	$('.content .content-wrap .block-product-detailed-info .cheaper a.foundcheaper').colorbox({iframe:true, innerWidth: 280, innerHeight: 365});
	
	
	/* fix for product info h*/
	var maxH = 0;
	$('.product-info').each(function(){
		var h = $(this).height();
		if (h > maxH) {
			maxH = h;
		}
	});
	$('.product-info').height(maxH);
	
	$('.comboboxItem').click(function() {
		var newPriceStr = $(this).parent().parent().find('select.combobox.with-button').find('option:selected').attr('pricewithunit');
		// var value = $(this).parent().parent().find('select.combobox.with-button').find('option:selected').val();
		$('#totalPrice').html(newPriceStr);
		var smallPrice = $(this).parent().parent().parent().parent().find('.product-price');
		smallPrice.html(newPriceStr);
		Cufon.replace('#totalPrice');
		// Cufon.replace(smallPrice);
	});
	
	$(".comboboxDropDownContainer").find('.comboboxItem:eq(0)').click();
	
	var contentHeight = $('.footer').height() + $('.header').height() + $('.content').height();
	
	if (contentHeight < window.innerHeight) {
		var staticBlocks = $('.footer').height() + $('.header').height();
		$('.content').height($(window).height() - staticBlocks);
	}
	
});
