
var IE = document.all?true:false;

function addMMoLstr(id, listener) {
    if(IE) {
        document.getElementById(id).onmousemove = listener;
    } else {
        document.getElementById(id).addEventListener("mousemove", listener, true);
    }
}

function addMOuLstr(id, listener) {
    if(IE) {
        document.getElementById(id).onmouseout= listener;
    } else {
        document.getElementById(id).addEventListener("mouseout", listener, true);
    }
}

function showFullImage(e) {
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
        targ = targ.parentNode;

    var Re=/img(\d+)/;
    var matches = Re.exec(targ.id);
    var gid = matches[1];

    var fullimg=document.getElementById("fullimg" + gid);
    var dfi=document.getElementById("dfi" + gid);
    dfi.style.display = "block";

    tempX = getMouseX(e);
    tempY = getMouseY(e);

    if((fullimg.width + 18) > getViewportWidth()){
        tempX = getDeltaX() + 6;
    } else if( (tempX + fullimg.width + 18) > (getDeltaX() + getViewportWidth()) ){ //right
        tempX = getDeltaX() + getViewportWidth() - fullimg.width - 18;
    }
    if((fullimg.height + 18) > getViewportHeight()){
        tempY = getDeltaY() + 6;
    } else if( (tempY + fullimg.height + 18) > (getDeltaY() + getViewportHeight()) ){ //bottom
        tempY = getDeltaY() + getViewportHeight() - fullimg.height - 18;
    }
    tempX = tempX + 6;
    tempY = tempY + 6;

    if( (tempY + fullimg.height + 18) > (getDeltaY() + getViewportHeight()) &&  (tempX + fullimg.width + 18) > (getDeltaX() + getViewportWidth()) ) { //bottom right corner
        tempX = getMouseX(e) - fullimg.width - 12;
    }

    dfi.style.top = tempY + "px";
    dfi.style.left = tempX + "px";
}

function getMouseX(e)
{
    return e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft))
}

function getMouseY(e)
{
    return e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
}

function getViewportWidth()
{
    return window.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);
}

function getViewportHeight()
{
    return window.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
}

function getDeltaY()
{
    return window.pageYOffset
                || document.documentElement.scrollTop
                || document.body.scrollTop
                || 0;
}

function getDeltaX()
{
    return window.pageXOffset
                || document.documentElement.scrollLeft
                || document.body.scrollLeft
                || 0;
}

function hideFullImage(e) {
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
        targ = targ.parentNode;

    var Re=/img(\d+)/;
    var matches = Re.exec(targ.id);
    var gid = matches[1];

    var dfi=document.getElementById("dfi" + gid);
    dfi.style.display = "none";
}


/* Gift rotation functions */
var Gifts = [];

function rotateGifts(id, list)
{
    var pattern = /,/;
    var arr = list.split(pattern);
    var iid;
    if(arr.length > 1){
        iid = window.setInterval("rotateGift('" + id + "')", 5000);
    } else {
        iid = 0;
    }
    Gifts[id] = [0, arr, iid];
}

function rotateGift(id, keep_current)
{
    var img_id = Gifts[id][0];
    var arr = Gifts[id][1];
    if(arr.length > 1){
        if(!keep_current) img_id = (arr.length > img_id + 1) ? img_id + 1 : 0;
        img = document.getElementById(id).src = "/gift/?t=t3&id=" + arr[img_id];
        fixPng(id);
        Gifts[id][0] = img_id;
    }
}

function stopRotateGifts()
{
    var images = getGiftImages();
    var iid;
    for(var i in images){
        iid = Gifts[images[i].id][2];
        if(iid) window.clearInterval(iid);
    }
}

function startRotateGifts()
{
    var images = getGiftImages();
    for(var i in images){
        gift_ids = images[i].title;
        images[i].title = images[i].alt;
        fixPng(images[i].id);
        rotateGifts(images[i].id, gift_ids);
    }
}

function getGiftImages()
{
    var result = [];
    var j=0;
    for(var i=0; i<document.images.length; i++)
    {
        var img = document.images[i];
        var img_id = img.id;
        var re = /^pvg\d+$/;
        if (img_id.match(re))
        {
            result[j++] = img;
        }
    }
    return result;
}

/* End Gift rotation functions */


/* Png fix */

var arVersion = navigator.appVersion.split("MSIE");
var navigatorVersion = parseFloat(arVersion[1]);

function fixPng(id){
    if ((navigatorVersion >= 5.5) && (navigatorVersion < 7.0) && (document.body.filters))
    {
        img = document.getElementById(id);
        var imgID = (img.id) ? "id='" + img.id + "' " : "";
        var imgClass = (img.className) ? "class='" + img.className + "' " : "";
        var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
        var imgStyle = "display:inline-block;" + img.style.cssText;
        if (img.align == "left") imgStyle = "float:left;" + imgStyle;
        if (img.align == "right") imgStyle = "float:right;" + imgStyle;
        if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
        var strNewHTML = "<span " + imgID + imgClass + imgTitle
        + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
        + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
        + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
        img.outerHTML = strNewHTML;
    }
}

function fixGiftsPng(){
    if ((navigatorVersion >= 5.5) && (navigatorVersion < 7.0) && (document.body.filters))
    {
       for(var i=0; i<document.images.length; i++)
       {
          var img = document.images[i];
          var imgName = img.src;
          var re = /\/gift\//;
          if (imgName.match(re))
          {
             var imgID = (img.id) ? "id='" + img.id + "' " : "";
             var imgClass = (img.className) ? "class='" + img.className + "' " : "";
             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
             var imgStyle = "display:inline-block;" + img.style.cssText;
             if (img.align == "left") imgStyle = "float:left;" + imgStyle;
             if (img.align == "right") imgStyle = "float:right;" + imgStyle;
             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
             var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
             img.outerHTML = strNewHTML;
             i = i-1;
          }
       }
    }
}

addOnLoadListener(fixGiftsPng);

/* End Png fix */
