function mycarousel_initCallback(carousel)
{
  // Disable autoscrolling if the user clicks the prev or next button.
  carousel.buttonNext.bind('click', function() {
    carousel.startAuto(0);
  });

  carousel.buttonPrev.bind('click', function() {
    carousel.startAuto(0);
  });

  // Pause autoscrolling if the user moves with the cursor over the clip.
  carousel.clip.hover(function() {
    carousel.stopAuto();
  }, function() {
    carousel.startAuto();
  });
};

$(function () {
    var tabContainers = $('div.tabs > div'); // получаем массив контейнеров
    tabContainers.hide().filter(':first').show(); // прячем все, кроме первого
    // далее обрабатывается клик по вкладке
    $('div.tabs ul.category_list a').click(function () {
        tabContainers.hide(); // прячем все табы
        tabContainers.filter(this.hash).show(); // показываем содержимое текущего
        $('div.tabs ul.category_list a').removeClass('selected').parent().removeClass('current'); // у всех убираем класс 'selected'
        $(this).addClass('selected').parent().addClass('current'); // текушей вкладке добавляем класс 'selected'
        return false;
    }).filter(':first').click();
});



jQuery(document).ready(function(){
	
	$('.calc_click').click(function(e){
		e.preventDefault();
		  var ul = $(this).parent().find('div.hide');
		  $(ul[0]).toggle("slow");
		  /*if($(ul[0]).css('display') == 'none' ){
			  $(this).text('Скрыть...');
		  } else {
			  $(this).text('Подробнее...');
		  }*/
		})

		$('.price').click(function(){
			var ddd = $(this).val();
			var sum = 0;
			var arr = $('input.price:checked');
			arr.each(function(index, el){
				var pr = $(this).attr('rel');
				sum += parseFloat(pr);
			});
			$('#sum').val(sum);
		})
		
		$("#upload_code").click(function(){
  		//	alert('aaa');
  			var now = new Date();
  			res ='/captcha/index.php?' +  now.getTime();
  			$("#captcha_img").attr({ src: res });   	
  	   	}
  	   	)

 $(".service").hover(function(){$(this).find("ul").css("display","block");$(this).addClass("active")},function(){$(this).find("ul").css("display","none");$(this).removeClass("active")})
 $('.scroll_pane').jScrollPane({showArrows:true});

  jQuery('#mycarousel').jcarousel({
    scroll: 1,
    auto: 2,
    wrap: 'last',
    initCallback: mycarousel_initCallback
  });
  
	$('.browse').bind('click', function(event){
		event.preventDefault();
		current_input = 'design';	
		BrowseServer();
	 });
	
})

var current_input = null;
var current_input_check = null;

function SetFinderSel(elem){
	current_input = elem;	
	BrowseServer();
}

function BrowseServer(){
	var finder = new CKFinder() ;
	finder.BasePath = '/core/lib/ckfinder/' ;	// The path for the installation of CKFinder (default = "/ckfinder/").
	finder.selectActionFunction = SetFileField;
	finder.popup() ;
	//finder.selectActionFunction = SetFileField;
	//finder.popup() ;

}

function SetFileField(fileUrl)
{	
	$('#'+current_input).attr('value',fileUrl) ;
}
