$(document).ready(function() {	
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		callback: function(){}
	});
});
 
jQuery(document).ready(function($) {
	$('a[rel*=facebox]').facebox({
		loading_image : 'loading.gif',
		close_image   : 'closelabel.gif'
	})
});

$(document).ready(function(){
	$("#dim").css("height", $(document).height());
	$(window).bind("resize", function(){
		 $("#dim").css("height", $(window).height());
	});
});

function menu(id) {
	$(".menu_sh").hide();
	$("#m"+id).slideToggle('slow');
	
	$("#dim").fadeIn();
	$("#ajax-content").hide();
	
	$.get('/cat/ajax/'+id, null, 
    function(data) {
    		$("#ajax-content").html(data);
			$("#ajax-content").slideToggle("slow");
    	}
	);
	$("#dim").fadeOut();
}

function vote(id,vote) {
	$.get('/vote?id='+id+'&vote='+vote, null,
	function(data) {
			$("#block_marks").hide();
        	$("#block_marks").html(data);
        	$("#block_marks").slideToggle('slow');
    	}
	);
}

function captcha() {
	$.post('/index/captcha', null,
	function(data) {
			$("#recaptcha").hide();
        	$("#recaptcha").html(data);
        	$("#recaptcha").show();
    	}
	);
}

function response(id)
{
	$("#ajax_icon").show();
	
	var data = new Array();
	
	data[0]=$.trim($("input[name='name']").val());
	data[1]=$.trim($("input[name='email']").val());
	data[2]=$.trim($("input[name='phone']").val());
	data[3]=$.trim($("textarea[name='content']").val());
	data[4]=$.trim($("input[name='code']").val());
	
	if (data[3].length > 5) {
		$.post('/response?id='+id+'&data='+data, null,
		function(data) {
			alert(data);
				if (data=='false') {
					alert('Внимание! Введен неверный код!');
					$("#ajax_icon").hide();
					$("#form_response").show();
				}
				else {
					closePopup();
					alert('Спасибо! Ваш отзыв принят и ожидает проверки!');
					$("input[name='name']").val('');
					$("input[name='email']").val('');
					$("input[name='phone']").val('');
					$("textarea[name='content']").val('');
					$("input[name='code']").val('');
					captcha();
					$("#ajax_icon").hide();
				}
	    	}
		);
	} else {
		alert('Напишите хотя бы 6 символов!');
		$("#ajax_icon").hide();
		$("#form_response").show();
	}
}

function shopping_cart(id) {
	$.get('/shopping_cart/add?id='+id+'&cc=1', null,
	function(data) {
        	$("#shopping-cart-box").hide();
			$("#shopping-cart-box").html(data);
			$(document).ready(function(){
				$("#shopping-cart-box").slideToggle("slow");
				$("#shopping-cart-box").show();
			});
    	}
	);
}

function comp(id)
{
	$.get('/comp/add?id='+id, null,
	function(data) {
			alert(data);
			$.get('/comp/counts?id='+id, null,
			function(data) {
					$("#comps").html(data);
		    	}
			);
    	}
	);
}

function viewinfo(place,id)
{
	$.get('/cat/viewinfo?id='+id, null,
	function(data) {
			if (data.length!=0)
			{
				$('#view'+place).html(data);
			}
    });
}

function comp_refer(id)
{
	comp(id);
	window.location=document.location;
}

/*****************************
**     Popup message
******************************/

//additional properties for jQuery object
$(document).ready(function(){
   //align element in the middle of the screen
   $.fn.alignCenter = function() {
      //get margin left
      var marginLeft = Math.max(40, parseInt($(window).width()/2 - $(this).width()/2)) + 'px';
      //get margin top
      var marginTop = Math.max(40, parseInt($(window).height()/2 - $(this).height()/2)) + 'px';
      //return updated element
      return $(this).css({'margin-left':marginLeft, 'margin-top':marginTop});
   };

});


//close pop-up box
function closePopup()
 {
   $('#opaco').toggleClass('hidden').removeAttr('style');
   $('#popup').toggleClass('hidden');
   return false;
 }

//open pop-up
function showPopup(popup_type)
 {
   //when IE - fade immediately
   if($.browser.msie)
   {
     $('#opaco').height($(document).height()).toggleClass('hidden');
   }
   else
   //in all the rest browsers - fade slowly
   {
     $('#opaco').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.5);
   }

   $('#popup')
     .html($('#popup_' + popup_type).html())
     .alignCenter()
     .toggleClass('hidden');

   return false;
 }

 
 /* popussss */
$(function () {
$('.bubbleInfo2').each(function () {
var distance = 10;
var time = 250;
var hideDelay = 500;
var hideDelayTimer = null;
var beingShown = false;
var shown = false;
var trigger = $('.trigger2', this);
var info = $('.popup2', this).css('opacity', 0);

$([trigger.get(0), info.get(0)]).mouseover(function () {
if (hideDelayTimer) clearTimeout(hideDelayTimer);
if (beingShown || shown) {
    // don't trigger the animation again
    return;
} else {
    // reset position of info box
    beingShown = true;

    info.css({
        top: -40,
        left: -33,
        display: 'block'
    }).animate({
        top: '-=' + distance + 'px',
        opacity: 1
    }, time, 'swing', function() {
        beingShown = false;
        shown = true;
    });
}
return false;
}).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                info.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    info.css('display', 'none');
                });

            }, hideDelay);

            return false;
        });
    });
});

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();
    });
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
   
   	scroll: 4, 
        auto: 10,
        wrap: 'both',
        initCallback: mycarousel_initCallback
      
    });
   jQuery('.first-and-second-carousel').jcarousel({
   	scroll: 4, 
        auto: 10,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    }); 
});

$(function(){
  $("#tabs").tabs();
	});