$(function(){
	$('.wide tbody tr').tooltip({ 
	    track: true, 
	    delay: 0,
	    bodyHandler: function(){ return 'Klicke auf das Anbieter-Logo für mehr Infos.'; }
	});
	
	$('a').each(
	function(i) {
		h = this.href.toLowerCase().replace(/http:\/\/www.musik-ohne-drm-kaufen.com\//, '');
		if(h.match(/^#/)) {
			$(this).click(
				function() {
					var x = this.href.split('#');
					if(x[1]!='')
						$.scrollTo('#'+x[1], 800);
				}
			);
		}
	});
	
	//~ $('.go-up a').each(
	//~ function(i) {
		//~ $(this).click(
			//~ function() {
					//~ $.scrollTo('body', 800);
			//~ }
		//~ );
	//~ });
});

//google.setOnLoadCallback(OnLoad);

var search = [
	['http://www.amazon.de', 'Amazon MP3'],
	['http://itunes.apple.com/de/', 'iTunes'],
	['http://de.7digital.com/', '7digital']
];

var searchControl;

function OnLoad() {
	var options = new google.search.SearcherOptions();
	options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
	options.setRoot(document.getElementById("searchresults"));
	
	var web = new google.search.WebSearch();
	//web.setUserDefinedLabel(s);
	//web.setSiteRestriction(s);

	searchControl = new google.search.SearchControl();
	searchControl.addSearcher(web, options);	  
	
	// Tell the searcher to draw itself and tell it where to attach
	searchControl.draw(document.getElementById("searchform"));
}

function doSearch(searchTerm) {
	searchControl.execute(searchTerm);
}

function mp3Search () {
	$("#sidebar").html("<h3>Anbieter auswählen:</h3><ul></ul>");
	var sidebar = $("#sidebar ul");
	// Alle Einträge Löschen
	
	
	var allSites = [];
	
	for (var s in search) {
		sidebar.append("<li><a href='"
			+ "javascript:doSearch($(\"#mp3search\").val()+\" site:" + s[0] 
			+ "\");'>" + s[1] + "</a></li>");
		allSites.push('site:'+s[0]); 
	}
	
	sidebar.prepend("<li><a href='javascript:doSearch($(\"#mp3search\").val()+\" "
		+ allSites.join(' OR ')
		+ "\");'>Alle Anbieter</a></li>");
		
	doSearch($("#mp3search").val()+" "+allSites.join(' OR '));
	return false;
}

