/* jmousewheel */
(function(c){var a=["DOMMouseScroll","mousewheel"];c.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var d=a.length;d;){this.addEventListener(a[--d],b,false)}}else{this.onmousewheel=b}},teardown:function(){if(this.removeEventListener){for(var d=a.length;d;){this.removeEventListener(a[--d],b,false)}}else{this.onmousewheel=null}}};c.fn.extend({mousewheel:function(d){return d?this.bind("mousewheel",d):this.trigger("mousewheel")},unmousewheel:function(d){return this.unbind("mousewheel",d)}});function b(f){var d=[].slice.call(arguments,1),g=0,e=true;f=c.event.fix(f||window.event);f.type="mousewheel";if(f.wheelDelta){g=f.wheelDelta/120}if(f.detail){g=-f.detail/3}d.unshift(f,g);return c.event.handle.apply(this,d)}})(jQuery);

/* jcarousellite */
(function($){$.fn.jCarouselLite=function(o){o=$.extend({btnPrev:null,btnNext:null,btnGo:null,mouseWheel:false,auto:null,speed:200,easing:null,vertical:false,circular:true,visible:3,start:0,scroll:1,beforeStart:null,afterEnd:null},o||{});return this.each(function(){var b=false,animCss=o.vertical?"top":"left",sizeCss=o.vertical?"height":"width";var c=$(this),ul=$("ul",c),tLi=$("li",ul),tl=tLi.size(),v=o.visible;if(o.circular){ul.prepend(tLi.slice(tl-v-1+1).clone()).append(tLi.slice(0,v).clone());o.start+=v}var f=$("li",ul),itemLength=f.size(),curr=o.start;c.css("visibility","visible");f.css({overflow:"hidden",float:o.vertical?"none":"left"});ul.css({margin:"0",padding:"0",position:"relative","list-style-type":"none","z-index":"1"});c.css({overflow:"hidden",position:"relative","z-index":"2",left:"0px"});var g=o.vertical?height(f):width(f);var h=g*itemLength;var j=g*v;f.css({width:f.width(),height:f.height()});ul.css(sizeCss,h+"px").css(animCss,-(curr*g));c.css(sizeCss,j+"px");if(o.btnPrev)$(o.btnPrev).click(function(){return go(curr-o.scroll)});if(o.btnNext)$(o.btnNext).click(function(){return go(curr+o.scroll)});if(o.btnGo)$.each(o.btnGo,function(i,a){$(a).click(function(){return go(o.circular?o.visible+i:i)})});if(o.mouseWheel&&c.mousewheel)c.mousewheel(function(e,d){return d>0?go(curr-o.scroll):go(curr+o.scroll)});if(o.auto)setInterval(function(){go(curr+o.scroll)},o.auto+o.speed);function vis(){return f.slice(curr).slice(0,v)};function go(a){if(!b){if(o.beforeStart)o.beforeStart.call(this,vis());if(o.circular){if(a<=o.start-v-1){ul.css(animCss,-((itemLength-(v*2))*g)+"px");curr=a==o.start-v-1?itemLength-(v*2)-1:itemLength-(v*2)-o.scroll}else if(a>=itemLength-v+1){ul.css(animCss,-((v)*g)+"px");curr=a==itemLength-v+1?v+1:v+o.scroll}else curr=a}else{if(a<0||a>itemLength-v)return;else curr=a}b=true;ul.animate(animCss=="left"?{left:-(curr*g)}:{top:-(curr*g)},o.speed,o.easing,function(){if(o.afterEnd)o.afterEnd.call(this,vis());b=false});if(!o.circular){$(o.btnPrev+","+o.btnNext).removeClass("disabled");$((curr-o.scroll<0&&o.btnPrev)||(curr+o.scroll>itemLength-v&&o.btnNext)||[]).addClass("disabled")}}return false}})};function css(a,b){return parseInt($.css(a[0],b))||0};function width(a){return a[0].offsetWidth+css(a,'marginLeft')+css(a,'marginRight')};function height(a){return a[0].offsetHeight+css(a,'marginTop')+css(a,'marginBottom')}})(jQuery);


function place_holder(id, default_text)
{
	if (!$(id))
	{
		return;
	}
	$(id).bind('focusin', function()
	{

		this.value = (this.value == default_text) ? '' : this.value;
	});
	$(id).bind('focusout', function()
	{
		this.value = (this.value == '') ? default_text : this.value;
	});
}
var w = $(window);
function getDistanceToBodyFromLeft() {
	return (w.width() < $('body').width()) ? 0 : ($('body').width() - w.width()) / 2;
}
function getCenterPosition(s) {
	var horizontal = ((w.width() - s.width()) / 2) + getDistanceToBodyFromLeft(); 
	s.css('left', horizontal);
} 


 


$(document).ready(function(){
	$('#logo-slide').jCarouselLite({
		btnPrev: '#jcarousel-prev',
		btnNext: '#jcarousel-next',
           	visible: 6,
                scroll: 1,
		mouseWheel: true,
		circular: true,
		auto: 2000,
 
                afterEnd: function(a) {

                $(a[3]).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
		.animate({
			marginTop: '-35px', /* The next 4 lines will vertically align this image */ 
			marginLeft: '0px',
			top: '50%',
			left: '50%',
			width: '180px', /* Set new width */
			height: '60px', /* Set new height */
			padding: '20px'
		}, 200);
},
                beforeStart: function(a) {
                $(a[3]).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
		        .animate({
			marginTop: '0', /* Set alignment back to default */
			marginLeft: '0',
			top: '0',
			left: '0',
			width: '90px', /* Set width back to default */
			height: '30px', /* Set height back to default */
			padding: '0px'
		        }, 100);

            }  

	});

	$("#all-partners").bind('click', function(){
		$("#partners-list").openPopup({follow:false, modalColor:'#fff',opacity:0.4});
		return false
	});
	$("#show-report").bind('click', function(){
		$("#report").openPopup({modalColor:'#fff',opacity:0.4});
		return false
	});
	place_holder('form.search input', 'поиск по сайту');
	
	/* Mail */
	$('#report form').submit(function(){
		$.ajax({
			type : 'POST',
			url : '/mail.php?'+Math.random(),
			data : $(this).serialize(),
			cache: false,
			async: false,
			success: function(data) {
				if (data == 'true') {
					$('#reportStatus').html('<h3 class="success">Спасибо, ваше сообщение отправлено.</h3>');
					$('#report textarea').text('');
				} else {
					$('#reportStatus').html('<h3 class="error">К сожалению, произошла какая-то ошибка и мы не смогли отправить письмо.</h3>');
				}
			}
		});
		return false;
	});
	
	$('a.photo').click(function(){
		var photoBox = $('#photobox');
		var xe = $(this).attr('href');
		$('#bigimg').hide()
		$('#bigimg').load(function() {  
			var imgWidth = $(this).width();
			var imgHeight = $(this).height();
			photoBox.animate({
				width: imgWidth + 130,
				height: imgHeight + 130
			}, 'fast');
			getCenterPosition($('#photobox'));
			photoBox.removeClass('load');
			$('#bigimg').fadeIn();
		}).attr('src', xe);
		$('#photobox #photoboxH2').text($(this).attr('title'));
		photoBox.openPopup({modalColor:'#fff',opacity:0.4});
		photoBox.children('.bClose').click(function(){
			photoBox.addClass('load');
		});
		return false;
	});
});
