﻿var linksUser = [
    {title:'home', url:'Default.aspx'},
    {title:'works', url:'works.aspx', child:'gallery.aspx'},
    {title:'cv', url:'cv.aspx'},
    {title:'texts', url:'texts.aspx'},
    {title:'news', url:'news.aspx', child:'newsExpanded.aspx'},
    {title:'4fun', url:'cookies.aspx'},
    {title:'contact', url:'contact.aspx'}
    ];
var linksAdmin = [
    {title:'homepage images', background:'CCCCCC', url:'home.aspx'},
    {title:'works main images', background:'FFFFCC', url:'worksImages.aspx'},
    {title:'works galleries', background:'FFFFCC', url:'worksCat.aspx'},
    {title:'works items', background:'FFFFCC', url:'worksItem.aspx'},
    {title:'news items', background:'CCCCCC', url:'news.aspx'},
    {title:'cv\\contact texts', background:'FFFFCC', url:'cvContact.aspx'},
    {title:'text galleries', background:'CCCCCC', url:'textCat.aspx'},
    {title:'text items', background:'CCCCCC', url:'textItem.aspx'},
    {title:'cookies galleries', background:'FFFFCC', url:'cookiesCat.aspx'},
    {title:'cookies items', background:'FFFFCC', url:'cookiesItem.aspx'},
    {title:'mail settings', background:'CCCCCC', url:'mailSettings.aspx'},
    {title:'statistics', background:'CCCCCC', url:'statistics.aspx'}
    ];
function ApplyToolBar(elm, links) 
{
    var ul = document.createElement('ul');
    var liArr = new Array(); 
    var isDefault = true; //is used to find if we are in the default page
    for ( var i=0 ; i<links.length; i++ ) {
        var li = document.createElement('li');
	    li.innerHTML = links[i].title;
	    li.title = links[i].title;
	    li.href = links[i].url;
	    if (links[i].background)// for admin site
	    {
	        li.style.backgroundColor = links[i].background; 
	    }
	    if (document.location.href.match(li.href) || ((links[i].child) && document.location.href.match(links[i].child)))
	    {
	        li.style.fontWeight = 'bolder';
            if (links[i].background)// for admin site
	        {
	            li.style.borderWidth = '2px';
	        }
	        isDefault = false;
        }
        li.onclick = function() {
            window.location = this.href;
        }
        li.onmouseover = function() {
            this.style.fontSize = '13px';
        }
        li.onmouseout = function() {
            this.style.fontSize = '15px';
        }
        liArr[i] = li;
    }
    if (isDefault){
        liArr[0].style.fontWeight = 'bolder';
    }
    for ( var i=0; i<liArr.length; i++ )
    {
        ul.appendChild(liArr[i]);
    }
    elm.appendChild(ul);
}
function isExplorer()
{
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
    {
        return true;
    } 
    return false;
}
function fadeOnLoadNotExplorer()
{
    if (!isExplorer())
    {
        var elm = document.getElementById('content');
        if (elm)
        {    
            var state = 50;
            intervalId = window.setInterval(function()
            {
                elm.style.MozOpacity = state/100; 
                elm.style.KhtmlOpacity = state/100; 
                state += 2;
                if (state == 100)
                { 
                    window.clearInterval(intervalId);
                }    
            }, 1);
        }
    } 
}
function ValidateExt( fileName, type )
{
    if (fileName.length < 3)
    {
        return 0;
    }
    var ext = fileName.substring(fileName.length-3, fileName.length);
    if(ext.toLowerCase() != type.toLowerCase()) 
    {
        return 0;
    }
    return 1;            
}
window.onload = function globalLoader() 
{
    var footer = document.getElementById('fTool');
    if (footer)
    {
        ApplyToolBar(footer, linksUser);   
    }
    var header = document.getElementById('hTool');
    if (header)
    {
        ApplyToolBar(header, linksAdmin);        
    }
    fadeOnLoadNotExplorer(); 
}
