var _sf_startpt = (new Date()).getTime()

$("<img>").attr("src", "img/buttonBg_active.jpg");
$("<img>").attr("src", "img/button_firefox2.jpg");
$("<img>").attr("src", "img/button_firefox3.jpg");

$("<img>").attr("src", "img/facebox/tl.png");
$("<img>").attr("src", "img/facebox/t.png");
$("<img>").attr("src", "img/facebox/tr.png");
$("<img>").attr("src", "img/facebox/l.png");
$("<img>").attr("src", "img/facebox/r.png");
$("<img>").attr("src", "img/facebox/bl.png");
$("<img>").attr("src", "img/facebox/b.png");
$("<img>").attr("src", "img/facebox/br.png");
$("<img>").attr("src", "img/ff.jpg");
$("<img>").attr("src", "img/ie.jpg");


// Show Help page if Glue installed and link to profiles
function buddyInstalledInit( installed ) {
	if( installed ) {
		$("a.glue").removeClass("glue");
		$("a.button.firefox").addClass("installed");
		$("#helpLink").fadeIn();
		$("#sitesLink").fadeIn();
		$("#spreadLink").fadeIn();
        $("#exploreLink").fadeOut();
        $("#quotes").fadeOut();
        $("#tourUninstalled").fadeOut(function() {
            $("#tourInstalled").fadeIn();
        });
        $("#tourContainer").css({"height": "auto"});
		waitUntilBuddyInitialized(function() {
			var info = getBuddyInfo();
			var favs = info.totalFavorites;
			var friends = info.friends;
			if(favs >= 5 && friends >= 5 ) {
				//$("#help").prepend($("#prependHelp"));
				$("a.tooltip").glueTip();
				$("#firstTip").initGlueTip();
			}
		}, 5000);
		$("ul#team li a").each(function() {
			$(this).attr("href", "glue://users/" + $(this).attr("username") + "/profile");
		});
	} else {
        $("#exploreLink").fadeIn();
    }
    $.each($.browser, function(i, val) {
      if($.browser.msie){
        styleIeButton();
          $(".ieonly").css({display: "none"}).removeClass("ieonly").fadeIn();
            if(parseInt($.browser.version) < 8)
                $(".ie7only").css({display: "none"}).removeClass("ie7only").fadeIn();
      } else if($.browser.mozilla) {
          if(jQuery.browser.version.substr(0,3) != "1.9") {
              $(".ie7only").addClass("ff2only").css({display: "none"}).removeClass("ie7only").fadeIn();
              $("span.browserName", $("#tour")).html("Firefox 3");
              $("span.browser", $("#tour")).html("Firefox");
              $("a#browserLink", $("#tour")).attr("href", "http://www.mozilla.com/en-US/products/download.html?product=firefox-3.0.10&os=win&lang=en-US");
          }
      } else {
         //$("a.install.button").attr("href", "#");    
		  $(".ie7only").css({display: "none"}).removeClass("ie7only").fadeIn();
      }
    });
	$("#installLink").fadeIn();
}

// this is replicated in facebox file
function styleIeButton() {
    $("a.button.firefox").addClass("ie");
    $("a.install.button").attr("href", "http://www.mozilla.com/en-US/products/download.html?product=firefox-3.0.10&os=win&lang=en-US");
}

$(function($){
	$("#firstTip").initGlueTip();
	var path = window.location.pathname;
	var page = path.substring(path.lastIndexOf('/') + 1);

	function track(path) {
		pageTracker._trackPageview("/track/" + path);
	}

	$("a.tracking").live("click", function() {
	  	track($(this).attr("track"));
	});

	// Set Tooltips
	$("a.tooltip").glueTip();

	// Set Firefox Download Button
	$("a.install.button").live("click", function() {
        installProcess();
	});

    function installProcess() {
        $("#protocolRedirectSplashContainer").hide();
        $("#facebox").fadeOut(500, function() {
            $.each($.browser, function(i, val) {
              if($.browser.mozilla){
                  $("#fullscreen_overlay").fadeIn(500, function() {$("#install_arrow_container").fadeIn(750); });
              } else if(!$.browser.msie) {
                  $("a.install.button").attr("href", "#");
                  $("#fullscreen_overlay").fadeIn(500, function() {
                  var top = ($(window).height() / 2) - ($("div.safari_overlay").height() / 2);
                  var left = ($(window).width() / 2) - ($("div.safari_overlay").width() / 2);
                  $("div.safari_overlay").css({top: top + "px", left: left + "px"}).fadeIn(750);
                  });
                  return false;
              }
            });
        });
    }

	// Hide overlay on click
	$("div.dialogClose, a.dialogClose").click(function() {
        closeDialog();
    });

    $("#facebox .close").live("click", function() {
       closeDialog();
        return false;
    });

    function closeDialog() {
        $("div.safari_overlay").fadeOut("fast");
        $("#fullscreen_overlay").fadeOut("fast");
        $("#facebox").fadeOut("fast");
        $("#install_arrow_container").fadeOut("fast");
        $("#protocolRedirectSplashContainer").fadeOut("fast");
    }

    $("div.safari_overlay .close").live("click", function() {
        closeDialog();
    });

    // display dialog when you click a glue link
    $("a.glue").live("click", function (){
        showProtocolDialog($(this).attr("message") ? $(this).attr("message") : "To view this link, you'll need to have the latest version of Glue added to your browser.", true)
        return false;
    });

    // Set functionality for Div Toggles
	$("a.toggle").click(function() {
		$(this).parent().next("div").toggle();
		$(this).toggleClass("open");

        // Clipboard library needs to be notified of
        // DOM changes so it can move itself
        if(typeof(clip) != "undefined")
			clip.reposition();

		return false;
    });

	// Video popupn hackz
	$('a[rel*=facebox]').click(function() {
		$("#video").attr("vid", $(this).attr("vid"));
	}).facebox();

	$("input.autoSelect").click(function() {
        $(this).focus().select();
    });


});