﻿var nHand;
function Open_Tree_Popup(sURL, sWINNAME, WIDTH, HEIGHT) {
    var left, top;
    left = (window.screen.width - WIDTH) / 2;
    top = (window.screen.height - HEIGHT) / 2;
    if (left < 0)
        left = 0;
    if (top < 0)
        left = 0;
    var wfeatures = 'left=' + left + ',top=' + top + ',toolbar=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=yes,width=' + WIDTH + ',height=' + HEIGHT;
    nHand = window.open(sURL, sWINNAME, wfeatures);
    //return nHand;
}


// Accordian
function getid(id) {
    return document.getElementById(id);
}
var div1 = 0;
var div2 = 0;
var cnt = '';
function accordian() {
    heading = getid('accord_bottom').getElementsByTagName('h2');
    image = getid('accord_bottom').getElementsByTagName('img');
    description = getid('accord_bottom').getElementsByTagName('div');
    for (j = 0; j < description.length; j++) {

        if (description[j].className == 'accord_1') {
            div1++;
            description[j].style.height = '162px';
            description[j].style.background = 'url(' + image[div1 - 1].src + ') no-repeat 1px top';

            outerDiv = document.createElement('div');
            outerDiv.setAttribute('id', 'outer' + div1);

            transCnt = document.createElement('div');
            transCnt.setAttribute('id', 'trans' + div1);
            transCnt.setAttribute('class', 'accord_tr');
            outerDiv.appendChild(transCnt);
            
            transContainer = document.createElement('div');
            transContainer.setAttribute('id', 'transCnt' + div1);
            transContainer.setAttribute('class', 'accord_trCnt');
            outerDiv.appendChild(transContainer)

            description[j].appendChild(outerDiv)
            heading[div1 - 1].style.display = 'none';
            image[div1 - 1].style.display = 'none';
            cnt = '<div class="heading" id="heading' + div1 + '">' + heading[div1 - 1].innerHTML + '</div>';
            description[j].onmouseover = new Function('popup(' + div1 + ')');
            getid('outer' + div1).className = 'accord_trCntOuter';
            getid('trans' + div1).className = 'accord_tr';
            if (navigator.userAgent.indexOf('MSIE 7') != -1 || navigator.userAgent.indexOf('MSIE 6') != -1) {
                getid('trans' + div1).className = 'accord_tr1';
            }
        }
        if (description[j].className == 'accordDsc') {
            div2++;
            description[j].setAttribute('id', 'dsc' + div2);
            description[j].style.display = 'none';
            cnt += description[j].innerHTML;
            getid('outer' + div2).style.height = '15px';
        }
        getid('transCnt' + div1).innerHTML = cnt;
    }
    document.onmousemove = getMouseXY;
}
var IE = document.all ? true : false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
        return [curleft, curtop];
    }

}

function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
        xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        yScroll = document.documentElement.scrollTop;
        xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
        xScroll = document.body.scrollLeft;
    }
    return [xScroll, yScroll]
}

function findPosRelativeToViewport(obj) {
    var objPos = this.findPos(obj)
    var scroll = this.getPageScroll()
    return [objPos[0] - scroll[0], objPos[1] - scroll[1]]
}


function getMouseXY(e) {
    if (IE) { // grab the x-y pos.s if browser is IE
        tempX = event.clientX + document.body.scrollLeft
        tempY = event.clientY + document.body.scrollTop
    } else {  // grab the x-y pos.s if browser is NS
        tempX = e.pageX
        tempY = e.pageY
    }
    // catch possible negative values in NS4
    if (tempX < 0) { tempX = 0 }
    if (tempY < 0) { tempY = 0 }
    // show the position values in the form named Show
    // in the text fields named MouseX and MouseY
    var xstrtPsn = findPosRelativeToViewport(getid('wrapper'))[0]; //getid('wrapper').offsetLeft + 60;
    var xendPsn = xstrtPsn + getid('accord_bottom').offsetWidth ;
    var ystrtPsn = findPosRelativeToViewport(getid('accord_bottom'))[1]; //getid('accord_bottom').offsetTop;
    var yendPsn = getid('accord_bottom').offsetTop + getid('accord_bottom').offsetHeight;

    //alert('tempX  = ' + tempX + ' tempY = ' + tempY + ' xstrtPsn= ' + xstrtPsn + ' xendPsn = ' + xendPsn + ' ystrtPsn = ' + ystrtPsn + ' yendPsn = ' + yendPsn);
    if (tempX >= xstrtPsn && tempX <= xendPsn && tempY >= ystrtPsn && tempY <= yendPsn)
    { } else {
        if (getid('outer1').style.height == '114px') {
            expand(getid('outer1'), [114], [15], 1, 10, 1, 1, 1);
            getid('heading1').className = 'heading';
        } else if (getid('outer2').style.height == '114px') {
            expand(getid('outer2'), [114], [15], 1, 10, 1, 1, 1);
            getid('heading2').className = 'heading';
        } 
    }

    return true
}

var strid = 0;
function popup(outerId) {
    if (('"' + window.location + '"').indexOf('/ar/') != -1 && navigator.userAgent.indexOf('IE8') != -1) {
        if (strid != outerId) {
            getid('heading' + outerId).className = 'headingClr';
            expand(getid('outer' + outerId), [15], [114], 1, 17, 1, 1, 0);
            if (strid) {
                getid('heading' + strid).className = 'heading';
                expand(getid('outer' + strid), [114], [15], 1, 17, 1, 1, 0);
            }
            strid = outerId;
        }
    } else {
        if (strid != outerId) {
            getid('heading' + outerId).className = 'headingClr';
            expand(getid('outer' + outerId), [15], [114], 1, 17, 1, 1, 0);
            if (strid) {
                getid('heading' + strid).className = 'heading';
                expand(getid('outer' + strid), [114], [15], 1, 17, 1, 1, 0);
            }
            strid = outerId;
        }
    }
}
var repeating = 0;
function expand(elem, startmar, endmar, finmar, steps, intervals, powr, repeat) {
    if (elem.bgFadeInt) window.clearInterval(elem.bgFadeInt);
    var actStep = 0;
    elem.bgFadeInt = window.setInterval(
	function() {
	    elem.style.height = easeInOut(startmar[0], endmar[0], steps, actStep, powr) + "px";
	    actStep++;
	    if (actStep > steps) {
	        elem.style.left = finmar;
	        window.clearInterval(elem.bgFadeInt);
	        if (repeat == 1) {
	            strid = 0;
	        }
	    }

	}, intervals)
}

function easeInOut(minValue, maxValue, totalSteps, actualStep, powr) {
    var delta = maxValue - minValue;
    var stepp = minValue + (Math.pow(((1 / totalSteps) * actualStep), powr) * delta);
    return Math.ceil(stepp)
}


