function initPage() {
	initgallery();
	mainHeight();
	mainMenu();
	scrollArray = VSA_initScrollbars();
	if (scrollArray) initAnchors();
	$('.newsPageInvisibleContent').removeClass('newsPageInvisibleContent');
}
if (window.addEventListener){
	window.addEventListener("load", initPage, false);
	}
else if (window.attachEvent){
	window.attachEvent("onload", initPage);
}
function initAnchors() {
	$('#anchors a').click(function(){
		var difference = $('#inner').height()-$('#scrollable').height();//calculate the difference - not needed if within the main slider code
		var targetclass = ($(this).attr('href'));//read the class of the clicked anchor
		targetclass = targetclass.substr(targetclass.indexOf("#") + 1);
		var position = $("#"+targetclass).position();//search for a div with matching class and read its position
		var topValue = -(position.top);//content top is just the negative of the top position
		if (topValue>0) topValue = 0;//stop the content scrolling down too much
		if (Math.abs(topValue)>difference) topValue = (-1)*difference;//stop the content scrolling up too much
		scrollArray[0].scrollContent.scrollTop = -topValue;
		scrollArray[0].scrollslider.style.top =  1 / scrollArray[0].scrollFactor * Math.abs(scrollArray[0].scrollContent.scrollTop) + scrollArray[0].scrollButtonHeight + "px";
		
		return false;
	});
}
function initgallery() {
	if (document.getElementById('imagevue'))
	{
		var params = {
			allowScriptAccess: 'always',
			allowFullScreen: true,
			wmode: 'transparent'
		};
		var flashVars = {
			foreground_color: 'EEEEEE'
		};
		flashVars.language = 'russian';
		flashVars.theme = 'overmaster';
		var attributes = {
			id: 'imagevue',
			name: 'imagevue'
		}
		console.log(swfobject);
		swfobject.addDomLoadEvent(function () {
			var playerVersion = swfobject.getFlashPlayerVersion();
			if (playerVersion.major < 9) {
				//location.href = '?' + SWFAddress.getPath();
				console.log('redirect1');
			}
		});
		swfobject.embedSWF("iv-includes/imagevue2.swf", "imagevue", "100%", "100%", "8.0.0", "iv-includes/expressInstall.swf", flashVars, params, attributes);
		if (swfmacmousewheel && navigator.appName != 'Microsoft Internet Explorer') swfmacmousewheel.registerObject(attributes.id);
	}
	if (document.getElementById('favorites'))
	{
		if (pluginlist.indexOf("Flash")!=-1 || true)
		{
			var params = {
				allowScriptAccess: 'sameDomain',
				allowFullScreen: true
			};
			swfobject.addDomLoadEvent(function () {
				var playerVersion = swfobject.getFlashPlayerVersion();
				if (playerVersion.major < 9) {
					document.getElementById('content').innerHTML = '<div id="holder"><div class="text-scroll scrollable" id="scrollable"><div class="text-box"><p>Для просмотра ролика необходима 9я версия Flash</p><br /><br /></div></div></div>';
					document.getElementsByTagName('body')[0].className = "";
				}
			});
			swfobject.embedSWF("fullscreen/main.swf", "favorites", "100%", "100%", "8.0.0", "fullscreen/main.swf", flashVars, params, attributes);
			if (swfmacmousewheel && navigator.appName != 'Microsoft Internet Explorer') swfmacmousewheel.registerObject(attributes.id);
		} else {
			document.getElementById('content').innerHTML = '<div id="holder"><div class="text-scroll scrollable" id="scrollable"><div class="text-box"><p>Установите Flash</p></div></div></div>';
			document.getElementsByTagName('body')[0].className = "";
		}
	}
}
function mainHeight() {
	var mainHolder = document.getElementById('main-holder');
	var contentHolder = document.getElementById('content');
	var scrollableHolder = document.getElementById('scrollable');
	var textHolder = document.getElementById('holder');
	var scrollContent = document.getElementById('scroll-content');
	var galleryHolder = document.getElementById('imagevue');
	var mainHeight = 0;
	if (document.getElementsByTagName('body')[0].className == 'gallery')
	{
		//console.log(document.location.href.match(/fullscreen\.shtml/i));
		mainHeight = mainHolder.offsetHeight;
		//mainHeight = mainHeight - 84 - ((!$.browser.mozilla) ? ((document.location.href.match(/fullscreen\.shtml/i) == null) ? 42 : 0) : 0);
		var brwsr = $.browser;
		mainHeight = mainHeight - 84 - ((!(brwsr.mozilla || brwsr.msie || brwsr.opera)) ? 42 : 0);
		if (galleryHolder) galleryHolder.style.height = mainHeight + "px";
		contentHolder.style.height = mainHeight + "px";
	}
	else
	{	
		scrollableHolder.style.height = "100px";
		mainHeight = mainHolder.offsetHeight;
		scrollableHolder.style.height = "auto";
		mainHeight = mainHeight - 144;
		
		if (contentHolder.offsetHeight < mainHeight){
			contentHolder.style.marginTop = (mainHeight - contentHolder.offsetHeight)/2 + 42 + "px";
			scrollableHolder.style.height = contentHolder.offsetHeight + "px";
		} else
			{ if (scrollableHolder){
				textHolder.style.height = mainHeight - 40 + "px";
				scrollableHolder.style.height = mainHeight - 40 + "px";
				contentHolder.style.height = mainHeight + "px";
				scrollableHolder.style.height = mainHeight - 44 + "px";
			}
		}
		
	}
	
}


jQuery(function(){
  jQuery("a").bind("focus",function(){if(this.blur)this.blur();});

  jQuery(".menu > li:first-child").addClass("first_menu");
  jQuery(".menu li ul li:has(ul)").addClass("parent_menu");

});

/*
dropdowm menu
*/


var menu=function(){
var t=15,z=50,s=6,a;
function dd(n){this.n=n; this.h=[]; this.c=[]}
dd.prototype.init=function(p,c){
a=c; //Old code: var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;

var w=p, s=w.getElementsByTagName('ul'), l=s.length, i=0;
for(i;i<l;i++){
var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
h.onmouseover=new Function(this.n+'.st('+i+',true)');
h.onmouseout=new Function(this.n+'.st('+i+')');
}
}
dd.prototype.st=function(x,f){
var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
clearInterval(c.t); c.style.overflow='hidden';
if(f){
p.className+=' '+a;
if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
if(c.mh==c.offsetHeight){c.style.overflow='visible'}
else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
}
function sl(c,f){
var h=c.offsetHeight;
if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
clearInterval(c.t); return
}
var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
c.style.height=h+(d*f)+'px'
}
return{dd:dd}
}();

document.getElementsByClassName = function (c, t) {
  t = this.getElementsByTagName(t ? t : "*");
  for (var i = 0, r = new Array(), l = t.length; i < l; i++)
    if (t[i].className == c)
      r[r.length] = t[i];
  return r;
}

var _Menus = new Array();
function initializeDateDropDowns(){
var box = document.getElementsByClassName('menu','ul');
if (box.length > 0) {
for(i = 0; i < box.length; i++) {
var id = box[i];
_Menus[i] = new menu.dd('_Menus[' + i + ']');
_Menus[i].init(id,"menuhover");
}
}
}
window.onload = initializeDateDropDowns;


function mainMenu() {
/*	
	var _parentSlide = 'ul#nav';
	var _linkSlide = 'li.submenu a';
	var _slideBlock = 'li.submenu ul';
	var _openClassS = 'active';
	var _durationSlideOpen = 400;
	var _durationSlideClose = 40;
	$(_parentSlide).each(function(){
		if (!$(this).is('.'+_openClassS)) {
			$(this).find(_slideBlock).css('display','none');
		}
	});
	
	$("ul#nav li.submenu").hover(
		function(){
			$(this).parents(_parentSlide).addClass(_openClassS);
			$(this).parents(_parentSlide).find(_slideBlock).slideDown(_durationSlideOpen);
		},
		function(){
			$(this).parents(_parentSlide).removeClass(_openClassS);
			$(this).parents(_parentSlide).find(_slideBlock).slideUp(_durationSlideClose);
		}
	);/*
	// Slide effect
    var _parentSlide = 'ul#nav';
    var _linkSlide = 'a.submenu';
    var _slideBlock = 'li.submenu ul';
    var _openClassS = 'active';
    var _durationSlide = 400;
    
    $(_parentSlide).each(function(){
		if (!$(this).is('.'+_openClassS)) {
			$(this).find(_slideBlock).css('display','none');
		}
    });
    $(_linkSlide,_parentSlide).click(function(){
		if ($(this).parents(_parentSlide).is('.'+_openClassS)) {
			$(this).parents(_parentSlide).removeClass(_openClassS);
			$(this).parents(_parentSlide).find(_slideBlock).slideUp(_durationSlide);
		} else {
			$(this).parents(_parentSlide).addClass(_openClassS);
			$(this).parents(_parentSlide).find(_slideBlock).slideDown(_durationSlide);
		}
		return false;
    });
	*/
}

