// JavaScript Document
$(document).ready(function(){
	
	// crop carrige into main page
	if($(window).width() > 994){
		$('#middle').css({'width':$(window).width()});
	}	
	$(window).resize(function(){ 
		if($(window).width() > 994){
			$('#middle').css({'width':$(window).width()}); 
		} else {
			$('#middle').css({'width':'995px'}); 
		}
	});
	
	// menu and other page hacks
	$("#menu-verxnee-menyu li:not('#menu-verxnee-menyu li:last-child')").after("<span class='rightline'>"+"</span>");
	$("#menu-verxnee-menyu li, #menu-levoe-menyu li, #menu-verxnee-menyu-1 li, #menu-nizhnee-menyu-blok1 li, #menu-nizhnee-menyu-blok2 li, #menu-nizhnee-menyu-blok3 li, #menu-nizhnee-menyu-blok4 li").removeClass("page_item menu-item menu-item-type-post_type menu-item-object-page current_page_item");
	$("#menu-verxnee-menyu li.menu-item-type-custom a").attr('target', '_blank');
	$("#bottom-nav ul li:first-child").addClass("bottom-nav-left");
	$("#bot-round-bg div.bot-block:first-child").css({"padding-left":"40px", "border-left":"none"});
	$(".contactsPage table th:first-child").css({"padding-left":"0px"});
	$(".contactsPage table td:first-child").css({"padding-left":"0px"});
	$(".contactsPage table td:last-child").css({"border-right":"none"});
	$(".contactsPage table td:last-child").css({"border-right":"none"});
	$("#menu-levoe-menyu li:last-child").addClass("last");
	$("#gallery-content .galleryBlock:nth-child(4n)").addClass("gbLast");
	
	// bxSlider inicialization
	$('#sliderNews').bxSlider({
            controls: false,
			mode: 'vertical', /*vertical | horizontal*/
            pager: true
	});
	$('#sliderGalery').bxSlider({
            controls: false,
			mode: 'vertical',
            pager: true
	});
	$('#sliderPressCentre').bxSlider({
            controls: false,
			mode: 'vertical',
            pager: true
	});	
	
	// vertical aligin in left navigation buttons
	var maxLength = 21;
	$("#left-navigation ul li a").each(function (){
		var content = $(this).html();
		 if (content.length > maxLength){
		 	$(this).parent().addClass("two-lines");
		 }
	});
	
	// fade effect when mouse hover in gallery images
	$('.galleryBlock img').mouseover(function() {
    	$(this).stop(true,true).fadeTo('slow',0.8);
    	$(this).stop(true,true).fadeTo('slow',1);    
    });
	
	// search form text
	$("input.authtext").each(function() {
		$(this).focus(function() {
        	if (!$(this).hasClass('active')) {
            	$(this).attr('value', '');
			}
            $(this).addClass("active");
		});
	    $(this).blur(function() {
			language = $("#searchform").attr("rel");
			if(language == "en"){
				inputText = "search";
			} else {
				inputText = "поиск по сайту";
			}
	    	insertText = $(this).attr('value');
	        if (insertText == '') {
	        	switch (this.id) {
	            	case 's': $(this).attr('value', inputText);break;
				}
	            $(this).removeClass("active");
			}
		});
	});

	// fancybox
	var thumbnails = 'a:has(img)[href$=".bmp"],a:has(img)[href$=".gif"],a:has(img)[href$=".jpg"],a:has(img)[href$=".jpeg"],a:has(img)[href$=".png"],a:has(img)[href$=".BMP"],a:has(img)[href$=".GIF"],a:has(img)[href$=".JPG"],a:has(img)[href$=".JPEG"],a:has(img)[href$=".PNG"]';

	$(thumbnails).addClass("fancybox").attr("rel","fancybox");
		$("a.fancybox:not('.thumbs a')").fancybox({
		'imageScale': true,
		'padding': 10,
		'zoomOpacity': true,
		'zoomSpeedIn': 500,
		'zoomSpeedOut': 500,
		'zoomSpeedChange': 300,
		'overlayShow': true,
		'overlayColor': "#666666",
		'overlayOpacity': 0.3,
		'enableEscapeButton': true,
		'showCloseButton': true,
		'hideOnOverlayClick': true,
		'hideOnContentClick': true,
		'frameWidth':  560,
		'frameHeight':  340,
		'callbackOnStart': null,
		'callbackOnShow': null,
		'callbackOnClose': null,
		'centerOnScroll': true
	});
});

$(function(){			
	$("a#mapLink").fancybox({
	'imageScale': true,
	'padding': 10,
	'zoomOpacity': true,
	'zoomSpeedIn': 500,
	'zoomSpeedOut': 500,
	'zoomSpeedChange': 300,
	'overlayShow': true,
	'overlayColor': "#666666",
	'overlayOpacity': 0.3,
	'enableEscapeButton': true,
	'showCloseButton': true,
	'hideOnOverlayClick': true,
	'hideOnContentClick': false,
	'frameWidth':  500,
	'frameHeight':  500,
	'callbackOnStart': null,
	'callbackOnShow': null,
	'callbackOnClose': null,
	'centerOnScroll': false
	});
});
