      function getMovieName(movieName)
    {
    if (navigator.appName.indexOf("Microsoft") != -1)
        { return window[movieName]; }
    else
        { return document[movieName]; }
    }
      function writeToPipe(name, data)
    {
    getMovieName("pipe").write(name, data);
    }
      function readFromPipe(name)
    {
    return getMovieName("pipe").read(name);
    }

$(document).ready(function(){
	if ($().autocomplete) {
	$("#menu-search > input[type='text']")
	    .autocomplete("/autocomplete/",
			  {max: 12,
				  scroll: false,
				  matchSubset: false,
				  formatItem: function(data, i, n, value){
				  match = value.match("^;;(ARTISTS|SONGS)::");
				  if (match) {
				      return "<div class='ac_category'>" + match[0].slice(2,-2) + "</div>";
				  } else {
				      return "<div class='ac_results_item'>" + value.slice(1) + "</div>";
				  }
			      },
				  formatResult: function(data, i, n){
				  value = data[0];
				  match = value.match("^;;(ARTISTS|SONGS)::");
				  if (match) {
				      return value;
				      //return value.replace(match[0], "");
				  } else {
				      return value.slice(1).replace("&amp;","&").replace("&#39;","'");
				  }
			      },
				  highlight: function(value, term) {
				  match = value.match("<div class='ac_category'>(ARTISTS|SONGS)</div>");
				  if (match) {
				      return value;
				  }else{
				      return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>");
				  }
			      }
				  });
	$("#menu-search > input[type='text']").keyup(function(e) {
		if(e.keyCode == 13) {
		    pageTracker._trackEvent('search', 'header-enter', $(this).val());
		    location.href = "/search/?unified=" + encodeURIComponent($(this).val()) + '&filter=' + $("#menu-search-options input:checked").val();
		}
	    });
	}
	$(".menu-nav-item").mouseover(function(){
		$(this).addClass("menu-nav-item-hover");
	    }).mouseout(function(){
		    $(this).removeClass("menu-nav-item-hover");
		});
	$(".menu-cart").mouseover(function(){
		$(this).addClass("menu-nav-item-hover");
	    }).mouseout(function(){
		    $(this).removeClass("menu-nav-item-hover");
		});
	$("#menu-search div.search-submit").click(function(){
		pageTracker._trackEvent('search', 'header-click', $('#menu-search > input').val());
		location.href = '/search/?unified=' + encodeURIComponent($('#menu-search > input').val()) + '&filter=' + $("#menu-search-options input:checked").val();
	    });
	// playlists
	$("image.profile-image").error(function() {
		$(this).unbind("error")
		    .attr("src",
			  "/static/images/profile128x128_processing.png");
	    });
	$(".make-public").click(function(){
		var parent = $(this).parent();
		$.post('/set_playlist_visibility/',
		       {public: true,
			       plid: $(this).attr("playlist")},
		       function(){
			   parent.siblings(".is-public").show();
			   parent.hide();
		       });
	    });
	$(".make-private").click(function(){
		var parent = $(this).parent();
		$.post('/set_playlist_visibility/',
		       {public: false,
			       plid: $(this).attr("playlist")},
		       function(){
			   parent.siblings(".is-private").show();
			   parent.hide();
		       });
	    });
	$("input.highlight-on-click").live('click', function(){
		$(this).focus().select();
	});
	$("a.condensed-playlist-share").click(function(){
		$('#share-playlist-popup').remove();
		var playlistData = $(this).attr('href').replace("#","").split("$$");
		var playlistId = playlistData[0];
		var playlistTitle = playlistData[1];
		var domain = document.location.protocol + "//" + document.location.host;
	        var popupMarkup = "<div id='share-playlist-popup' style='position: absolute; left: -20px; width: 280px; background-color: #444; border: solid 1px #333; padding: 10px; z-index: 1000;'><span class='close' style='position: absolute; top: 0px; right: 0px;'><a href='#'><img src='/static/images/close.png' alt='X' /></a></span><strong>Share this playlist with your friends</strong><br /><table><tr><td>Email & IM Link:</td><td><input class='highlight-on-click' type='text' value='" + domain + "/playlist/" + playlistId + "?n=2' style='width: 185px;'/></td></tr><tr><td>Direct Link:</td><td><input class='highlight-on-click' type='text' value='" + domain + "/playlist/" + playlistId + "' style='width: 185px;'/></td></tr></table><br /><strong>Other ways to share: </strong><a href='http://twitter.com/home?status=GetPlaylists " + playlistTitle + " " + domain + "/playlist/" + playlistId + "%3Fn=7' target='_blank'><img style='margin-left: 5px; margin-right: 5px;' src='/static/images/icons/twitter.png' /></a><a href='http://www.facebook.com/share.php?u=<url>' class='fb_share_button' onclick='return fbs_click()' target='_blank' style='text-decoration:none; padding: 0px; width: 16px;'></a><a href=\"javascript:GetThis('" + playlistTitle + "','Visit GetPlaylists to download " + playlistTitle + "!', '" + domain + "/playlist/" + playlistId + "?&=8', '6')\"><img style='margin-left: 5px' src='http://cms.myspacecdn.com/cms/post_myspace_icon.gif' border='0' alt='Post to MySpace!' /></a></div>";
	        var popup = $(this).parent().append(popupMarkup);
	        $('.close', popup).click(function(){ $(this).parent().remove(); return false; });
		return false;
	});
    });

// Fix for IE
// We should probably just do everything in jQuery
if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
			if(this[i]===obj){
				return i;
			}
		}
		return -1;
	}
}
