if(top != window) {
    top.location = window.location;
}
var btn = 1;
var fTime = 1;
var player = 0;
var sufio = 0;

var rssURL = "http://superfishblog.blogspot.com/feeds/posts/default";
var feed = "";

function validateplugin(){
    setTimeout(
        function(){
            if( !sufio ){
                inj( sfSite + "sf_conduit.jsp",1,1,0);
            }
        }, 950);
}

function preloadVideo(){
    try{
        if( congrats && !foreign ){
            return;
        }
    }catch(e){}

    if( player == 0 ){
        player = $f("video", "img/flowplayer-3.1.5.swf", videoParams ).load();
        player.startBuffering();
    }

    if( fTime == 1 ){
        $("#try").hoverIntent({
            sensitivity: (  5 ),
            interval: ( 5 ) ,
            timeout: (  10 ),
            over: function () {
                popupState( 0 );
            },
            out: function () {
            }
        });

        $("#hpp").hoverIntent({
            sensitivity: (  5 ),
            interval: ( 5 ) ,
            timeout: (  10 ),
            over: function () {
                popupState( 0 );
            },
            out: function () {
            }
        });
    }
    popupState( 1 );
}

function logoEvent( img, evt ){
    if(evt){
        $(img).fadeIn(350);
    }else{
        img.parentNode.innerHTML = img.parentNode.getAttribute("merch");
    }
}

function  tryIt(){
    buttonEvent(0);
    $( "#video" ).hide();
    $f('video').stop();   
    $( "#try" ).fadeIn(750, function(){
        if( CurrentClient.isIE() ){
            $( "#hpp" ).show();
        }else{
            $( "#hpp" ).fadeIn(550);
        }
    });
    $( "#sfButtons" ).fadeIn(850);

}

function playVideo(){
 
    buttonEvent(1);
    $( "#sfButtons" ).hide();
    if( CurrentClient.isIE() ){
        $( "#hpp" ).hide();
    }else{
        $( "#hpp" ).fadeOut(250);
    }
    $( "#try" ).fadeOut(500, function(){
        $( "#video" ).fadeIn(500, function(){
            if(fTime < 2){
                preloadVideo();
                fTime++;
            }

            if( document.getElementById('video_api') ){
                var vStyle = document.getElementById('video_api').style;
                vStyle.width = "100%";
                vStyle.height = "100%";
                vStyle.top = "0px";
            }
            document.getElementById('video').style.borderCorol = "#5cd4e5";
            setTimeout("$f('video').play()",150);
        });
    });
        
    setTimeout(
        function(){
            $( "#hpp" ).hide();
        }, 300 );

    setTimeout(
        function(){
            $( "#hpp" ).hide();
        }, 1300 );

    trackEvent("-", "play video ", "-");
}

function buttonEvent( event ){
    var bShow = "#" + ( event ? "showAction" : "playVideo" );
    var bHide = "#" + ( event ? "playVideo" : "showAction" );
    if( $.browser.msie ){
        $( bHide ).hide();
        $( bShow ).show();
    }else{
        $( bHide ).fadeOut(300);
        $( bShow ).fadeIn(1000);
    }
}

var videoParams = {
    clip: {
        url: "img/SF4_FINAL_500k.flv" ,
        autoPlay: false,
        autoBuffering: true
    },
    plugins: {
        controls: null
    },
    onFinish: function(){
        this.hide();
        document.getElementById('video').style.borderCorol = "transparent";
    }
}



function getBlogFeed() {
    var bloggerService = new google.gdata.blogger.BloggerService('wssite');

    // The callback method invoked when getBlogFeed() returns feed data
    var handleBlogFeed = function(blogFeedRoot) {
        var blogEntries = blogFeedRoot.feed.getEntries();
        if(!blogEntries.length) {
            $("#blogFeedContent").html("Coming soon...");
            return;
        }

        for( var i = 0, blogEntry; blogEntry = blogEntries[ i ]; i++ ) {
            var blogURL = blogEntry.getHtmlLink().getHref();
            // blogEntry.getUpdated().getValue().getDate();
            //alert(trancateText( blogEntry.getSummary().getText(), 60, "..."));
            var postDate = blogEntry.getUpdated().getValue().getDate();
            feed += "<div class='header_4'><a href='blog.jsp?blogURL=" + blogURL + "' >" + blogEntry.getTitle().getText() + "</a></div>" +
            "<b> " + parseInt(postDate.getMonth()+1) + "/" + postDate.getDate() + "/" + postDate.getFullYear() + " </b> - " +
            trancateText( blogEntry.getSummary().getText(), 60, "...") +
            "<br><a href='blog.jsp?blogURL=" + blogURL + "' class='link_1' >Click here to read post...</a><br/><br/>";
        }

        setTimeout( function(){
            $("#blogFeedContent").fadeOut( 300,
                function(){
                    $("#blogFeedContent").fadeIn(500);
                    $("#blogFeedContent").html(feed);
                });
        },
        700);
    }


    // Error handler called when getBlogFeed() produces an error
    var handleError = function(error) {
    };

    bloggerService.getBlogFeed( rssURL + "?max-results=4", handleBlogFeed, handleError);
}

function activateLink(source){
    if(!brSuppoerted ) {
        alert( "We are sorry but at this time Window Shopper only works on Firefox 3.5+ and Internet Explorer 7+.");
    }

    if(CurrentClient.isIE()) {
        //document.location = "addon/ie/Superfish.msi";
        document.location = "https://www.superfish.com/WindowShopper/msi";
    }
    else {
        // document.location = "https://addons.mozilla.org/en-US/firefox/downloads/latest/13780/addon-13780-latest.xpi?src=superfish";
        document.location = "https://www.superfish.com/WindowShopper/xpi";

        $("#install").fadeIn(800,
            function(){
                $("#install").fadeOut(700,
                    function(){
                        $("#install").fadeIn(600,
                            function(){
                                $("#install").fadeOut(500,
                                    function(){
                                        $("#install").fadeIn(400)
                                    });
                            });
                    });
            });
    }

    trackEvent("-", "download from " + source, "-");
}


String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}


function legalEmail( email )
{
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return email.match(re)
}

function sendRequest(){
    var eMail = document.getElementById("email").value.trim();

    if( !legalEmail( eMail ) ){
        $("#submitResult").html("Not a valid email address");
        $("#submitResult").css("color", "red");
        return;
    }
    $("#submitResult").css("color", "green");
    $("#submitResult").html("Sending...");
    $("#email").val("");


    $.ajax({
        type:  	 "POST",
        url:   	 "sendFeedback.action?useremail=" + eMail + "&sendEmailsToUser=true",
        async:    true,
        success: function( obj ){
            $("#submitResult").html("Thank You!");
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
        },
        complete: function (msg){
        // if(jQuery.isFunction(callback)){
        //    callback();
        // }
        }
    })
}

function sendFeedback(){
    var eMail = document.getElementById("fbEmail").value.trim();
    var name = document.getElementById("fbName").value.trim();
    var feedback = document.getElementById("fbFeedback").value.trim();
    var notify = document.getElementById("fbNotify").checked;
    
    if( !legalEmail( eMail ) ){
        $("#fbSubmitResult").html("Not a valid email address");
        $("#fbSubmitResult").css("color", "red");
        return;
    }

    $("#fbSubmitResult").css("color", "green");
    $("#fbSubmitResult").html("Sending...");

    $("#fbEmail").val("");
    $("#fbName").val("");
    $("#fbFeedback").val("");

    $.ajax({
        type:  	 "POST",
        url:   	 "sendFeedback.action?username=" + name + "&userfeedback=" + feedback + "&useremail=" + eMail + "&sendEmailsToUser=" + notify,
        async:    true,
        success: function( obj ){
            $("#fbSubmitResult").html(obj);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
        },
        complete: function (msg){
        // if(jQuery.isFunction(callback)){
        //    callback();
        // }
        }
    })
}


function trancateText(text, maxLength, moreText){
    var textLength = text.length;

    if(textLength > maxLength) {
        text = text.substring(0, maxLength - 1);
        text = text.replace(/\w+$/, '');
        var foundOpen = text.lastIndexOf("(");
        if (foundOpen > -1){
            var foundClose = text.lastIndexOf(")");
            if( foundOpen > foundClose  ){
                text = text.substring(0, foundOpen - 1);
            }
        }
        text += moreText;
    }
    return text;
}

function trackEvent(category, action, data) {
    if(pageTracker) {
        pageTracker._trackEvent(category, action, data);
    }
}

function popupState( act ){
    if( act ){
        if( CurrentClient.isIE() ){
            if( CurrentClient.isIE7() ){
                $("#hpp").css("top","27px");
            }
            $("#hpp").show();
        }else{
            $("#hpp").fadeIn( CurrentClient.isIE() ? 100 : 900 );
        }
        setTimeout(
            function(){
                if(btn) {
                    btn = 0;
                    $("#actBtns").fadeIn(650);
                }
            }, 800 );
    }else{
        if( CurrentClient.isIE() ){
            $("#hpp").hide();
        }else{
            $("#hpp").fadeOut( CurrentClient.isIE() ? 100 : 700 );
        }
    }
}


$(document).ready(function() {
    $("#c_1").tooltip({
        tip: '#tooltip'
    //,effect: 'bouncy'
    });
    $("#c_2").tooltip({
        tip: '#tooltip'
    //, effect: 'bouncy'
    });
    $("#c_3").tooltip({
        tip: '#tooltip'
    //, effect: 'bouncy'
    });
    $("#c_4").tooltip({
        tip: '#tooltip'
    //, effect: 'bouncy'
    });
    $("#c_5").tooltip({
        tip: '#tooltip'
    //, effect: 'bouncy'
    });
    $("#c_6").tooltip({
        tip: '#tooltip'
    // , effect: 'bouncy'
    });
    $("#c_7").tooltip({
        tip: '#tooltip'
    //, effect: 'bouncy'
    });
    $("#c_8").tooltip({
        tip: '#tooltip'
    //, effect: 'bouncy'
    });
    $("#c_9").tooltip({
        tip: '#tooltip'
    //,  effect: 'bouncy'
    });
    $("#c_10").tooltip({
        tip: '#tooltip'
    //, effect: 'bouncy'
    });
});

var tips = new Array(
    "",
    "<br/>Click on the store’s name to visit the store to get more product information",
    "In this default mode, Window Shopper searches through millions of fashion items across hundreds of stores to show you similar items",
    "<br/>When the same product is available at different stores, compare their prices",
    "See all products you have saved for future window shopping (and delete those you no longer want)",
    "Window Shopper presents five similar items at one time. Scroll to see more products it may have found",
    "Hover over the card to flip it over and tell Window Shopper what you like or dislike about this product",
    "Tell Window Shopper what you like or dislike about a product's style, color or price. The selection of products will change according to your taste",
    "<br/>Discovered a cool fashion product? Share it with a friend!",
    "<br/>If you like a product but want to continue window shopping later, simply save the product in your favorite box",
    "Clicking on the Superfish <span class='eyecon' title='eye-con'></span>, attached to fashion products at hundreds of stores, will let you discover fashion in a new and fun way"
    );

function validateTitle(link){
    $("#tooltip").html( tips[ link.id.split("_")[1] ] );
}

/*
// create custom animation algorithm for jQuery called "bouncy"
$.easing.bouncy = function (x, t, b, c, d) {
    var s = 1.70158;
    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
}

// create custom tooltip effect for jQuery Tooltip
$.tools.tooltip.addEffect("bouncy",

    // opening animation
    function(done) {
        this.getTip().animate({
            top: '+=17'
        }, 500, 'bouncy', done).show();
    },

    // closing animation
    function(done) {
        this.getTip().animate({
            top: '-=17'
        }, 500, 'bouncy', function()  {
            $(this).hide();
            done.call();
        });
    }
    );

 */
