    /* Player functions */
	var playerWindow = null;
    var WINDOW_OPTIONS = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=744, height=526';
    
    function openPlayerWindow(playerOptions, playerCommand)
    {
    	playerWindow = open ( "", "playerWindow", WINDOW_OPTIONS);
		if (!playerWindow || playerWindow.closed || !playerWindow.bpropPlaySong ) {
			playerWindow = window.open(playerOptions,'playerWindow',WINDOW_OPTIONS)
		} else { playerWindow.focus(); playerCommand(); }
    }
    
	function playsong(id) {	
        new Ajax.Request('/explicit_play_song.ashx?id='+id);        
		openPlayerWindow('player/player.aspx?songId=' + id, function() { playerWindow.bpropPlaySong(id); });
	}

	function playRecommended(startingIndex) {
	    openPlayerWindow('player/player.aspx?recommended=' + startingIndex, function() { playerWindow.bpropPlayRecommended(startingIndex); });
	}

	function playSongs(name, ids) {
		openPlayerWindow('player/player.aspx?externalPlaylist=' + name + '&songIds=' + ids,
		 function() { playerWindow.bpropPlayExternalList(name, ids); });
	}

	function getMovieName(movieName) {
	    if (navigator.appName.indexOf("Microsoft") != -1) {
	        return window[movieName]
	   }
	   else {
	       return document[movieName]
	   }
	}
	
	/* AJAX Song Paging */
	function getNextSongs() {
	    this.page = (this.page == undefined) ? 2 : this.page + 1;
	    
	    new  Ajax.Updater('songs', window.location.pathname, {
	        method: 'get',
	        parameters: (window.location.search + "&moreSongs="+page)
	        });
	        
	    swapAds();
	}
	
    function getPreviousSongs() {
	    this.page = (this.page == undefined) ? 1 : this.page - 1;
	    
	    new  Ajax.Updater('songs', window.location.pathname, {
	        method: 'get',
	        parameters: (window.location.search + "&moreSongs="+page)
	        });
	   
	    swapAds();
	}
	
	/* AJAX Similars Paging */
	function getNextSimilars() {
	    this.page = (this.page == undefined) ? 2 : this.page + 1;
	    
	    new  Ajax.Updater('similars', window.location.pathname, {
	        method: 'get',
	        parameters: (window.location.search + "&moreSimilars="+page)
	        });
	        
	    swapAds();
	}
	
    function getPreviousSimilars() {
	    this.page = (this.page == undefined) ? 1 : this.page - 1;
	    
	    new  Ajax.Updater('similars', window.location.pathname, {
	        method: 'get',
	        parameters: (window.location.search + "&moreSimilars="+page)
	        });

	    swapAds();
	}

	function swapAds() {
	
	    $('topAd').src = $('topAd').src.replace(/cb=[a-zA-Z0-9-_]+(&.*)?/, 'cb='+Math.floor(Math.random()*99999999999)+'$1');
	    $('bottomAd').src = $('topAd').src.replace(/cb=[a-zA-Z0-9-_]+(&.*)?/, 'cb='+Math.floor(Math.random()*99999999999)+'$1');
	    
	    // sometimes the bottomRightAd does not exist
	    if ($('bottomRightAd') != undefined) {
	        $('bottomRightAd').src = $('bottomRightAd').src.replace(/cb=[a-zA-Z0-9-_]+(&.*)?/, 'cb='+Math.floor(Math.random()*99999999999)+'$1');
	    }
	    
	    /*
	    new Ajax.Updater('topAd', 'top_ad.aspx', {
	        method: 'get',
	        evalScripts: true
	    });
	    
	    new Ajax.Updater('bottomAd', 'bottom_ad.aspx', {
	        method: 'get',
            evalScripts: true
	    });
	    
	    new Ajax.Updater('bottomRightAd', 'bottomRight_ad.aspx', {
	        method: 'get',
            evalScripts: true
	    }); */
	}
	
	/* AJAX Video Paging */
	function getNextVideos() {
	    this.videoPage = (this.videoPage == undefined) ? 2 : this.videoPage + 1;	    

	    new  Ajax.Updater('videoList', window.location.pathname, {
	        method: 'get',
	        parameters: (window.location.search + "&moreVideos="+videoPage)
	        });
	}
	
    function getPreviousVideos() {
	    this.videoPage = (this.videoPage == undefined) ? 1 : this.videoPage - 1;
	    
	    new  Ajax.Updater('videoList', window.location.pathname, {
	        method: 'get',
	        parameters: (window.location.search + "&moreVideos="+videoPage)
	        });
    }
    
    /* Video updating */
    function getNextVideo() {
        this.videoIndex = (this.videoIndex == undefined) ? 1 : this.videoIndex + 1;
        
        new Ajax.Updater('videoDescription', window.location.pathname, {
            method: 'get',
            parameters: (window.location.search + "&showVideo="+videoIndex),
            evalScripts: true
            });
    }
    
    function getPreviousVideo() {
        this.videoIndex = (this.videoIndex == undefined) ? 0 : this.videoIndex - 1;
        
        new Ajax.Updater('videoDescription', window.location.pathname, {
            method: 'get',
            parameters: (window.location.search + "&showVideo="+videoIndex),
            evalScripts: true
            });
    }
    
    function getSpecificVideoIndex(index) {
        this.videoIndex = index;
        
        new Ajax.Updater('videoDescription', window.location.pathname, {
            method: 'get',
            parameters: (window.location.search + "&showVideo="+videoIndex),
            evalScripts: true
            });
    }
    
    /* Updating video controls */
    var videoPlayerReady = false
    function setVideoReady() {
        videoPlayerReady = true
    }
    
    function setForwardButtonState(state) {
        if (!videoPlayerReady) {
		    setTimeout(function() { setForwardButtonState(state) },1000);
	    }
	    else {
		    getMovieName("BpropVideoPlayer").setForwardButtonState(state)
	    }
    }
    
    function setBackButtonState(state) {
        if (!videoPlayerReady) {
		    setTimeout(function() { setBackButtonState(state) },1000);
	    }
	    else {
		    getMovieName("BpropVideoPlayer").setBackButtonState(state)
	    }
    }
    
    function loadVideo(flvFile, previewUrl) {
        if (!videoPlayerReady) {
		    setTimeout(function() { loadVideo(flvFile, previewUrl) },1000);
	    }
	    else {
		    getMovieName("BpropVideoPlayer").loadVideo(flvFile, previewUrl)
	    }
    }
    
    function downloadSong(id) {
        pageTracker._trackPageview('/downloads/'+id);
        swapAds();
        setTimeout(function() {OnFreeSong(id)}, 1500);
    }
    
	function OnBuySong( url )
	{
		if( url == "" )
			ShowPanel( "no_buy_cd", true )
		else
			OnPopupSite( url )
	}

	var g_song_id=0;
	var g_song_file="";
	var g_menu = ""

	function OnListenMenu( id, can_download )
	{
		g_song_id = id
		if( can_download )
			g_menu = "listen_menu_dl"
		else
			g_menu = "listen_menu"
			
		ShowPanel( g_menu, true )
	}
	

	function OnListenRemoteMenu( id, file, can_download )
	{
		g_song_id = id
		g_song_file = file
		if( can_download )
			g_menu = "listen_menu_remote_dl"
		else
			g_menu = "listen_menu_remote"
			
		ShowPanel( g_menu, true )
	}

	function OnMenuListenLo()
	{
		ShowPanel( g_menu, false )
		if( g_song_id > 0 )
			OnListenSong( g_song_id, "lo" )
		g_song_id = 0
	}
	
	function OnMenuListenHi()
	{
		ShowPanel( g_menu, false )

		if( g_song_id > 0 )
			OnListenSong( g_song_id, "hi" )
		g_song_id = 0
	}
	
	function OnMenuListenRemote()
	{
		ShowPanel( g_menu, false )
		
		if( g_song_file != "" )
			OnListenRemote( g_song_file )
		g_song_file = ""

	}
	
	function OnMenuDownload()
	{
		ShowPanel( g_menu, false )

		if( g_song_id > 0 )
			OnFreeSong( g_song_id )

	}
	function OnMenuAdd()
	{
		ShowPanel( g_menu, false )

		if( g_song_id > 0 )
			OnSaveSong( g_song_id )
	}

	function OnListenSong( id, quality )
	{
		if( id > 0 )
		{
			playsong(id)
		}
	}
	
	function OnListenRemote( file )
	{
		if( file != "" )
		{
			var i_frame = GetElement( "music_player" )

			i_frame.src = file
			ShowPanel( "listen_song", true )
			setTimeout( "OnListenTimer()", 5000 )
		}
	}
	
	function ValidateSearch()
	{
		var entry = new String( document.search_form.search_text.value )
		alert( entry )
		
	}
	
	function OnListenTimer()
	{
		ShowPanel( "listen_song", false )
	}
	
	function OnPopupSite( url )
	{
		if( url != "" )
		{
			var url_str = new String( url )
			url_str.toLowerCase()
		
			if( url_str.slice( 0, 7 ) != "http://" )
				url_str = "http://"+url_str
			var popUpWin = window.open( url_str, "bp", "location=yes,toolbar=yes,resizable=yes,status,menubar=yes,scrollbars=yes,width=800,height=480" )
			popUpWin.focus()
		}
	}
	
	
	function OnAlbumImage( file_name )
	{
		var name_str = new String( file_name )
		name_str = name_str.replace( "_60.jpg", "_480.jpg" )
		var popUpWin = window.open( "http://betterpropaganda.com/images/artwork/"+name_str, "album_image", "resizable=yes,status,menubar=no,scrollbars=no,width=500,height=500" )
		popUpWin.focus()
	}
	
	function NoFreeSong()
	{
		ShowPanel( "stream_only", true )
	}
	
	function OnFreeSong( id )
	{
		location.href = "/mp3_download.ashx?id="+id
	}
	
	function OnSaveSong( id )
	{
		var i_frame = GetElement( "music_player" )
		i_frame.src = "/_save_song.asp?id_song="+id
	}
	
	function OnSongSaved()
	{
		ShowPanel( "song_saved", true )
	}
	
	
	//' redirect to same page, using "more" to indicate expanded content id	
	function OnContent( id_content )
	{
		var url = new String( location.href )
		var idx1 = url.indexOf( "genre=" )
		var id_genre=0
		if( idx1 > 0 )
			id_genre = parseInt( url.substring( idx1+6 ) )
		var idx2 = url.indexOf( ".asp" )
		if( idx2 < 4 )
			url = location.href
		else
			url = url.slice( 0, idx2+4 )
		
		location.href = "home_page.asp?more="+id_content+"&genre="+id_genre
	}
	
 	
	function OnRegister()
	{
		var url = new String( location.href )
		location.href = "registration.asp?url="+url
	}

	function OnBpRadio()
	{
		ShowPanel( "bp_radio", true )
	}
		
	function OnBpRadioPlay( id, quality )
	{
		if( id >= 0 )
		{
			//location.href = "downloads/playlists/BP_radio_"+id+".m3u"
			location.href = "_play_radio.asp?genre="+id+"&quality="+quality
		}
		ShowPanel( "bp_radio", false )
	}
	
	function GetElement(item) 
	{
		if (document.all) return(document.all[item]);
		if (document.getElementById) return(document.getElementById(item));
		return(false);
	}	

	function ShowPanel( div_id, show_it )
	{
		var panel_div
		
		panel_div = GetElement( div_id )
		panel_div.style.top = document.body.scrollTop+100
		if( show_it )
			panel_div.style.visibility = "visible"	
		else
			panel_div.style.visibility = "hidden"	
	}

	function OnStream( form )
	{	
		var f = eval( "document.f_"+form )
		f.stream_rate.value = "high"
		var songArray = new Array()
		var i = 1
		while (eval("f.song_" + i) != null) {
			songArray = songArray.concat(eval("f.song_" + i).value)
			i++
		}
		playSongs(f.stream_type.value, songArray)
	}
	
	function OnStreamHigh( form )
	{	
		OnStream(form)
	}

	function AD( image_file, url )
	{
		this.image = image_file
		this.url = url
		this.selected = false
	}
	var ad_ary = new Array()
	
	
	function OnAdTimer()
	{
		ChangeAd( 1 )
		ChangeAd( 2 )
		setTimeout( "OnAdTimer()", 40000 )
	}
	
	function ChangeAd( ad_num )
	{
		var banner = GetElement( "banner"+ad_num )
		var alink = GetElement( "alink"+ad_num )
		var file, idx
		
		if( banner == null )  return 
		var old_idx = FindBanner( banner.src )
		
		do
		{  
			idx = parseInt( Math.random()*(ad_ary.length) )
			file = ad_ary[ idx ]
		}
		while( ad_ary[idx].selected == true )
		//alert( "old id = "+old_idx+", new id = "+idx )
		ad_ary[idx].selected = true
		banner.src = "/images/axs/"+ad_ary[idx].image
		alink.href = "javascript:OnPopupSite( '"+ad_ary[idx].url+"' )"
		if( old_idx > -1 )
			ad_ary[old_idx].selected = false
	}
	
	function FindBanner( file_name )
	{
		var i
		var file_str = new String( file_name )
		file_str = file_str.slice( file_str.indexOf( "/images/axs/" )+11 )
		for( i=0; i<ad_ary.length; i++ )
		{
			if( ad_ary[i].image == file_str )
				return i
		}
		return -1
	}