loadingFrame = 0;
fancybox_animate_loading = function() {
	if ( loadingFrame  > 12 ){
            loadingFrame = 0;
	}
	jQuery('div', loading).css('top', (loadingFrame * -40) + 'px');
	loadingFrame = (loadingFrame + 1) % 12;
}

function setTexture (sel){
  document.forms.calc.texture_idx.value=sel.selectedIndex;
  /*ceilingCalc.calc();*/
  return true;
}

// возвращает cookie если есть или undefined
function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape( cookie.substring(offset, end).replace(/\+/g, " ") );
		}
	}
	return(setStr);
}

function initReinit() {

adcookie = getCookie("adSourcePhone");
if(adcookie!=null) {
$('.adsourcephone').text( adcookie );
} 

			jQuery.fn.getTitle = function() {
			var arr = jQuery("a.fancybox");
			jQuery.each(arr, function() {
				var title = jQuery(this).children("img").attr("title");
				jQuery(this).attr('title',title);
			})
		}

		// Supported file extensions
		var thumbnails = '.content a:has(img)[href$=".bmp"],.content a:has(img)[href$=".gif"],.content a:has(img)[href$=".jpg"],.content a:has(img)[href$=".jpeg"],.content a:has(img)[href$=".png"],.content a:has(img)[href$=".BMP"],.content a:has(img)[href$=".GIF"],.content a:has(img)[href$=".JPG"],.content a:has(img)[href$=".JPEG"],.content a:has(img)[href$=".PNG"]';

		jQuery(thumbnails).addClass("fancybox").attr("rel","fancybox").getTitle();

jQuery('.okna-dop-a').click( function() { 
$( this ).parent().children('.slidediv').slideToggle();
return false;
});

    jQuery("a.fancybox").fancybox({
			'imageScale': true,
			'padding': 10,
            'margin' : 50,
			'overlayShow': true,
			'overlayColor': "#666666",
			'overlayOpacity': 0.3,
			'enableEscapeButton': true,
			'showCloseButton': true,
			'hideOnOverlayClick': true,
			'hideOnContentClick': true,
			'centerOnScroll': false,
            'titlePosition':"inside",
            'onComplete' : function() { 
									if ( window.yaCounter449550 !== undefined ) {
										yaCounter449550.hit( this.href, $('h1.title').text() + ' ' + this.title, document.location.href ) 
											}
										},
            'titleShow': true,
            'titleFormat':formatTitle
		});
function formatTitle(title, currentArray, currentIndex, currentOpts) {
         var el = $(currentArray[currentIndex]).parent().parent();
         var caption = el.children('.wp-caption-text').text();
         title = caption;// if ( caption && caption.lenght ) { title = caption; } else { title = title; }
         var description = el.children('.wp-caption-description').html();
        // if ( !title && !description ) return false;
         return '<div class="fancybox-caption-title">' + (title && title.length ? '<b>'+title+'</b>' : '' ) + (description && description.length ? description : '' ) +' <small>' + ( currentIndex > 0 ? '<a class="prevnext" href="#" onclick="$.fancybox.prev();return false;">&larr;</a>' : '' ) + ' Изображение ' + (currentIndex + 1) + ' из ' + currentArray.length + ' ' + ( currentIndex+1 < currentArray.length ? '<a class="prevnext" href="#" onclick="$.fancybox.next();return false;">&rarr;</a>' : '') +'</small></div>';
}

// навигация без перезагрузки страницы
/*
$('#left-col a, .breadcrumbs > a, .album-gallery > a, #productsandservices #menu-item-24 a,#productsandservices #menu-item-25 a,#productsandservices #menu-item-26 a').unbind('click');
$('#left-col a, .breadcrumbs > a, .album-gallery > a, #productsandservices #menu-item-24 a,#productsandservices #menu-item-25 a,#productsandservices #menu-item-26 a').click( function () {
if ( $.browser.msie && parseInt($.browser.version, 10) < 8 ) {
  return;
}
host = window.location.host; // если домен .рф
if ( host.indexOf('.рф') > 0 || host.indexOf('--p1ai') > 0 ) return;
loading = $('div#fancybox-loading');
loading.removeClass( 'fancybox-ie' );
loading.show();
loadingTimer = setInterval(fancybox_animate_loading, 66);
overlay = $('div#fancybox-overlay');
overlay.css('background', '#fff');
overlay.css('opacity', '0.7');
overlay.css('display', 'block');
overlay.css('height', $(document).height() +'px');
if ( window._gaq !== undefined ) _gaq.push([ '_trackPageview', this.href ]); // хит для гугл аналитикс
if ( window.yaCounter449550 !== undefined ) yaCounter449550.hit( this.href ); // хит для метрики http://help.yandex.ru/metrika/?id=1108684
$('div#cont').load(this.href + ' div#cont > div.cont-inner', function(data) {
  initReinit();
  // Cufon.refresh( );
  clearInterval(loadingTimer);
  loading.hide();
  overlay.hide();
  loading.addClass( 'fancybox-ie' );
  $('html:not(:animated)'+( ! $.browser.opera ? ',body:not(:animated)' : '' ) ).animate({scrollTop:$('#cont').offset().top}, 'slow');
});
return false;
});
*/

VK.Widgets.Group("vk_groups", {mode: 1, width: "200", height: "400"}, 3633529);
VK.Widgets.Poll("vk_poll", {}, "4060419_ac5a5ff8c6ff2952e2");

}


$(document).ready(function() {
initReinit();

if ( typeof head_carousel_data !== 'undefined', head_carousel_data.length >= 2 ) {
 $("#head_carousel").agile_carousel({
                carousel_data: head_carousel_data,
                carousel_outer_height: 280,
                carousel_height: 280,
                slide_height: 280,
                carousel_outer_width: 620,
                slide_width: 620,
                transition_time: 300,
                transition_type: "slide",
                timer: 4000,
                continuous_scrolling: true,
                control_set_1: "numbered_buttons",
                no_control_set: "hover_previous_button,hover_next_button"
            });
}
});

function preloadImages(imgs){

	var picArr = [];

		for (i = 0; i<imgs.length; i++){

				picArr[i]= new Image(100,100);
				picArr[i].src=imgs[i];


			}

	}
