var Event = YAHOO.util.Event;
var _fp_imagewidth = 75
var _fp_rows = 5

var $ = function(id) {
    if (!id)
        return null;
    if (typeof id == 'string')
        return document.getElementById(id);
    else
        return id;
}

var reload = function() {
     get("/ui/pages/front-page-images.xqy?count=" + getCount(),
        function ok(e) {
            $('image-panel').innerHTML = e.responseText;
        })
}


var loaded = function(img) {
    /*var oh = img.naturalHeight;
    var ow = img.naturalWidth;
    var k = oh / ow;*/
    img.style.display = "inline"
    if (img.naturalWidth) {
        img.style.width = img.naturalWidth / 2 + "px";
        img.style.height = img.naturalHeight / 2 + "px";
    } else
    {        
        img.style.width = img.width / 2 + "px";
        //img.style.height = img.height / 2 + "px";
    }
    img.style.display = "inline"
}

function attachResizeEvent() {
    Event.addListener(window, "resize", reload)
}

function getCount() {
    var w = $('image-panel').offsetWidth;
    /*$("debug").innerHTML = w*/
    /*return Math.floor((w-26) / (_fp_imagewidth + 5)) * _fp_rows;*/
    return 16*5
}

function get(url, succ, fail) {
    YAHOO.util.Connect.asyncRequest("get", url, {
            success:succ,
            failure:fail
        })
}

var transparency = function(element) {
    var transpPct = 80;
    var element = $(element);
    try {
        element.style['opacity'] = (transpPct / 100);
        element.transpPct = transpPct;
    } catch(e) {
    }
    try {
        element.style['-moz-opacity'] = (transpPct / 100);
        element.transpPct = transpPct;
    } catch(e) {

    }
    try {
        element.style['filter'] = "alpha( opacity = " + transpPct + " )";
        element.transpPct = transpPct;
    } catch(e) {

    }
}

function toggle(id) {
    var el = $(id)
    if (el) {
        el.style.visibility = (el.style.visibility == "hidden" || el.style.visibility == "") ? "visible" : "hidden"
    }
}

