//////////////////////////////////////////////////
/////////// CUFON ////////////////////////////////
//////////////////////////////////////////////////
Cufon.replace('h2'); 
Cufon.replace('h3');
Cufon.replace('.cufon');

//////////////////////////////////////////////////
/////////// CHECKBOX /////////////////////////////
//////////////////////////////////////////////////
jQuery(document).ready(function(){
	jQuery('.checkbox input:checked').parent().addClass('checked');
	jQuery('.checkbox input').change(function(){
		if($(this).attr('checked'))	{
			$(this).parent().addClass('checked');
		} else {
			$(this).parent().removeClass('checked');
		}
	})
});

//////////////////////////////////////////////////
/////////// ACCORDION ////////////////////////////
//////////////////////////////////////////////////
jQuery(document).ready(function() {
    SetAccordition();
});

function SetAccordition() {
    jQuery('.acc:not(".open") .acc-body').hide();
    jQuery('.acc-link').click(function() {
        var $acc = $(this).parents('.acc');
        //var s = $acc.find('img').attr("src");
        if ($acc.hasClass('open')) {
            $acc.removeClass('open');
        } else {
            $acc.addClass('open');
          //var $bimg = $acc.find('.acc-body img');
          //$bimg.attr("src", s.replace("s.jpg", "xxl.jpg"));
          //$bimg.show();
        }
        $acc.find('.acc-body').animate({ height: 'toggle' }, 'fast');
        return false;
    });
}

function SetCompareAccordition() {
    jQuery('.checkbox input:checked').parent().addClass('checked');
    jQuery('.checkbox input').change(function() {
        if ($(this).attr('checked')) {
            $(this).parent().addClass('checked');
        } else {
            $(this).parent().removeClass('checked');
        }
    })

    $(".compare-options .showall input").live('change', function() {
        var acs = $(".compare-options .acc");
        if ($(this).attr('checked')) {
            $(acs).each(function() {
                if (!$(this).hasClass("open")) { $(this).addClass("open"); $(this).find('.acc-body').animate({ height: 'toggle' }, 'fast'); }
            });
        } else {
            $(acs).each(function() {
                if ($(this).hasClass("open")) { $(this).removeClass("open"); $(this).find('.acc-body').animate({ height: 'toggle' }, 'fast'); }
            });
        }
    });    

    jQuery('.compare-options .acc:not(".open") .acc-body').hide();
    jQuery('.compare-options .acc-link').click(function() {
        var $acc = $(this).parents('.acc');
        if ($acc.hasClass('open')) {
            $acc.removeClass('open');
        } else {
            $acc.addClass('open');
        }
        $acc.find('.acc-body').animate({ height: 'toggle' }, 'fast');
        return false;
    });
}

//////////////////////////////////////////////////
/////////// SLIDERS //////////////////////////////
//////////////////////////////////////////////////
jQuery(document).ready(function(){
	var sliderOptions = {
		price   : { range: true, min: 500000, max: 20000000, step: 10000, values: [ 500000, 20000000 ] }, // Цена
		mileage : { range: true, min: 0,      max: 50000,    step: 100,   values: [ 100, 50000 ] },       // Пробег
		release : { range: true, min: 2008,   max: 2011,     step: 1,     values: [ 2009, 2010 ] },       // Год выпуска
		power   : { range: true, min: 0,     max: 50000,     step: 100,   values: [ 0, 49000 ] },         // Мощность двигателя
		amount  : { range: true, min: 0,     max: 50000,     step: 100,   values: [ 0, 50000 ] }          // Объём двигателя
	};
	
   	$('.slider-box').each(function(){
		for (var key in sliderOptions) {
			if ($(this).hasClass(key+'-type')) {
				sliderOptions[ key ].slide = function( event, ui ) {
					$(this).parent().find('.value-left').text(ui.values[ 0 ]);
					$(this).parent().find('.value-right').text(ui.values[ 1 ]);
				};
				$(this).find('.slider-range').slider(sliderOptions[key]);
				$(this).find('.value-left').text(sliderOptions[ key ].values[ 0 ]);
				$(this).find('.value-right').text(sliderOptions[ key ].values[ 1 ]);
				break;
			}
		}
	});
});

//////////////////////////////////////////////////
/////////// CUSEL ////////////////////////////////
//////////////////////////////////////////////////
/*
jQuery(document).ready(function(){
	var params = { 
   		changedEl: "select",
		checkZIndex: true
	};
	if ($('select').length > 0) {
		cuSel(params);
	}
});
*/
// Селектов на странице много, один под другим.
// Поэтому они накладываются друг на друга, этот фикс решает данную проблему.
jQuery(document).ready(function(){
	var i = 500;
	$('.select-box').each(function(){
		$(this).css('z-index', i);
		i--;
	});
});
