$(document).ready(function() {

	$("body").click(function(){
		$(".menu, .modal").fadeOut("100");
	});

	/**
	 *  Corrections for CSS
	 * 
	 */

	$("#home-featured .quarter:nth-child(3)").addClass("last");
	$("#home-store .home-store-item:nth-child(4)").addClass("last");
	$(".single-post p:first").addClass("intro");
	
	$('.home-store-item-info h5 a span').each(function(index) {
		var str = $(this).html();
		$(this).html( str.replace(/.00/gi, "").replace("$ / ", "") );
		//alert(str);
	});
	
	$('.sidebar-store-item-info h5 span').each(function(index) {
		var str = $(this).html();
		$(this).html( str.replace(/.00/gi, "").replace("$ / ", "") );
		//alert(str);
	});
	
	$(".scroll").click(function(event){
			//alert("scroll");
			//prevent the default action for the click event
			event.preventDefault();
	
			//get the full url - like mysitecom/index.htm#home
			var full_url = this.href;
	
			//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
			var parts = full_url.split("#");
			var trgt = parts[1];
	
			//get the top offset of the target anchor
			var target_offset = $("#"+trgt).offset();
			var target_top = target_offset.top;
			
			//alert(target_top);
			
			//goto that anchor by setting the body scroll top to anchor top
			$('html, body').animate({scrollTop:target_top}, 1500, "easeOutQuad");
			location.hash = trgt;
		});
		
	/**
	 * 
	 *  Home Store Music Player
	 * 
	 */


	$("#home-store-player").jPlayer({
		ready: function () {
			//$(this).jPlayer("setMedia", {
				//mp3: "content/audioclip.mp3"
			//});
		},
		ended: function (event) {
			//$(this).jPlayer("play");
			$('.home-store-item-preview').addClass('play').removeClass('pause').removeClass('active').delay(2000).fadeOut(2000);
		},
		solution: 'html,flash',
		swfPath: "/wp-content/themes/rabbitroom/js/jplayer",
		supplied: "mp3",
		preload: 'metadata',
		volume: 0.8,
		muted: false,
		backgroundColor: '#000000',
		cssSelectorAncestor: '#home-store',
		cssSelector: {
			//videoPlay: '.jp-video-play',
			play: '.jp-play',
			//pause: '.jp-pause',
			//stop: '.jp-stop',
			//seekBar: '.jp-seek-bar',
			//playBar: '.jp-play-bar',
			//mute: '.jp-mute',
			//unmute: '.jp-unmute',
			//volumeBar: '.jp-volume-bar',
			//volumeBarValue: '.jp-volume-bar-value',
			//currentTime: '.jp-current-time',
			//duration: '.jp-duration'
		},
		errorAlerts: false,
		warningAlerts: false
	});

	$(".show-search-modal").click(function(){
		$(".header-search-modal").fadeIn(200);
		return false;
	});

	$(".modal").click(function(e){
		e.stopPropagation();
	});

	$(".home-store-item-preview").click(function(){
		if ( $(this).hasClass("active")===false ) {
			$(".home-store-item-preview.active").addClass('play').removeClass('pause').removeClass('active').delay(2000).fadeOut(2000);
			$(this).addClass("active").addClass("pause");
			$("#home-store-player").jPlayer( "clearMedia" ).jPlayer("setMedia", {mp3: $(this).attr("rel") } ).jPlayer("load").jPlayer("play");
			return false;
		}
		else {
			$(this).addClass('play').removeClass('pause').removeClass('active').delay(2000).fadeOut(2000);
			$.jPlayer.pause();
		}
	});
	

	$('#podcast').jPlayer({
			ready: function () {
			//	$(this).jPlayer("setMedia", {
			//		mp3: "longday.mp3"
			//	});
			},
			
			swfPath: '/wp-content/themes/rabbitroom/js/jplayer',
			solution: 'html,flash',
			supplied: 'mp3',
			preload: 'metadata',
			volume: 0.8,
			muted: false,
			backgroundColor: '#000000',
			cssSelectorAncestor: '#parent',
			cssSelector: {
				videoPlay: '.jp-video-play',
				play: '.jp-play',
				pause: '.jp-pause',
				stop: '.jp-stop',
				seekBar: '.ma_audio_progress_bar_loaded',
				playBar: '.ma_audio_progress_bar_elapsed',
				mute: '.jp-mute',
				unmute: '.jp-unmute',
				volumeBar: '.jp-volume-bar',
				volumeBarValue: '.jp-volume-bar-value',
				currentTime: '.ma_audio_progress_time',
				duration: '.ma_audio_volume'
			},
			errorAlerts: false,
			warningAlerts: false
		});
		
		
		$(".ma_audio_play_pause").click(function(){
			if ( $(this).hasClass("active")===false ) {
				$(".ma_audio_play_pause").removeClass("active").removeClass("playing");
				$("#podcast").jPlayer( "clearMedia" ).jPlayer("setMedia", {mp3: $(this).attr("rel") } ).jPlayer("load").jPlayer("play");
				$(this).addClass('playing').addClass('active');
				var parent = "#" + $(this).parents(".ma_audio_controller").attr("id");
				//alert(parent);
				$("#podcast").jPlayer("option", "cssSelectorAncestor", parent);
			}
			else if ( $(this).hasClass("playing")===false ) {
				$(this).addClass('playing').addClass('active');
				//$("#player").jPlayer( "clearMedia" ).jPlayer("setMedia", {mp3: $(this).attr("rel") } ).jPlayer("load").jPlayer("play");
				$("#podcast").jPlayer("play");
				return false;
			}
			else {
				$(this).removeClass('playing');
				$.jPlayer.pause();
			}
		});




	var storeHoverConfig = {    
	     over: showStoreDetail, // function = onMouseOver callback (REQUIRED)    
	     timeout: 800, // number = milliseconds delay before onMouseOut    
	     out: hideStoreDetail // function = onMouseOut callback (REQUIRED)    
	};
	
	$(".home-store-item").hoverIntent( storeHoverConfig );

});

function replaceZeros(){
	var str = $("#home-store .home-store-info h5 span").html();
	 str.replace(".00", "");
}


function showStoreDetail(){
	$(this).children(".home-store-item-info").fadeIn();
	$(this).children(".home-store-item-preview").delay(200).fadeIn(800);
}

function hideStoreDetail(){
	$(this).children(".home-store-item-info").fadeOut("slow");
	$(this).children(".home-store-item-preview:not(.active)").fadeOut("slow");
}





