function swapImg(eSwap){if (eSwap.src){
    var sExt = eSwap.src.substr(eSwap.src.lastIndexOf('.'), eSwap.src.length - eSwap.src.lastIndexOf('.'));
    if (!(eSwap.src.lastIndexOf('_s' + sExt) > 0)){eSwap.src = (eSwap.src.indexOf('_ro' + sExt) > 0) ? eSwap.src.replace('_ro' + sExt, sExt) : eSwap.src.replace(sExt,'_ro' + sExt);}}
}
function swapSection(sSection, nIndex){
    if (!window[sSection + '_currentIndex']) window[sSection + '_currentIndex'] = 1
    if (window[sSection + '_currentIndex']){ 
        if (document.getElementById(sSection + '_' + window[sSection + '_currentIndex']).style.display!='block') window[sSection + '_currentIndex'] = 1
        document.getElementById(sSection + '_' + window[sSection + '_currentIndex']).style.display='none'; 
        var eSwap=document.getElementById(sSection + '_' + window[sSection + '_currentIndex'] + '_b');
        if (eSwap) var sExt = eSwap.src.substr(eSwap.src.lastIndexOf('.'), eSwap.src.length - eSwap.src.lastIndexOf('.'));
        if (eSwap && (eSwap.src.indexOf('_s' + sExt) != -1)) {eSwap.src = eSwap.src.replace('_s' + sExt, sExt);}
    }
    document.getElementById(sSection + '_' + nIndex).style.display='block';
    var eSwap=document.getElementById(sSection + '_' + nIndex + '_b');
    if (eSwap) var sExt = eSwap.src.substr(eSwap.src.lastIndexOf('.'), eSwap.src.length - eSwap.src.lastIndexOf('.'));
    if (eSwap && !(eSwap.src.indexOf('_s' + sExt) != -1)) { eSwap.src = (eSwap.src.indexOf('_ro' + sExt) != -1) ? eSwap.src.replace('_ro' + sExt,'_s' + sExt) : eSwap.src.replace(sExt,'_s' + sExt);}
    window[sSection + '_currentIndex'] = nIndex;
}
function swapInputFocus(eSwap, bRestore){
    if (!eSwap.initialized && eSwap.value.length > 0){eSwap.initialized = true; if (bRestore) {eSwap.valueInitialize = eSwap.value;  eSwap.value = '';} }
    else {if (eSwap.initialized == true && eSwap.value.length == 0){if (bRestore) eSwap.value = eSwap.valueInitialize; eSwap.initialized = false;}}
    eSwap.parentNode.className = (eSwap.parentNode.className.indexOf(' input_f') != -1) ? eSwap.parentNode.className.replace(' input_f','') : eSwap.parentNode.className += ' input_f';
}
function swapSelected(eSwap){
    //eSwap.className = (eSwap.className.indexOf(' selected') != -1) ? eSwap.className.replace(' selected', '') : eSwap.className + ' selected';
    eSwap.className = (eSwap.className.indexOf('selected') != -1) ? ((eSwap.className.indexOf('selected') == 0) ? eSwap.className.replace('selected', ''):eSwap.className.replace(' selected', '')) : ((eSwap.length > 0) ? eSwap.className + ' selected' : eSwap.className + 'selected');
}
function toggleDropdown(sId) {
    var eDrowDown = document.getElementById(sId);
    var eDrowDownContent = document.getElementById(sId + '_content');
    if (eDrowDownContent.style.display!='block') {
        eDrowDown.className = eDrowDown.className.replace('dropdown', 'dropdown_hover');
        eDrowDownContent.style.display = 'block';
    }
    else {
        eDrowDown.className = eDrowDown.className.replace('dropdown_hover', 'dropdown');
        eDrowDownContent.style.display = 'none';
    }
    return false;
}
function cancelHideDropDown(sId) {
    var eDrowDown = document.getElementById(sId);
    lTimeout = eDrowDown.timeout;
    if (lTimeout) clearTimeout(lTimeout);
}
function hideDropDown(sId) {
    var eDrowDown = document.getElementById(sId);
    lTimeout = eDrowDown.timeout;
    if (lTimeout) clearTimeout(lTimeout);
    lTimeout = setTimeout("doHideDropdown('" + sId + "');", 1500); 
    eDrowDown.timeout = lTimeout;
}
function doHideDropdown(sId) {  
    var eDrowDown = document.getElementById(sId);
    var eDrowDownContent = document.getElementById(sId + '_content');
    if (eDrowDownContent.style.display = 'block') {
        toggleDropdown(sId);
    }
}
function showPopup(sImg, lWidth, lHeight, sGalleryId, nGalleryIndex, sGalleryLabel){
    var eBg;
    var ePopup;
    var eClose;
    var eImg;
    var eNav;
    var eNavLabel;
    var eNavActive;
    var eContainer = document.getElementById('container');
    if (!window['backdrop']){ window['backdrop'] = document.createElement('div'); window['backdrop'].className = 'overlay';document.body.appendChild(window['backdrop']);}
    if (!window['popup']){window['popup'] = document.createElement('img');window['popup'].className = 'popup';document.body.appendChild(window['popup']);}
    if (!window['popup_close']){
        window['popup_close'] = document.createElement('div');
        window['popup_close'].className = 'popup_close';
        document.body.appendChild(window['popup_close']);
        window['popup_close'].onclick = function(){hidePopup();};
        window['popup_close'].onmouseover = function(){this.className += ' popup_close_ro';};
        window['popup_close'].onmouseout = function(){this.className = this.className.replace(' popup_close_ro','');};
    } 
    if (window.onscroll && !window['scroll_restore']){window['scroll_restore'] = window.onscroll;};
    window.onscroll = function(){positionPopup();};
    if (sGalleryId){
        if (!window['popup_gallery_index']) window['popup_gallery_index'] = nGalleryIndex;
        if (!window['popup_gallery_indexTotal']){
            window['popup_gallery_indexTotal'] = 1;
            while(document.getElementById(sGalleryId + '_' + (window['popup_gallery_indexTotal'] + 1))) window['popup_gallery_indexTotal'] += 1;
        }
        if (!window['popup_nav']){
            window['popup_nav'] = document.createElement('div');
            window['popup_nav'].className = 'popup_nav';
            window['popup_nav_label'] = document.createElement('div');
            window['popup_nav_label'].id = 'label';
            window['popup_nav_label'].className = 'label';
            window['popup_nav_label'].innerHTML = sGalleryLabel;
            window['popup_nav'].appendChild(window['popup_nav_label']);
            var eTemp = document.createElement('div');
            eTemp.innerHTML = sGalleryLabel;
            window['popup_nav'].appendChild(eTemp);
            window['popup_nav_active'] = document.createElement('div');
            window['popup_nav_active'].className = 'popup_nav_active';
            window['popup_nav_active'].appendChild(window['popup_nav']);
            window['popup_nav_active'].onmouseover = function(){window['popup_nav'].style.display = 'block';};
            window['popup_nav_active'].onmouseout = function(){window['popup_nav'].style.display = 'none';};
            document.body.appendChild(window['popup_nav_active']);
        }
        window['popup_nav_active'].onclick = function(){navPopup(sGalleryId, 1); return false;};
    }
    else window['popup_nav'] = undefined;
    eBg = window['backdrop'];
    ePopup = window['popup'];
    eClose = window['popup_close'];
    eNav = window['popup_nav'];
    eNavLabel = window['popup_nav_label'];
    eNavActive = window['popup_nav_active'];
    eBg.style.height = eContainer.clientHeight + 'px';
    eBg.style.zIndex = 2;
    eBg.style.display = 'block';
    ePopup.style.width = lWidth + 'px';
    ePopup.style.height = lHeight + 'px';
    ePopup.style.left = '50%';
    ePopup.style.marginLeft = '-' + (lWidth/2) + 'px';
    ePopup.style.top = getScrollTop() + 80 + 'px';
    ePopup.src = sImg;
    ePopup.style.display = 'block';
    eClose.style.left = '50%';
    eClose.style.display = 'block';
    eClose.style.top = getScrollTop() + 80 - (eClose.clientHeight/2) + 'px';
    eClose.style.marginLeft = (lWidth/2) - (eClose.clientWidth/2) + 'px';
    if (eNav && eNavLabel && eNavActive && window['popup_gallery_indexTotal'] > 1){
        eNavLabel.innerHTML = window['popup_gallery_index'] + '/' + window['popup_gallery_indexTotal'];
        eNavActive.style.width = ePopup.style.width;
        eNavActive.style.height = ePopup.style.height;
        eNavActive.style.left = ePopup.style.left;
        eNavActive.style.top = ePopup.style.top;
        eNavActive.style.marginLeft = ePopup.style.marginLeft;
        eNavActive.style.display = 'block';
        eNav.style.top = '50%';
    }
}
function showContentPopup(eContent, sClassName, lWidth){
    var eBg;
    var ePopup;
    var eClose;
    var eImg;
    var eNav;
    var eNavLabel;
    var eNavActive;
    var eContainer = document.getElementById('container');
    if (!window['backdrop']){ window['backdrop'] = document.createElement('div'); window['backdrop'].className = 'overlay';document.body.appendChild(window['backdrop']);}
    if (!window['popup']){window['popup'] = document.createElement('div');window['popup'].className = sClassName;document.body.appendChild(window['popup']);}
    if (!window['popup_close']){
        window['popup_close'] = document.createElement('div');
        window['popup_close'].className = 'popup_close';
        document.body.appendChild(window['popup_close']);
        window['popup_close'].onclick = function(){hidePopup();};
        window['popup_close'].onmouseover = function(){this.className += ' popup_close_ro';};
        window['popup_close'].onmouseout = function(){this.className = this.className.replace(' popup_close_ro','');};
    } 
    if (window.onscroll && !window['scroll_restore']){window['scroll_restore'] = window.onscroll;};
    window.onscroll = function(){positionPopup();};
    
    eBg = window['backdrop'];
    ePopup = window['popup'];
    eClose = window['popup_close'];
    eBg.style.height = eContainer.clientHeight + 'px';
    eBg.style.zIndex = 2;
    eBg.style.display = 'block';
    ePopup.style.left = '50%';
    ePopup.style.marginLeft = '-' + (lWidth/2) + 'px';
    ePopup.style.top = getScrollTop() + 80 + 'px';
    ePopup.innerHTML = eContent.innerHTML;
    ePopup.style.display = 'block';
    eClose.style.left = '50%';
    eClose.style.display = 'block';
    eClose.style.top = getScrollTop() + 80 - (eClose.clientHeight/2) + 'px';
    eClose.style.marginLeft = (lWidth/2) - (eClose.clientWidth/2) + 'px';
}
function navPopup(sGalleryId, nDirection){
    var nIndex;
    var nIndex = window['popup_gallery_index'];
    var ePopup = document.getElementById(sGalleryId + '_' + (nIndex + nDirection))
    if (!ePopup) {nIndex = 1; ePopup = document.getElementById(sGalleryId + '_' + nIndex)}
    else nIndex += nDirection;
    window['popup_gallery_index'] = nIndex;
    eval(ePopup.getAttributeNode('onclick').nodeValue);
}
function positionPopup(){
	var ePopup = window['popup'];
	var eClose = window['popup_close'];
	var eNav = window['popup_nav'];
    var eNavLabel = window['popup_nav_label'];
    var eNavActive = window['popup_nav_active'];
        
	if (ePopup && eClose){
		ePopup.style.top = getScrollTop() + 80 + 'px';
		eClose.style.top = getScrollTop() + 80 - (eClose.clientHeight/2) + 'px';
        if (eNav && eNavLabel && eNavActive && window['popup_gallery_indexTotal'] > 1){
            eNavActive.style.top = ePopup.style.top;
            eNav.style.top = '50%';
        }
	}
}
function hidePopup(){
    if (window['scroll_restore']){window.onscroll = window['scroll_restore']; window['scroll_restore'] = undefined};
	if (window['backdrop']) window['backdrop'].style.display = 'none';
    if (window['popup']) {window['popup'].parentNode.removeChild(window['popup']); window['popup']= undefined;}
    if (window['popup_close']) window['popup_close'].style.display = 'none'; 
    if (window['popup_nav']) window['popup_nav'].style.display = 'none'; 
    if (window['popup_nav_active']) window['popup_nav_active'].style.display = 'none'; 
    if (window['popup_gallery_index']) window['popup_gallery_index'] = undefined;
    if (window['popup_gallery_indexTotal']) window['popup_gallery_indexTotal'] = undefined;   
}
function getScrollTop(){
    var nTop=0;
    if (document.documentElement.scrollTop) if (document.documentElement.scrollTop>0) nTop = document.documentElement.scrollTop;
    if (document.body.scrollTop) if (document.body.scrollTop>0) nTop = document.body.scrollTop;
    return nTop;
}
function swapToolTip(eAlign, sText){
    var eTemp;
    if (!window['tooltip']){
        window['tooltip'] = document.createElement('div');
        window['tooltip'].className = 'tooltip';
        document.body.appendChild(window['tooltip']);
        eTemp = document.createElement('div');
        eTemp.className = 'top';
        window['tooltip'].appendChild(eTemp);
        var eTemp = document.createElement('div');
        eTemp.className = 'content';
        eTemp.id = 'tooltip_content';
        window['tooltip_content'] = eTemp;
        window['tooltip'].appendChild(eTemp);
        eTemp = document.createElement('div');
        eTemp.className = 'bottom';
        window['tooltip'].appendChild(eTemp);
    }
    window['tooltip_content'].innerHTML = sText;
    window['tooltip'].style.display = (sText.length != 0) ? 'block':'none';
    if (sText.length != 0){
        window['tooltip'].style.left = (getOffsetLeft(eAlign) -1) + 'px';
        window['tooltip'].style.top = (getOffsetTop(eAlign) - (window['tooltip'].clientHeight + 4)) + 'px';
    }
}
function swapToolImage(eAlign, sImg, lWidth, lHeight){
    var eTemp;
    if (!window['toolimg']){
        window['toolimg'] = document.createElement('img');
        window['toolimg'].className = 'toolimg';
        document.body.appendChild(window['toolimg']);
    }
    if (sImg.length != 0) window['toolimg'].src = sImg;
    window['toolimg'].width = lWidth;
    window['toolimg'].height = lHeight;
    window['toolimg'].style.width = lWidth + 'px';
    window['toolimg'].style.height = lHeight + 'px';
    window['toolimg'].style.display = (sImg.length != 0) ? 'block':'none';
    if (sImg.length != 0){
        window['toolimg'].style.left = (getOffsetLeft(eAlign) -1) + 'px';
        window['toolimg'].style.top = (getOffsetTop(eAlign) - (window['toolimg'].clientHeight + 4)) + 'px';
    }
}
function getOffsetLeft(eOffset){
    var nLeft = eOffset.offsetLeft;
    var elem = eOffset.offsetParent;
    while (elem && elem.nodeType==1){
        nLeft += elem.offsetLeft;
        elem = elem.offsetParent;
    } 
    return nLeft;
}
function getOffsetTop(eOffset){
    var nTop = eOffset.offsetTop;
    var elem = eOffset.offsetParent;
    while (elem && elem.nodeType==1){
        nTop += elem.offsetTop;
        elem = elem.offsetParent;
    } 
    return nTop;
}
function scrollTopic(sListId, nDirection, nTotal, nList){
    var oTopics = document.getElementById(sListId + '_topics');
    var oTopicsOld = document.getElementById(sListId + '_topics_old');
    var oOldTopic = undefined;
    var oNewTopic = undefined;
    if (!window[sListId + '_topic_index']) window[sListId + '_topic_index'] = 1;
    var nIndex = window[sListId + '_topic_index'];
    if (nDirection < 0){
        if (nIndex == 1) nIndex = nTotal - 1
        else{
            if (nIndex > 2) nIndex -= 2
            else nIndex = nTotal
        }
    }
    for (var i=0; i<nList; i++){
        if (nIndex == nTotal) nIndex = 1
        else nIndex += 1
        if (i==0) window[sListId + '_topic_index'] = nIndex;
        oOldTopic = oTopics.childNodes[i];
        oNewTopic = document.getElementById(sListId + '_topic_' + nIndex);
        if (oOldTopic) oTopics.replaceChild(oNewTopic, oOldTopic);
        else oTopics.appendChild(oNewTopic);
        if (oOldTopic && oNewTopic) {
            if (oOldTopic != oNewTopic) oTopicsOld.appendChild(oOldTopic);
        }
    }    
}
function swapHidden(sId, eTrigger, bHideTrigger){
    if (eTrigger && bHideTrigger) eTrigger.style.display='none';
    var eSwap = document.getElementById(sId);
    if (eSwap) eSwap.style.display = (eSwap.style.display!='block') ? 'block' : 'none';
}