/* -------------------------------------------------- *
 * Project scripts
 * -------------------------------------------------- *
 * Author: Morozov Igor
 * URL: http://www.morozoff.info/
 * Copyright: 2010 Morozov Igor
** -------------------------------------------------- */

$(document).ready(function() {
	Cufon.replace(['.shakula'], {hover: true});
	
	if($('a.thickbox').length) {
		$('a.thickbox').colorbox({
			maxHeight:'100%',
			maxWidth:'100%'
		});
	}
	
	if($('.bmninfo').length) {
		var $vis = $('.bmninfo');
//		$("#visarea").scrollable({circular:true, }).navigator();
  $("#visarea").scrollable({circular:true,item:'li'}).navigator().autoscroll({
  	interval: 8000
 });
		var apiarea = $("#visarea").data("scrollable"); 
		
		$('.b-navigation a').click(function(){
		
			$('.b-navigation a').removeClass('hr');
			$(this).addClass('hr');
			Cufon.refresh('.shakula');
			var idx = $('.b-navigation a').index($(this));
			$('.pane',$vis).hide();
			$('.pane',$vis).eq(idx+1).show();
			apiarea.stop();
			return false;
		})
		$('.bmninfo .close').click(function(){
			$('.pane',$vis).hide();
			$('.b-navigation a').removeClass('hr');
			$('.pane',$vis).eq(0).show();
			apiarea.play();
			Cufon.refresh('.shakula');
			return false;
		})
		
		
		
		if(apiarea.getNaviButtons().length) {
			var $area = $("#visarea");
			var $navi = $(apiarea.getNaviButtons());
			
			var viNewsindex = $('li',$area).index($('li[class="vis-news"]:first',$area))
			var viProjindex = $('li',$area).index($('li[class="vis-proj"]:first',$area))
			var vi3dindex = $('li',$area).index($('li[class="vis-3d"]:first',$area))
			if($('body').hasClass('main-page-en')) {
				if(viNewsindex > -1) {
				$('a',$navi).eq(viNewsindex-1).before('<small>News:</small>')
			}
			if(viProjindex > -1) {
				$('a',$navi).eq(viProjindex-1).before('<small>Completed projects:</small>')
			}
			if(vi3dindex > -1) {
				$('a',$navi).eq(vi3dindex-1).before('<small>3D-projects:</small>')
			}
			} else {
			if(viNewsindex > -1) {
				$('a',$navi).eq(viNewsindex-1).before('<small>Новости:</small>')
			}
			if(viProjindex > -1) {
				$('a',$navi).eq(viProjindex-1).before('<small>Реализованные проекты:</small>')
			}
			if(vi3dindex > -1) {
				$('a',$navi).eq(vi3dindex-1).before('<small>3D-проекты:</small>')
			}
}
			
		}
		
		
	}
	
	$('.link-smap').click(function(){
		
		if($(this).hasClass('active-smap')) {
			$(this).removeClass('active-smap')
			$('.bottom').css({marginTop:'-120px',height:'120px'})
			$('.outer').css({paddingBottom:'180px'});
			$('.b-sitemap-i').hide();
		}
		else {
			$(this).addClass('active-smap')
			var hgh = $('.b-sitemap-i').height();
			$('.bottom').css({marginTop:'-'+parseInt(140+hgh)+'px',height:140+hgh+'px'})
			$('.outer').css({paddingBottom:200+hgh+'px'});
			$('.b-sitemap-i').show();
		}
		return false;
	});
	
	if($('#structcomp').length) {
		$("#structcomp .b-tabs").tabs("div.panes > .pane", {
			tabs:'dd',
			current:'active'
		});
	}
	
	if($('#news-all-list').length) {
		var $newsall = $('#news-all-list');
		var shnews = 1;
		totalRow = Math.ceil($('li',$newsall).length/5);
		//console.info(totalRow)
		$('li',$newsall).slice('5').hide();
		$('#all-newslink').show().click(function(){
			//console.info(totalRow)
			if(shnews < (totalRow - 1)) {
				$('li',$newsall).slice(shnews*5,(shnews*5)+5).show('15');
				shnews++;
			}
			else {
				$('li',$newsall).slice(shnews*5).show('15');
				$(this).hide();
			}
			return false;
		});
	};
	
	if($('.b-feedback .feedbackform__ttl').length) {
		$('.b-feedback .feedbackform__ttl').click(function(){
			$('.b-feedbackform').toggle();
		});
		$('.b-feedback .close').click(function(){
			$('.b-feedbackform').hide();
			return false;
		});
	};
	
	
});

