/*
 Muusika24.ee javascript
*/
function replacePlayer( locationId, song, key ) {
	swfobject.embedSWF( mediaUrl + "hot/flash/player.swf", locationId, "17", "18", "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 buyItem( moduleId, id ) {
	//var parameters = {moduleId:moduleId, method:'pr_buyItem', buyId:id};
	//new Ajax.Updater('shopingCartItems',rootPageUrl+'process.php',{parameters: parameters, method:'get'} );
	document.location = "http://muusika24.ee/hot/buyId,"+id;
	//document.getElementById("buyMessage").style.display = "";
}

function closeBuyWindow() {
	document.getElementById("buyMessage").style.display = "none";
}

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

if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	document.writeln('<style type="text/css">img, input.image { visibility:hidden; } </style>');
	window.attachEvent("onload", startUp);
}

function startUp() {
	//IE flash update
	/*objects = document.getElementsByTagName("object");
	for (var i = 0; i < objects.length; i++)
	{
		objects[i].outerHTML = objects[i].outerHTML;
	}*/
	// load png
	fnLoadPngs();
}

function fnLoadPngs() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (itsAllGood && img.src.match(/\.png$/i) != null) {
			fnFixPng(img);
			img.attachEvent("onpropertychange", fnPropertyChanged);
		}
		img.style.visibility = "visible";
	}

	var nl = document.getElementsByTagName("INPUT");
	for (var i = nl.length - 1, e = null; (e = nl[i]); i--) {
		if (e.className && e.className.match(/\bimage\b/i) != null) {
			if (e.src.match(/\.png$/i) != null) {
				fnFixPng(e);
				e.attachEvent("onpropertychange", fnPropertyChanged);
			}
			e.style.visibility = "visible";
		}
	}
}

function fnPropertyChanged() {
	if (window.event.propertyName == "src") {
		var el = window.event.srcElement;
		if (!el.src.match(/x\.gif$/i)) {
			el.filters.item(0).src = el.src;
			el.src = "img/x.gif";
		}
	}
}

function dbg(o) {
	var s = "";
	var i = 0;
	for (var p in o) {
		s += p + ": " + o[p] + "\n";
		if (++i % 10 == 0) {
			alert(s);
			s = "";
		}
	}
	alert(s);
}

function fnFixPng(img) {
	/*var src = img.src;
	img.style.width = img.width + "px";
	img.style.height = img.height + "px";
	img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
	img.src = "templates/images/delfi/x.gif";*/
}



/*
 SEARCH BOX
*/

function doSearchByStyle( style ) {
	window.location = pageUrl+"Eesti/otsing/&type="+document.getElementById('searchType').value+"&word="+document.getElementById('searchWord').value+"&style="+style;
}
		
function doSearch( webSitePart ) {
	window.location = pageUrl+"Eesti/otsing/&type="+document.getElementById('searchType').value+"&word="+document.getElementById('searchWord').value;
}

function testEnter( e, webSitePart ){
	var key = (navigator.appName == "Netscape") ? e.which : e.keyCode;
	if( key == 13 ) {
		doSearch( webSitePart );
	}
}
