
// search validation
function search() {
    var keywords = $('keywords').value;

    if ( keywords.length < 1 || keywords == 'Enter your search here' ) {
        alert('Please enter a search phrase.');
    } else {
        keywords = keywords.replace(/ /,'+');
        window.location = '/search.php?keywords=' + keywords;
    }
}

// show the player for an episode
function play( id, type, url, podcastId, episodeId ) {
    //alert(id);
    if ( $(id).style.display == 'block' ) {
        $(id).innerHTML = '';
        $(id).hide();
        return;
    }
    
    // send request to log-action.php
    new Ajax.Request('/log-action.php',{method: 'post',parameters: 'mode=view&podcastId=' + podcastId + '&episodeId=' + episodeId });
    
    if ( type == 'audio' ) {
        
        var swfobj = new SWFObject('/swf/player.swf','audioplayer',300,48,8,'#FFFFFF');
        
        swfobj.addParam('quality','high');
        swfobj.addParam('menu','false');
        swfobj.addVariable('soundFile',url);
        swfobj.addVariable('playerID','1');
        swfobj.addVariable('bg','0xf8f8f8');
        swfobj.addVariable('leftbg','0xeeeeee');
        swfobj.addVariable('lefticon','0x666666');
        swfobj.addVariable('rightbg','0xcccccc');
        swfobj.addVariable('rightbghover','0x999999');
        swfobj.addVariable('righticon','0x666666');
        swfobj.addVariable('righticonhover','0xFFFFFF');
        swfobj.addVariable('text','0x666666');
        swfobj.addVariable('slider','0x666666');
        swfobj.addVariable('track','0xFFFFFF');
        swfobj.addVariable('border','0x666666');
        swfobj.addVariable('loader','0x9FFFB8');
        swfobj.addVariable('autostart','yes');

        $(id).innerHTML = swfobj.getSWFHTML() + '<br /><br /><a style="font-size:11px;color:#666;" href="javascript:void(0);" onclick="$(\'' + id + '\').hide()">(Close Player)</a>';
        $(id).style.display = 'block';
        
    } else if ( type == 'video' ) {
        
        var qt = new QTObject(url, "player", "360", "240");
        
		qt.addParam("autostart", "true");

		var html = qt.getHTML() + '<br /><br /><a style="font-size:11px;color:#666;" href="javascript:void(0);" onclick="$(\'' + id + '\').hide()">(Close Player)</a>';
        
        $(id).innerHTML = html;
        $(id).style.display = 'block';
    }
}

// subscribe to a podcast
function subscribe( title, feed, podcastId ) {
    
    new Ajax.Request('/log-action.php',{method: 'post',parameters: 'mode=subscribe&podcastId=' + podcastId });
    
	var nav = navigator.userAgent.toLowerCase();
	
	if ( nav.indexOf('macintosh') < 0 ) {
		// if windows, use pcast file jsp
		window.open('/pcast.php?feed=' + feed + '&title=' + title);
	} else {
	    feed = unescape(feed);
		// if mac & firefox, use pcast protocol
		if ( nav.indexOf('firefox') > -1 ) {
			feed = feed.replace("http://","itpc://");
			window.location = feed;
		} else if ( nav.indexOf('safari') > -1 ) {
			feed = feed.replace("http://","pcast://");
			window.location = feed;
		}
	}
}

