
// rotator initializer object;
var startRotator = {
	path: location + 'wp-content/themes/msc/js/rotator.js',
	begin: function(){
		// check if the rotator wrapper is on the page then load and execute the script
		if(jQuery('#rotator_wrapper').length) {
			jQuery.getScript(this.path);
		}
	}
};

function init(){
// ------ *** BEGIN DOM Specific *** ------ //
	
	// add .js clas to html tag
	jQuery('html').addClass('js');
	
	// add first/last classes to menu
	jQuery('#nav li:first').addClass('first');
	jQuery('#nav li:last').addClass('last');

// ------ *** END DOM Specific *** ------ //
	
	// initialize image rotator;
	if($('#rotator').length){
		startRotator.begin();
	}
	
// ------ *** BEGIN Form  *** ------ //
	$('form input').bind('focus', function(){
		$('#msg').hide();
	});

	$('#send').bind('click', function(){
		var str = $('form').serialize(),
			name = $('form #name:input').val(),
			email = $('form #email:input').val(),
			msg = '';
		
		if(name !== '' || email !== ''){
			
			$.ajax({
				type: 'POST', 
				url: 'wp-content/themes/msc/form.php', 
				data: str, 
				success: test
			});
			
		}else{
		 	$('#msg').text('Please enter your email or name').show();
		}
		
		return false;
	});
	
	function test(serverResponse){
		$('#contact-content form').fadeOut().delay(3000).fadeIn();
		$('#contact-form form #name:input').val('');
		$('#contact-form form #email:input').val('');
		$('#contact-form form #message:input').val('');
		$('#contact-form #success').text(serverResponse).fadeIn().delay(3000).fadeOut();
	}
// ------ *** End Form  *** ------ //

// ------ *** BEGIN Sermon Widget  *** ------ //

 if($('#sermon_widget').length){
	
	var state = false;
 
 	$('#sermon_widget div.play-btn a').bind('click', function(){
 		
 		if(state === false){
			$('#player').append('<span id="jquery_jplayer_1"></span>');
 			$('#sermon_widget div.play-btn a').text('Stop').addClass('pause');
 			state = true;
 		}else{
			$('#jquery_jplayer_1').remove();
 			$('#sermon_widget div.play-btn a').text('Play').removeClass('pause');
 			state = false;
 		}
		
		var url = $('.play-btn p a').attr('href').replace(location.href, '');
	//console.log($('.play-btn p a').attr('href').replace(location.href, ''));
	//console.log(location.href);
	//var  url = 'wp-content/uploads/2011/02/02.13.11.mp3';
	  $("#jquery_jplayer_1").jmp3({
			  playerpath: "wp-content/themes/msc/flash/",
			  //playerpath: "http://sites:8888/wordpress3/wp-content/themes/msc/flash/",
			  filepath: url,
			  backcolor: "ffffff",
			  forecolor: "000000",
			  width: 1,
			  height: 1,
			  showdownload: "true",
			  autoplay: "true"
		  });

 		return false;
 	});
 }

// ------ *** END Sermon Widget  *** ------ //
}

jQuery(document).ready(function($) {
	init();
	
	/*$("#jquery_jplayer_1").jPlayer({
        ready: function () {
			alert('test');
          $(this).jPlayer("setMedia", {
            mp3: url
           
          });
        },
        swfPath: "http://74.52.92.242/~msconlin/msc_wp/wp-content/themes/msc/js/",
        supplied: "mp3"
    });*/
});
