spsupport = {};
spsupport.p = { // params
    sfDomain :  superfish.b.pluginDomain,
    cdnUrl : superfish.b.cdnUrl,
    appVersion : superfish.b.appVersion,
    clientVersion : superfish.b.clientVersion,
    site :  superfish.b.pluginDomain,
    isIEQ : ( +document.documentMode == 5 ? 1 : 0 ),
    sfIcon : {
        maxSmImg : {
            w : 88,
            h : 70
        },
        icons : [0, 0, 0, 0],
        big : {
            w : 64,
            h : 48
        },
        small : {
            w : 42,
            h : 38
        },
        iconsAnim : 0,        
        prog : {
            time : 1000,
            node : 0,
            color : "#398AFD",
            opac  : "0.3",
            w : [ 62, 40 ],
            h : 13
        }
    },

    onFocus : -1,
    psuHdrHeight : 22,
    psuRestHeight : 26,
    oopsTimer : 3*1000,
    oopsTm : 0,
    iconTm : 0,
    dlsource : superfish.b.dlsource,
    w3iAFS : superfish.b.w3iAFS,
    CD_CTID: superfish.b.CD_CTID,
    userid: superfish.b.userid,
    statsReporter: superfish.b.statsReporter,
    minImageArea : ( 60 * 60 ),
    aspectRatio : ( 1.0/2.0 ),
    supportedSite : 0,
    frameLoaded : 0,
    frameResponse : 0,
    frameResponseDisplayed : 0,
    frameExLoading: 0,
    overIcon: 0,
    alreadySent : 0,
    //    iconsReplace: 0, // ? not in use
    icons: 0,
    partner : ( superfish.b.partnerCustomUI ? superfish.b.images + "/" : "" ),

    // Result state - identical (first), similar (second)
    //rState: [ 0, 0 ],
    prodPage: {
        s: 0,   // sent - first request
        i: 0,   // images count
        p: 0,   // product image
        e: 0,   // end of session slideup session
        d: 210, // dimension of image
        l: 1000 // line - in px from top
    },
    before : -1  // Close before
};
spsupport.api = {
    log : function( msg ){
        if( typeof(console)!="undefined"){
            console.log( msg );
        }
    },

    getDomain: function(){
        var dD = document.location.host;
        var dP = dD.split(".");
        var len = dP.length;
        if ( len > 2 ){
            var co = ( dP[ len - 2 ] == "co" ? 1 : 0 );
            dD = ( co ? dP[ len - 3 ] + "." : "" ) + dP[ len - 2 ] + "." + dP[ len - 1 ];
        }
        return dD;
    },
    validDomain: function(){
        try{
            var d = document;
            if( d == null || d.domain == null ||
                d == undefined || d.domain == undefined || d.domain == ""
                || d.location == "about:blank" || d.location == "about:Tabs"
                || d.location.toString().indexOf( "superfish.com/congratulation.jsp" ) > -1  ){
                return false;
            }else{
                return (/^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,5}$/).test( document.domain );
            }
        }catch(e){
            return false;
        }
    },

    init: function(){
        var spp = spsupport.p;
        if( window.sufio )
            return; 

        if( !spsupport.api.validDomain() )
            return;

        //  if(spp.clientVersion == null)
        if( !spp.clientVersion )
            spp.clientVersion  = "unknown";

        spsupport.api.dojoReady = false;

        if ( ! top.djConfig ){
            djConfig = {}
        }
        djConfig.afterOnLoad = true;
        // djConfig.baseUrl = spp.cdnUrl;
        djConfig.baseScriptUri = spp.cdnUrl;
        djConfig.useXDomain = true;
        djConfig.scopeMap = [ ["dojo", "sufio"], ["dijit", "sufiw"], ["dojox", "sufix"] ];
        djConfig.require = ["dojo.io.script" ,"dojo._base.html", "dojo.window"];
        djConfig.modulePaths =  {
            "dojo": spp.cdnUrl + "dojo",
            "dijit": spp.cdnUrl + "dijit",
            "dojox": spp.cdnUrl + "dojox"
        };

        superfish.b.inj(  spp.cdnUrl + "dojo/dojo.xd.js",
            1,1,
            function(){
                sufio.addOnLoad(function(){
                    spsupport.api.dojoLoaded();
                });
            });

    },
    gotMessage: function( param, from ){
        if(from && from.indexOf("superfish.com") == -1 ){
            return;
        }
               
        if ( param ){
            var prep = param.split( "|" );
        }
 
        var fromPsu = ( prep.length > 1 );
        if ( fromPsu ) {
            if (spsupport.p.prodPage.e ) {
                return;
            }
        }
       
        param = ( +prep[ 0 ] );
       
        if( param == 101 ){ // sys down
            superfish.util.sysDown();
        }
        else{
            if( param == -7890 ){ // init
                spsupport.p.frameLoaded = 1;
                if( superfish.util && superfish.util.standByData != 0 ){
                    superfish.util.sendRequest( superfish.util.standByData );
                //superfish.util.standByData = 0;
                }
            }
            else if( param >= 200 ){
                // 20 -  ( slideup paused )
                // 200 - ( idrentical only - false, failure )
                // 201 - ( idrentical only - false, identical is empty, similar not empty )
                // 210 - ( idrentical only - false, identical is not empty, similar is empty )
                // 211 - ( idrentical only - false, identical is not empty, similar is not empty )
 
                superfish.util.hideFishPreload();
                spsupport.p.before = 0;
                
                if( !fromPsu && param == 200 ){
                    if (superfish.p.onAir != 2) {
                        if (superfish.util.currImg) {
                            superfish.util.currImg.setAttribute("sfnoicon", "1");
                        }
                        var actIcon = sufio.byId(superfish.util.activeIconId);
                        spsupport.p.iconTm = setTimeout(function() {
                            if (actIcon) {
                                sufio.fadeOut({
                                    node: actIcon,
                                    duration: 600,
                                    onEnd: function() {
                                        actIcon.style.display = "none";
                                    }
                                }).play(10);
                            }
                        }, 300 );

                        spsupport.p.oopsTm = setTimeout(function() {                            
                            if(!sufio.isIE){
                                sufio.fadeOut({
                                    node: superfish.util.bubble(),
                                    duration: 800,
                                    onEnd: function() {
                                        superfish.util.closePopup( 1 );
                                    }
                                }).play(10);
                            }
                            else {
                                superfish.util.closePopup( 1 );
                            }
                        }, spsupport.p.oopsTimer );
                    }
                }

                if( param > 200 ){
                    if( superfish.b.suEnabled == 11 && fromPsu){
                        if( spsupport.p.prodPage.s && !spsupport.p.prodPage.e && superfish.p.onAir == 2){
                            if( prep[ 1 ] && prep[ 2 ] && prep[ 3 ] && prep[ 4 ]){
                                var item = {
                                    title : prep[ 1 ],
                                    imagePath : decodeURIComponent(prep[ 2 ]),
                                    price : prep[ 3 ],
                                    merchantName : prep[ 4 ],
                                    merchantUrl : prep[ 5 ]
                                };
                                superfish.b.initPSU( item );
                            }
                        }
                    }
                    spsupport.p.prodPage.e = 1;
                    spsupport.p.prodPage.s = 0;
                }
                else{
                    if( param > 0 && !spsupport.p.prodPage.e &&  spsupport.p.prodPage.s ) {
                        superfish.util.bCloseEvent( document.getElementById("SF_CloseButton"), 2 );
                        spsupport.p.prodPage.e = 1;
                        spsupport.p.prodPage.s = 0;
                    }
                }
            }
            else if( param == 10 ){
                superfish.util.bCloseEvent( document.getElementById("SF_CloseButton"), 4);
                if (superfish.b && superfish.b.closePSU) {
                    superfish.b.closePSU (document.getElementById("SF_SLIDE_UP_CLOSE"), 5);
                }

            }
            else if( param == 11 ){
                superfish.util.bCloseEvent( document.getElementById("SF_CloseButton"), 5);
                if (superfish.b && superfish.b.closePSU) {
                    superfish.b.closePSU (document.getElementById("SF_SLIDE_UP_CLOSE"), 0);
                }
            }
            else if( param == 20 ){
                superfish.util.closePopup( 1 );
            }

        }
    },

    dojoLoaded: function()  {
        spsupport.api.dojoReady = true;
        spsupport.api.userIdInit();
        if( window.sufio && window.sufio.isIE && window.spMsiSupport ){
            if( !this.isOlderVersion( '1.2.1.0', spsupport.p.clientVersion ) ){
                spMsiSupport.validateUpdate();
            }
            if(window.sufio.isIE == 7) {
                spsupport.p.isIEQ = 1;
            }
        }

        setTimeout( function(){
            setTimeout("spsupport.sites.care()", 200);
        }, 200 );

    },

    userIdInit: function(){
        var spp = spsupport.p;
        var data = {
            "dlsource":spp.dlsource
        }
        if(spp.w3iAFS != ""){
            data.w3iAFS = spp.w3iAFS;
        }

        if( spp.CD_CTID != "" ){
            data.CD_CTID = spp.CD_CTID;
        }

        if(spp.userid != "" && spp.userid != undefined){
            spsupport.api.onUserInitOK({
                userId: spp.userid,
                statsReporter: spp.statsReporter
            });
        } else { // widget
            spsupport.common.jsonpRequest(
                spp.sfDomain + "initUserJsonp.action",
                data,
                spsupport.api.onUserInitOK,
                spsupport.api.onUserInitFail,
                "superfishInitUserCallbackfunc"
                );
        }
    },

    onUserInitOK: function(obj) {
        if(!obj || !obj.userId || (obj.userId == "")){
            spsupport.api.onUserInitFail();
        } else{
            spsupport.p.userid = obj.userId;
            spsupport.p.statsReporter = obj.statsReporter;
            spsupport.api.isURISupported( document.location );
        }
    },


    ASU_OK : function( obj ){
        if( !obj ){
            spsupport.api.AS_Fail();
        }
        else{ }
    },
    ASU_Fail : function(){},



    isURISupported: function(url){
        spsupport.p.merchantName = "";
        spsupport.common.jsonpRequest(
            spsupport.p.sfDomain + "getSupportedSitesJSON.action?ver=" + superfish.b.wlVersion,
            0,
            spsupport.api.isURISupportedCB,
            spsupport.api.isURISupportedFail,
            "SF_isURISupported");
    },

    isURISupportedCB: function(obj) {
        spsupport.p.totalItemCount = obj.totalItemCount;
        var sS = obj.supportedSitesMap[ spsupport.api.getDomain() ];

        if( sS ) {
            spsupport.p.supportedSite = 1;
        }
        else if( superfish.b.ignoreWL ){
            if ( superfish.publisher ) {
                superfish.publisher.init();
            }
            if( superfish.b.injectCheckBgScript ) {
                superfish.b.injectCheckBgScript();
            }
            
            sS = {};
            sS.imageURLPrefixes = "";
            sS.merchantName = spsupport.api.getDomain();
        }

        if( sS && !spsupport.api.isBLSite( obj ) ){
            spsupport.api.injectIcons( sS );
        }

        if( !spsupport.p.icons ){
            setTimeout(spsupport.api.saveStatistics, 400);
        }

    },

    isURISupportedFail: function(obj) {
    },

    isBLSite: function(obj){
        var isBL = 0;
        if ( obj.blockedSubDomains ){
            for (var s = 0 ; s < obj.blockedSubDomains.length && !isBL ; s++ ){
                var loc = top.location + "";
                if (loc.indexOf(obj.blockedSubDomains[s]) >= 0){
                    isBL = 1;
                }
            }
        }
        return isBL;
    },
    injectIcons: function( sS ) {
        //        spsupport.p.supportedSite = 1;
        spsupport.p.supportedImageURLs = sS.imageURLPrefixes;
        spsupport.p.merchantName = sS.merchantName;
        spsupport.sites.preInject();
        spsupport.api.careIcons( 0 );
    },
    addSuperfishSupport: function(){
        superfish_xd_messanger.init(
            spsupport.api.gotMessage,
            ( sufio.isIE == 7 || (+document.documentMode) == 7 ? 200 : 0 ) );

        if( !top.superfishMng ){
            top.superfishMng = {};
        }
        if( !top.superfish ){
            top.superfish = {};
        }

        if( !top.superfish.p ){ // params
            top.superfish.p = {
                site : spsupport.p.site,
                totalItemsCount: spsupport.p.totalItemCount,
                cdnUrl : spsupport.p.cdnUrl,
                appVersion : spsupport.p.appVersion
            };
        }

        if( !top.superfish.util ){
            superfish.b.inj( "js/sf.js?version=" + spsupport.p.appVersion, 1,0 );
        }

        if( !spsupport.api.pluginDiv() ) {
            sufio.place("<div id='superfishPlugin'></div>", sufio.body());
        }
        sufio.place("<div id='sfiframesync'></div>", sufio.body());
    },
    
    careIcons: function( rep ){
        spsupport.p.icons = this.startDOMEnumeration();
        if( spsupport.p.icons > 0 || spsupport.sites.ph2bi() ){
            superfish.b.inj(
                "js/postMessage" +
                ( ( +sufio.isIE == 7 ) || ( +document.documentMode == 7 ) ? "_IE7" : "" ) + ".js?ver=" + spsupport.p.appVersion,
                1, 0,
                function(){
                    spsupport.api.addSuperfishSupport();
                });
                
            spsupport.domHelper.addOnresizeEvent(function() {
                spsupport.api.setPopupInCorner();
                spsupport.api.startDOMEnumeration();
            });
            
            if (superfish.b.suEnabled == 11) {
                spsupport.domHelper.addMouseMoveEvent(function() {
                    if (spsupport.p.onFocus == -1) {
                        spsupport.p.onFocus = 1;
                        if (superfish.b.setTimer) {
                            superfish.b.setTimer();
                        }
                    }
                });
            }
            
            spsupport.domHelper.addFocusEvent(function() {
                spsupport.p.onFocus = 1;
                if (superfish.b.setTimer) {
                    superfish.b.setTimer();
                }
                spsupport.api.startDOMEnumeration();
            });
            
            spsupport.domHelper.addBlurEvent(function() {
                spsupport.p.onFocus = 0;
                if (superfish.b.tm) {
                    clearTimeout(superfish.b.tm);
                }
            });

            spsupport.domHelper.addUnloadEvent(spsupport.api.unloadEvent);
            //spsupport.domHelper.addEListener( sufio.byId("ires"), spsupport.api.onDOMSubtreeModified, "DOMSubtreeModified");
            spsupport.api.vMEvent();

            sufio.addOnLoad(function(){
                setTimeout( function(){
                    spsupport.api.wRefresh( 150 );
                    setTimeout("spsupport.api.saveStatistics()", 850)
                }, 500 );
            });
        }else{
            if( rep == 7 ){
                spsupport.api.saveStatistics();
            }else{
                setTimeout( "spsupport.api.careIcons( " + ( ++rep ) + ");", ( 1300 + rep * 400 ) ) ;
            }
        }
    },

    vMEvent : function(){
        var pDiv = spsupport.api.pluginDiv();
        if( pDiv ){
            spsupport.domHelper.addEListener( pDiv, spsupport.api.blockDOMSubtreeModified, "DOMSubtreeModified");
        }else{
            setTimeout( "spsupport.api.vMEvent()", 500 );
        }

    },

    puPSearch : function(){
        var sp = spsupport.p;
        if( superfish.b.suEnabled ){
            if( !sp.prodPage.s || ( superfish.p && superfish.p.onAir == 1 ) ){
                setTimeout(
                    function(){
                        try{
                            if( !sp.prodPage.s && !sp.prodPage.e){
                                var o = spsupport.api.getItemJSON( sp.prodPage.p );
                                superfish.util.prepareData(o, 1);
                                superfish.util.openPopup(o, sp.appVersion, 1 );
                                sp.prodPage.s = 1;
                            }
                        }catch(e){
                            setTimeout(spsupport.api.puPSearch, 50);
                        }
                    }, 50 );
            }
        }
    },
    
    isSuperfishReady : function(){
        try{
            return( +document.getElementById("sfiframesync").getAttribute("codeReady") );
        }catch(ex){ }
        return 0;
    },
    onDOMSubtreeModified: function( e ){
        spsupport.api.killIcons()
        if(spsupport.api.DOMSubtreeTimer){
            clearTimeout(spsupport.api.DOMSubtreeTimer);
        }
        spsupport.api.DOMSubtreeTimer = setTimeout("spsupport.api.onDOMSubtreeModifiedTimeout()",1400);
    },
    onDOMSubtreeModifiedTimeout: function(){
        clearTimeout(spsupport.api.DOMSubtreeTimer);
        spsupport.api.startDOMEnumeration();
    //      spsupport.sites.revalidate();
    },
    blockDOMSubtreeModified: function(e,elName){
        e.stopPropagation();
    },
    createImg : function(src) {
        var img = new Image();
        img.src = src;
        return img;
    },
    loadIcons : function() {
        var sps = spsupport.p;
        var cust = ( sps.dlsource == "similarweb" || sps.dlsource == "ddfinder" ? sps.dlsource + "/" : "" );
        for (var i = 0; i < 4; i++) {
            sps.sfIcon.icons[ i ] = spsupport.api.createImg( sps.sfDomain + "images/" + cust + "i" + i + ".png?v=" + sps.appVersion);
        }
    },

    killIcons : function() {
        var bs = spsupport.api.sfButtons();
        if( bs ){
            document.body.removeChild( bs );
            try{
                if( superfish && superfish.util ){
                    superfish.util.activeIconId = "";
                }
            }catch(ex){}
        }
    },

    startDOMEnumeration: function( iA ){
        spsupport.api.killIcons();

        var imSpan = sufio.place("<span id='sfButtons' display='none'></span>", sufio.body());
        var images = ( iA ? iA : document.images );
        var isImgSupported = 0;
        var found = 0;

        for( var i = 0; i < images.length; i++ ){
            isImgSupported = spsupport.api.isImageSupported( images[ i ] );
            if(isImgSupported){
                if (!found) {
                    spsupport.api.loadIcons();
                    spsupport.api.addSFProgressBar( imSpan );
                }

                spsupport.api.addSFImage( imSpan, images[ i ], spsupport.api.sfIPath(isImgSupported ), isImgSupported, i );
                found++;
            }
        }

        if( found > 0 ){
            //spsupport.api.addSFProgressBar( imSpan );
            sufio.style( "sfButtons","opacity","0");
            sufio.fadeIn({
                node: imSpan,
                duration: 300
            }).play();

            setTimeout(
                function(){
                    if( ! spsupport.p.alreadySent ){
                        spsupport.api.saveStatistics();
                        spsupport.p.alreadySent = 1;
                    }
                }, 700);
        }
        return found;
    },

    imageSupported: function( src ){
        if( src.indexOf( "amazon.com" ) > -1  && src.indexOf( "videos" ) > -1 ){
            return 0;
        }
   
        try{
            var sIS = spsupport.p.supportedImageURLs;

            if( sIS.length == 0 )
                return 1;
            for( var i = 0; i < sIS.length; i++ ){
                if( src.indexOf( sIS[ i ] ) > -1 ){
                    return 1;
                }
            }
        }catch(ex){
            return 0;
        }
        return 0;
    },

    isImageSupported: function(img){
        var src = "";
        try{
            src = img.src.toLowerCase();
        }catch(e){
            return 0;
        }

        var iHS = src.indexOf("?");
        if( iHS ){
            src = src.substring( 0, src.length - iHS );
        }

        var sps = spsupport.p;

        for( var z = 0; z < 4; z ++ ){
            if( src.substring( sps.sfIcon.icons[ z ] ) > -1 ){
                return 0;
            }
        }

        if( src.length < 4 )
            return 0;

        var ext = src.substring(src.length - 4,src.length);
        if((ext == ".gif") || (ext == ".png")) {
            return 0;
        }

        var iW = img.width;
        var iH = img.height;

        if( ( iW * iH ) < sps.minImageArea ) {
            return 0;
        }
        var ratio = iW/iH;
        if( ( iW * iH > 2 * sps.minImageArea ) &&
            ( ratio < sps.aspectRatio || ratio > ( 1 / sps.aspectRatio ) ) ) {
            return 0;
        }

        if( !this.imageSupported( img.src ) ) {
            return 0;
        }

        if( !spsupport.api.isVisible( img ) ){
            return 0;
        }
        
        if( !spsupport.p.supportedSite) {
            //            if ( sufio.isIE ) {
            if (! sufio.isFF ) {
                return 0;
            }
            else if ( superfish.b.imgAPI ) {
                var isWhite = superfish.b.imgAPI.isSupported( img );
                if (! isWhite) {
                    return 0;
                }
            }
        }
        
        if( spsupport.sites.imgSupported( img ) ){
            if(( iW <= sps.sfIcon.maxSmImg.w ) || ( iH <= sps.sfIcon.maxSmImg.h ) ) {
                return 2;
            }
            else {
                return 1;
            }
        }else{
            return 0;
        }
    },

    setPopupInCorner : function () {
        if( superfish && superfish.p && superfish.p.onAir == 2 && spsupport.p.before == 0 ){
            var vp = sufio.window.getBox();
            var sl = superfish.util.bubble().style;
            if( superfish.b.suEnabled != 11 || (superfish.b.suEnabled == 11 && superfish.b.slideUpOn ) ){
                var slL = (vp.w - superfish.p.width - 4);
                var slT = (vp.h - superfish.p.height - 4);
                if( spsupport.p.isIEQ ){
                    slL = slL + vp.l;
                    slT = slT + vp.t;
                } 
                sl.left = slL + "px";
                sl.top = slT + "px";
            }
            var pSU = superfish.util.preslideup();
            if( pSU ){
                slL = vp.w - parseInt( pSU.style.width ) - 111;
                slT = vp.h - parseInt( pSU.style.height );
                if (spsupport.p.isIEQ) {
                    slL = slL + vp.l;
                    slT = slT + vp.t;
                }
                pSU.style.left = slL + "px";
                if (superfish.b.slideUpOn) {
                    pSU.style.top = ( parseInt( sl.top ) - spsupport.p.psuHdrHeight ) + "px";
                }
                else {
                    pSU.style.top = (superfish.b.preSlideUpOn == 2 ? slT : (slT + parseInt( pSU.style.height ) - spsupport.p.psuRestHeight))  + "px";
                }
            }
        }
    },

    fixPosForIEQ : function( e ) {
        spsupport.api.setPopupInCorner();
        var oS = superfish.util.overlay().style;
        oS.left = document.body.scrollLeft;
        oS.top = document.body.scrollTop;
    },


    wRefresh : function( del, im ){ // Widget Refresh
        sufio.fadeOut({
            node: spsupport.api.sfButtons(),
            duration: del ,
            onEnd: function() {
                setTimeout( function() {
                    spsupport.api.startDOMEnumeration( im );
                }, del * 2 );
            }
        }).play();
    },


    isViewable: function ( vP, obj ){
        return (   vP.scrollLeft < ( obj.offsetLeft  + obj.offsetWidth ) &&
            ( obj.offsetLeft + obj.offsetWidth - vP.scrollLeft < vP.offsetWidth )  );
    },

    isVisible: function( obj ){
        if( obj == document ) return 1;
        if( !obj ) return 0;
        if( !obj.parentNode ) return 0;

        if( obj.style ){
            if( obj.style.display == 'none' ||
                obj.style.visibility == 'hidden' ){
                return 0;
            }
        }

        if( window.getComputedStyle ){
            var style = window.getComputedStyle(obj, "");
            if( style.display == 'none' ||
                style.visibility == 'hidden'){
                return 0;
            }
        }
        // Computed style using IE's silly proprietary way
        var cS = obj.currentStyle;
        if( cS ){
            if( cS['display'] == 'none' ||
                cS['visibility'] == 'hidden'){
                return 0;
            }
        }
        return spsupport.api.isVisible( obj.parentNode );
    },

    sfIPath: function( iType ){ // 1 - large, 2 - small
        var sps = spsupport.p;
        var icn = ( iType == 2  ?  2  :  0 );
        return( {
            r : sps.sfIcon.icons[ icn ].src,
            o : sps.sfIcon.icons[ icn + 1 ].src
        } );
    },

    addSFImage: function( parent, img, icPath, iType,  imID ){
        var noRes = img.getAttribute('sfnoicon');

        if (noRes != '1') {
            var nI = document.createElement("img");
            nI.id = "sf_icon_" + imID;
            nI.title = " See Similar ";
            nI.pW = spsupport.p.sfIcon.prog.w[ iType - 1 ];
            var sps = spsupport.p;
            var iProp = ( iType == 2  ?  sps.sfIcon.small  :  sps.sfIcon.big );
            var hWidth = parseInt(spsupport.p.sfIcon.prog.w[ iType - 1 ]/3.2);            
            var itemJson = 0;
            
            var anim = sufio.animateProperty({
                node: spsupport.p.sfIcon.prog.node,
                duration: spsupport.p.sfIcon.prog.time,
                properties: {
                    width: {
                        start: "0",
                        end:  spsupport.p.sfIcon.prog.w[ iType - 1 ],
                        unit: "px"
                    }
                },
                onEnd : function() {
                    if( nI == spsupport.p.overIcon ){
                        goSend(3);
                    }
                }
            });
            
            var goSend = function(ev) {
                var sfu = superfish.util;
                itemJson = itemJson ? itemJson : spsupport.api.getItemJSON( img );
                if(sfu) {
                    if (ev == 1 || ev == 2) {                         
                        if (sfu.activeIconId != nI.id) {
                            sfu.activeIconId = nI.id;
                            sfu.currImg = img;
                            sfu.prepareData(itemJson, 0);
                            clearTimeout(spsupport.p.iconTm);
                            clearTimeout(spsupport.p.oopsTm);
                            spsupport.p.prodPage.e = 1;
                        }
                    }
                    if (ev == 1 || ev == 3) {
                        //                        if (sfu.activeIconId == nI.id) {
                        spsupport.p.overIcon = 0;
                        nI.src = icPath.r;
                        resetPBar();
                        sfu.openPopup(itemJson, spsupport.p.appVersion, 0);
                    //                        }
                    }
                }
                else {
                    setTimeout (function(){
                        goSend(ev);
                    }, 400);                   
                }
            };
            
            var handle = sufio.connect( anim,'onAnimate', function( curveValue ){
                if ( parseInt(curveValue.width) >= hWidth) {
                    if( nI == spsupport.p.overIcon ){
                        goSend(2);
                    //sufio.disconnect(handle);
                    }
                }
            });
                       
            var resetPBar = function() {
                var pBar = spsupport.p.sfIcon.prog.node;
                if( pBar ){
                    anim.stop();
                    sufio.style(
                        pBar ,{
                            width : "0px",
                            display : "none"
                        });
                }
            };

            sps.sfIcon.prog.node.onmousedown = function(e){                
                spsupport.p.overIcon.onmousedown();
            };

            sps.sfIcon.prog.node.onmouseout = function(e){
                if (!e) {
                    var e = window.event;
                }
                var relTarget = ( e.relatedTarget ? e.relatedTarget : e.toElement );
                if( !relTarget || !relTarget.id || ( relTarget.id && ( relTarget.id != spsupport.p.overIcon.id ) ) ){
                    if( spsupport.p.overIcon ){
                        spsupport.p.overIcon.onmouseout( e );
                    }
                }
            };


            nI.onmouseout = function(e){
                if (!e) {
                    var e = window.event;
                }
                var relTarget = ( (e.relatedTarget) ? e.relatedTarget : e.toElement );
                if( relTarget != spsupport.p.sfIcon.prog.node ){
                    this.src = icPath.r;
                    spsupport.p.overIcon = 0;
                    resetPBar();
                    if (spsupport.p.before == 2) {
                        superfish.util.reportClose();
                    }
                }
            };

            nI.onmouseover  = function(e){
                if( !window.superfish || !window.superfish.p || window.superfish.p.onAir != 1 ){
                    if (!e) {
                        var e = window.event;
                    }
                    var relTarget = ( (e.relatedTarget) ? e.relatedTarget : e.fromElement );
                    if ( relTarget != spsupport.p.sfIcon.prog.node) {
                        this.src = icPath.o;
                        spsupport.p.overIcon = this;
                        if (spsupport.p.sfIcon.prog.node ) {
                            var dif = iProp.h - spsupport.p.sfIcon.prog.h;
                            sufio.style(
                                spsupport.p.sfIcon.prog.node, {
                                    display : "block",
                                    top : parseInt( nI.style.top ) + dif - 2 + "px",
                                    left : parseInt( nI.style.left ) + 2 + "px"
                                });
                            anim.play();
                        }
                    }
                }
            };

            nI.onmousedown = function(e){                
                var evt = e || window.event;
                try{
                    if( evt.button == 2 )
                        return;
                }catch(ex){}
                //                spsupport.p.overIcon = 0;
                //                this.src = icPath.r;
                //                resetPBar();
                //                try{
                goSend(1);
            //                        superfish.util.openPopup((itemJson ? itemJson : spsupport.api.getItemJSON(img)), spsupport.p.appVersion, 0 );
            //                }catch(ex){
            //                    setTimeout(
            //                        ( function( ic, ev ){
            //                            return function(){
            //                                ic.onmousedown( ev );
            //                            }
            //                        } )( this, evt ), 300 );
            //                }
            };

            nI.src = icPath.r;
            nI.style.position = "absolute";
            var zindex = img.style.zIndex;
            if((zindex == "auto") || (zindex == "0") || (zindex == "") ){
                zindex = "3";
            }
            nI.style.zIndex = ( +zindex ) + 12002;
            var imgPos = spsupport.api.getImagePosition(img);
            nI.style.top = "" + parseInt( imgPos.y + img.height - iProp.h + 3 ) + "px";
            nI.style.left = "" + parseInt( imgPos.x - 2 ) + "px";
            nI.style.cursor = "pointer";
            // BUG IN IE
            //nI.style.display = 'block';
            nI.style.width = "" + iProp.w + "px";
            nI.style.height = "" + iProp.h + "px";
            // ^^^
            parent.appendChild( nI );
            spsupport.api.validateSU( img, nI.style.top );
        }
    },

    validateSU: function( im, iT ){
        var sp = spsupport.p;
        if( !sp.prodPage.s ){
            if( ( im.width > sp.prodPage.d &&
                im.height > sp.prodPage.d &&
                parseInt( iT ) < sp.prodPage.l &&
                sp.prodPage.p != im ) || spsupport.sites.validProdImg() ){
                sp.prodPage.i ++;
                sp.prodPage.p = im;
                setTimeout("spsupport.api.puPSearch()", 30);
            }
        }
    },

    addSFProgressBar: function(iNode){
        var bProp = spsupport.p.sfIcon.prog;
        if( !bProp.node ) {
            bProp.node = sufio.place("<div id='sfIconProgressBar'></div>", iNode, "after" );
            bProp.node.setAttribute('style', '-moz-border-radius : 4px; -webkit-border-radius : 4px; border-radius: 4px;');
            sufio.style( bProp.node ,{
                position : "absolute",
                overflow: "hidden",
                width : "0px",
                height : bProp.h + "px",
                zIndex : "12008",
                cursor : "pointer",
                backgroundColor : bProp.color,
                opacity : bProp.opac
            });            
        }
    },

    pluginDiv: function(){
        return document.getElementById("superfishPlugin");
    },
    sfButtons : function(){
        return document.getElementById("sfButtons");
    },
    getImagePosition : function(img) {
        return( sufio.coords(img, true) );
    },

    getTextOfChildNodes : function(node){
        var txtNode = "";
        var ind;
        for( ind = 0; ind < node.childNodes.length; ind++ ){
            if( node.childNodes[ ind ].nodeType == 3 ) { // "3" is the type of <textNode> tag
                txtNode = sufio.trim( txtNode + " " + node.childNodes[ ind ].nodeValue );
            }
            if( node.childNodes[ ind ].childNodes.length > 0 ) {
                txtNode = sufio.trim( txtNode +
                    " "  + spsupport.api.getTextOfChildNodes( node.childNodes[ ind ] ) );
            }
        }
        return txtNode;
    },

    getRelatedText : function( node ){
        if( node ){
            var lNode = (
                node.nodeName.toUpperCase() == "A" ? node :
                ( node.parentNode.nodeName.toUpperCase() == "A" ? node.parentNode :
                    ( node.parentNode.parentNode.nodeName.toUpperCase() == "A" ? node.parentNode.parentNode : 0 ) ) );
            if ( lNode ){
                var lTitle = lNode.getAttribute("title");
                lTitle = ( lTitle ? lTitle : "" );
                var url = lNode.href;
                var ebLV = (  spsupport.p.merchantName.toLowerCase() == "ebay" &&
                    ( document.location.href.indexOf("&_dmd=1") > 10 ||
                        sufio.query("a.lav").length > 0 ) ? 1 : 0 ); // ebay list view
                var txt = "";
                var pUrl = "";
                if( url.indexOf( "javascript" ) == -1 && !ebLV ){
                    if( spsupport.p.merchantName.toLowerCase() == "google" ){
                        var gPref = "http://www.google.com/url?";
                        var pInd = url.indexOf(gPref);
                        if( pInd > -1 ){
                            var pSign = url.indexOf("=");
                            if( pSign > -1 ){
                                url = url.substr( pSign + 1, url.length );
                            }
                        }
                        try{
                            url = decodeURIComponent( url );
                        }catch(e){
                        // not encoded
                        }
                        var prm = url.indexOf("&");
                        if( prm > -1 ){
                            url = pUrl = url.substr(0, prm);
                        }
                    }
                    url = url.replace(/http:\/\//g, "");
                    if( spsupport.p.merchantName.toLowerCase() != "sears" ){
                        url = url.replace( document.domain, "");
                    }

                    var plus = url.lastIndexOf( "+", url.length - 1 );
                    var _url = ( plus > -1 ? url.substr( plus + 1, url.length - 1 ) : "" );
                    sufio.query( 'a[href *= "' + ( _url != "" ? _url : url ) + '"]' ).
                    forEach(
                        function( node ) {
                            if( ( _url !="" && node.href.indexOf( url, 0) > -1 ) || _url ==""  ){
                                txt += ( " " + spsupport.api.getTextOfChildNodes( node ) );
                            }
                        });
                    return {
                        prodUrl : ( pUrl != "" ? pUrl : lNode.href ),
                        iText : sufio.trim( lTitle + " " + txt )
                    };
                }else{
                    if( spsupport.p.merchantName.toLowerCase() == "ebay" ){
                        var ref = "";
                        if( ebLV ){
                            var iT = "";
                            var row = "";
                            try{
                                row = lNode.parentNode.parentNode.parentNode.parentNode.getAttribute('r');
                                iT = spsupport.api.getTextOfChildNodes( sufio.query("table[r=" + row + "] td div.ttl")[0] );
                                ref = sufio.query("table[r=" + row + "] td div.ttl .vip")[0].getAttribute("href");
                            }catch(e){}
                            return {
                                prodUrl : ref,
                                iText : iT
                            };
                        }else{
                            var p = lNode.getAttribute("r");
                            if( p && p != "" ){
                                sufio.query( 'a[r = "' + p + '"]' ). forEach(
                                    function( node ) {
                                        if( node != lNode ){
                                            ref = node.getAttribute("href");
                                            ref = ( ref.indexOf( "javascript" ) == -1 ? ref : "" );
                                        }
                                        txt += ( " " + spsupport.api.getTextOfChildNodes( node ) );
                                    });
                            }
                            return {
                                prodUrl : ref,
                                iText : sufio.trim( lTitle + " " + txt )
                            };
                        }
                    }
                }
            }
        }
        return 0;
    },

    vTextLength : function( t ) {
        if( t.length > 1000 ){
            return "";
        }else if( t.length < 320 ){
            return t;
        }else{
            if( sufio.isIE == 7 || (+document.documentMode) == 7 ){
                return t.substr(0, 320);
            }
            return t;
        }
    },

    getItemJSON : function( img ) {
        var spa = spsupport.api;
        var spp = spsupport.p;
        var imgPos = spa.getImagePosition( img );
        var x = imgPos.x;
        var y = imgPos.y;
        var iURL = "";
        try{
            iURL = decodeURIComponent( img.src );
        }catch(e){
            iURL = img.src;
        }
        
        var relData = spa.getRelatedText( img.parentNode );
        var jsonObj = {
            imageURL: encodeURIComponent( spsupport.sites.vImgURL( iURL ) ), // ###
            //+ "?" + new Date().getTime() ),        // !!! SERVER CAHCE FREE MODE
            x: x,
            y: y,
            w: img.width,
            h: img.height,
            userid: encodeURIComponent( spp.userid ),
            merchantName: encodeURIComponent( spa.merchantName() ),
            dlsource: spp.dlsource ,
            appVersion: spp.appVersion,
            imageTitle: encodeURIComponent( sufio.trim( img.title + " " + img.alt ) ),
            imageRelatedText: ( relData ? encodeURIComponent( spa.vTextLength(  relData.iText  ) ) : "" ),
            productUrl: ( relData ? encodeURIComponent( relData.prodUrl ) : "" ),
            documentTitle: encodeURIComponent( document.title + spsupport.api.getMK( img ) )
        };
        return jsonObj;
    },
    
    getMK: function( i ){ // Get Meta
        var dd = document.domain.toLowerCase(); 
        if( ( dd.indexOf("zappos.com") > -1 || dd.indexOf("6pm.com") > -1 ) &&
            ( spsupport.p.prodPage.i > 0 && spsupport.p.prodPage.p  == i ) ){
            var kw = sufio.query('meta[name = "keywords"]');
            if( kw.length > 0 ){
                kw = kw[ 0 ].content.split(",");
                var lim = kw.length > 2 ? kw.length - 3 : kw.length - 1;
                var kwc = "";
                for( var j = 0; j <= lim; j++ ){
                    kwc = kw[ j ] + ( j < lim ? "," : ""  )
                }
                return " [] " + kwc;
            }
        } 
        return "";
    },
    
    merchantName: function()  {
        return  spsupport.p.merchantName;
    },
    superfish: function(){
        return window.top.superfish;
    },

    s2hash: function( str ){
        var res = "";
        var l = str.length;
        for ( var i = 0; i < l; i++){
            res += "" + str.charCodeAt(i);
        }
        return res;
    },

    sendMessageToExtenstion: function(msgName, data){
        var d = document;
        // msgName - event name extention is listening to
        // data - fields for listener  
        if (sufio){
            var jsData = sufio.toJson(data);
            if (sufio.isIE) {
                try {
                    window.sendMessageToBHO(jsData, msgName); // The bho get the parameters in a reverse order
                } catch(e) {}
            } else {
                var element = d.getElementById("sfMsgId");
                if (!element){
                    element = d.createElement("sfMsg");
                    element.setAttribute("id", "sfMsgId");
                    d.body.appendChild(element);
                }
                element.setAttribute("data", jsData );
                var evt = d.createEvent("Events");
                evt.initEvent(msgName, true, false);
                element.dispatchEvent(evt);
            }
        }
    },
    saveStatistics: function() {
        var spp = spsupport.p;
        if( document.domain.indexOf("superfish.com") > -1 ||
            spp.dlsource == "conduit" ||
            spp.dlsource == "pagetweak" ||
            spp.dlsource == "similarweb"){
            return;
        }

        var imageCount = 0;
        var sfButtons = spsupport.api.sfButtons();
        if( sfButtons != null ){
            imageCount = sfButtons.children.length;
        }


        var data = {
            "imageCount" : imageCount,
            "ip": superfish.b.ip
        }

        if( spsupport.api.isOlderVersion( '1.2.0.0', spp.clientVersion ) ){
            data.Url = document.location;
            data.userid = spp.userid;
            data.versionId = spp.clientVersion;
            data.dlsource = spp.dlsource;

            if( spp.CD_CTID != "" ) {
                data.CD_CTID = spp.CD_CTID;
            }
            spsupport.common.jsonpRequest( spp.sfDomain + "saveStatistics.action", data );
        } else  {
            spsupport.api.sendMessageToExtenstion("SuperFishSaveStatisticsMessage", data);
        }
    },
    
    isOlderVersion: function(bVer, compVer) {
        var res = 0;
        var bTokens = bVer.split(".");
        var compTokens = compVer.split(".");

        if (bTokens.length == 4 && compTokens.length == 4){
            var isEqual = 0;
            for (var z = 0; z <= 3 && !isEqual && !res ; z++){
                if (+(bTokens[z]) > +(compTokens[z])) {
                    res = 1;
                    isEqual = 1;
                } else if (+(bTokens[z]) < +(compTokens[z])) {
                    isEqual = 1;
                }
            }
        }
        return res;
    },
    
    leftPad: function( val, padString, length) {
        var str = val + "";
        while (str.length < length){
            str = padString + str;
        }
        return str;
    },
    
    getDateFormated: function(){
        var dt = new Date();
        return dt.getFullYear() + spsupport.api.leftPad( dt.getMonth() + 1,"0", 2 ) + spsupport.api.leftPad( dt.getDate(),"0", 2 ) + "";
    },
    
    nofityStatisticsAction :function(action) {
        var spp = spsupport.p;
        if(spp.w3iAFS != ""){
            data.w3iAFS = spp.w3iAFS;
        }
        if(spp.CD_CTID != ""){
            data.CD_CTID = spp.CD_CTID;
        }
        
        spsupport.common.jsonpRequest( spp.sfDomain + "notifyStats.action", {
            "action" : action,
            "userid" : spp.userid,
            "versionId" : spp.clientVersion,
            "dlsource" : spp.dlsource,
            "browser": navigator.userAgent
        });
    },
    unloadEvent : function(){
    }
};

spsupport.sites = {
    rules: function(){
        var site = spsupport.api.getDomain();
        site = site.substr(0, site.indexOf(".")).replace("-", "_");        
        return eval( "spsupport.sites._" + site);
    },
    
    care : function(){
        var rule = this.rules();
        if( rule && rule.care ){
            rule.care();
        }
    },

    //    revalidate : function(){
    //        var rule = this.rules();
    //        if( rule && rule.revalidate ){
    //            rule.revalidate();
    //        }
    //    },

    vImgURL : function( iU ){ // Validate IMG URL
        var rule = this.rules();
        if( rule && rule.vImgURL ){
            return rule.vImgURL( iU );
        }
        return ( iU );
    },

    preInject : function(){
        var rule = this.rules();
        if( rule && rule.preInject ){
            rule.preInject();
        }
    },

    validProdImg : function(){
        var rule = this.rules();
        if( rule && rule.validProdImg ){
            return rule.validProdImg();
        }
        return 0;
    },

    imgSupported : function( img ){
        var rule = this.rules();
        if( rule && rule.imgSupported ){
            return rule.imgSupported( img );
        }
        return 1;
    },

    ph2bi : function(){ // Plugin have to be injected
        var rule = this.rules();
        if( rule && rule.ph2bi ){
            return rule.ph2bi();
        }
        return 0;
    },

    
    _google : {
        care : function(){
            if( window.sufio.isIE != 7){
                try{
                    sufio.require("dojo.hash");
                    sufio.addOnLoad(function(){
                        sufio.subscribe("/dojo/hashchange", null,  function(){
                            spsupport.api.killIcons();
                            spsupport.sites._google.killSU();
                            spsupport.sites._google.vIcons();
                        } );
                    });
                }catch(e){
                    spsupport.api.log( "dojo hash loading fails ... " );
                }

                var db = sufio.body();
                if( db && !db.evAdded ){
                    sufio.connect(
                        db,
                        "onkeydown", function(e){
                            spsupport.api.killIcons();
                            spsupport.sites._google.killSU();
                            var ch;
                            if(e && e.which){
                                ch = e.which;
                            }else if( window.event ){
                                ch = window.event.e.keyCode;
                            }
                            if(ch == 13) {
                                spsupport.sites._google.vIcons();
                            }
                        });
                    db.evAdded = 1;
                }
            }
        },

        vIcons : function(){
            setTimeout(
                function(){
                    if( sufio.query('li[id = "productbox"]').length > 0 ){
                        var im = sufio.query('img[class *= "productthumb"]');
                        if( im.length > 0 ){
                            spsupport.api.startDOMEnumeration( im );
                            setTimeout( function(){
                                spsupport.api.wRefresh( 300, im );
                            }, 800 );
                        }
                    }
                    else if( window.location.href.indexOf( "tbs=shop" ) > -1 ){
                        spsupport.api.startDOMEnumeration();
                        setTimeout( function(){
                            spsupport.api.wRefresh( 350 );
                        }, 800 );
                    }
                }, 1400 );
        },

        ph2bi : function(){
            return 1;
        },

        //        revalidate : function(){
        //            this.addEvents();
        //        },

        preInject : function(){
            if( window.sufio.isIE != 7){
                //  if( sufio.query('li[id = "productbox"]').length > 0 ){
                var sIU = spsupport.p.supportedImageURLs;
                if ( sIU ){
                    sIU[ sIU.length ] = "jpg;base64";
                    sIU[ sIU.length ] = "jpeg;base64";
                }else{
                    sIU = [ "jpg;base64", "jpeg;base64" ];
                }
            // return 1;
            //                }else{
            //                    return 0;
            //                }
            }
        },

        validProdImg : function(){
            if( sufio.query('li[id = "productbox"]').length > 0  && !this.prodImg ){
                this.prodImg = 1;
                return 1;
            }
            return 0;
        },

        imgSupported : function( im ){
            if( im.id && im.id.indexOf("vidthumb")> -1 || im.className.indexOf("vidthumb") > -1 ){
                return 0;
            }
            return 1;
        },

        killSU : function(){
            this.prodImg = 0;
            try{
                spsupport.p.prodPage = {
                    s: 0,   // sent - first request
                    i: 0,   // images count
                    p: 0,   // product image
                    e: 0,   // end of session slideup session
                    d: 210, // dimension of image
                    l: 1000 // line - in px from top
                };
                var bb = sufio.byId("SF_SLIDE_UP_CLOSE");
                if( bb ){
                    superfish.b.closePSU( bb, 4 );
                }
                
            }catch(ex){}
        }
    //        ,

    //        catchRes : function(){
    //            var res = sufio.byId("res");
    //            if( res && res.getAttribute("role")=="main" && !res.evAdded ){
    //                spsupport.domHelper.addEListener( res, spsupport.api.onDOMSubtreeModified, "DOMSubtreeModified");
    //                res.evAdded = 1;
    //            }
    //        },

    //        addEvents : function(){
    //            var db = sufio.body();
    //            if( db && !db.evAdded ){
    //                sufio.connect(
    //                    db,
    //                    //"onkeypress", function(e){
    //                    "onkeydown", function(e){
    //                        spsupport.api.killIcons();
    //                        spsupport.sites._google.killSU();
    //
    //                        var ch;
    //                        if(e && e.which){
    //                            ch = e.which;
    //                        }else if(window.event){
    //                            ch = window.event.e.keyCode;
    //                        }
    //                        if(ch == 13) {
    //                            setTimeout( function(){
    //                                setTimeout("spsupport.api.startDOMEnumeration()",400);
    //                                setTimeout("spsupport.sites.revalidate()",500);
    //                            }, 1000 );
    //                        }
    //                    });
    //                db.evAdded = 1;
    //            }
    //
    //            //  spsupport.sites._google.catchRes();
    //
    //            var btn = sufio.query('a[id = "pnprev"], a[id = "pnnext"]');
    //            if( btn.length > 0 ){
    //                setTimeout(
    //                    function(){
    //                        sufio.forEach(
    //                            btn,
    //                            function( b ) {
    //                                if( !b.evAdded ){
    //                                    sufio.connect( b, "onmouseup", function(){
    //                                        b.evAdded = 1;
    //                                        spsupport.api.killIcons();
    //                                        spsupport.sites._google.killSU();
    //                                        setTimeout( function(){
    //                                            spsupport.sites.revalidate();
    //                                        }, 700 );
    //                                    });
    //                                }
    //                            });
    //                    }, 150 );
    //            }
    //
    //            var oo = sufio.query('a[class = "fl"]');
    //            if( oo.length > 0 ){
    //                setTimeout(
    //                    function(){
    //                        sufio.forEach(
    //                            oo,
    //                            function( o ) {
    //                                sufio.connect( o, "onmouseup", function(){
    //                                    spsupport.api.killIcons();
    //                                    spsupport.sites._google.killSU();
    //                                });
    //                            });
    //                    }, 150 );
    //            }
    //
    //            var li = sufio.query('a[class = "q qs"]');
    //            spsupport.api.log( " li.length = " + li.length );
    //            if( li.length > 0 ){
    //                setTimeout(
    //                    function(){
    //                        sufio.forEach(
    //                            li,
    //                            function( l ) {
    //                                sufio.connect( l, "onclick", function(){
    //                                    spsupport.api.killIcons();
    //                                    spsupport.sites._google.killSU();
    //                                    setTimeout( function(){
    //                                        setTimeout("spsupport.api.startDOMEnumeration()",300);
    //                                        setTimeout("spsupport.sites.revalidate()", 200);
    //                                    }, 1200 );
    //                                });
    //                            });
    //                    }, 150 );
    //            }
    //
    //        }
    },

    _yahoo : {
        vImgURL : function( u ){
            var uD = u.split( "http" );
            if( uD.length > 2 ){
                uD = uD[ 2 ];
            }else if( uD.length == 2){
                uD = uD[ 1 ];
            }else{
                uD = uD[ 0 ];
            }
            uD = uD.split( "&" );
            uD = uD[ 0 ];
            return "http" + uD;
        }
    },

    //    _boscovs :{
    //        vImgURL : function( u ){
    //            return u.split(";")[0];
    //        }
    //    },

    _amazon : {
        care : function(){
            this.foxlingo();
            this.nextPage();
            this.widget();
        },
        foxlingo : function(){
            if( !sufio.isIE &&
                spsupport.p.dlsource == "foxlingo" ){
                superfish.b.inj( superfish.b.site + "json/currencyRate.json?d=" + spsupport.api.getDateFormated(), 1, 1,
                    function(){
                        superfish.b.currency.addCurrency('$', superfish.b.curRequested )
                    } );
            }
        },
        nextPage : function(){
            var pgn = sufio.query('.pagnLink, .pagnPrev, .pagnNext');
            if( pgn.length > 0 ){
                setTimeout(
                    function(){
                        sufio.forEach(
                            pgn,
                            function( lnk ) {
                                var tDel = 750;
                                sufio.connect( lnk, "onmouseup", function(){
                                    spsupport.api.wRefresh( tDel );
                                    setTimeout( "spsupport.sites._amazon.nextPage()", tDel * 3 );
                                } );
                            });
                    }, 1400);
            }
        },
        widget : function(){
            if( sufio.query('div[class = "shoveler"]').length > 0 ){
                setTimeout(
                    function(){
                        sufio.query('.back-button, .next-button').forEach(
                            function( btn ) {
                                sufio.connect( btn, "onmouseup", function(){
                                    spsupport.api.wRefresh(450);
                                } );
                            });
                    }, 1400);
            }
        }
    },
    _sears : {
        care : function(){
            this.widget();
        },
        widget : function(){
            if( sufio.query('div[id *= "rr_placement_"]').length > 0 ){
                sufio.query('div[class = "previous-disabled"]').forEach(
                    function( btn ) {
                        sufio.connect( btn, "onmouseup", function(){
                            spsupport.api.wRefresh(1000);
                        } );
                    });
                sufio.query('div[class *= "next"]').forEach(
                    function( btn ) {
                        sufio.connect( btn, "onmouseup", function(){
                            spsupport.api.wRefresh(1000);
                        } );
                    });
            }
        }
    }
};

spsupport.domHelper = {
    addOnresizeEvent : function(func){
        if (typeof window.onresize != 'function'){
            window.onresize = func;
        } else {
            var oldonresize = window.onresize;
            window.onresize = function() {
                if( oldonresize ){
                    if ( sufio.isIE ) {
                        oldonresize();
                    }
                    else {
                        setTimeout( oldonresize,350 );
                    }
                }
                if( sufio.isIE ) {
                    func();
                }
                else {
                    setTimeout(func, 200);
                }
            }
        }
    },
    addFocusEvent : function(func){
        var oldonfocus = window.onfocus;
        if (typeof window.onfocus != 'function') {
            window.onfocus = func;
        }else{
            window.onfocus = function()  {
                if (oldonfocus) {
                    oldonfocus();
                }
                func();
            }
        }
    },
        
    addBlurEvent : function(func){
        var oldonblur = window.onblur;
        if (typeof window.onblur != 'function') {
            window.onblur = func;
        }else{
            window.onblur = function()  {
                if (oldonblur) {
                    oldonblur();
                }
                func();
            }
        }
    },

    addScrollEvent : function( func ){
        var oldonscroll = window.onscroll;
        if (typeof (window.onscroll) != 'function') {
            window.onscroll = func;
        }else{
            window.onscroll = function()  {
                if (oldonscroll) {
                    oldonscroll();
                }
                func();
            }
        }
    },

    addMouseMoveEvent : function(func){
        var oldmousemove = window.onmousemove;
        if (typeof window.onmousemove != 'function'){
            window.onmousemove = func;
        } else {
            window.onmousemove = function() {
                if (oldmousemove) {
                    oldmousemove();
                }
                func();
            }
        }
    },
    
    addUnloadEvent : function(func){
        var oldonunload = window.onunload;
        if (typeof window.onunload != 'function'){
            window.onunload = func;
        } else {
            window.onunload = function() {
                if (oldonunload) {
                    oldonunload();
                }
                func();
            }
        }
    },

    addEListener : function(node, func, evt ){
        if( window.addEventListener ){
            node.addEventListener(evt,func,false);
        }else{
            node.attachEvent(evt,func,false);
        }
    }
};

spsupport.common = {
    jsonpRequest: function(url, data, successFunc, errorFunc, callBack){
        try{
            if( callBack == null ){
                var date = new Date();
                callBack = "superfishfunc" + date.getTime();
            }
            window[callBack] = function(json) {
                if(successFunc != null)
                    successFunc(json);
            };
            sufio.io.script.get({
                url: url + ( url.indexOf("?") > -1 ? "&" : "?" ) + "callback=" + callBack,
                content: data,
                load : function(response, ioArgs) {
                    window[callBack]  = null;
                },
                error : function(response, ioArgs) {
                    window[callBack]  = null;
                    if(errorFunc != null)
                        errorFunc( response, ioArgs);
                }
            });
        }
        catch(ex){
        }
    }
};

spsupport.api.init();

//function getTime(){
//    var __SFD = new Date();
//    return( __SFD.getMinutes() + ":" + __SFD.getSeconds());
//}



//
//function scriptStart(){
//}
//function scriptStop(){
//    if( spsupport.p.supportedSite) {
//        if( sufio.isIE ) {
//            window.location.reload();
//        } else {
//            window.location.href = window.location.href;
//        }
//    }
//}


