//СОБЫТИЯ
$(function(){
    
    /*$("a[href=not_img]").click(function(){
        alert("В данном разделе нет дополнителных изображений");    
        return false;
    })*/
    
    
	$.datepicker.setDefaults({
		firstDay: 1,
		dateFormat: 'yy-mm-dd',
		dayNames: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
		dayNamesMin: ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'],
		monthNames: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'],
		duration: 'fast',
		changeYear: true
	});
	
	
/* 	$('.catalog_all_boxs > div.box > div.foto-good > ul').hover(
		function() {
			$(this).addClass('gallery_cat');
		},
		function() {
			$(this).removeClass('gallery_cat');
		}
	);
	$('.catalog_all_boxs > div.box > div.foto-good > ul').click(
		function() {
			$(this).addClass('gallery_cat');
		},
		function() {
			$(this).removeClass('gallery_cat');
		}
	);	 */
   /*$('#gallery_cat_381').ppGallery();
	$('#gallery_cat_2').ppGallery();
	$('#gallery_cat_3').ppGallery();*/
	// FEEDBACK
	$("#feedback").fancybox({
		'scrolling'  : 'no',
		'titleShow'  : false
	});
    
    //Галерея--------------------------
    $(".gallery_cat").fancybox({
        'width':1000,
		'scrolling'  : 'no',
		'titleShow'  : false,
        'showCloseButton' : true,
        'showNavArrows' : false,
        'padding' : 0,
        'margin' : 0,
        'overlayColor': '#000',
        'overlayOpacity' : 0.5,
        'onComplete' : function(){
            $("#slider_block").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		speed: 500,
		visible: 5,
		circular: false
    
    });
        
        
        }
        
        
	});
    $("#playpp").live('click',function (){
        if ($(this).html()=='Stop'){
            
            $(this).html("Play");
        }
        else {
          $(this).html("Stop");
         
        }
    })
    $("#playpp").live('click',play_bl)
    
    
    function play_bl()
    {
       
      if ($("#playpp").html()!='Play')
      {
       var next_imgi = $(".showing").next().children()
        if (next_imgi.length)
        {
             $(".borderBoxpp").html(next_imgi.clone().css({'height':'auto','width':'700px','margin-bottom':'15px'}))
            
            $.each($(".thumbNail_1"), function (){
                $(this).parent().removeClass('showing');   
            })
            get_normal_height();
            $(".next").click();
            next_imgi.parent().addClass('showing');
           if ($("#playpp").html()=='Stop') setTimeout(play_bl, 2000);
        } 
      }
    }
    
    function next_img()
    {
        if ($("#playpp").html()=='Stop') $("#playpp").html('Play');
       
        var next_imgi = $(".showing").next().children()
        if (next_imgi.length)
        {
             $(".borderBoxpp").html(next_imgi.clone().css({'height':'auto','width':'700px','margin-bottom':'15px'}))
            get_normal_height();
            $.each($(".thumbNail_1"), function (){
                $(this).parent().removeClass('showing');   
            })
            
            $(".next").click();
            next_imgi.parent().addClass('showing');
            
        }
    } 
    
     function prev_img()
    {
        if ($("#playpp").html()=='Stop') $("#playpp").html('Play');
        
        var prev_imgi = $(".showing").prev().children()
        if (prev_imgi.length)
        {
             $(".borderBoxpp").html(prev_imgi.clone().css({'height':'auto','width':'700px','margin-bottom':'15px'}))
           get_normal_height();
            $.each($(".thumbNail_1"), function (){
                $(this).parent().removeClass('showing');   
            })
            
            $(".prev").click();
            prev_imgi.parent().addClass('showing');
            
        }
    } 
    
    $("#previousButtonBoxpp").live('click',prev_img);
    
    $("#nextButtonBoxpp").live('click',next_img)
    $(".thumbNail_1").live('click',function(){
         $.each($(".thumbNail_1"), function (){
            $(this).parent().removeClass('showing');   
         })
        $(this).parent().addClass('showing');
        $(".borderBoxpp").html($(this).clone().css({'height':'auto','width':'700px','margin-bottom':'15px'}))
        get_normal_height();
    })  
    
    function get_normal_height()
    {
        if ($("#lightBoxGallerypp").height()>$("#descr_tov").height()) 
        {
            $("#fancybox-wrap").height($("#lightBoxGallerypp").height());
        }
    }
    //-------------------------------------------------
    
	//SUBSCRIBE
	$('#subscribe-add').click(function(){
		var vars = {
			ru : {
				errors : {
					emptyMail : 'Введите e-mail',
					wrongMail : 'E-mail некорректен'
				},
				loading : 'Загрузка',
				enter : 'Подписаться'
			},
			en : {
				errors : {
					emptyMail : 'Enter e-mail',
					wrongMail : 'E-mail is incorrect'
				},
				loading : 'Loading',
				enter : 'Subscribe'
			}
		};
		var that = this;
		var el = $('#subscribe-mail');
		var val = el.val();
		var msg = [];
		if( val=='' || val==el.attr('title') ) msg.push(vars[_LANG_].errors.emptyMail);
		else if( !val.match(/^[\d\w\.-]+@([\d\w-]+)((\.[\w\d-]+)+)?\.\w{2,6}$/) ) msg.push(vars[_LANG_].errors.wrongMail);
		
		if(msg.length>0){
			alert(msg.join("\n"));
			return false;
		}
		$(this).text(vars[_LANG_].loading).attr('disabled', 'disabled');
		$.get(ajaxFile, {go:'subscribe_add', mail:val}, function(html){
			$(that).text(vars[_LANG_].enter).removeAttr('disabled');
			alert(html);
		});
	});
	
	$("#pikame").PikaChoose({transition:[5],carousel:true,startOn:3});

	$("#pikame").jcarousel({scroll:3,
		initCallback: function(carousel) 
		{
			$(carousel.list).find('img').click(function() {
				//console.log($(this).parents('.jcarousel-item').attr('jcarouselindex'));
				carousel.scroll(parseInt($(this).parents('.jcarousel-item').attr('jcarouselindex')));
			});
		}
	});
	/*Cufon.replace('.main_menu ul li a');
	Cufon.replace('.title_cat');
	Cufon.replace('.left_menu li a');
	Cufon.replace('.list_menu');*/

	$('#othen').click(
		function() {
			$('#othen_box').is(':hidden') ? $('#othen_box').show('fast') : $('#othen_box').hide('fast');
			return false;
		}
	);
/* 	$('.img_box').tooltip({
		delay: 0, 
		showURL: false, 
		bodyHandler: function() {
			return $("<img />").attr("src", $(this).prev().text()); 
		} 
	}); */
});

$(function(){
	$('.needClear')
		 .focus(function(){
			  if(this.value==this.title) this.value='';
		 })
		 .blur(function(){
			  if(this.value=='') this.value=this.title;
		 });
});

function checkSearchForm(f){
	var msg = [];
	
	if(f['what'].value=='Поиск по сайту' || f['what'].value=='') msg.push('Введите слово для поиска');
	else if(f['what'].value.length<3) msg.push('Слово для поиска должно быть длиннее 3-х символов');
	
	if(msg.length>0){
		alert(msg.join("\n"));
		return false;
	}
	return true;
}
$.fn.center = function () {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}

