//Global
	var url = location.href;
	var obj_array;
	var first_time = true;
	var intervalID=0;
	var clt_updatetime = 0;
    var client = new APE.Client; // Push Client
	var rpxJsHost = (("https:" == document.location.protocol) ? "https://" : "http://static.");
	document.write(unescape("%3Cscript src='" + rpxJsHost + "rpxnow.com/js/lib/rpx.js' type='text/javascript'%3E%3C/script%3E"));
	  var rel_scrollerParam = {
					num_display:3,
					slide_width:180,
					slide_height:99,
					slide_margin:1,
					button_width:30,
					ctrl_height:20,
					margin:10,
					auto_scroll:true,
					delay:40000,
					scroll_speed:1000,
					easing:"",
					move_one:false,
					ctrl_type:"index",
					display_buttons:false,
					display_scrollbar:false,
					display_indexes:true,
					display_caption:true,
					mouseover_caption:true,
					caption_align:"bottom",
					caption_position:"inside",
					cont_nav:true,
					shuffle:false,
					lightbox_on:false
				};

	var modal_fav_login_opt = {
		title: "Please login",
		resizable: false,
		width:600,
		modal: true,
		autoOpen: false,
		buttons: {
			'Login | Register': function() {
				login();
				$(this).dialog('close');
			},
			'Cancel': function() {
				$(this).dialog('close');
			}
		}
	};

	var inited_modal_windows = new Array();


function tinyMCEInit(){
		var save = (rpx_logged !== false)?'save,':'';
		$("#note_form").submit = false;
		tinyMCE.init({
			// General options
			mode : "textareas",
			theme : "advanced",
			plugins : "safari,pagebreak,style,layer,ajaxsave,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount",
			width : "100%",
			height : "275",


			setup : function(ed) {
				if(!rpx_logged){
					ed.onClick.add(function(ed) {
					  $('#modal_login',window.parent.document).dialog("destroy");
						$('#modal_register').dialog({
							title: "Please login",
							width:"400",
							modal: true,
							autoOpen: false,
							buttons: {
								'Login | Register': function() {
									login();
									$(this).dialog('close');
								},
								'Cancel': function() {
									$('#modal_register').dialog('close');
								}
							}
						});
						$('#modal_register').dialog("open");
					});
				}
				ed.onInit.add(function(ed) {
					ed.ajaxpath 	= '/ajax/notes.php';
					ed.ajaxtype 	= 'json';
					ed.ajaxCallback = 'notes_success';
					ed.ajaxobj 		= {
										act			:	'saveNotes',
										posting_id	:	posting.id
										};

				});


			},
			// Theme options
			theme_advanced_buttons1 : save+"print,|,undo,redo,|,bold,italic,underline,strikethrough,|,formatselect,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "cut,copy,paste,|,bullist,numlist,|,outdent,indent,blockquote,link,unlink,anchor,cleanup,preview,|,forecolor,backcolor,|,charmap,emotions,iespell",
			theme_advanced_buttons3 : "justifyleft,justifycenter,justifyright,justifyfull,|,fullscreen,advhr",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : false,


			// Drop lists for link/image/media/template dialogs
			template_external_list_url : "lists/template_list.js",
			external_link_list_url : "lists/link_list.js",
			external_image_list_url : "lists/image_list.js",
			media_external_list_url : "lists/media_list.js",

			// Replace values for the template plugin
			template_replace_values : {
				username : "Some User",
				staffid : "991234"
			}
		});

	}

function notes_success(){
	alert('Note has been saved!');
}

function getTabNumber(){
	var n = $('div#tabs-archive ul.ui-tabs-nav li').index($("#"+show_tab));
	if(n==-1) n = 0;
	return n;
}

function RemoveTab(id){
	$tabs.tabs( "remove" , $('#tabs-ul li').index($('a[href="#'+id+'"]').parent()) );
	$tabs.tabs( "select" ,	$("#tabs-ul li").length-1);
}

function addCategoryTab(categoryNId,categoryName,type,name){
	var id = 's'+categoryNId+'_'+categoryName+'-tab';
	var additional_params = {};

	additional_params.categoryNId 	= categoryNId;
	additional_params.categoryName	= categoryName;
	additional_params.type			= type;


	if($('#'+id).length){
	}
	else{
		$('#tabs-archive').append('<div class="category_tabs" id="'+id+'"></div>');
		$tabs.tabs( "add" ,'#'+id , name  );
		$("#tabs-ul li:last a").append('<span onclick="RemoveTab(\''+id+'\')" class="removetab ui-icon ui-icon-circle-close" style="float:right;  margin: -2px -5px 0 5px; cursor:pointer;"> </span>');
		pager(1,'category',additional_params);
	}

	$tabs.tabs( "select" ,$('#tabs-ul li').index($('a[href="#'+id+'"]').parent()) );


}

var iframeReloaded = false;
		
		/* bible tab iframe reload */
function reloadBibleIframe() {
			
	if (!iframeReloaded) {
		var iframe = $('#bible-tab').find('iframe');
		iframe.attr('src', iframe.attr('src')); // reload iframe
		//alert('reloaded');
		iframeReloaded = true;
	}
}

function openBibleTab()
{
	$('#tabs').tabs( "select" ,$('#tabs li').index($('a[href="#bible-tab"]').parent()) );
	$tabs.tabs( "select" ,$('#tabs-ul li').index($('a[href="#bible-tab"]').parent()) );
	
	reloadBibleIframe();
	
	return false;
}

function getFavorites(type){
	if(rpx_logged){
		pager(1,'favorites', new Object, type);
	}
	else{
		initDialog('modal_fav_login',modal_fav_login_opt);
		if(type == 'mc')
			$( "#modal_fav_login" ).dialog( "option", "width", 500 );
		$('#modal_fav_login').dialog('open');
	}
}

function del_favorite(posting_id){
	$.post('/ajax/ajax_router.php',
		{	'route':'favorites_postings',
			'ic_version':ic_version,
			'act'			: 'deleteFavorite',
			'posting_id'	: posting_id,
		},
		function(data){
			$('#trfavorites_'+posting_id).remove();
		},'json');
}

function add_favorite(){
	if(rpx_logged){
	$.post('/ajax/ajax_router.php',
		{
			'route':'favorites_postings',
			'ic_version':ic_version,
			'act'			:'setFavorite',
			'posting_id'	:posting.id,
			'channel_id'		: channelid
		},
		function(data){
			if(data.result == 1){
				$('#addToFavorites_msg').show();
				setTimeout("$('#addToFavorites_msg').hide()",5000);
			}
			else{ //Dublicate
				$('#addToFavorites_errmsg').show();
				setTimeout("$('#addToFavorites_errmsg').hide()",5000);
			}
		},'json');
	}
	else{
		initDialog('modal_fav_login',modal_fav_login_opt);
		$('#modal_fav_login').dialog('open');
	}
}

function initDialog(id,options){
	if(inited_modal_windows.indexOf(id) == -1){
		$('#'+id).dialog(options);
		inited_modal_windows.push(id);
	}
}

function pager(page,playlist_type,params, widthType){
	var url_params = '';
	for(key in params){
		url_params += '&'+key+'='+params[key];
	}
	
	if (playlist_type == 'series'){
		$.ajax({
		   type: "POST",
		   url: "/ajax/ajax_router.php",
		   data: "route=ic_series_list&playlist_type="+playlist_type+"&page="+page+"&clientid="+clientid+"&channelid="+channelid+url_params + '&ic_version='+ic_version,
		   success: function(out){
				$('#series_container').html(out);
		   }
		});
		
	} else if(playlist_type=='channels'){
		$.ajax({
		   type: "POST",
		   url: "/ajax/ajax_router.php",
		   data: "route=ic_channels_list&playlist_type="+playlist_type+"&page="+page+"&clientid="+clientid+"&channelid="+channelid+url_params + '&ic_version='+ic_version,
		   success: function(out){
				$('#channels_container').html(out);
		   }
		});
	}
	else if(playlist_type=='favorites'){
		$.post('/ajax/ajax_router.php',
		{
			'route':'favorites_postings',
			'ic_version':ic_version,
			'act':'getFavorites',
			'page':page
		},
		function(data){
			$("#favorites_dialog").html(data);
			var dialog_options = {
						autoOpen: false,
						bgiframe: true,
						resizable: false,
						width:600,
						modal: true,
						overlay: {
							backgroundColor: '#000',
							opacity: 0.5
						}
					};
			initDialog('favorites_dialog',dialog_options);
			if(widthType == 'mc')
				$( "#favorites_dialog" ).dialog( "option", "width", 500 );
			$('#favorites_dialog').dialog('open');
		},'html');
	}
	else{
		$.ajax({
		   type: "POST",
		   url: "/ajax/ajax_router.php",
		   data: "route=ic_playlist&playlist_type="+playlist_type+"&page="+page+"&clientid="+clientid+"&channelid="+channelid+url_params+"&current_posting_id="+posting.id  + '&ic_version='+ic_version,
		   success: function(out){
				if(playlist_type=='category'){
					var id = 's'+params.categoryNId+'_'+params.categoryName+'-tab';
					$('#'+id).html(out);
				}
				else{
					$('#table_container').html(out);
				}
		   }
		});
	}
}

$(document).ready(function() {


$('#tabs').tabs({
		collapsible: true,
		selected: 0
	});

$('#img-channel-tab').click(function() { // Added click-function for image
	$tabs.tabs('select', $('#tabs-ul li').index($('a[href="#playlist-tab"]').parent())); // Switching
    return false;
});

$('#link-channel-tab').click(function() { // Added click-function for link
	$tabs.tabs('select', $('#tabs-ul li').index($('a[href="#playlist-tab"]').parent())); // Switching
    return false;
});
	
/* reload Bible iframe when the Bible tab is clicked */
$('#tabs').bind('tabsselect', function(event, ui) {

	
	if ($(ui.tab).attr('href') == '#bible-tab') {
		reloadBibleIframe();
	}
		
});

$('#tabs').tabs().find(".ui-tabs-nav").sortable({axis:'x'});


$('#logintabs').tabs();
$("#save_note_in_pdf").click(function(){
	$("#note_form").attr("action","/admin/save_note_to_pdf.php");
	$("#note_form").submit();
});


	$(function() {
	if($( "#tabs-archive" ).length){
		$tabs = $( "#tabs-archive" ).tabs({
					add: function(event, ui) {
						$tabs.tabs('select', '#' + ui.panel.id);
					}
				});

		$tabs.tabs( "select",getTabNumber());


	}
   });

$.cookie('rpxbackurl',window.location, {path: '/', expires: 10});
	// Navigation menu



	$('ul#navigation li').hover(function(){
		$(this).addClass('sfHover2');
	},
	function(){
		$(this).removeClass('sfHover2');
	});


	//Hover states on the static widgets

	$('.ui-state-default').hover(
		function() { $(this).addClass('ui-state-hover'); },
		function() { $(this).removeClass('ui-state-hover'); }
	);

	//Sortable portlets

	$('.sortable .column').sortable({
		cursor: "move",
		connectWith: '.sortable .column',
		dropOnEmpty: false
	});

	if(jQuery.browser.mozilla)
	{
		$(".column").css("-moz-user-select", "-moz-none");
		$(".shareLinkDiv p input").css("-moz-user-select", "all");
	}
	else
	{
		$(".column").disableSelection();
	}


	$(".side_sort").sortable({
		axis: 'y',
		cursor: "move",
		connectWith: '.side_sort'
	});


	//Close/Open portlets
	$(".portlet-header").hover(function() {
		$(this).addClass("ui-portlet-hover");
	},
	function(){
		$(this).removeClass("ui-portlet-hover");
	});

	$(".portlet-header .ui-icon").click(function() {
		$(this).toggleClass("ui-icon-circle-arrow-n");
		$(this).parents(".portlet:first").find(".portlet-content").toggle();
	});


	//Search Button
	$("#search_text_channels,#search_text_postings").keypress(function(event) {
		var key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (key == 13){

		opt = {
				autoOpen: false,
				bgiframe: true,
				resizable: false,
				height:400,
				width:640,
				position:['',110],
				dialogClass: 'custom_dialog',
				modal: true,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				}
			};
		record_search($(this).val(),1);
		$("#search_records").attr('value',$(this).val());
		showModal('search_link_window',opt);
	}
	});
	$("#search_records").keypress(function(event) {
		var key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (key == 13){
			record_search($("#search_records").val(),1);
		}
	});


	// Dialog Link

	$('#open_favorites').click(function(){
		getFavorites();
	});

	$('#open_favorites_mc').click(function(){
		getFavorites('mc');
	});

	//Subscribe link
	$('#subscribe_link').click(function(){
			$('#subscribe').dialog('open');
		return false;
	});


	$('#subscribe').dialog({
		autoOpen: false,
			bgiframe: true,
			resizable: false,
			width:600,
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			}
		});


	//Subscribe link mc
	$('#subscribe_link_mc').click(function(){
		$( "#subscribe" ).dialog( "option", "width", 500 );
		$('#subscribe').dialog('open');
		return false;
	});



	$('#addToFavorites').click(function(){
		add_favorite();
	});

	// Dialog
	$('#modal_echo_login').dialog({
		title: "Please login",
		resizable: false,
		width:600,
		modal: true,
		autoOpen: false,
		buttons: {
			'Login | Register': function() {
				login();
				$(this).dialog('close');
			},
			'Cancel': function() {
				$(this).dialog('close');
			}
		}
	});

	// Donate Link



	$('#modal_confirmation_link').click(function(){
		$('#modal_confirmation').dialog('open');
		return false;
	});

	// Donate Confirmation

		$("#modal_confirmation").dialog({
			autoOpen: false,
			bgiframe: true,
			resizable: false,
			width:500,
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			}
		});

	// Login Link



	$('#modal_login_link').click(function(){
		login();
		return false;
	});



	// Simple drop down menu

	var myIndex, myMenu, position, space=20;


	$(".drop-down li.drop_down_li").hover(function(){
		$("ul",this).slideDown('fast');

		//get the index, set the selector, add class
		myIndex = $(".main1").index(this);
		myMenu = $(".drop-down a.btn:eq("+myIndex+")");
	}, function(){
		$("ul",this).slideUp('fast');
	});


	$("#share_link").click(function(){
		$(this).select();
	});
    // APE CLIENT CONFIGURATION BEGIN
    var channelName = 'record'+posting.id;
	client.load({
			'domain': APE.Config.domain,
			'server': APE.Config.server,
			'identifier': 'action',
			'channel': channelName,
			'transport':2,
			'complete': function(ape){
				ape.addEvent('pipeCreate', function(type, pipe, options){
					pipe.send(color);
				});
			},
			    'scripts': APE.Config.scripts //Scripts to load for APE JSF */
		});
		client.addEvent('load', function() {
			client.core.start({"name":String((new Date()).getTime()).replace(/\D/gi,'')});
		});
        // APE CLIENT CONFIGURATION END
            client.addEvent('raw', function(raw) {
			if (raw.raw == 'call_to_action') {

               // console.log('Receiving CallToAction');
			//	alert('message = ' + raw.data.message);
                var str = raw.data.message;
                pushStr = str;
                str = str.replace(/~/g, "\"");
                str = str.replace(/@@/g, "\\");
		  //alert(str);
				data = jQuery.parseJSON(str);

                if(data.msg=='cltClose'){
					$("#call_to_action").hide();
				}
				else if(data.msg=='cltSame'){
					$("#call_to_action").show();
				}
				else{
                  //  console.log('Updating');
					clt_updatetime = data.updatetime;
					$("#call_to_action").html(data.msg);
					$("#call_to_action").show();
					$("#call_to_action .container").wtScroller(scrollerParam);
				}
			}

            if (raw.raw == 'channel_call_to_action') {
              //  console.log('Receiving ChannelCallToAction');
			//	alert('message = ' + raw.data.message);
                var str = raw.data.message;
                pushStr = str;
		//console.log(str);
                str = str.replace(/~/g, "\"");
                str = str.replace(/@@/g, "\\");
		//fix bag with comma and quot
		str = str.replace(/\\\\&#039/g, "&#039");
		str = str.replace(/\\\\&quot/g, "&quot");
		str = str.replace(/\\\\/g, "\\");
		//alert(srt);
              //  console.log(str);
				data = jQuery.parseJSON(str);
		//console.log(str);
                if(data.msg=='cltClose'){
					$("#call_to_action_ch").hide();
				}
				else if(data.msg=='cltSame'){
					$("#call_to_action_ch").show();
				}
				else{
                  //  console.log('Updating');
					// clt_updatetime = data.updatetime;
					$("#call_to_action_ch .portlet-content").html(data.msg);
					$("#call_to_action_ch").show();
//					$("#call_to_action_ch .container").wtScroller(scrollerParam);
				}
			}

            if (raw.raw == 'liveStarted') {
              //  console.log('Receiving liveStarted');
            }

            if (raw.raw == 'liveStoped') {
              //  console.log('Receiving liveStoped');
            }
		});
		
		
		
		
		
		
		
		

});
var pushStr = '';
function record_search(val,page_number){
		$.post('/ajax/ajax_router.php',
		{
			'route':'search_records',
			'ic_version':ic_version,
			'search_option':val,
			'clientid':clientid,
			'channelid':channelid,
			'page_number':page_number


		},
		function(data){
			var records = data.records;
			if(records.length){
				var html = '<table id="search_result" class="search_result">';
				html += '<thead><tr>'+
								'<th>Artwork</th>'+
								'<th>Title</th>'+
								'<th>Date</th>'+
								'<th>Categories</th>'+
								'<th>Media</th>'+
							'</tr></thead><tbody>';
				for(key in records){
					obj = records[key];
					var media_icons = '';
					var categories = '';
					var location = icampus_channel_url +'/'+ obj.posting.id;
					if(!obj.speaker_name_category) 	obj.speaker_name_category	=	'';
					if(!obj.speaker_name) 			obj.speaker_name			=	'';
					if(!obj.series_name_category) 	obj.series_name_category	=	'';
					if(!obj.series) 					obj.series					=	'';
					if(!obj.scripture_name_category) obj.scripture_name_category	=	'';
					if(!obj.scripture) 				obj.scripture				=	'';


					categories += '<div>' + obj.speaker_name_category + ' ' + obj.speaker_name + '</div>';
					categories += '<div>' + obj.series_name_category + ' ' + obj.series + '</div>';
					categories += '<div>' + obj.scripture_name_category + ' ' + obj.scripture + '</div>';

					if(obj.posting.pdf_file!='' && obj.posting.pdf_file!=null){
						media_icons += '<img src="/images/document-pdf-text.png"/>'
					}
					if(obj.posting.audio_file!='' && obj.posting.audio_file!=null){
						media_icons += '<img src="/images/microphone.png"/>'
					}
					if(obj.posting.video_file!='' && obj.posting.video_file!=null){
						media_icons += '<img src="/images/film.png"/>'
					}
					if(obj.posting.live!='0'){
						media_icons += '<img src="/images/document-clock.png"/>'
					}

					html += '<tr onclick="location.href=\''+location+'\'">'+
								'<td><img width="80px" height="44px" src="'+obj.artwork.path+'" class="search_list_artworks"/></td>'+
								'<td>'+obj.posting.title+'</td>'+
								'<td>'+obj.posting.posted+'</td>'+
								'<td>'+categories+'</td>'+
								'<td>'+media_icons+'</td>'+
							'</tr>';
				}
					html +='</tbody></table>';
					html += '<div class="div_ajax_pager_search" id="div_ajax_pager_search">';
					html += data.pager;
					html += '</div>';

				$("#search_records_result").html(html);
				$("#search_result")
					.tablesorter({
						widgets: ['zebra'],
						headers: {

									0: {

										sorter: false
									},

									3: {

										sorter: false
									}
								}
					});
			}
			else{
				$("#search_records_result").html('<div class="no_results" id="no_results">No matches found</div>');
			}
		},'json');
	}

/* $("#modal_login",window.parent.document).dialog({ */

function login(){
	$("#modal_login",document).dialog({
		autoOpen: false,
		bgiframe: true,
		resizable: false,
		width:500,
		modal: true,
		overlay: {
			backgroundColor: '#93BBFF',
			opacity: 0.5
		}
	});
	$('#modal_login',document).dialog('open');
}

function showModal(id,options){
var opt=(typeof(options)!='undefined')?options:{
				autoOpen: false,
				bgiframe: true,
				resizable: false,
				width:640,
				height:500,
				position:['',110],
				dialogClass: 'custom_dialog',
				modal: true,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				}
			};

	if($("#"+id).length){
		$("#"+id).dialog(opt);
		$("#"+id).dialog('open');
//		$("#"+id).height(max_height);
/*		var max_height = window.screen.height/2;
		if($("#"+id).height() > max_height){
			$("#"+id).height(max_height);
		}*/
	}
}

function turnOffLoader(tab){
			$("#iframe_"+tab).css("visibility","visible");
			$("#loader_"+tab).hide();
}
var scrollerParam = {
					num_display:5,
					slide_width:120,
					slide_height:60,
					slide_margin:1,
					button_width:30,
					ctrl_height:20,
					margin:10,
					auto_scroll:true,
					delay:40000,
					scroll_speed:1000,
					easing:"",
					move_one:false,
					display_buttons:false,
					display_scrollbar:false,
					display_indexes:true,
					display_caption:false,
					mouseover_caption:true,
					caption_align:"bottom",
					caption_position:"inside",
					cont_nav:true,
					shuffle:false,
					lightbox_on:false,
					lightbox:{
							rotate:true,
							delay:4000,
							display_number:true,
							display_timer:true,
							display_caption:false,
							caption_align:"bottom",
							transition_speed:600,
							cont_nav:true,
							auto_fit:true,
							easing:""
					}
				};

function callToAction(sermonid,first){
	//if(develop) return 0; //???? ?? ?????? ??????? ?? ????? ??????????
alert(123);
	var date = new Date();
	$.post('/ajax/ajax_router.php',{
			'route'		: 'call_to_action_publishing',
			'ic_version': ic_version,
			'id_posting': sermonid,
			'updatetime': clt_updatetime,
			'act'		: 'getPublish',
			'first'		: first

		},function(data){
			if(data){
				if(data.msg=='cltClose'){
					$("#call_to_action").hide();
				}
				else if(data.msg=='cltSame'){
					$("#call_to_action").show();
				}
				else{
					clt_updatetime = data.updatetime;
					$("#call_to_action").html(data.msg);
					$("#call_to_action").show();
					$("#call_to_action .container").wtScroller(scrollerParam);
				}
			}
	},'json');



}

function setTimeForAction(sermonid){
	$.post('/ajax/ajax_router.php',{
			'route'		: 'call_to_action_publishing',
			'ic_version': ic_version,
			'id_posting':sermonid,
			'act'		:'getUpdateTime'
		},function(data){

			clt_updatetime = data.updTime;
		},'json');
}

function execCallToAction(sermonid){
    /*
	setTimeForAction(sermonid);
	if(intervalID){
		clearInterval(intervalID);

	}
	callToAction(sermonid,'true');
	intervalID = setInterval("callToAction("+sermonid+",'false')",3000);
    */

}

function setSharelink(sermonid){
	$("#share_link").attr('value',icampus_channel_url+'/'+sermonid);
}

/**************** No flash and Mobile version. Also used in "Now plaing" section in Flash version.****************************/
//Global

var media_type='';
var global_artwork='';
var use_live1 = '';
var first_record = false;
var current_recordid = 0;

function showPdf(sermonid,autoplay){
	media_type = 'pdf';
	if(autoplay=='true'){
		window.open('http://mdsone.com/download.php?c='+clientid+'-count_pdf_download-'+sermonid+'-.pdf,,true,,'+sermonid);

	}
}

function showVideof(sermonid,autoplay,art,time){
	media_type = 'video';
	jwrespond('http://mdsone.com/download.php?c='+clientid+'-count_video_main-'+sermonid+'-.mp4,'+art+',true,'+time+','+sermonid);
	 return false;
}

function showAudiof(sermonid,autoplay,art,time){
	media_type = 'audio';
	jwrespond('http://mdsone.com/download.php?c='+clientid+'-count_audio_main-'+sermonid+'-.mp3,'+art+',true,'+time+','+sermonid);


	 return false;
}

function setShareButtons(recid,title){
	if($(".twitter-share-button").length){
		$(".twitter-share-button").attr("src",'http://platform0.twitter.com/widgets/tweet_button.html?_=1282725842864&count=horizontal&lang=en&text='+title+'&url='+icampus_default_channel_url+'/'+recid);
	}
	if($("#facebook-like-button").length){
		$("#facebook-like-button").attr('src','http://www.facebook.com/plugins/like.php?href='+icampus_default_channel_url+'/'+recid+'&layout=button_count&show_faces=false&action=like&font=arial&colorscheme=light&width=50&height=21');
	}
}

function floadBible(data){

var param = data.split(',');
		if ($('#tabs').length > 0 && (3 !=  $('#tabs').tabs('option', 'selected')))
			$('#tabs').tabs('select', 3);


		if ( bible_version != 'esv') {
			str = param[0];
			param[0] = str.replace('esv', bible_version);
		}
		if(typeof(console) !== 'undefined' && console != null) {


		console.log('floadBible = '+param[0]);
		}
	 $('#bible_reference').attr('src',param[0])
 }

function loadyouversion(bid){
	$('#tabs').tabs('select', (ic_version	== 'default')?4:3);
	var scrip = $(bid).text();
	var art = scrip.match(/(\d){1,3}:(\d){1,3}/g);
	var ind = art[0].split(':');
	scrip = jQuery.trim(scrip);
	var art = scrip.match(/^(\d\s)?(\S)+/g);
	bibleUrl(art[0],ind[0],ind[1],'false');
}


function setRPXSocialButton(recid,data){
	$("#rpx_social").unbind();
	$("#rpx_social").bind('click',function(){RPX1(recid,data.title,data.description,data.artwork);});
}

function RPX1(recid,title,description,artwork){
RPXNOW.init(
			{appId: 'gphnodcajnnmpjlaegfp',
		     xdReceiver: '/rpx_xdcomm.html'}
		 );

 RPXNOW.loadAndRun(['Social'], function () {
	var activity = new RPXNOW.Social.Activity(
		  "Share this with your social network!",
		  "is listening to "+title,
		   icampus_channel_url+'/'+recid);
	   activity.setTitle(title);
				activity.setDescription(description);

				var image = new RPXNOW.Social.ImageMediaCollection()

				image.addImage(artwork,  icampus_channel_url+'/'+recid);
				activity.setMediaItem(image);
	  RPXNOW.Social.publishActivity(activity);
  });

}

var bible_code = new Array();
var bible_title = new Array();

bible_code[0] = 'Gen';
bible_title[0] = 'Genesis';
bible_code[1] = 'Exod';
bible_title[1] = 'Exodus';
bible_code[2] = 'Lev';
bible_title[2] = 'Leviticus';
bible_code[3] = 'Num';
bible_title[3] = 'Numbers';
bible_code[4] = 'Deut';
bible_title[4] = 'Deuteronomy';
bible_code[5] = 'Josh';
bible_title[5] = 'Joshua';
bible_code[6] = 'Judg';
bible_title[6] = 'Judges';
bible_code[7] = 'Ruth';
bible_title[7] = 'Ruth';
bible_code[8] = '1Sam';
bible_title[8] = '1 Samuel';
bible_code[9] = '2Sam';
bible_title[9] = '2 Samuel';
bible_code[10] = '1Kgs';
bible_title[10] = '1 Kings';
bible_code[11] = '2Kgs';
bible_title[11] = '2 Kings';
bible_code[12] = '1Chr';
bible_title[12] = '1 Chronicles';
bible_code[13] = '2Chr';
bible_title[13] = '2 Chronicles';
bible_code[14] = 'Ezra';
bible_title[14] = 'Ezra';
bible_code[15] = 'Neh';
bible_title[15] = 'Nehemiah';
bible_code[16] = 'Esth';
bible_title[16] = 'Esther';
bible_code[17] = 'Job';
bible_title[17] = 'Job';
bible_code[18] = 'Ps';
bible_title[18] = 'Psalms';
bible_code[19] = 'Prov';
bible_title[19] = 'Proverbs';
bible_code[20] = 'Eccl';
bible_title[20] = 'Ecclesiastes';
bible_code[21] = 'Song';
bible_title[21] = 'Song of Solomon';
bible_code[22] = 'Isa';
bible_title[22] = 'Isaiah';
bible_code[23] = 'Jer';
bible_title[23] = 'Jeremiah';
bible_code[24] = 'Lam';
bible_title[24] = 'Lamentations';
bible_code[25] = 'Ezek';
bible_title[25] = 'Ezekiel';
bible_code[26] = 'Dan';
bible_title[26] = 'Daniel';
bible_code[27] = 'Hos';
bible_title[27] = 'Hosea';
bible_code[28] = 'Joel';
bible_title[28] = 'Joel';
bible_code[29] = 'Amos';
bible_title[29] = 'Amos';
bible_code[30] = 'Obad';
bible_title[30] = 'Obadiah';
bible_code[31] = 'Jonah';
bible_title[31] = 'Jonah';
bible_code[32] = 'Mic';
bible_title[32] = 'Micah';
bible_code[33] = 'Nah';
bible_title[33] = 'Nahum';
bible_code[34] = 'Hab';
bible_title[34] = 'Habakkuk';
bible_code[35] = 'Zeph';
bible_title[35] = 'Zephaniah';
bible_code[36] = 'Hag';
bible_title[36] = 'Haggai';
bible_code[37] = 'Zech';
bible_title[37] = 'Zechariah';
bible_code[38] = 'Mal';
bible_title[38] = 'Malachi';
bible_code[39] = 'Matt';
bible_title[39] = 'Matthew';
bible_code[40] = 'Mark';
bible_title[40] = 'Mark';
bible_code[41] = 'Luke';
bible_title[41] = 'Luke';
bible_code[42] = 'John';
bible_title[42] = 'John';
bible_code[43] = 'Acts';
bible_title[43] = 'Acts';
bible_code[44] = 'Rom';
bible_title[44] = 'Romans';
bible_code[45] = '1Cor';
bible_title[45] = '1 Corinthians';
bible_code[46] = '2Cor';
bible_title[46] = '2 Corinthians';
bible_code[47] = 'Gal';
bible_title[47] = 'Galatians';
bible_code[48] = 'Eph';
bible_title[48] = 'Ephesians';
bible_code[49] = 'Phil';
bible_title[49] = 'Philippians';
bible_code[50] = 'Col';
bible_title[50] = 'Colossians';
bible_code[51] = '1Thess';
bible_title[51] = '1 Thessalonians';
bible_code[52] = '2Thess';
bible_title[52] = '2 Thessalonians';
bible_code[53] = '1Tim';
bible_title[53] = '1 Timothy';
bible_code[54] = '2Tim';
bible_title[54] = '2 Timothy';
bible_code[55] = 'Titus';
bible_title[55] = 'Titus';
bible_code[56] = 'Phlm';
bible_title[56] = 'Philemon';
bible_code[57] = 'Heb';
bible_title[57] = 'Hebrews';
bible_code[58] = 'Jas';
bible_title[58] = 'James';
bible_code[59] = '1Pet';
bible_title[59] = '1 Peter';
bible_code[60] = '2Pet';
bible_title[60] = '2 Peter';
bible_code[61] = '1John';
bible_title[61] = '1 John';
bible_code[62] = '2John';
bible_title[62] = '2 John';
bible_code[63] = '3John';
bible_title[63] = '3 John';
bible_code[64] = 'Jude';
bible_title[64] = 'Jude';
bible_code[65] = 'Rev';
bible_title[65] = 'Revelation';

function arraySearch(val,arr) {
    for (var i=0; i<arr.length; i++)
    if (arr[i] == val)
    return i;
    return false;
}
function bibleUrl(scripture_book, ch, vs, open) {

	var book =  arraySearch(scripture_book, bible_title);
	 floadBible('http://m.youversion.com/bible/esv/'+bible_code[book]+'/'+ch+'/'+vs+'/,'+open);

}

function js_array_to_php_array (a)
{
    var a_php = "";
    var total = 0;
    for (var key in a)
    {
        ++ total;
        a_php = a_php + "s:" +
                String(key).length + ":\"" + String(key) + "\";s:" +
                String(a[key]).length + ":\"" + String(a[key]) + "\";";
    }
    a_php = "a:" + total + ":{" + a_php + "}";
    return a_php;
}

function sermonpage (serid,type) {
    $.cookie('currmedia',null);
    var currmedia = [serid,type];
    $.cookie('currmedia', js_array_to_php_array(currmedia), {path: '/', expires: 10});
	if (ic_version!='gvtv') {
    window.location = icampus_channel_url + '/'+serid;
	}else{
	 window.location = icampus_default_channel_url + '/'+serid;}
    return false;
}
