function ___getPageSize() {
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = window.innerWidth + window.scrollMaxX;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
if(document.documentElement.clientWidth){
windowWidth = document.documentElement.clientWidth;
} else {
windowWidth = self.innerWidth;
}
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = xScroll;
} else {
pageWidth = windowWidth;
}
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
return arrayPageSize;
};

function hidewidget () {
    	$('#ajax_container').hide();
		$('.widget-overlay').hide();
			$('.widget-overlay').html('<img class="loadergif" id="loadergif" src="/i/loader.gif" />');
			$('#ajax_container').html('');
    }
  
function showregtrue () {
	var data = '<div class="inv_card"><div class="invitation_card clearfix"><div class="caption_card clearfix"><p class="sm" style="text-align: center;">Вы успешно зарегистрировались  на сайте</p></div></div></div>';
	$('.widget-overlay').show();
	var arrPageSizes = ___getPageSize();
	var body_height = arrPageSizes[1];
	$('.widget-overlay').height(body_height);
	$('#loadergif').hide();
	$('#ajax_container').html(data);
	$('#ajax_container').width(780);
	$('#ajax_container').show();
	var marginleft = (arrPageSizes[0]-$('#ajax_container').width())/2 + 'px';
		if($.browser.msie && $.browser.version.substr(0,3)!="8.0" && $.browser.version.substr(0,3)!="9.0"){
			$('#ajax_container').css('left', marginleft);
		} else {
			$('#ajax_container').css('margin-left', marginleft);
		}
	var margintopnopx = (body_height-$('#ajax_container').height())/2;
	if (margintopnopx < 0) {
	  margintopnopx = 100;
	  var all_height = $('#ajax_container').height() + 120;
	  $('.widget-overlay').height(all_height);
		
	}
	var margintop = margintopnopx + 'px';				
	$('#ajax_container').css('margin-top', margintop);
	setTimeout(hidewidget, 2000);
	return false;
}
  
function makepage(src) {
  // We break the closing script tag in half to prevent
  // the HTML parser from seeing it as a part of
  // the *main* page.
  return "<html>\n" +
    "<head>\n" +
    "<title>Temporary Printing Window</title>\n" +
    "<script>\n" +
    "function step1() {\n" +
    "  setTimeout('step2()', 10);\n" +
    "}\n" +
    "function step2() {\n" +
    "  window.print();\n" +
 //   "  window.close();\n" +
    "}\n" +
    "</scr" + "ipt>\n" +
    "</head>\n" +
    "<body onLoad='step1()'>\n" +
    "<img src='" + src + "'/>\n" +
    "</body>\n" +
    "</html>\n";
}

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);
    });
    
    $(".nivo-controlNav a").click(function(){
    	carousel.scroll(parseInt($(this).attr("href")));
    	carousel.startAuto(0);
    	return false;
    });
    
    $('#slider li a').click(function(){
      	carousel.startAuto(0);
    });
};

function mycarousel_visCallback(carousel)
{
	var activeId = parseInt(carousel.first);
	$(".nivo-controlNav a").removeClass("active");
    $("#ban_"+activeId).addClass("active");
};

$(document).ready(function(){ 

  /* var carousel = $('#slider').jcarousel({
        auto: 3,
        wrap: 'last',
        scroll: 1,
        animation: "slow",
        initCallback: mycarousel_initCallback,
        itemVisibleInCallback: mycarousel_visCallback
    });*/
    $(function(){
	  var slider = $('#slider').bxSlider({
	    auto: true,
		pause: 4000,
	    pager: true,
	    speed: 500
	  });
	  $('#slider a').click(function(){
	    slider.stopShow();
	  });
	});
    	
    
    
	
	if ($(".mainInclude").height() < 15) {
			$(".mainInclude").css("border", "none");
	}
	$(".navline ul").each(function(){
		var width = $(this).parent().width();
		var nnwidth = width/2;
        if($.browser.msie && $.browser.version.substr(0,3)!="8.0" && $.browser.version.substr(0,3)!="9.0"){
	        var margin = (0 - nnwidth) + 'px';
	        $(this).css('margin-left', margin);
        }
	});
	$(".navline ul:last").each(function(){
		var width = $(this).parent().width();
		var nnwidth = width/2;
		if($.browser.msie && $.browser.version.substr(0,3)!="8.0" && $.browser.version.substr(0,3)!="9.0"){
	        var margin = (0 - nnwidth - 76) + 'px';
	        $(this).css('margin-left', margin);
        }
	});

	$(".navline td").hover(
		function () {
			$(this).addClass("jshover");
		},
		function () {
			$(this).removeClass("jshover");
		}
	);
	$("#search").focus(function(){$(this).attr("value",'')});
	$("#subscribe").focus(function(){$(this).attr("value",'')});
	
	$("p.errorsubscribe").click(function(){$(this).hide(500)});
	
		$(window).resize(function() {
		var arrPageSizes = ___getPageSize();
		var body_height = arrPageSizes[1];
		var marginleft = (arrPageSizes[0]-$('#ajax_container').width())/2 + 'px';
		if($.browser.msie && $.browser.version.substr(0,3)!="8.0" && $.browser.version.substr(0,3)!="9.0"){
			$('#ajax_container').css('left', marginleft);
		} else {
			$('#ajax_container').css('margin-left', marginleft);
		}
		var margintop = (body_height-$('#ajax_container').height())/2 + 'px';
		$('#ajax_container').css('margin-top', margintop);
	});
	
	$('.widget-overlay').click(function() {
		/*$('.widget-overlay').hide();
		$('.widget-overlay').html('<img class="loadergif" id="loadergif" src="/i/loader.gif" />');
		$('#ajax_container').html('');
		$('#ajax_container').hide();*/
		hidewidget();
		return false;
	});
	$(".royal img").fadeTo(0, 0.6);
	$(".royal img").hover(
		function () {
			$(this).fadeTo(0, 1);
		},
		function () {
			$(this).fadeTo(0, 0.6);
		}
	);
	
	$("span.show_gmap").click(function() {
		$('.widget-overlay').show();
		var arrPageSizes = ___getPageSize();
		var body_height = arrPageSizes[1];
		$('.widget-overlay').height(body_height);
		$('#loadergif').hide();
		$('#ajax_container').append($("div.gmap_wrap").clone());
		
		
		$('#ajax_container').show();
		$("#ajax_container div.gmap_wrap").show();
		var marginleft = (arrPageSizes[0]-$('#ajax_container').width())/2 + 'px';
			if($.browser.msie && $.browser.version.substr(0,3)!="8.0" && $.browser.version.substr(0,3)!="9.0"){
				$('#ajax_container').css('left', marginleft);
			} else {
				$('#ajax_container').css('margin-left', marginleft);
			}
		var margintopnopx = (body_height-$('#ajax_container').height())/2;
		if (margintopnopx < 0) {
		  margintopnopx = 100;
		  var all_height = $('#ajax_container').height() + 120;
		  $('.widget-overlay').height(all_height);
		}
		var margintop = margintopnopx + 'px';				
		$('#ajax_container').css('margin-top', margintop);
			
		$('#close_link').click(function() {
		hidewidget();
		return false;
		});
	});

});
