/*
 Muusika24.ee javascript
*/
/*
 FLASH
*/

function replacePlayer( locationId, song, key ) {
	swfobject.embedSWF( mediaUrl + "muusika24/flash/player.swf", locationId, "42", "12", "9.0.0", false, {song: song, playerName:locationId, key: key, allowscriptaccess: "always"} );
}

function makePlayerLocation( id, song, key  ){
	try {
		e = document.createElement("<div id="+id+" class=\"sub\" onclick=\"replacePlayer('"+id+"','"+song+"','"+key+"')\" />");
	} catch (er) {
		e = document.createElement("div");
		e.setAttribute("id", id);
		e.setAttribute("class", "sub");
		e.setAttribute("onClick","replacePlayer('"+id+"','"+song+"','"+key+"')");
	}
	t = document.getElementById( id+"Border" ).appendChild( e );
}

function removePlayer( id, song, key  ) {
	document.getElementById( id+"Border" ).innerHTML = "";
	makePlayerLocation( id, song, key );
}

function replaceFlashCom( locationId, sourceUrl ) {
	swfobject.embedSWF( mediaUrl + "muusika24/flash/flash.swf", locationId, "354", "167", "9.0.0", false, {pageUrl: pageUrl, sourceUrl:sourceUrl, allowscriptaccess: "always"} );
}

/*
 -----------------
*/

function toggleDownloadCheckBoxes(link){
	$(".downloadCheckbox").attr('checked', 'checked');
}

var itemMenuShownFor = 0;
function showItemMenu( id, artistName, songName, link, image ) {
	
	
	var itemMenu = $('#itemMenu');
	var location = $('#itemMenuButton_'+id);
	
	
	if( itemMenuShownFor == id ) {
		itemMenuShownFor = 0;
		itemMenu.hide();
		return;
	} else {
		itemMenuShownFor = id;
		itemMenu.show();
	}
	
	var offset = location.offset();
	itemMenu.css('left',offset.left);
	itemMenu.css('top',offset.top+19)
	
	var title = "";
	if( artistName ) {
		title = artistName+" - ";
	}
	title += songName;
	
	if( image ) {
		image = uploadUrl+image
	} else {
		image = mediaUrl+"/muusika24/defaultArtist.PNG";
	}
	
	var infoLink = $('#itemMenuInfoLink');
	infoLink.get(0).href = pageUrl+link;
	
	var addToCartLink = $('#itemMenuAddToCart');
	addToCartLink.get(0).href = currentUrl+"&addToCart="+id;
	
	var twitterLink = $('#itemMenuTwitterLink');
	twitterLink.get(0).href = "http://twitter.com/home?status="+title+" "+pageUrl+link;
	
	
	var facebookLink = $('#itemMenuFacebookLink');
	facebookLink.get(0).href = "http://www.facebook.com/sharer.php?u="+pageUrl+link+"&t="+title+"";
	
	var orkutLink = $('#itemMenuOrkutLink');
	orkutLink.get(0).href = "http://promote.orkut.com/preview?nt=orkut.com&tt="+title+"&du="+pageUrl+link+"&tn="+image;
}

/*
 SEARCH BOX
*/

function openSearchBox() {
	sbe = document.getElementById("searchOptions");
	clearTimeout(sbe.timeOut);
	
	ssb = document.getElementById("searchSelectButton");
		
	sbe.style.display = "";
	var top = ssb.offsetHeight;
	var left = ssb.offsetWidth;
			
	for (; ssb; ssb = ssb.offsetParent){
		top+= ssb.offsetTop;
		left += ssb.offsetLeft;
	}
	sbe.style.left = left+"px";
	sbe.style.top = top+"px";	
}
		
function closeSearchBox() {
	sbe = document.getElementById("searchOptions");
	sbe.timeOut = setTimeout("document.getElementById('searchOptions').style.display = 'none';", 200);
}
function setSearchType( value, textValue ) {
	document.getElementById("searchType").value = value;
	document.getElementById("searchTypeValue").innerHTML = "&nbsp;"+textValue;
}
		
function searchLetter( letter, webSitePart ) {
	document.getElementById("searchWord").value = letter;
	a = setTimeout('doSearch(\''+webSitePart+'\')',200);
}
		
function testEnter( e, webSitePart ){
	var key = (navigator.appName == "Netscape") ? e.which : e.keyCode;
	if( key == 13 ) {
		doSearch( webSitePart );
	}
}
		
function doSearchByStyle( style, webSitePart ) {
	window.location = pageUrl+webSitePart+"/otsing/&fromTypes="+document.getElementById('searchType').value+"&word="+document.getElementById('searchWord').value+"&styles="+style;
}

function doSearchByType( type, webSitePart ) {
	window.location = pageUrl+webSitePart+"/otsing/&fromTypes="+document.getElementById('searchType').value+"&word="+document.getElementById('searchWord').value+"&types="+type;
}
		
function doSearch( webSitePart ) {
	//if( webSitePart == 'Audio') {
	//	window.location = pageUrl+webSitePart+"/otsing/&from="+document.getElementById('searchType').value+"&word="+document.getElementById('searchWord').value;
	//} else {
		window.location = pageUrl+webSitePart+"/otsing/&fromTypes="+document.getElementById('searchType').value+"&word="+document.getElementById('searchWord').value;

	//}
}
