﻿// initialize variables
var menuArray = new Array();
var globalObject = '';
var isActive = false;
var ourTimer;


var fancyBoxRefresh=false;

/*function initFancyboxCusomize(){
	fancyBoxRefresh=window.setInterval(function(){fancyboxCusomize();},250);
}

function fancyboxCusomize(){
	$('#fancy_outer:visible:has(div.formOrderContainer)').each(function(){
			var orderContainer=$(this).find('.formOrderContainer');
			var fancyContent=$(this).find('#fancy_content');
			var boxHeight = orderContainer.height()+($(this).height()-fancyContent.height()+30);
			//var boxHeight = $('.formOrderContainer',this).height()+($(this).height()-$('#fancy_content',this).height()+30);
			if( boxHeight < 300){boxHeight=300;}
			if ($.browser.opera){if( boxHeight > 600){boxHeight=600;}}
			$(this).height(boxHeight);
	});
}*/



/**
	Purpose  : show or hide a particular div
	Params   : obj - menu div to show/hide
			   onlink - true if mouse is over a link
*/
function showhide(obj, onlink)
{
    var objectDIV = document.getElementById(obj);
    targetObject = objectDIV.style;
    globalObject = objectDIV;
    
    if(onlink)
    {
        clearTimeout(ourTimer);
        
        for (i=0; i < menuArray.length; i++)
        {
            var tempObject = menuArray[i].style;
            tempObject.visibility = "hidden";
	    menuArray[i].linkli.className = menuArray[i].id;
        }
        
	targetObject.visibility = 'visible';
	objectDIV.linkli.className = objectDIV.linkli.className + ' hover';
	isActive = true;
    }
    else
    {
        isActive = false;
        layerTimer();
    }
}

/**
	Purpose: starts our timer and hides the menu when complete
*/
function layerTimer()
{
    ourTimer = setTimeout("hideMenu()",050);
}

/**
	Purpose: hides the menu div if its not active
*/
function hideMenu()
{
    if( !isActive )
    {
	globalObject.linkli.className = globalObject.id;
        globalObject.style.visibility = 'hidden';
    }
}

/**
	Purpose  : checks if the mouse is still over the div
	Params   : flag - true if mouse is over the div
*/
function layerCheck(flag)
{
    if(flag)
    {
        isActive = true;
        clearTimeout(ourTimer);
    }
    else
    {
        isActive = false;
        layerTimer();
    }
}

function getChilds(parent, child) {
 var retarray = new Array();
 var childItem;
 for (childItem=0; childItem<parent.childNodes.length; childItem++) {
   if (parent.childNodes[childItem].nodeName.toLowerCase() == child) {
	retarray.push(parent.childNodes[childItem]);
      }
   }
 return retarray;
}

function init() {
    if (arguments.callee.done) return;
    arguments.callee.done = true;

    var fullmenu = document.getElementById("menuslist");
    var x;
    var lis = getChilds(fullmenu,"li");
    for (x=0;x<lis.length;x++){
		var classLI = lis[x].className;
		var nomer = "";
     		if(classLI.indexOf("active")==-1) {
			nomer = classLI.substr(4);
		} else {
			nomer = classLI.substr(11);
		}

		var e = document.getElementById("item"+nomer);
		if(!e) { continue; }		
		e.onmouseover = function(e)
		{
			layerCheck(true);
		}
		e.onmouseout = function(e)
		{
			layerCheck(false);
		}

		menuArray[x] = e;
		lis[x].subdiv = e.id;
		e.linkli = lis[x];
//positioning
var shiftx=lis[x].offsetLeft + lis[x].offsetParent.offsetLeft;
var shifty = lis[x].offsetTop + lis[x].offsetParent.offsetTop + lis[x].offsetHeight;
var ver = navigator.appVersion;
var err = document.getElementById("wrapper").offsetWidth - shiftx - e.offsetWidth;
if(err<0) shiftx += err - 30;
e.style.left = shiftx+'px';e.style.top=shifty+'px';



		lis[x].onmouseover = function() {
				showhide(this.subdiv, true); 
		}
		lis[x].onmouseout = function() {
				showhide(this.subdiv, false); 
		}
     }

//office
	x=x-1; //because of hack GLAVNAYA
	var e = document.getElementById("office-submenu");
	var office = document.getElementById("office");
	if(e) { 		
	e.onmouseover = function(e)
	{
		layerCheck(true);
	}
	e.onmouseout = function(e)
	{
		layerCheck(false);
	}

	menuArray[x] = e;
	office.subdiv = e.id;
	e.linkli = office;

	office.onmouseover = function() {
			showhide(this.subdiv, true); 
	}
	office.onmouseout = function() {
			showhide(this.subdiv, false); 
	}
}
}

// ff, opera
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
}

// ie
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)>");
document.write("<\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
    if (this.readyState == "complete") {
        init();
    }
};
/*@end @*/

// safari
if (/WebKit/i.test(navigator.userAgent)) {
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            clearInterval(_timer);
            delete _timer;
            init();
        }
    }, 10);
}

// others
window.onload = init;

/*
	Slimbox v1.58 - The ultimate lightweight Lightbox clone
	(c) 2007-2009 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.
*/
var Slimbox=(function(){var G=window,v,h,H=-1,q,x,F,w,z,N,t,l=r.bindWithEvent(),f=window.opera&&(navigator.appVersion>="9.3"),p=document.documentElement,o={},u=new Image(),L=new Image(),J,b,i,K,e,I,c,B,M,y,j,d,D;G.addEvent("domready",function(){$(document.body).adopt($$(J=new Element("div",{id:"lbOverlay"}),b=new Element("div",{id:"lbCenter"}),I=new Element("div",{id:"lbBottomContainer"})).setStyle("display","none"));i=new Element("div",{id:"lbImage"}).injectInside(b).adopt(K=new Element("a",{id:"lbPrevLink",href:"#"}),e=new Element("a",{id:"lbNextLink",href:"#"}));K.onclick=C;e.onclick=g;var O;c=new Element("div",{id:"lbBottom"}).injectInside(I).adopt(O=new Element("a",{id:"lbCloseLink",href:"#"}),B=new Element("div",{id:"lbCaption"}),M=new Element("div",{id:"lbNumber"}),new Element("div",{styles:{clear:"both"}}));O.onclick=J.onclick=E});function A(){var P=G.getScrollLeft(),O=f?p.clientWidth:G.getWidth();$$(b,I).setStyle("left",Math.round(P+(O/2)));if(w){J.setStyles({left:P,top:G.getScrollTop(),width:O,height:G.getHeight()})}}function n(O){["object",G.ie6?"select":"embed"].forEach(function(Q){$each(document.getElementsByTagName(Q),function(R){if(O){R._slimbox=R.style.visibility}R.style.visibility=O?"hidden":R._slimbox})});J.style.display=O?"":"none";var P=O?"addEvent":"removeEvent";G[P]("scroll",A)[P]("resize",A);document[P]("keydown",l)}function r(P){var O=P.code;if(v.closeKeys.contains(O)){E()}else{if(v.nextKeys.contains(O)){g()}else{if(v.previousKeys.contains(O)){C()}}}P.stop()}function C(){return a(x)}function g(){return a(F)}function a(O){if(O>=0){H=O;q=h[O][0];x=(H||(v.loop?h.length:0))-1;F=((H+1)%h.length)||(v.loop?0:-1);s();b.className="lbLoading";o=new Image();o.onload=m;o.src=q}return false}function m(){b.className="";d.set(0);i.setStyles({width:o.width,backgroundImage:"url("+q+")",display:""});$$(i,K,e).setStyle("height",o.height);B.setHTML(h[H][1]||"");M.setHTML((((h.length>1)&&v.counterText)||"").replace(/{x}/,H+1).replace(/{y}/,h.length));if(x>=0){u.src=h[x][0]}if(F>=0){L.src=h[F][0]}N=i.offsetWidth;t=i.offsetHeight;var O=Math.max(0,z-(t/2));if(b.offsetHeight!=t){j.chain(j.start.pass({height:t,top:O},j))}if(b.offsetWidth!=N){j.chain(j.start.pass({width:N,marginLeft:-N/2},j))}j.chain(function(){I.setStyles({width:N,top:O+t,marginLeft:-N/2,visibility:"hidden",display:""});d.start(1)});j.callChain()}function k(){if(x>=0){K.style.display=""}if(F>=0){e.style.display=""}D.set(-c.offsetHeight).start(0);I.style.visibility=""}function s(){o.onload=Class.empty;o.src=u.src=L.src=q;j.clearChain();j.stop();d.stop();D.stop();$$(K,e,i,I).setStyle("display","none")}function E(){if(H>=0){s();H=x=F=-1;b.style.display="none";y.stop().chain(n).start(0)}return false}Element.extend({slimbox:function(O,P){$$(this).slimbox(O,P);return this}});Elements.extend({slimbox:function(O,R,Q){R=R||function(S){return[S.href,S.title]};Q=Q||function(){return true};var P=this;P.forEach(function(S){S.removeEvents("click").addEvent("click",function(T){var U=P.filter(Q,this);Slimbox.open(U.map(R),U.indexOf(this),O);T.stop()}.bindWithEvent(S))});return P}});return{open:function(Q,P,O){v=$extend({loop:false,overlayOpacity:0.8,overlayFadeDuration:400,resizeDuration:400,resizeTransition:false,initialWidth:250,initialHeight:250,imageFadeDuration:400,captionAnimationDuration:400,counterText:"Image {x} of {y}",closeKeys:[27,88,67],previousKeys:[37,80],nextKeys:[39,78]},O||{});y=J.effect("opacity",{duration:v.overlayFadeDuration});j=b.effects($extend({duration:v.resizeDuration},v.resizeTransition?{transition:v.resizeTransition}:{}));d=i.effect("opacity",{duration:v.imageFadeDuration,onComplete:k});D=c.effect("margin-top",{duration:v.captionAnimationDuration});if(typeof Q=="string"){Q=[[Q,P]];P=0}z=G.getScrollTop()+((f?p.clientHeight:G.getHeight())/2);N=v.initialWidth;t=v.initialHeight;b.setStyles({top:Math.max(0,z-(t/2)),width:N,height:t,marginLeft:-N/2,display:""});w=G.ie6||(J.currentStyle&&(J.currentStyle.position!="fixed"));if(w){J.style.position="absolute"}y.set(0).start(v.overlayOpacity);A();n(1);h=Q;v.loop=v.loop&&(h.length>1);return a(P)}}})();

// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
Slimbox.scanPage = function() {
	$$($$("a").filter(function(el) {
		return el.rel && el.rel.test(/^lightbox/i);
	})).slimbox({/* Put custom options here */}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
};
if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
	window.addEvent("domready", Slimbox.scanPage);
}
