window.onload = function() {
 if (typeof(interfaceLoad)=='function') { 
   interfaceLoad();
   }
}

function showPhoto(el) {
    var id = el.getAttribute('photo_id');
    var w = el.getAttribute('width')*1+20;
    var h = el.getAttribute('height')*1+20;
    var x = Math.floor((screen.width - w - 10)/2);
    var y = Math.floor((screen.height - h - 60)/2);
    var win = window.open('/picture/?id='+id, 'IMAGE_WINDOW', 'dependent=yes, disrectories=no, width='+w+', height='+h+', innerWidth='+w+', innerHeight='+h+
', location=no, menubar=no, resizable=no, screenX='+x+', screenY='+y+', scrollbars=no, titlebar=no, toolbar=no');
    win.focus();
}


function editPhoto(el){
 var id = el.getAttribute('photo_id');
 var w = 800;
 var h = 450;
 var x = Math.floor((screen.width - w -10)/2);
 var y = Math.floor((screen.height - h - 60)/2);
 
 var win = window.open('/ed_photo/?id='+id, 'IMAGE_WINDOW', 'dependent=yes, disrectories=no, width='+w+', height='+h+', innerWidth='+w+', innerHeight='+h+
', location=no, menubar=no, resizable=no, screenX='+x+', screenY='+y+', scrollbars=yes, titlebar=no, toolbar=no');
 win.focus();
 }

function editContest(el){
 var id = el.getAttribute('contest_id');
 var w = 800;
 var h = 450;
 var x = Math.floor((screen.width - w -10)/2);
 var y = Math.floor((screen.height - h - 60)/2);
 
 var win = window.open('/ed_contest/?id='+id, 'IMAGE_WINDOW', 'dependent=yes, disrectories=no, width='+w+', height='+h+', innerWidth='+w+', innerHeight='+h+
', location=no, menubar=no, resizable=no, screenX='+x+', screenY='+y+', scrollbars=yes, titlebar=no, toolbar=no');
 win.focus();
 }

function editUser(el){
 var id = el.getAttribute('user_id');
 var w = 800;
 var h = 450;
 var x = Math.floor((screen.width - w -10)/2);
 var y = Math.floor((screen.height - h - 60)/2);
 
 var win = window.open('/ed_user/?id='+id, 'IMAGE_WINDOW', 'dependent=yes, disrectories=no, width='+w+', height='+h+', innerWidth='+w+', innerHeight='+h+
', location=no, menubar=no, resizable=no, screenX='+x+', screenY='+y+', scrollbars=yes, titlebar=no, toolbar=no');
 win.focus();
 }

function addPhoto(el){
 var id = el.getAttribute('contest_id');
 var photo_id = el.getAttribute('photo_id');
 var w = 800;
 var h = 450;
 var x = Math.floor((screen.width - w -10)/2);
 var y = Math.floor((screen.height - h - 60)/2);
  if(photo_id==null){
 var win = window.open('/add_photo/?id='+id, 'IMAGE_WINDOW', 'dependent=yes, disrectories=no, width='+w+', height='+h+', innerWidth='+w+', innerHeight='+h+
', location=no, menubar=no, resizable=no, screenX='+x+', screenY='+y+', scrollbars=yes, titlebar=no, toolbar=no');
 }else{
  var win = window.open('/add_photo/?id='+id+'&amp;photo_id='+photo_id, 'IMAGE_WINDOW', 'dependent=yes, disrectories=no, width='+w+', height='+h+', innerWidth='+w+', innerHeight='+h+
', location=no, menubar=no, resizable=no, screenX='+x+', screenY='+y+', scrollbars=yes, titlebar=no, toolbar=no');
 }
 win.focus();
 }

function editNom(el){
 var id = el.getAttribute('contest_id');
 var w = 450;
 var h = 450;
 var x = Math.floor((screen.width - w -10)/2);
 var y = Math.floor((screen.height - h - 60)/2);
 
 var win = window.open('/ed_nom/?id='+id, 'IMAGE_WINDOW', 'dependent=yes, disrectories=no, width='+w+', height='+h+', innerWidth='+w+', innerHeight='+h+
', location=no, menubar=no, resizable=no, screenX='+x+', screenY='+y+', scrollbars=yes, titlebar=no, toolbar=no');
 win.focus();
 }

function editAva(el){
 var id = el.getAttribute('cat_id');
 var w = 450;
 var h = 450;
 var x = Math.floor((screen.width - w -10)/2);
 var y = Math.floor((screen.height - h - 60)/2);
 
 var win = window.open('/ed_ava/?id='+id, 'IMAGE_WINDOW', 'dependent=yes, disrectories=no, width='+w+', height='+h+', innerWidth='+w+', innerHeight='+h+
', location=no, menubar=no, resizable=no, screenX='+x+', screenY='+y+', scrollbars=yes, titlebar=no, toolbar=no');
 win.focus();
 }


var IE = document.all ? 1 : 0;

/*  Common JavaScript library  */
/*    1) Small DOM helpers     */
/*    2) Content loader (CL)   */


function $goto(url) {
    window.location = url;
}

$ = function(element) {
    if (arguments.length > 1) {
        for (var i = 0, elements = [], length = arguments.length; i < length; i++)
            elements.push($(arguments[i]));
        return elements;
    } else {
        return document.getElementById(element);
    }
}


$new = function(params,parent) {
    var tag = params['tag'] || 'div';
    var newEl = document.createElement(tag);
    for (var paramName in params) {
        if ((paramName != 'tag') && (paramName != 'text') && (!paramName.match(/^on\w+/))) { newEl[paramName] = params[paramName]; }
        if (paramName.match(/^on(\w+)/)) {
            var eventName = RegExp.$1;
            $attachEvent(newEl, eventName, params[paramName]);
        }
    }
    if (params['text'] != null) { newEl.appendChild($text(params['text'])); }
    if (parent!=null) { parent.appendChild(newEl); }
    return newEl;
}

$text = function(string) {
    return document.createTextNode(string);
}
$char = function(code) {
    return String.fromCharCode(code);
}
$getText = function(node) {
    if (node.innerText != undefined) return node.innerText; else return node.textContent;
}


$clearDOM = function(el) {
    while (el.childNodes.length>0) { el.removeChild(el.firstChild); }
}

$addClass = function(node, className) {
    $removeClass(node, className);
    node.className += ' '+className;
}

$removeClass = function(node, className) {
    var classes = node.className.split(' ');
    for (var i=0; i<classes.length; i++) {
        if (classes[i] == className) {
            classes.splice(i, 1);
        }
    }
    node.className = classes.join(' ');
}

$style = function(node, args) {
    for (var arg in args) {
        if ((arg == 'left') || (arg == 'top') || (arg == 'width') || (arg == 'height') || (arg == 'right') || (arg == 'bottom')) args[arg] += 'px';
        node.style[arg] = args[arg];
    }
}

$point = function(x, y) { this.x = x; this.y = y; }
$position = function(node, toNode) {
    var el = node;
    var x = 0; var y = 0;
    while ((el)&&(el!=toNode)) {
        if (el.offsetLeft) { x += el.offsetLeft; }
        if (el.offsetTop) { y += el.offsetTop; }
        el = el.offsetParent;
    }
    return new $point(x, y);
}
$attachEvent = function(object, event, method, methodId) {
    if (!methodId) { methodId = ''; }
    object['event_'+event+methodId] = function(event) { method.apply(object, [event]); };
    if (typeof(object['addEventListener']) == 'function') { 
        object.addEventListener(event, object['event_'+event+methodId], false);
    } else {
        object.attachEvent('on'+event, object['event_'+event+methodId]);
    }
}

$detachEvent = function(object, event, methodId) {
    if (!methodId) { methodId = ''; }
    if (typeof(object['removeEventListener']) == 'function') {
        object.removeEventListener(event, object['event_'+event+methodId], false);
    } else {
        object.detachEvent('on'+event, object['event_'+event+methodId]);
    }
}
_GLOBAL = new Object();
JS = new Object();
// Browser checking
//TODO: write more if need
JS.agent = navigator.userAgent;
if (JS.agent.match(/MSIE\s+(\d+)/)) {
    JS.IE = true;
    JS.IE_Version = RegExp.$1;
    if (JS.IE_Version < 7) JS.IE_OLD = true;
}

JS.KHTML = JS.agent.match(/KHTML/);
JS.Opera = JS.agent.match(/Opera/);
JS.Gecko = (!JS.KHTML && JS.agent.match(/Gecko/));
JS.DOM = document.getElementById ? true : false;

/* array copy ----------- */
function $A(source) {
    var ret = [];
    ret = source.slice(0, source.length);
    return ret;
}

