$(document).ready(function(){

/* slides */
if ( $('#slides').length > 0){
$('#slides').slides({
				preload: true,
				preloadImage: '/common/img/loading.gif',
				play: 8000,
				pause: true,
				hoverPause: true
			});

$('#slides').bind('mouseover', function(){});
}
/* /slides */


/* main_menu */
$("#menu_list").hide();
$("#menu_more a").click(function(){
	$(this).toggleClass("sel").parent("#menu_more").next("#menu_list").stop(true,true).slideToggle();
	return false;
});
/* /main_menu */

/* form */
if ( $('table.form-table').length > 0){
$("table.form-table input, table.form-table textarea, table.form-table select, table.form-table button").uniform({fileDefaultText: 'Выберите файл', fileBtnText: 'Обзор'});
}

if ( $('div.search-page form').length > 0){
$("input.search-button, input.search-query").uniform();
}

/*
if ( $('table.data-table').length > 0){
$("table.data-table input, table.data-table textarea").uniform();
}
*/

/* /form */

/* select_city */
$('#city_wrap span.text_sel').text( $('#city_wrap select.select option:selected').text() );
 $('#city_wrap select.select').change(function(){
  var value = $(this).val();
  $('#city_wrap span.text_sel').text( value );
 });
/* /select_city */

/* select */
	$('select.select').change(function(){
		var value = $('select.select option:selected').text();
		$(this).next("span.text_sel").text(value);
	});
/* /select */


/* lang */
	/*$("#lang_more i").show();*/
	$("#lang").css({width: '26px'});
	$("#top_search input.inp").css("width", "385px");
	$("#lang span").click(function(){
	$("#lang").animate({width: '75px'}, 300);
	$("#top_search input.inp").animate({width: '335px'}, 300);
	});


	 $("#top_search input.inp").focus(function () {
	 $("#lang").animate({width: '26px'}, 300);
	 $("#top_search input.inp").animate({width: '385px'}, 300);
    });
	
/* /lang */

	
if ($.browser.opera){ $("#panel a.big").css("font-weight","bold");}

/* list */
	$("div.more").not(":first").hide();
	$("h2.head").click(function(){
	$(this).toggleClass("sel").next("div.more").slideToggle();
	return false;
	});
/* /list */

$("table.param td img").removeAttr("title");
$("table.param td p").append("<span></span>");
/*$("table.param td p span").hide();*/
$("table.param td p").hover(function() {
		//$(this).animate({opacity: "0.2"},100);
		var largeAlt = $(this).children("img").attr("alt");
		//alert(largeAlt);
		$(this).children().next("span").addClass("show").text(largeAlt);
	}, function() {
		//$(this).animate({opacity: "1"},50);
		$(this).children().next("span").removeClass("show");
	});


/* checkbox */
$('.form_option input[type=checkbox]').each(function(){
 name = "[name="+$(this).attr('id').substr(1)+"]";
 c = $("#"+$(this).attr('id'));
 if($(c).is(":checked")){
  $(name).attr('disabled',false);
  if(name == "[name=power]"){
   $("[name=num]").attr('disabled',false);
  }
 }else{
  $(this).parent().next("td").toggleClass("hide");
  $(name).attr('disabled','disabled');
  if(name == "[name=power]"){
   $("[name=num]").attr('disabled','disabled');
  }
 }
 
			$($("label[for="+$(this).attr('id')+"]")).click(function(e){
			name = "[name="+$(this).attr('for').substr(1)+"]"; 
				$(this).parent().next("td").toggleClass("hide");
				e.preventDefault();
				c = $("#"+$(this).attr('for'));
				if($(c).is(":checked")){
				 if(name == "[name=power]"){
				  $("[name=num]").attr('disabled','disabled');
				 }
				 $(name).attr('disabled','disabled');
				}else{
				 $(name).attr('disabled',false);
				 if(name == "[name=power]"){
				  $("[name=num]").attr('disabled',false);
				 }
				}
				$(c).attr('checked',!$(c).is(':checked')).is(':checked') ? $(this).removeClass('checkbox_unchecked').addClass('checkbox_checked') : $(this).removeClass('checkbox_checked').addClass('checkbox_unchecked');
			}).addClass($(this).is(':checked') ? 'checkbox_checked' : 'checkbox_unchecked');
		}).hide();
/* /checkbox */

/* tooltip  */
//$('td span.radio label').hide();
$('td span.radio input').css("opacity","0");
$('td span.radio input').bind('click', function(){
$(this).parent().parent().find('label').hide();
/*$('span.radio label').hide();*/
$(this).parent().parent().find('label').hide();
$(this).parent().parent().find('span.radio').removeClass('sel');
//$('span.radio').removeClass('sel');
$(this).parent('span.radio').addClass('sel');
$(this).next('label').show();
	});

 /* /tooltip */

/* up_slow
$("#one_col .cont h2").click(function() {
      //  var anc = $(this).attr("href").substring(1);
        $("html:not(:animated)"+( ! $.browser.opera ? ",body:not(:animated)" : "")).animate({scrollTop: $("#one_col").position().top});
        return false;
    }); 
 /up_slow */

 
// reset products search form
$('form.form_option input.but_clear').click(function(){
 $('form.form_option th :checkbox').attr('checked', 'checked');
 $('form.form_option th label').removeClass('checkbox_unchecked').addClass('checkbox_checked');
 $('form.form_option td').removeClass("hide");
 $('form.form_option :input').attr('disabled',false);
 $('form.form_option td :radio').removeAttr('checked');
 $('form.form_option span.radio').removeClass('sel');
 $('form.form_option span label').hide();
 $('form.form_option input[type=text]').attr('value','');
 $('form.form_option #ip option:selected').removeAttr('selected');
 $('form.form_option #ip option:first').attr('selected', 'selected');
 $('form.form_option span.text_sel').html('&nbsp;');
});
// no input non digits
$("form.form_option input[type=text]").keypress(function(event){
  if(event.which == 13){
   $('form.form_option').submit();
  }
  var controlKeys = [8, 9, 13, 35, 36, 37, 39, 44];
  var isControlKey = controlKeys.join(",").match(new RegExp(event.which));
  if (!event.which || (48 <= event.which && event.which <= 57) || isControlKey) { 
    return;
  } else {
    event.preventDefault();
  }
});


if($("body").find('#cbx_fade').length>0){

	 $('#cbx_fade_a').click(function(){
	  $('#cbx_fade img').fadeOut('fast');
	  $('#cbx_fade_a').css('font-weight','bold');
	  $('#cbx_fade_n').css('font-weight','normal');
	  return false;
	 });
	 $('#cbx_fade_n').click(function(){
	  $('#cbx_fade img').fadeIn('fast');
	  $('#cbx_fade_n').css('font-weight','bold');
	  $('#cbx_fade_a').css('font-weight','normal');
	  return false;
	 });
	$('#cbx_fade_n').css('font-weight','bold');
	$('#cbx_fade').click(function(){
	$('#cbx_fade img').toggle();
	});
 
}

/* pre */
var num_max = $("#pre_slide div.pre").length;
var n = 0;
num_max = num_max-1
$("#pre_slide div.pre").not(":first").hide();

$("a#next_pre").click(function () {
			if (num_max != n )
			{
				$("#pre_slide div.pre").eq(n).hide();
				$("#pre_slide div.pre").eq(n+1).show();
				++n;
			}
			else
			{
				$("#pre_slide div.pre").eq(n).hide();
				n = 0;
				$("#pre_slide div.pre").eq(n).show();
			}

return false;
    });
/* /pre */

});
