// Start Config =================================
var partner = "os";

// stat สำหรับตอนที่คลิกแล้วเปิดหน้า mv
var px = new Date().getTime();
var cgn = "NetRadioPartnering";
var cgs = partner;

//stat truehit

var statframe_time1 = "http://truemusic.truelife.com/home/inc/stat.php?pagename=NETRADIO_OS_PLAYER&bgcolor=000000&cgn=Partnering&cgs=NETRADIO_OS_PLAYER";
var statframe_time2 = "http://truemusic.truelife.com/home/inc/stat.php?pagename=NETRADIO_OS_STREAMING&bgcolor=000000&cgn=Partnering&cgs=NETRADIO_OS_STREAMING";

// small ad banner
var adsframe1_time1 = "http://truemusic.truelife.com/home/inc/ad_banner.php?siteid=24&zoneid=90&width=460&height=50&keyword=-";
var adsframe1_time2 = "http://truemusic.truelife.com/home/inc/ad_banner.php?siteid=24&zoneid=90&width=460&height=50&keyword=";

// big ad banner
var adsframe2_time1 = "http://truemusic.truelife.com/home/inc/ad_banner.php?siteid=24&zoneid=218&width=560&height=140&keyword=-";
var adsframe2_time2 = "http://truemusic.truelife.com/home/inc/ad_banner.php?siteid=24&zoneid=218&width=560&height=140&keyword=";

//var nr_partner_player_url = "http://truemusic.truelife.com/home/player/theme_netradio/"+partner+"/index.php";
var nr_partner_player_url = "http://truemusic.truelife.com/home/p/netradio.php";

// End Config =================================

function player_nr_partner_init() /*Net Radio*/
{

	w = new $wmplayer('wmp');
	w.bindevent("PlayStateChange", "w_playstatechange");
	w.bindevent("OpenStateChange", "w_openstatechange_netradio_partner");
	mute_state = w.ismute();
	meta_invalid = true;


	//for load meta data and stream
	//do_load_music_meta(guid,stream_type);

	init_player_nr_partner_buttons()
	load_item_to_singlecontent();
	set_quality_set("audio");
	set_low_quality();	// default
}

function w_play_nr_partner(guid,newwin){
	if (guid != "")
	{
		w_play_nr_partner_item(guid,newwin);
	}
	else
	{
		alert("ไม่พบรหัสเพลง");
	}
}

function w_play_nr_partner_item(guid, newwin)
{
	last_guid = guid;
	if (newwin != null && newwin != "undefined")
			window.open(nr_partner_player_url+"?guid="+last_guid);
	else
			window.location.href = nr_partner_player_url+"?guid="+last_guid;
}

// ใช้ฟังชั่นนี้เวลาคลิกจากหน้าของ partner แล้วเปิด player ของ trueworld  ต้องการเก็บ stat ด้วยว่าเปิดจากหน้า partner กี่ครั้ง
// สำหรับ song player
function w_play_song_songguid_item_ads(guid, newwin)
{
	last_guid = guid;
	cgs = cgs + "_song";
	$("statpartner").src = "http://webstat.truelife.com/webstat/webstat.dll/web?px="+px+"&prj=BB&uri=/&sip=trueworld.truelife.com&WT.ul=th&WT.cd=32&WT.sr=1024x768&WT.jo=Yes&WT.js=Yes&WT.cg_n="+cgn+"&WT.cg_s="+cgs;
	
	if (newwin != null && newwin != "undefined")
	{
		window.open(songplayer_url+"?songguid="+last_guid);
	}
	else
	{
		window.location.href = songplayer_url+"?songguid="+last_guid;
	}
}
// สำหรับ mv player
function w_play_mv_songguid_item_ads(guid, newwin)
{
	last_guid = guid;
	cgs = cgs + "_mv";
	$("statpartner").src = "http://webstat.truelife.com/webstat/webstat.dll/web?px="+px+"&prj=BB&uri=/&sip=trueworld.truelife.com&WT.ul=th&WT.cd=32&WT.sr=1024x768&WT.jo=Yes&WT.js=Yes&WT.cg_n="+cgn+"&WT.cg_s="+cgs;

	if (newwin != null && newwin != "undefined")
	{
		window.open(mvplayer_url+"?songguid="+last_guid);
	}
	else
	{
		window.location.href = mvplayer_url+"?songguid="+last_guid;
	}
}
//********************//
function init_player_nr_partner_buttons()
{
	//$register_button("object name", "normal img", "hover img" , "select img","group")
	//$set_button_handler(bindex, callback_mouseout, callback_hover, callback_selected)
	$register_button("c_back", theme_path+"images/bt1_back.gif", theme_path+"images/bt2_back.gif", theme_path+"images/bt2_back.gif","1");
	$set_button_handler("c_back","","","w_playserverprev");
	$register_button("c_play", theme_path+"images/bt1_play.gif", theme_path+"images/bt2_play.gif", theme_path+"images/bt2_play.gif","1");
	$set_button_handler("c_play","","","w_play");
	$register_button("c_pause", theme_path+"images/bt1_pause.gif", theme_path+"images/bt2_pause.gif", theme_path+"images/bt2_pause.gif","1");
	$set_button_handler("c_pause","","","w_pause");
	$register_button("c_stop", theme_path+"images/bt1_stop.gif", theme_path+"images/bt2_stop.gif", theme_path+"images/bt2_stop.gif","1");
	$set_button_handler("c_stop","","","w_stop");
	$register_button("c_next", theme_path+"images/bt1_next.gif", theme_path+"images/bt2_next.gif", theme_path+"images/bt2_next.gif","1");
	$set_button_handler("c_next","","","w_playservernext");

	$register_button("q_lo", theme_path+"images/audio1_01.gif", theme_path+"images/audio2_01.gif", theme_path+"images/audio2_01.gif","2");
	$set_button_handler("q_lo","","","set_low_quality");
	$register_button("q_me", theme_path+"images/audio1_02.gif", theme_path+"images/audio2_02.gif", theme_path+"images/audio2_02.gif","2");
	$set_button_handler("q_me","","","set_med_quality");
	$register_button("q_hi", theme_path+"images/audio1_03.gif", theme_path+"images/audio2_03.gif", theme_path+"images/audio2_03.gif","2");
	$set_button_handler("q_hi","","","set_hi_quality");
}

/*===open state change===*/

function w_openstatechange_netradio_partner(nstate)
{
	
if (nstate == 13)	// media opened
	{	// show meta from media stream
		
		var content_meta = null;
		try
		{
			var asxTitleJsonEncoded = w.getmediaattribute("asxTitle");
			var asxTitleJson = asxTitleJsonEncoded.replace(/&quot;/img, "\"");

			content_meta = eval('(' + asxTitleJson +')');
		}
		catch (e)
		{
			//content_meta
			alert(e);
		}
		if (content_meta != null)
		{
			if (content_meta.action == "reload") // reload page ,ads
			{
				//alert(content_meta.action);
				w_play(current_id);
			}
			$(station_title_text_name).innerHTML = content_meta.playlistTitle;
			if (content_meta.title != "")
			{
				$(song_title_text_name).innerHTML = content_meta.title;
			}
			else
			{
				$(song_title_text_name).innerHTML ="";
			}

			if (content_meta.artist != "")
			{
				$(artist_title_text_name).innerHTML = "<a class=\"metalink\" href=\""+domain_music+"home/artist.php?guid=" + content_meta.artistGUID +"\" target=\"_blank\">" + content_meta.artist  + "</a>" ;
			}
			else
			{
				$(artist_title_text_name).innerHTML = "";
			}
			$(cp_title_text_name).innerHTML = content_meta.CP;

			$(album_title_text_name).innerHTML = "<a class=\"metalink\" href=\""+domain_music+"home/artist_album.php?guid=" + content_meta.artistGUID +"&album_guid=" + content_meta.albumGUID +"\" target=\"_blank\">" + content_meta.album  + "</a>" ;
			$(next_song_text_name).innerHTML = content_meta.nextContentTitle;
			
			if (content_meta.albumImageURL != "")
			{
				$("thumb").src = content_meta.albumImageURL;
				//alert(content_meta.albumImageURL);
			}
			else
			{
				$("thumb").src = domain_music+"home/player/images/thumb.gif";
			}
			
			if (content_meta.bannerAdSource == "undefined" )
			{
				$("adsframe1").src = adsframe1_time1;
				$("adsframe2").src = adsframe2_time1;
				//$("adsframe3").src = "http://banads.truelife.com/ads/adframe.php?what=zone:9&source=-&target=_blank";
			}
			else{
				$("adsframe1").src = adsframe1_time2+content_meta.bannerAdSource;
				$("adsframe2").src = adsframe2_time2+content_meta.bannerAdSource;
				//$("adsframe3").src = "http://banads.truelife.com/ads/adframe.php?what=zone:9&source="+content_meta.bannerAdSource+"&target=_blank";
			}
			
			
			if (content_meta.isAd == "False" || content_meta.isAd == "false")
			{
				if (isFirstTime)
				{
					
					$("statframe").src = statframe_time1;
					isFirstTime = false;
					statMusicChart_netradio(guid,content_meta.playlistTitle,content_meta.songGroup);
				}
				else
				{
					$("statframe").src = statframe_time2;
				}
			}
		}

	}
}

