

/*****************Dropdown Menu********************/
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;
var list = null;
var size = 0;

function subMenuItem_onMouseOver(id, count) {
    mcancelclosetime();
    
    list = document.getElementById(id);
    size = 0;
    
    if (count>0){
        size = (count*33)
    }
    subMenuOpen(size);
    
}
function subMenuItem_onMouseOut(control) {
    list = control;
    startCloseTimer();
}

function subMenuOpen() {
    // close old layer
    if (list.style.height != size+'px') {
        $(list).animate
        (
            {
                height: size
            },
            200,
            function() { }
        );
    }
}
//Close submenu
function subMenuClose() {
    if (list) {
        $(list).animate
        (
            {
                height: 0
            },
            200,
            function() { }
        );
    }
}
//Start timer
function startCloseTimer() {
    closetimer = window.setTimeout(subMenuClose, timeout);
}
// cancel close timer
function mcancelclosetime() {

    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}


/***************** Footer position **********************/
function adaptFooter() {
    var footerHeight = 150;
    var bodyHeight;
    var footerPosition;

    //GET CONTENT HEIGHT:    
    if (document.body.offsetHeight) {
        bodyHeight = document.getElementById('wrap').offsetHeight;
    } else {
        bodyHeight = document.getElementById('wrap').clientHeight;
    }

    //IF CONTENT HEIGHT IS HEIGHER THEN WINDOW:
    if (bodyHeight > getWidthHeight()[1]) {
        footerPosition = bodyHeight + 20;

    } else {
        //IF THE EMPTY SPACES HEIGHT IS LOWER THEN THE FOOTER:
    if ((getWidthHeight()[1] - bodyHeight) <= footerHeight) {
            footerPosition = bodyHeight;   //- (getWidthHeight()[1] - bodyHeight);
        } else {
            footerPosition = getWidthHeight()[1] - footerHeight;  //- footerHeight;
        }
    }

    document.getElementById('footerWrap').style.top = footerPosition + 'px';
    showFooter();
}

function showFooter() {
    //    document.getElementById('wrap_footer').setAttribute('style', 'display:table');
    
    document.getElementById('footerWrap').style.display = 'block';
    //alert(document.getElementById('wrap_footer').style.display);

}



/***************** Footer Slideshow ********************/
var interval = 0;
var currPos = new Array();

function startFooterGallery() {
    var container;
    var image;
    var text;
    var desc;
    var src;

    for (i = 1; i < (images.length); i++) {
        currPos.push(i);
        src = images[i].split(';')[0];
        desc = images[i].split(';')[1];

        container = document.getElementById('footer' + i);
        image = container.getElementsByTagName('div')[0];
        text = container.getElementsByTagName('div')[1];

        setOpacity(0, container);

        $(container).animate(
        {opacity: 1},
        1000,
        function() { }
        );   
    }
    interval = setInterval('getNextImage()', 1000);
}

function getNextImage() {
    clearInterval(interval);
    interval = 0;


    var container = document.getElementById('footer_roler');
    var item = container.getElementsByTagName('div')[0];
    var clonenode = item.cloneNode(true);
    
    container.appendChild(clonenode);
    container.style.left = 0;
    container.removeChild(item);
        
    var newItem = container.getElementsByTagName('div')[(container.getElementsByTagName('div').length - 1)];
    setOpacity(0, newItem);
    $(container).animate(
        { left: -330 }, 1000, function() {
        $(newItem).animate(
            { opacity: 1 }, 1000, function() { }
            );
        }
    );
    
    interval = setInterval('getNextImage()', 5000);
}



function randomNum(num) {
    var randomnumber = Math.floor(Math.random() * num);

    return randomnumber;
}
function setOpacity(value, obj) {
    obj.style.opacity = value / 10;
    obj.style.filter = 'alpha(opacity=' + value * 10 + ')';
}




//********************************************************************************
//WINDOW FUNCTIONS
//********************************************************************************
function getWidthHeight() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [myWidth, myHeight];
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [scrOfX, scrOfY];
}