<!--

/*
 * Common functions
 */
blankPNG = new Image();
blankPNG.src = '/CommonFiles/SmartHead/WPM_Templates/Images/CommonPages/pixels/t_pixel.gif';

function loadPNG(obj){

    if (navigator.appName == 'Microsoft Internet Explorer' && obj.src.indexOf('png') != -1) {
    
        obj.onload = '';
        obj.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + obj.getAttribute('src') + '", sizingMethod="noscale")';
        obj.src = blankPNG.src;
        
    }
    
}

function getWindowSize(){
    var myWidth = 0, myHeight = 0;
    if (typeof(window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth - 15;
        myHeight = window.innerHeight - 8;
    }
    else 
        if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth - 10;
            myHeight = document.documentElement.clientHeight - 15;
        }
        else 
            if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
                //IE 4 compatible
                myWidth = document.body.clientWidth;
                myHeight = document.body.clientHeight;
            }
    var windowSize = new Array();
    windowSize[0] = myWidth;
    windowSize[1] = myHeight;
    return windowSize;
}

Object.prototype.attachEvent = function(sEvent, fnHandler, bUseCapture){
    if (typeof(sEvent) == 'string') {
        this.addEventListener(sEvent.substring(2), fnHandler, bUseCapture);
    }
}

Object.prototype.detachEvent = function(sEvent, fnHandler, bUseCapture){
    if (typeof(sEvent) == 'string') {
        this.removeEventListener(sEvent.substring(2), fnHandler, bUseCapture);
    }
}

function getStyleSize(parameter){
    return parseInt(parameter);
}

function getRandomDigit(min, max){
    return Math.round(Math.random() * (max - min)) + min;
}

/* --- common functions --- */

/**
 *  initializing of variables
 */
isIE = jQuery.browser.msie;
isMozilla = jQuery.browser.mozilla;

scrollAmount = '';

contentRightBorder = 615;

staticMenuAreaRange = 30;
staticMenuPositionsArr = Array();
staticMenuPositionsArr['about'] = Array(527, 80);
staticMenuPositionsArr['services'] = Array(437, 80);
staticMenuPositionsArr['portfolio'] = Array(329, 70);
staticMenuLastObj = '';

lastDragElementObj = '';

shadowSize1 = 11;

randomElementsArr = Array();
dragElementsPositionsArr = Array();

cookieMenuArr = '';
cookieElementsArr = '';

currentVisibleCharsAmount = 0;

randomCharsArr = Array();

currentLargeImage = -1;

function checkBodyClick(event){
    switchFeedbackForm(event);
}

function getEventSrcElement(event){
    return (isIE) ? event.srcElement : event.target;
}

/* --- initializing of variables --- */

/**
 * scroller functions
 */
function resizeContent(){
    setBackgroundSize();
    currentContentHeight = document.body.clientHeight - 409 - 100;
    if (document.body.clientHeight < 700) {
        currentContentHeight = 190;
    }
    if (document.all.scroll_container_1) {
        document.all.scroll_container_1.style.height = currentContentHeight;
        document.all.content_1.style.height = currentContentHeight + 100;
        document.all.content_1.style.display = 'block';
        if (scrollAmount) {
            initScrollVariables();
            var contentScrollTop = document.all.scroll_container_1.scrollTop;
            if (scrollAmount != 0) {
                document.all.scroller_1.style.top = parseInt(contentScrollTop / scrollAmount) + 'px';
            }
            else {
                document.all.scroller_1.style.top = '0px';
            }
        }
    }
    scrollAmountCorrection = (isMozilla) ? 118 : 112;
    if (document.all.scroller_1) {
        var maxScrollerHeight = 142;
        var minScrollerHeight = 5;
        var minContentHeight = 190;
        var minScrollLineHeight = 218;
        var scrollLineHeight = document.all.scrollLine.offsetHeight;
        var mainContentHeight = $('#MainContent').height();
        $('#scroller_1').css('height', maxScrollerHeight);
        if (scrollLineHeight / mainContentHeight < 0.4) {
            //if (currentContentHeight>minContentHeight) {
            //tmp = maxScrollerHeight-minContentHeight/currentContentHeight*maxScrollerHeight*minScrollLineHeight/scrollLineHeight;
            tmp = maxScrollerHeight * (scrollLineHeight / mainContentHeight) * 2.5;
            if (tmp < minScrollerHeight) 
                tmp = minScrollerHeight;
            $('#scroller_1').css('height', parseInt(tmp));
            //}
        }
        scrollAmountCorrection = scrollAmountCorrection - (maxScrollerHeight - parseInt(document.all.scroller_1.style.height));
    }
    checkScroller();
    checkResizing();
}

function freeScroll(){
    resizeContent();
    initScrollVariables();
	if (document.all.scroller_1) {
		document.all.scroller_1.style.top = 0 + 'px';
	}
	if (document.all.scroll_container_1) {
		document.all.scroll_container_1.scrollTop = 0;
	}
    checkScroller();
}

function checkScroller(){
    if (typeof contentInnerHeight != 'undefined') {
        if (contentInnerHeight <= currentContentHeight) {
            document.getElementById('scroller_1_div').className = "scrollBarOff";//setAttribute("class","scrollBarOff");
            document.getElementById('scrollLine').className = "scrollLineOff";//.setAttribute("class","scrollBarOn");
            document.getElementById('scroller_top').className = "scrollerTopOff";//.setAttribute("class","scrollBarOn");
            document.getElementById('scroller_bottom').className = "scrollerBottomOff";
        }
        else {
            document.getElementById('scroller_1_div').className = "scrollBarOn";//.setAttribute("class","scrollBarOn");
            document.getElementById('scrollLine').className = "scrollLineOn";//.setAttribute("class","scrollBarOn");
            document.getElementById('scroller_top').className = "scrollerTopOn";//.setAttribute("class","scrollBarOn");
            document.getElementById('scroller_bottom').className = "scrollerBottomOn";//.setAttribute("class","scrollBarOn");
        }
    }
    
}

function initScrollVariables(){
    if (document.all.scroll_container_1) {
        contentInnerHeight = document.all.scroll_container_1.scrollHeight;
        contentScrollAmount = contentInnerHeight - currentContentHeight;
        scrollerScrollAmount = currentContentHeight - scrollAmountCorrection;
        scrollAmount = contentScrollAmount / scrollerScrollAmount;
    }
}

function startScrollDrag(event){
    initScrollVariables();
    scrollerMouseY = event.clientY;
    scrollerTopPosition = getStyleSize(document.all.scroller_1.style.top);
    document.body.attachEvent('onmousemove', continueScrollDrag, true);
}

function continueScrollDrag(event){
    var currentScrollerMouseY = event.clientY;
    var scrollDifference = scrollerMouseY - currentScrollerMouseY;
    var scrollerPositionY = -scrollDifference + scrollerTopPosition;
    if (scrollerPositionY <= 0) {
        scrollerPositionY = 0;
    }
    else 
        if (scrollerPositionY >= currentContentHeight - scrollAmountCorrection) {
            scrollerPositionY = currentContentHeight - scrollAmountCorrection;
        }
    document.all.scroller_1.style.top = scrollerPositionY;
    document.all.scroll_container_1.scrollTop = scrollerPositionY * scrollAmount;
}

function stopScrollDrag(event){
    document.body.detachEvent('onmousemove', continueScrollDrag, true);
    
}

/* --- scroller functions ---  */

/**
 * hint functions
 */
/* TODO rebuild functions to jquery */

function workWithHits(){
    var pos = document.cookie.search("hitsAlready");
    if (pos == -1) {
        showHint(document.all.hint_1);
        showHint(document.all.hint_2);
        showHint(document.all.hint_3);
    }
}

function showHint(obj){
    var tmp = $(obj);
    tmp.css('visibility', 'visible');
    if (!isIE) {
        tmp.stop().fadeIn(0, 'slow');
    }
    hideHint(obj);
}

function hideHint(obj){
    var tmp = $(obj);
    setTimeout(function(){
        if (!isIE) {
            tmp.stop().fadeOut('slow', function(){
                tmp.css('visibility', 'hidden');
            });
        }
        else {
            tmp.css('visibility', 'hidden');
        }
    }, '5000');
}

/* --- hint functions ---*/


/**
 * menu and other page Elements functions
 */
function initMenuElements(event){
    loadCrossElement();
    var tempMenuArr = Array('menu_about', 'menu_services', 'menu_portfolio');
    if (!cookieMenuArr) {	
        menuElementsPositionsArr = Array();
    }
    for (var a = 0, b = tempMenuArr.length; a < b; a++) {
        loadMenuElements(document.all[tempMenuArr[a]], a);		
        attachStartDragEvent(document.all[tempMenuArr[a]], event);
    }
}

function loadCrossElement(){
    otherElementsPositionsArr = Array();
    var crossCoordsArr = document.all.delete_cross.getElementsByTagName('area')[0].getAttribute('coords').split(',');
    var crossWidth = crossCoordsArr[2] - crossCoordsArr[0];
    var crossHeight = crossCoordsArr[3] - crossCoordsArr[1];
    var crossImageBottom = getStyleSize(document.all.delete_cross_image.style.bottom);
    var crossImageRight = getStyleSize(document.all.delete_cross_image.style.right);
    var crossImageWidth = document.all.delete_cross_image.getAttribute('width');
    var crossImageHeight = document.all.delete_cross_image.getAttribute('height');
    var crossLeft = Number(document.body.scrollWidth) - crossImageRight - crossImageWidth + Number(crossCoordsArr[0]);
    var crossTop = Number(document.body.scrollHeight) - crossImageBottom - crossImageHeight + Number(crossCoordsArr[1]);
    document.all.delete_cross_image.style.right = '0px';
    //document.all.delete_cross_image.style.left = document.body.scrollWidth - contentRightBorder - document.all.delete_cross_image.clientWidth - 20-20;
    //document.all.delete_cross_image.style.right = -(document.body.scrollWidth - document.body.clientWidth);
    //document.all.delete_cross_image.style.bottom = -(document.body.scrollHeight - document.body.clientHeight) + Number(document.all.delete_cross_image.getAttribute('bottom'));
    otherElementsPositionsArr.push(Array(crossWidth, crossHeight, crossLeft, crossTop));
    var chapterImageLeft = Number(document.body.clientWidth) - document.all.chapter_image.offsetWidth;
    var chapterImageTop = Number(document.body.clientHeight) - document.all.chapter_image.offsetHeight;
    otherElementsPositionsArr.push(Array(document.all.chapter_image.offsetWidth, document.all.chapter_image.offsetHeight, chapterImageLeft, chapterImageTop));
}

function loadMenuElements(obj, index){
    if (!cookieMenuArr || index.length == 0) {
        var randXPositionMin = contentRightBorder;
        var randXPositionMax = document.body.scrollWidth - obj.offsetWidth;
        var randYPositionMin = 0;
        var randYPositionMax = document.body.scrollHeight - obj.offsetHeight - 60;
        var randLeft = getRandomDigit(randXPositionMin, randXPositionMax);
        var randTop = getRandomDigit(randYPositionMin, randYPositionMax);
        var left = (Math.round(randLeft / 30) * 30);
        var top = (Math.round(randTop / 30) * 30);
        var width = getVisibleObjectSize(obj.offsetWidth);
        var height = getVisibleObjectSize(obj.offsetHeight);
        if (!checkNonCrossPosition(left, top, width, height, menuElementsPositionsArr)) {
            loadMenuElements(obj, index);
            return;
        }
        if (!checkNonCrossPosition(left, top, width, height, otherElementsPositionsArr)) {
            loadMenuElements(obj, index);
            return;
        }
        if (dragElementsPositionsArr && !checkNonCrossPosition(left, top, width, height, dragElementsPositionsArr)) {
            loadMenuElements(obj, index);
            return;
        }
        menuElementsPositionsArr.push(Array(width + shadowSize1, height + shadowSize1, left, top));
    }
    else {
        var currentSizesArr = staticMenuPositionsArr[obj.id.substr(5)];
        var left = cookieMenuArr[index][2];
        var top = cookieMenuArr[index][3];
        if (currentSizesArr[0] == cookieMenuArr[index][2] && currentSizesArr[1] == cookieMenuArr[index][3]) {
            var imagesArr = obj.getElementsByTagName('img');
            imagesArr[1].style.display = 'none';
        }
    }
    obj.style.left = left;
    obj.style.top = top;
    obj.style.visibility = 'visible';
    //menuElementsPositionsArr.push(Array(width + shadowSize1, height + shadowSize1, left, top));
    saveElementsPositions(true);
    obj.onclick = function(){
        clickMenu(this);
    }
}

function loadElements(event){
    var elementsArr = Array();
    for (var a = 1; a <= 45; a++) {
        elementsArr.push(a);
    }
    var min = 1;
    var max = 45;//elementsArr.length;
    randomElementsArr = Array();
    dragElementsPositionsArr = Array();
    var randomAmount = getRandomDigit(min, 5);
    if (!cookieElementsArr) {
        for (var a = 0; a < randomAmount; a++) {
	            var tempRand = getRandomDigit(min - 1, max - 1);
	            var newObj = new Image();
            	newObj.src = '/CommonFiles/SmartHead/WPM_Templates/Images/CommonPages/elements2/' + elementsArr[tempRand] + '.png';				
	            newObj.onload = function(){			
	            newObj.className = 'drag_element_1';
	            newObj.style.top = 0;
	            newObj.style.left = contentRightBorder;
	            newObj.style.visibility = 'hidden';
	            document.body.insertBefore(newObj, document.all.temp_elements_div);
	            randomElementsArr.push(newObj);
                positionElements(this);
            	attachStartDragEvent(newObj, event);				
            }
        }
    }
    else {
        for (var a = 0; a < cookieElementsArr.length; a += 5) {
            var newObj = new Image();
            newObj.className = 'drag_element_1';
            newObj.style.top = cookieElementsArr[a + 3];
            newObj.style.left = cookieElementsArr[a + 2];
            newObj.style.visibility = 'hidden';
            document.body.insertBefore(newObj, document.all.temp_elements_div);
            randomElementsArr.push(newObj);		
            newObj.onload = function(){
                this.style.visibility = 'visible';
                dragElementsPositionsArr.push(Array(cookieElementsArr[a], cookieElementsArr[a + 1], cookieElementsArr[a + 2], cookieElementsArr[a + 3]));
                if (isIE && !this.style.filter) {
                    document.body.onload = '';
                    this.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + this.src + '", sizingMethod="noscale")';
                    this.src = '/CommonFiles/SmartHead/WPM_Templates/Images/CommonPages/pixels/t_pixel.gif';				
                }
            }
			newObj.src = cookieElementsArr[a + 4];
            if (cookieElementsArr[a + 4].indexOf('chars1') != -1) {
                currentVisibleCharsAmount++;
                randomCharsArr.push(newObj);
            }
            attachStartDragEvent(newObj, event);
        }		
    }
    saveElementsPositions();
}

function loadChars(max_amount, event){
    var charsArr = Array();
    for (var a = 1; a <= 39; a++) {
        charsArr.push(a);
    }
    charsFilesArr = Array('а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я', '+', '-', '.', ',', '!', '?');
    var min = 1;
    var max = charsArr.length;
    var randomAmount = getRandomDigit(min, max_amount);
    if (max_amount != 1) {
        randomCharsArr = Array();
        currentVisibleCharsAmount = randomAmount;
        dragCharsPositionsArr = Array();
    }
    for (var a = 0; a < randomAmount; a++) {
        var tempRand = getRandomDigit(min - 1, max - 1);
        var newObj = new Image();
        if (max_amount == 1) {
            var found = 0;
            for (var c = 0, d = charsFilesArr.length; c < d; c++) {
                if (document.all.new_char.value.toLowerCase() == charsFilesArr[c]) {
                    currentVisibleCharsAmount++;
                    var found = 1;
                    break;
                }
            }
            if (found == 0) {
                showHint(document.all.hint_1);
                return;
            }
        }
        newObj.className = 'drag_element_2';
        newObj.style.top = 0;
        newObj.style.left = contentRightBorder;
        newObj.style.visibility = 'hidden';
        document.body.insertBefore(newObj, document.all.temp_elements_div);
        randomCharsArr.push(newObj);
        var src = (max_amount == 1) ? charsArr[c] : charsArr[tempRand];
        newObj.onload = function(){
            positionElements(this);
        }
        newObj.src = '/CommonFiles/SmartHead/WPM_Templates/Images/CommonPages/chars1/' + src + '.png';
        attachStartDragEvent(newObj, event);
    }
}

function attachStartDragEvent(obj, event){
    if (isIE) {
        obj.onmousedown = function(){
            startDragElement(this, event);
            return false;
        }
    }
    else {
        obj.onmousedown = function(event){
            startDragElement(this, event);
            return false;
        }
    }
    obj.onmousemove = function(event){
        return false
    }
}

function startDragElement(obj, e){
    if (!isIE) {
        event = e;
    }
    lastDragElementObj = obj;
    lastDragElementX = getStyleSize(obj.style.left);
    lastDragElementY = getStyleSize(obj.style.top);
    lastDragElementXDifference = lastDragElementX - event.clientX;
    lastDragElementYDifference = lastDragElementY - event.clientY;
    var tempArray = (obj.className == 'drag_menu') ? menuElementsPositionsArr : dragElementsPositionsArr;
    for (var a = 0, b = tempArray.length; a < b; a++) {
        //if (obj.width == tempArray[a][0] && obj.height == tempArray[a][1] && lastDragElementX == tempArray[a][2] && lastDragElementY == tempArray[a][3]) {
        if (obj.offsetWidth == tempArray[a][0] && obj.offsetHeight == tempArray[a][1] && lastDragElementX == tempArray[a][2] && lastDragElementY == tempArray[a][3]) {
            tempArray.splice(a, 1);
            break;
        }
    }
    if (obj.className == 'drag_menu') {
        menuElementsPositionsArr = tempArray;
    }
    else {
        dragElementsPositionsArr = tempArray;
    }
    document.body.attachEvent('onmousemove', continueDragElement, true);
    if (lastDragElementObj.className == 'drag_menu') {
        var imagesArr = lastDragElementObj.getElementsByTagName('img');
        imagesArr[1].style.display = '';
    }
}

function continueDragElement(event){
    var currentScrollerMouseX = event.clientX;
    var currentScrollerMouseY = event.clientY;
    var left = currentScrollerMouseX + lastDragElementXDifference;
    var top = currentScrollerMouseY + lastDragElementYDifference;
    var width = getVisibleObjectSize(lastDragElementObj.offsetWidth);
    var height = getVisibleObjectSize(lastDragElementObj.offsetHeight);
    lastDragElementObj.style.left = left;
    lastDragElementObj.style.top = top;
    if ((top + height - shadowSize1 >= otherElementsPositionsArr[0][3] && top <= otherElementsPositionsArr[0][3] + otherElementsPositionsArr[0][1]) && (left + width - shadowSize1 >= otherElementsPositionsArr[0][2] && left <= otherElementsPositionsArr[0][2] + otherElementsPositionsArr[0][0])) {
        document.all.delete_cross_image_highlight.style.visibility = 'visible';
    }
    else {
        document.all.delete_cross_image_highlight.style.visibility = 'hidden';
    }
    if (lastDragElementObj.className == 'drag_menu') {
        lastDragElementObj.setAttribute('is_draging', 'true');
    }
}

function stopDragElement(event){
    if (!lastDragElementObj) {
        return;
    }
    checkAllowedPosition();
    freeDragElement();
    saveElementsPositions();
}

function saveElementsPositions(flag){
    var imagesArr = document.getElementsByTagName('img');
    var tempMenuElementsPositionsArr = Array();
    var tempDragElementsPositionsArr = Array();
    var regular_expression = /src="(.*?)"/;
	var tmp = '';
    for (var a = 0, b = imagesArr.length; a < b; a++) {
        if (imagesArr[a].className == 'drag_element_1' || imagesArr[a].className == 'drag_element_2') {
			var src = imagesArr[a].getAttribute('src');
			if (src.search('elements2')==-1 && src.search('chars1')==-1) {
	            if (isIE) {
	                if (imagesArr[a].style.filter) {								
	                    var regular_expression_result = regular_expression.exec(imagesArr[a].style.filter);
	                    var src = regular_expression_result[1];					
	                }
	            }				
			}
            tempDragElementsPositionsArr.push(Array(imagesArr[a].offsetWidth, imagesArr[a].offsetHeight, getStyleSize(imagesArr[a].style.left), getStyleSize(imagesArr[a].style.top), src));
			if (flag) {
				tmp += tempDragElementsPositionsArr.toString() + '  ';
			}						
        }
    }
    tempMenuElementsPositionsArr.push(Array(document.all.menu_about.offsetWidth, document.all.menu_about.offsetHeight, getStyleSize(document.all.menu_about.style.left), getStyleSize(document.all.menu_about.style.top), 'menu_about'));
    tempMenuElementsPositionsArr.push(Array(document.all.menu_services.offsetWidth, document.all.menu_services.offsetHeight, getStyleSize(document.all.menu_services.style.left), getStyleSize(document.all.menu_services.style.top), 'menu_services'));
    tempMenuElementsPositionsArr.push(Array(document.all.menu_portfolio.offsetWidth, document.all.menu_portfolio.offsetHeight, getStyleSize(document.all.menu_portfolio.style.left), getStyleSize(document.all.menu_portfolio.style.top), 'menu_portfolio'));
    document.cookie = 'menuElementsPositionsArr=' + tempMenuElementsPositionsArr;	
	document.cookie = 'dragElementsPositionsArr=' + tempDragElementsPositionsArr;		
}

function clickMenu(obj){
    if (obj.getAttribute('is_draging') == 'true') {
        obj.setAttribute('is_draging', 'false');
        return;
    }
    else {
        prepareMenuActivation(obj);
    }
}

function getVisibleObjectSize(size){
    return size - shadowSize1;
}

function checkAllowedPosition(){
    var width = getVisibleObjectSize(lastDragElementObj.offsetWidth);
    var height = getVisibleObjectSize(lastDragElementObj.offsetHeight);
    var left = getStyleSize(lastDragElementObj.style.left);
    var top = getStyleSize(lastDragElementObj.style.top);
    if (lastDragElementObj.className == 'drag_menu') {
        if (setActiveMenu(lastDragElementObj, left, top)) {
            return;
        }
    }
    
    var positionsArr = checkAllowedPositionArray(width, height, left, top, dragElementsPositionsArr);
    var positionsArr = checkAllowedPositionArray(width, height, positionsArr[0], positionsArr[1], menuElementsPositionsArr);
    if (lastDragElementObj.className != 'drag_menu') {
        positionsArr[0] = (Math.round(positionsArr[0] / 30) * 30);
        positionsArr[1] = (Math.round(positionsArr[1] / 30) * 30);
        lastDragElementObj.style.left = positionsArr[0];
        lastDragElementObj.style.top = positionsArr[1];
        var left = positionsArr[0];
        var top = positionsArr[1];
        dragElementsPositionsArr.push(Array(width + shadowSize1, height + shadowSize1, left, top));
    }
    if ((top + height - shadowSize1 >= otherElementsPositionsArr[0][3] && top <= otherElementsPositionsArr[0][3] + otherElementsPositionsArr[0][1]) && (left + width - shadowSize1 >= otherElementsPositionsArr[0][2] && left <= otherElementsPositionsArr[0][2] + otherElementsPositionsArr[0][0])) {
        if (lastDragElementObj.className != 'drag_menu') {
            for (var a = 0, b = dragElementsPositionsArr.length; a < b; a++) {
                if (width + shadowSize1 == dragElementsPositionsArr[a][0] && height + shadowSize1 == dragElementsPositionsArr[a][1] && left == dragElementsPositionsArr[a][2] && top == dragElementsPositionsArr[a][3]) {
                    dragElementsPositionsArr.splice(a, 1);
                    if (lastDragElementObj.className == 'drag_element_2') {
                        currentVisibleCharsAmount--;
                    }
                    var parent = lastDragElementObj.parentNode;
                    parent.removeChild(lastDragElementObj);
                    lastDragElementObj = '';
                    document.all.delete_cross_image_highlight.style.visibility = 'hidden';
                    break;
                }
            }
            return;
        }
        else {
            positionsArr[0] = lastDragElementX;
            positionsArr[1] = lastDragElementY;
            lastDragElementObj.style.left = positionsArr[0];
            lastDragElementObj.style.top = positionsArr[1];
        }
        document.all.delete_cross_image_highlight.style.visibility = 'hidden';
    }
    if ((top + height >= otherElementsPositionsArr[1][3] && top <= otherElementsPositionsArr[1][3] + otherElementsPositionsArr[1][1]) && (left + width >= otherElementsPositionsArr[1][2] && left <= otherElementsPositionsArr[1][2] + otherElementsPositionsArr[1][0])) {
        positionsArr[0] = lastDragElementX;
        positionsArr[1] = lastDragElementY;
        lastDragElementObj.style.left = positionsArr[0];
        lastDragElementObj.style.top = positionsArr[1];
    }
    if (lastDragElementObj.className == 'drag_menu') {
        var staticPositionArr = staticMenuPositionsArr[lastDragElementObj.id.substr(5)];
        if (positionsArr[0] != staticPositionArr[0] || positionsArr[1] != staticPositionArr[1]) {
            positionsArr[0] = (Math.round(positionsArr[0] / 30) * 30);
            positionsArr[1] = (Math.round(positionsArr[1] / 30) * 30);
        }
        lastDragElementObj.style.left = positionsArr[0];
        lastDragElementObj.style.top = positionsArr[1];
        menuElementsPositionsArr.push(Array(width + shadowSize1, height + shadowSize1, positionsArr[0], positionsArr[1]));
        var currentMenuElementPositionsArr = staticMenuPositionsArr[lastDragElementObj.id.substr(5)];
        if (lastDragElementX == positionsArr[0] && lastDragElementY == positionsArr[1] && positionsArr[0] == currentMenuElementPositionsArr[0] && positionsArr[1] == currentMenuElementPositionsArr[1]) {
            var imagesArr = lastDragElementObj.getElementsByTagName('img');
            imagesArr[1].style.display = 'none';
        }
    }
}

function checkAllowedPositionArray(width, height, left, top, arr){
    var returnArray = Array(left, top);
    for (var a = 0, b = arr.length; a < b; a++) {
        if (((top + height >= arr[a][3] && top <= Number(arr[a][3]) + Number(arr[a][1]) - shadowSize1) &&
        (left + width >= arr[a][2] && left <= Number(arr[a][2]) + Number(arr[a][0]) - shadowSize1)) ||
        (top < 0 || top + height + 60 + shadowSize1 > document.body.clientHeight || left + width + shadowSize1 > document.body.clientWidth - 16 || left < contentRightBorder)) {
            returnArray[0] = lastDragElementX;
            returnArray[1] = lastDragElementY;
            lastDragElementObj.style.left = returnArray[0];
            lastDragElementObj.style.top = returnArray[1];
            break;
        }
    }
    return returnArray;
}

function setActiveMenu(obj, left, top){
    var currentMenuElementPositionsArr = staticMenuPositionsArr[obj.id.substr(5)];
    if (((currentMenuElementPositionsArr[0] - left > 0 &&
    currentMenuElementPositionsArr[0] - left <= staticMenuAreaRange) ||
    (left - currentMenuElementPositionsArr[0] > 0 &&
    left - currentMenuElementPositionsArr[0] <= staticMenuAreaRange)) &&
    ((currentMenuElementPositionsArr[1] - top > 0 &&
    currentMenuElementPositionsArr[1] - top <= staticMenuAreaRange) ||
    (top - currentMenuElementPositionsArr[1] > 0 &&
    top - currentMenuElementPositionsArr[1] <= staticMenuAreaRange))) {
        activateCurrentMenu(obj, currentMenuElementPositionsArr);
        return true;
    }
    else 
        if (left < contentRightBorder && lastDragElementX == currentMenuElementPositionsArr[0] && lastDragElementY == currentMenuElementPositionsArr[1]) {
            activateCurrentMenu(obj, currentMenuElementPositionsArr);
            return true;
        }
    return false;
}

function prepareMenuActivation(obj){
    for (var a = 0, b = menuElementsPositionsArr.length; a < b; a++) {
        if (obj.offsetWidth == menuElementsPositionsArr[a][0] && obj.offsetHeight == menuElementsPositionsArr[a][1]) {
            menuElementsPositionsArr.splice(a, 1);
            break;
        }
    }
    var currentMenuElementPositionsArr = staticMenuPositionsArr[obj.id.substr(5)];
    activateCurrentMenu(obj, currentMenuElementPositionsArr);
}

function checkMenuPositions(){
    for (var a in staticMenuPositionsArr) {
        if (document.all['menu_' + a] && getStyleSize(document.all['menu_' + a].style.left) == staticMenuPositionsArr[a][0] && getStyleSize(document.all['menu_' + a].style.top) == staticMenuPositionsArr[a][1]) {
            var imagesArr = document.all['menu_' + a].getElementsByTagName('img');
            imagesArr[1].style.display = '';
            loadMenuElements(document.all['menu_' + a], '');
        }
    }
}

function activateCurrentMenu(obj, currentMenuElementPositionsArr){
    checkMenuPositions();
    staticMenuLastObj = obj;
    obj.style.left = currentMenuElementPositionsArr[0];
    obj.style.top = currentMenuElementPositionsArr[1];
    var imagesArr = obj.getElementsByTagName('img');
    imagesArr[1].style.display = 'none';
    lastDragElementX = currentMenuElementPositionsArr[0];
    lastDragElementY = currentMenuElementPositionsArr[1];
    item1 = getUrlItem(1);
    if (item1 != obj.getAttribute('location')) {
        changeActivePage(obj.getAttribute('location') + '/' + obj.getAttribute('sublocation'));
        getSubContentPage('CommonPages', obj.getAttribute('location'));
        loadPNG(document.getElementById('chapter_image'));
    }
}

function freeDragElement(){
    document.body.detachEvent('onmousemove', continueDragElement, true);
    lastDragElementObj = '';
}

function positionElements(obj){
    if (obj.style && obj.style.filter) {
        return;
    }
    var randXPositionMin = contentRightBorder;
    var randXPositionMax = document.body.scrollWidth - obj.offsetWidth - shadowSize1;
    var randYPositionMin = 0;
    var randYPositionMax = document.body.scrollHeight - obj.offsetHeight - 60 - shadowSize1;
    var randLeft = getRandomDigit(randXPositionMin, randXPositionMax);
    var randTop = getRandomDigit(randYPositionMin, randYPositionMax);
    var left = (Math.round(randLeft / 30) * 30);
    var top = (Math.round(randTop / 30) * 30);
    var width = getVisibleObjectSize(obj.offsetWidth);
    var height = getVisibleObjectSize(obj.offsetHeight);
    if (!checkNonCrossPosition(left, top, width, height, dragElementsPositionsArr)) {
        positionElements(obj);
        return;
    }
    if (!checkNonCrossPosition(left, top, width, height, otherElementsPositionsArr)) {
        positionElements(obj);
        return;
    }
    if (!checkNonCrossPosition(left, top, width, height, menuElementsPositionsArr)) {
        positionElements(obj);
        return;
    }
    obj.style.left = left;
    obj.style.top = top;
    obj.style.visibility = 'visible';
    dragElementsPositionsArr.push(Array(width + shadowSize1, height + shadowSize1, left, top));
    if (isIE && !obj.style.filter) {
        document.body.onload = '';
        obj.onload = function(){
        };
        obj.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + obj.src + '", sizingMethod="noscale")';
        obj.src = '/CommonFiles/SmartHead/WPM_Templates/Images/CommonPages/pixels/t_pixel.gif';
    }
    saveElementsPositions();
}

function checkNonCrossPosition(left, top, width, height, arr){
    for (var a = 0, b = arr.length; a < b; a++) {
        if ((top + height - shadowSize1 >= arr[a][3] && top <= Number(arr[a][3]) + Number(arr[a][1])) && (left + width - shadowSize1 >= arr[a][2] && left <= Number(arr[a][2]) + Number(arr[a][0]))) {
            return false;
        }
    }
    return true;
}

function addChar(event){
    if (currentVisibleCharsAmount < 30) {
        loadChars(1, event);
    }
    document.all.new_char.value = '';
}

function checkAddChar(event){
    if (event.keyCode == 13) {
        addChar(event);
    }
}

/* --- menu and other page Elements functions  -- */

/**
 * Cookies functions. TODO rebuild them.
 */
function setCookie(){
    document.cookie = 'action_2=1';
}

function getCookie(){
    if (document.cookie && document.cookie.search('menuElementsPositionsArr') != -1) {
        var arrStart = document.cookie.search('menuElementsPositionsArr');
        var arrContent = document.cookie.substring(arrStart);
        var arr1 = arrContent.split(';');
        if (arr1.length == 0 || !arr1[1]) {
            return;
        }
        var tempCookieMenuArr = arr1[0].split('=');
        if (tempCookieMenuArr[1] == '""') {
            return;
        }
        var tempCookieMenuArr = tempCookieMenuArr[1].split(',');
        cookieMenuArr = Array();
        for (var a = 0, b = tempCookieMenuArr.length; a < b; a += 5) {
            cookieMenuArr.push(Array(tempCookieMenuArr[a], tempCookieMenuArr[a + 1], tempCookieMenuArr[a + 2], tempCookieMenuArr[a + 3]));
        }
        menuElementsPositionsArr = cookieMenuArr;
        var arrStart = document.cookie.search('dragElementsPositionsArr');
        var arrContent = document.cookie.substring(arrStart);
        var arr1 = arrContent.split(';');
        cookieElementsArr = arr1[0].split('=');
        cookieElementsArr = cookieElementsArr[1];
        cookieElementsArr = cookieElementsArr.split(',');
    }
}

/* -- Cookies functions --- */

/**
 * gallery functions
 */
function checkGalleryClick(event){
    var srcEl = getEventSrcElement(event);
    while (srcEl.tagName.toLowerCase() != 'body') {
        if (srcEl.id == 'photo_container' || srcEl.getAttribute('large_image') == '1') {
            return;
        }
        srcEl = srcEl.parentNode;
    }
    if (document.all.photo_container && document.all.photo_container.style.visibility == 'visible') {
        closePhoto();
    }
}

function switchGalleryArrows(){
    if (currentLargeImage + currentGalleryDirection < 0 || currentLargeImage == 0) {
        document.all.largePhotoLeft.style.visibility = 'hidden';
        document.all.largePhotoRight.style.visibility = 'visible';
    }
    else 
        if (currentGalleryDirection + currentLargeImage > largeImagesArr[currentImageArr].length - 1) {
            document.all.largePhotoLeft.style.visibility = 'visible';
            document.all.largePhotoRight.style.visibility = 'hidden';
        }
        else {
            document.all.largePhotoLeft.style.visibility = 'visible';
            document.all.largePhotoRight.style.visibility = 'visible';
        }
}

function showLargeImage(direction, id){
    showPreloader();
    if (id) {
        currentImageArr = id;
    }
    currentGalleryDirection = direction;
    if (currentLargeImage + direction < 0 || direction + currentLargeImage > largeImagesArr[currentImageArr].length - 1) {
        return;
    }
    document.all.photo_container.style.visibility = 'hidden';
    if (document.all.popup.style.display == 'none') {
        document.all.popup.style.width = document.body.scrollWidth;
        document.all.popup.style.height = document.body.scrollHeight;
        document.all.popup.style.display = '';
        slideOpacity(20);
    }
    currentLargeImage = currentLargeImage + direction;
    document.all.largePhotoLeft.style.visibility = 'hidden';
    document.all.largePhotoRight.style.visibility = 'hidden';
    document.all.photo_container.style.left = 0;
    document.all.photo_container.style.top = 0;
    document.all.photo_container.getElementsByTagName('span')[0].innerHTML = '<img>';
    document.all.photo_container.getElementsByTagName('span')[0].getElementsByTagName('img')[0].onload = function(){
        resizeLargeImage(this);
    }
    document.all.photo_container.getElementsByTagName('span')[0].getElementsByTagName('img')[0].src = largeImagesArr[currentImageArr][currentLargeImage];
    document.all.photo_container.getElementsByTagName('span')[0].getElementsByTagName('img')[0].style.border = "10px solid #fff";
}

function showLargeFlash(direction, id, width, height){
    showPreloader();
    if (id) {
        currentImageArr = id;
    }
    currentGalleryDirection = direction;
    if (currentLargeImage + direction < 0 || direction + currentLargeImage > largeImagesArr[currentImageArr].length - 1) {
        return;
    }
    document.all.photo_container.style.visibility = 'hidden';
    if (document.all.popup.style.display == 'none') {
        document.all.popup.style.width = document.body.scrollWidth;
        document.all.popup.style.height = document.body.scrollHeight;
        document.all.popup.style.display = '';
        slideOpacity(20);
    }
    currentLargeImage = currentLargeImage + direction;
    document.all.largePhotoLeft.style.visibility = 'hidden';
    document.all.largePhotoRight.style.visibility = 'hidden';
    var tmp = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" id="simple" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="' + largeImagesArr[currentImageArr][currentLargeImage] + '" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="' + largeImagesArr[currentImageArr][currentLargeImage] + '" quality="high" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="simple" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
    document.all.photo_container.getElementsByTagName('span')[0].innerHTML = tmp;
    document.all.photo_container.style.width = width + 'px';
    document.all.largePhotoLeft.style.top = (width / 2 + 10) + 'px';
    document.all.largePhotoRight.style.top = (height / 2 + 10) + 'px';
    setBackgroundSize();
    document.all.photo_container.style.visibility = 'visible';
    hidePreloader();
}

function resizeLargeImage(obj){
    document.all.photo_container.style.width = obj.clientWidth;
    document.all.largePhotoLeft.style.top = obj.clientHeight / 2 + 10;
    document.all.largePhotoRight.style.top = obj.clientHeight / 2 + 10;
    document.all.photo_container.style.visibility = 'visible';
    setBackgroundSize();
    switchGalleryArrows();
    hidePreloader();
}

function slideOpacity(digit){
    document.all.popup.style.filter = 'alpha(opacity=' + digit + ')';
    document.all.popup.style.opacity = '0.' + digit;
    if (digit < 80) {
        setTimeout('slideOpacity(' + (digit + 10) + ')', '1');
    }
}

function closePhoto(){
    document.all.popup.style.display = 'none';
    document.all.photo_container.style.visibility = 'hidden';
    document.all.largePhotoLeft.style.visibility = 'hidden';
    document.all.largePhotoRight.style.visibility = 'hidden';
    document.all.photo_container.getElementsByTagName('span')[0].innerHTML = "";
    currentLargeImage = -1;
}

function shadowImage(obj){
    obj.parentNode.onmouseover = function(){
        var imagesArr = this.getElementsByTagName('img');
        imagesArr[0].style.filter = 'alpha(opacity=30)';
        imagesArr[0].style.opacity = '0.3';
        imagesArr[1].style.left = imagesArr[0].offsetLeft + (imagesArr[0].offsetWidth / 2) - 18;
        imagesArr[1].style.top = imagesArr[0].offsetTop + (imagesArr[0].offsetHeight / 2) - 21;
        imagesArr[1].style.visibility = 'visible';
        imagesArr[1].style.display = 'block';
    }
    
    obj.parentNode.onmouseout = function(){
        var imagesArr = this.getElementsByTagName('img');
        imagesArr[0].style.filter = 'alpha(opacity=100)';
        imagesArr[0].style.opacity = '1';
        imagesArr[1].style.visibility = 'hidden';
        imagesArr[1].style.display = 'none';
    }
}

function setBackgroundSize(){
    var popup = document.all.popup;
    var container = document.all.photo_container;
    if (popup.style.display != 'none') {
        popup.style.width = document.body.scrollWidth;
        popup.style.height = document.body.scrollHeight;
        if (container && container.style) {
            var img = container.getElementsByTagName('span')[0].getElementsByTagName('img')[0];
            if (!img) {
                img = document.all.simple;
                if (!img.width) 
                    img = img[0];
            }
            var bodyWidth = document.body.clientWidth;
            var bodyHeight = document.body.clientHeight;
            var contWidth = img.width;
            var contHeight = img.height;
            var winLeft = parseInt((bodyWidth - contWidth) / 2);
            var winTop = parseInt((bodyHeight - contHeight) / 2);
            if (winLeft < 20) {
                winLeft = 20;
            }
            if (winTop < 20) {
                winTop = 20;
            }
            container.style.left = winLeft + 'px';
            container.style.top = winTop + 'px';
        }
    }
}

function checkPopupClosing(){
    $(window).keydown(function(evt){
        if ($('#popup').css('display') != 'none' && $('#photo_container').is(':visible')) {
            if (evt.which == 27) {
                closePhoto();
            }
        }
    });
}

/* --- gallery functions --- */

/*
 * mouse wheel functions.
 */
function initWheelEvent(){
    if (document.all.scroll_container_1) {
        if (document.all.scroll_container_1.addEventListener) {
            document.all.scroll_container_1.addEventListener('DOMMouseScroll', initWheel, false);
        }
        window.onmousewheel = document.all.scroll_container_1.onmousewheel = initWheel;
    }
}

function handleWheel(delta){
    initScrollVariables();
    scrollerTopPosition = getStyleSize(document.all.scroller_1.style.top);
    var scrollDifference = delta * 10;
    var scrollerPositionY = -scrollDifference + scrollerTopPosition;
    if (scrollerPositionY <= 0) {
        scrollerPositionY = 0;
    }
    else 
        if (scrollerPositionY >= currentContentHeight - scrollAmountCorrection) {
            scrollerPositionY = currentContentHeight - scrollAmountCorrection;
        }
    document.all.scroller_1.style.top = scrollerPositionY;
    document.all.scroll_container_1.scrollTop = scrollerPositionY * scrollAmount;
}



function initWheel(event){

    var delta = 0;
    
    if (!event) {
    
        event = window.event;
        
    }
    
    
    if (event.wheelDelta) {
    
        delta = event.wheelDelta / 120;
        
        if (window.opera) {
        
            //delta = -delta;
        
        }
        
    }
    
    else 
        if (event.detail) {
        
            delta = -event.detail / 3;
            
        }
    
    if (delta) {
    
        handleWheel(delta);
        
    }
    
}

/* --- mouse wheel functions. --- */

/* 06.05.2008 */

function resetArea(){

    document.cookie = 'menuElementsPositionsArr=""';
    document.cookie = 'dragElementsPositionsArr=""';
    cookieMenuArr = '';
    cookieElementsArr = '';
    
    deleteObjects();
    
    bodyLoaded();
    
}



function deleteObjects(){

    var imagesArr = document.body.getElementsByTagName('img');
    
    for (var a = 0, b = imagesArr.length; a < b; a++) {
    
        if (imagesArr[a] && (imagesArr[a].className == 'drag_element_1' || imagesArr[a].className == 'drag_element_2')) {
        
            var parent = imagesArr[a].parentNode;
            parent.removeChild(imagesArr[a]);
            a = -1;
            
        }
        
    }
    
}



/** map functions */

function showMap(){

    slideOpacity(20);
    
    document.all.popup.style.width = document.body.scrollWidth;
    document.all.popup.style.height = document.body.scrollHeight;
    
    document.all.map_container.style.left = (document.body.clientWidth - document.all.map_container.clientWidth) / 2;
    document.all.map_container.style.top = (document.body.clientHeight - document.all.map_container.clientHeight) / 2;
    document.all.map_container.style.visibility = 'visible';
    
}



function closeMap(){

    document.all.popup.style.display = 'none';
    document.all.map_container.style.visibility = 'hidden';
    
}

/* --- map functions --- */

/* /06.05.2008 */


menuElementsPositionsArr = '';
chapter = null;
chapters = new Array();
chapters['news'] = new Image();
chapters['company'] = new Image();
chapters['portfolio'] = new Image();
chapters['services'] = new Image();
language = 'ru';

/* preloader */
function showPreloader(top, left){
    if (top == null && left == null) {
        var size = getWindowSize();
        left = parseInt((size[0] - 242) / 2);
        top = parseInt((size[1] - 84) / 2);
    }
    $('#Preloader').css({
        'visibility': 'visible',
        top: top,
        left: left
    });
}

function hidePreloader(){
    $('#Preloader').css({
        'visibility': 'hidden',
        top: 0,
        left: 0
    });
}

/* --- preloader --- */

/* content functions */

function checkResizing(){
    var windowSize = getWindowSize();
    var bodyHeight = document.body.clientHeight;
    var minHeight = 700;
    if (windowSize[1] < minHeight) {
        document.body.style.height = minHeight + 'px';
        document.getElementsByTagName('table')[0].style.height = minHeight + 'px';
    }
    else {
        document.body.style.height = '100%';
        document.getElementsByTagName('table')[0].style.height = '100%';
    }
}

function testChapter(){
    chapter = document.getElementById('chapter_image');
    if (typeof(chapter) == 'undefined') {
        setTimeout('testChapter()', 200);
    }
}

function getSubContentPage(domain, page){
    testChapter();
    var item1 = getUrlItem(1);
    chapters[item1].src = '/CommonFiles/SmartHead/WPM_Templates/Images/CommonPages/chapters_images/' + item1 + '_1.png';
    chapters[item1].onload = function(){
        chapter.src = chapters[item1].src;
        chapter.width = chapters[item1].width;
        chapter.height = chapters[item1].height;
        if (isIE) {
            loadPNG(chapter);
        }
    }
    $("#ScrollContentPage").load("/" + domain + "/" + language + "/" + page + ".shtml", {}, ongetSubContentPage);
    if (menuElementsPositionsArr && page == 'news') {
        var count = 0;
        for (var a in staticMenuPositionsArr) {
            if ('menu_' + a == staticMenuLastObj.id) {
                var index = count;
                break;
            }
            count++;
        }
        if (staticMenuLastObj) {
            var imagesArr = staticMenuLastObj.getElementsByTagName('img');
            imagesArr[1].style.display = '';
            loadMenuElements(staticMenuLastObj, '');
            attachStartDragEvent(staticMenuLastObj, '');
        }
    }
}

function ongetSubContentPage(){
    getMainContent();
}

function getMainContent(num){
    showPreloader(400, 200);
    if (typeof(num) == 'undefined') {
        num = 0;
    }
    if (typeof(num) == 'string') {
        url = num;
    }
    if (typeof(num) == 'number') {
        var url = $("#subNavigation>div>a").eq(num).attr("urlpath");
    }
    var item1 = getUrlItem(1);
    var item2 = getUrlItem(2);
    var item3 = getUrlItem(3);
    url = "/CommonPages/ru/" + item1 + "/" + item2 + ".shtml";
    getContentPage(url, {
        'page': item3
    });
    createActiveLink(item2);
}

function getContentPage(url, params){
    var item1 = getUrlItem(1);
    var item2 = getUrlItem(2);
    var tmp = item1 + '/' + item2;
    if (params.page > 1) {
        tmp += '/' + params.page;
    }
    changeActivePage(tmp);
    hidePreloader();
    showPreloader(400, 200);
    if (typeof(params) == 'object') {
        $.post(url, params, ongetContentPage);
    }
    if (typeof(params) == 'undefined') {
        $.post(url, {}, ongetContentPage);
    }
}

function ongetContentPage(data){
    $("#MainContent").html(data);
    if ($('#contentPostScript')) {
        $('#contentNavigation').html($('#contentPostScript').html());
    }
    if (document.getElementById('JSPostScript')) {
        eval(document.getElementById('JSPostScript').innerHTML);
    }
    hidePreloader();
    refreshPageContent();
}

function refreshPageContent(){
    setPageTitle();
    //resizeContent();    
    freeScroll();
    initWheelEvent();
}

function createActiveLink(item2){
    var itemname = $("#currentPageTitle").attr('class');
    var links = $("#subNavigation>div>a");
    var classname = '';
    var classParentName = '';
    for (i = 0; i < links.length; i++) {
        if (item2 == links[i].getAttribute('subitemname')) {
            classname = 'subitem' + itemname;
            classParentName = 'navigation_1_2';
        }
        else {
            classname = '';
            classParentName = 'navigation_1_1';
        }
        links[i].setAttribute('class', classname);
        links[i].className = classname;
        links[i].parentNode.setAttribute('class', classParentName);
        links[i].parentNode.className = classParentName;
        
    }
}

/* -- content functions --- */

/* url functions */
function setPageTitle(){
    document.title = $("#currentPageTitle").text();
}

function setStatusText(text){
    window.status = text;
}

function unsetStatusText(){
    window.status = '';
}

function getUrlItem(param){
    var url = location.href;
    var item1 = 'news';
    var item2 = 'lastnews';
    var item3 = 1;
    var pos1 = url.search('#');
    if (pos1 > (-1) && pos1 != url.length - 1) {
        var tmp = url.split('#');
        url = tmp[1];
        tmp = url.split('/');
        item1 = tmp[0];
        if (tmp.length > 1) {
            item2 = tmp[1];
            if (tmp.length > 2) {
                item3 = tmp[2];
            }
        }
    }
    if (param == 1) {
        return item1;
    }
    if (param == 2) {
        return item2;
    }
    if (param == 3) {
        return item3;
    }
}

function changeActivePage(newpage){
    tmp = '/#' + newpage;
    location.href = tmp;
}

lastURL = '';
function testURL(){
    var url = location.href;
    if ((lastURL != '' && url != lastURL && /\#[a-z]+\/[a-z]+[\/]?[0-9]*$/i.test(url)) || lastURL == '') {
        var lastArr = lastURL.split('/');
        var curArr = url.split('/');
        if (lastArr[0] != curArr[0]) {
            var item1 = getUrlItem(1);
            getSubContentPage("CommonPages", getUrlItem(1));
            if (item1 != 'news') {
                if (item1 == "company") 
                    item1 = "about";
                prepareMenuActivation(document.getElementById('menu_' + item1));
            }
        }
        else {
            var tmp = url.split('#');
            getMainContent(tmp[1]);
        }
    }
    
    lastURL = url;
    setTimeout('testURL()', 25);
}

/* --- url functions --- */

/*
 * Email form
 */
function switchFeedbackForm(event){
    var srcEl = getEventSrcElement(event);
    while (srcEl.tagName.toLowerCase() != 'body') {
        if (srcEl.id == 'top_feedback_form_bg' || srcEl.id == 'top_feedback_form') {
            if (getStyleSize(document.all.top_feedback_form_bg.style.top) == 0) {
                return;
            }
            document.all.top_feedback_form_bg.style.top = 0;
            document.all.top_feedback_form.style.top = 0;
            return;
        }
        srcEl = srcEl.parentNode;
    }
    document.all.top_feedback_form_bg.style.top = -148;
    document.all.top_feedback_form.style.top = -148;
}

function sendEMailMessage(){
    onSendEMailMessage("Отправление");
    params = {
        feedback_email: document.getElementById('feedback_email').value,
        feedback_message: document.getElementById('feedback_message').value
    };
    $.post("?Action=sendMessage", params, onSendEMailMessage);
}

function onSendEMailMessage(data){
    $('#mailMessageText').attr('style', 'background-color: transparent;    ').html('&nbsp;').attr('style', 'background-color: #fff;    ').html(data);
}

function parseMessageForm(){
    onSendEMailMessage("Проверка");
    if (/^[a-z\d_]{3,20}@[a-z\d_^.]{2,15}\.[a-z]{2,4}$/im.test(document.feedback_form.feedback_email.value) && /[\w\s\"\']{5,200}/i.test(feedback_form.feedback_message.value)) {
        sendEMailMessage();
        return false;
    }
    else {
        onSendEMailMessage("Ошибка заполнения!");
        return false;
    };
    }

/* --- email form --- */

$(window).load(function(event){
    //window.detachEvent('onload', bodyLoaded, true);
    initFunctions(event);	
    getSubContentPage("CommonPages", getUrlItem(1));
    $('body').click(function(event){
        checkBodyClick(event);
    });
    $('body').mouseup(function(event){
        stopScrollDrag(event);
        stopDragElement(event);
        return false;
    });
});
$(window).resize(function(){
    resizeContent();
    loadCrossElement();
});
$(window).scroll(function(){
    loadCrossElement();
});

function initFunctions(event){
    getCookie();
    if (!cookieElementsArr) {
        loadChars(6, event);
    }			
    initMenuElements(event);
    loadElements(event);
    testURL();
    checkPopupClosing();
    resizeContent();
    preloader = document.getElementById('Preloader');
    workWithHits();
    initWheelEvent();
    
    item1 = getUrlItem(1);
    if (item1 != 'news') {
        if (item1 == "company") 
            item1 = "about";
        prepareMenuActivation(document.getElementById('menu_' + item1));
    }
    document.cookie = 'hitsAlready=1';
    
}

//-->

