﻿var imgWH = [[210, 300], [10008.5, 240], [105, 45], [200, 300], [80, 95], [635, 320], [270, 570], [500, 85]], MasterId = "ctl00_ContentPlaceHolder1_", _tooltipId = "Tooltip", _imgno = 0, _imgcount = 0, logoTimeOut, _EnlargeImage = { EnlargeTimeOut: Object, top: 0, left: 0 };
var createImag = function(othis, id, title, margin) {
    var img = new Image();
    img.onload = function() {
        resizeImg(this, id, margin);
        $(othis).parent().parent().append(img);
    };
    if (title != undefined && title != null) { $(img).attr("title", title); }
    img.src = $(othis).attr("src");
}
var resizeImg = function(othis, id, margin) {
    if (margin == undefined) margin = true;
    var vDefaultW = imgWH[id][0], vDefaultH = imgWH[id][1], vWProp = 1, vHProp = 1, vProp = 1, w = "", h = "";
    if (othis.readyState == "complete" || othis.readyState == "loaded" || othis.complete) {
        if (othis.width > vDefaultW || othis.height > vDefaultH) {
            vWProp = (othis.width - vDefaultW) / othis.width; vHProp = (othis.height - vDefaultH) / othis.height;
            if (vWProp < vHProp) {
                vProp = 1 - vHProp;
                w = (othis.width * vProp).toString() + "px"; h = vDefaultH.toString() + "px";
                $(othis).css({ "width": w, "height": h });
            }
            else { vProp = 1 - vWProp; h = othis.height * vProp; othis.width = vDefaultW; othis.height = h; if (margin) { $(othis).css("marginTop", ((vDefaultH - h) / 2).toString() + "px"); } }
        } else {
            if (margin) { $(othis).css("marginTop", ((vDefaultH - othis.height) / 2).toString() + "px"); }
        }
        if (id == 5) { $(othis).mouseover(function() { EnlargeImage(this); });/* $(othis).mouseout(function() { closeEnlargeImage(); });*/ }
    }
}
function isEmail(strEmail) {
    if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}
///Title Pop
function title__findPosX(obj) {var curleft = 0;if (obj.offsetParent) {while (obj.offsetParent) {curleft += obj.offsetLeft;obj = obj.offsetParent;}}else if (obj.x)curleft += obj.x;return curleft;}
function title_findPosY(obj) {var curtop = 0;if (obj.offsetParent) {while (obj.offsetParent) { curtop += obj.offsetTop; obj = obj.offsetParent; }}else if (obj.y) curtop += obj.y;return curtop;}
function title_show(parent, e) {var it = document.getElementById(_tooltipId), posX = 20, posY = 25;var img = parent;if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;if (posX < 0) posX = 0;var x = title__findPosX(img) + posX, y = title_findPosY(img) + posY; var x = e.pageX, y = e.pageY + posY;if (window.event) {x = e.clientX; y = e.clientY;};it.style.top = y + posY + 'px';it.style.left = x + 'px';it.style.display = '';}
function title_hide() {var it = document.getElementById(_tooltipId);$("#"+_tooltipId).hide();/*it.style.display = 'none';*/}
function title_move(parent, e) {var it = document.getElementById(_tooltipId), posX = 20, posY = 25;var img = parent;if (window.event) e = window.event;if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;if (posX < 0) posX = 0;var x = e.pageX, y = e.pageY + posY;if (window.event) {x = e.clientX; y = e.clientY + posY;};it.style.top = y + 'px'; it.style.left = x + 'px';}
$(document).ready(function() {
    $("#headermenu > ul >li").each(function() { var a = $(this).find("a")[0], count = $("#hdnviewcartcount").text(); var i = $(a).attr("href").indexOf("ShoppingCarts.aspx"); if (i >= 0 && count.length > 0) { var html = $(a).html(); $(a).html(html + count); } });
    $("#partner > ul").mouseover(function(event) { title_show(this, event); }).mousemove(function(event) { title_move(this, event); }).mouseout(function() { title_hide(); }); createPartnerLogoImage();
    if($("#partner").length>0){$("#partner").LogoImagesScroll({ line: 5, speed: 500, timer: 2000 }); $("#ctl00_TxtSearch").SmartJump({ url: "App_Ashx/GetSearch.ashx", type: "POST", width: "320px", controls: [{ name: "browser", id: "ctl00_Dr_Country"}] }, search);};
    $("#ctl00_btnSearch").click(function() { if ($("#ctl00_TxtSearch").val().length > 0) { return true; } else { return false; } });
});
function createPartnerLogoImage() { $("#partner > ul > li").each(function() { createImag($(this).find("div>img"), 7); }); }
function partner_logo() {_imgcount = $("#partner > img").length;if (_imgno > 0) { $("#partner > img").eq(_imgno - 1).css("display", "none"); }; resetsizeImg($("#partner > img").eq(_imgno), 7);$("#partner > img").eq(_imgno).css("display", "");_imgno++;if (_imgno > _imgcount) { _imgno = 0; };}
var resetsizeImg = function(othis, id, margin) {
    if (margin == undefined) margin = true;
    var vDefaultW = imgWH[id][0], vDefaultH = imgWH[id][1], vWProp = 1, vHProp = 1, vProp = 1, w = "", h = "", imgW = othis.width(), imgH = othis.height();
    if (imgW > vDefaultW || imgH > vDefaultH) {
        vWProp = (imgW - vDefaultW) / imgW; vHProp = (imgH - vDefaultH) / imgH;
        if (vWProp < vHProp) {
            vProp = 1 - vHProp;
            w = (imgW * vProp).toString() + "px"; h = vDefaultH.toString() + "px";
            $(othis).css({ "width": w, "height": h });
        }
        else { vProp = 1 - vWProp; h = imgH * vProp; $(othis).css("width", vDefaultW); $(othis).css("height", h); if (margin) { $(othis).css("marginTop", ((vDefaultH - h) / 2).toString() + "px"); } }
    } else {
        if (margin) { $(othis).css("marginTop", ((vDefaultH - imgH) / 2).toString() + "px"); }
    }
}
var createImages = function(othis, src, id, title, margin) {var img = new Image();img.onload = function() { resizeImg(this, id, margin); $(othis).append(img); }; if (title != undefined && title != null) { $(img).attr("title", title); };img.src = src;}
function search(othis) { var id = $($(othis).find("input").first()).val(), ids; ids = id.split("|"); $("#ctl00_TxtSearch").val($(othis).text()); window.location = "Categoryinfo.aspx?categoryid=" + ids[0] + "&categoryitem=" + ids[1] + "&itemid=" + ids[2] + "&country=" + $("#ctl00_Dr_Country").val(); return false; }
function EnlargeImage(othis, opt) {
    clearTimeout(_EnlargeImage.EnlargeTimeOut);
    if (opt == null || opt == undefined) { opt = {}; };
    var src = $(othis).attr("src"), w = 0, h = 0, top = 0, left = 0, imgid = "enlarge_image", img, offset = $(othis).offset(), _mh = 800, _rate=0; //if ($("#" + imgid).length>0) { $("#" + enlarge_image).remove(); }
    if ($("#" + imgid).length <= 0) {
        top = offset.top / 2; left = $(othis).width() + 20 + offset.left; _EnlargeImage.top = parseInt(offset.top + $(othis).height() / 2) + "px"; _EnlargeImage.left = parseInt(offset.left) + "px";
        img = document.createElement("img"); img.style.width = "0px"; img.style.height = "0px";
        /*img.setAttribute("id", imgid);img.style.position = "fixed"img.style.zIndex = "9999";*/img.style.width = "auto"; img.style.height = "auto"; img.src = src;img.style.marginTop = "10px";  /*img.style.top = _EnlargeImage.top; img.style.left = _EnlargeImage.left;*/
        var div = "<div id=\"" + imgid + "\" style=\"position:absolute;background-color:Transparent;z-index:99;width:auto;height:auto;top:" + _EnlargeImage.top + ";left:" + _EnlargeImage.left + "\"><div style=\"background-image:url('App_Images/Pages/Close_09152010.gif');cursor:pointer;width:20px;height:20px;display:none;position:absolute;z-index:2;left:0;top:0\" title=\"Close\">&nbsp;</div><iframe style=\"z-index:-1;position:absolute;top:0;margin-top:10px;left:0;width:95%;\" scrolling=\"no\" frameborder=\"0\" src=\"about:blank\"></iframe></div>";
        $(div).appendTo(document.body); $("#" + imgid).append(img); h = $("#" + imgid).height();w = $("#" + imgid).width(); $("#" + imgid).css({ width: 0, height: 0 });// $("#" + imgid).mouseout(function() { closeEnlargeImage(); }); $("#" + imgid).mouseover(function() { clearTimeout(_EnlargeImage.EnlargeTimeOut); });
        if (h > _mh) {
            _rate = _mh / h; h = _mh;w = w * _rate;
        }
        $("#" + imgid + ">div").click(function() { $("#" + imgid).remove(); }); $("#" + imgid).css({ opacity: "0.2" }); $("#" + imgid).animate({ width: w + 20, height: h - 20, top: top, left: left, opacity: "1" }, 1500, function() { $("#" + imgid + ">iframe").height($("#" + imgid).height()+10).width($("#" + imgid).width() - 20); $("#" + imgid + ">div").css({ "left": (($("#" + imgid).width()) - 30 + "px")}).show(); });
    }
}
function closeEnlargeImage() { _EnlargeImage.EnlargeTimeOut = setTimeout('removeEnlargeImage()', 1500); }
function removeEnlargeImage() { $("#enlarge_image").animate({ width: 0, height: 0, top: _EnlargeImage.top, left: _EnlargeImage.left,opacity:"0.2" }, 1500, function() { $("#enlarge_image").remove(); clearTimeout(_EnlargeImage.EnlargeTimeOut); }); };
