/* -------------------------------------------------------------------------------------------------
Script copyright 2010 Performance Audio, LLC. All rights reserved.
------------------------------------------------------------------------------------------------- */

var featureMenuIntervalID			= 0;
var shouldAnimateFeatureMenu		= new Boolean(true);
var selectedAppID					= 1;

$(document).ready(function() {

	$("#post_window_wrapper").hide();
	$("#iphone_screens_main")							.css({"opacity": "1.0"});
	$("#description_wrapper .menuicon-audiotool")		.css({"opacity": "1.0"});
	featureMenuIntervalID			= setInterval( "animateFeatureMenu('#iphone_screens_main')" , 5000 );
	// ---------------------------------------------------------------------------------------------
	$("#iphone_wrapper").mouseenter(function() {
		shouldAnimateFeatureMenu	= false;
	});
	$("#iphone_wrapper").mouseleave(function() {
		shouldAnimateFeatureMenu	= true;
	});
	// AUDIO TOOL
	// ---------------------------------------------------------------------------------------------
	$("#description_wrapper .menuicon-audiotool")		.mouseenter(function() {
		$("#description_wrapper .menuicon-audiotool")	.animate({"opacity": "1.0"}, 350);
	});
	$("#description_wrapper .menuicon-audiotool")		.mouseleave(function() {
		if (selectedAppID != 1) {
			$("#description_wrapper .menuicon-audiotool").animate({"opacity": "0.5"}, 350);
		}
	});
	$("#description_wrapper .menuicon-audiotool")		.click(function() {
		clearInterval(featureMenuIntervalID);
		featureMenuIntervalID							= setInterval( "animateFeatureMenu('#iphone_screens_main')" , 5000 );
		selectedAppID									= 1;
		$("#iphone_screens_main")						.animate({"opacity": "1.0"}, 350);
		$("#iphone_screens_dbmeter")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_tonegen")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_micpro")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audiocalc")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audioatlas")					.animate({"opacity": "0.0"}, 350);
		$("#description_wrapper .selection-arrow")		.animate({"left": "44"}, 350);
		$("#description-bubble ul")						.animate({"left": "0px"}, 350);
		$("#description_wrapper .menuicon-audiotool")	.animate({"opacity": "1.0"}, 350);
		$("#description_wrapper .menuicon-dbmeter")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-tonegen")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-micpro")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audiocalc")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audioatlas")	.animate({"opacity": "0.5"}, 350);
	});
	// DECIBEL METER PRO
	// ---------------------------------------------------------------------------------------------
	$("#description_wrapper .menuicon-dbmeter")			.mouseenter(function() {
		$("#description_wrapper .menuicon-dbmeter")		.animate({"opacity": "1.0"}, 350);
	});
	$("#description_wrapper .menuicon-dbmeter")			.mouseleave(function() {
		if (selectedAppID != 2) {
			$("#description_wrapper .menuicon-dbmeter")	.animate({"opacity": "0.5"}, 350);
		}
	});
	$("#description_wrapper .menuicon-dbmeter")			.click(function() {
		clearInterval(featureMenuIntervalID);
		featureMenuIntervalID							= setInterval( "animateFeatureMenu('#iphone_screens_dbmeter')" , 5000 );
		selectedAppID									= 2;
		$("#iphone_screens_main")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_dbmeter")					.animate({"opacity": "1.0"}, 350);
		$("#iphone_screens_tonegen")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_micpro")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audiocalc")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audioatlas")					.animate({"opacity": "0.0"}, 350);
		$("#description_wrapper .selection-arrow")		.animate({"left": "144"}, 350);
		$("#description-bubble ul")						.animate({"left": "-623px"}, 350);
		$("#description_wrapper .menuicon-audiotool")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-dbmeter")		.animate({"opacity": "1.0"}, 350);
		$("#description_wrapper .menuicon-tonegen")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-micpro")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audiocalc")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audioatlas")	.animate({"opacity": "0.5"}, 350);
	});
	$("#textlink-meter")								.click(function() {
		event.preventDefault();
		clearInterval(featureMenuIntervalID);
		featureMenuIntervalID							= setInterval( "animateFeatureMenu('#iphone_screens_dbmeter')" , 5000 );
		selectedAppID									= 2;
		$("#iphone_screens_main")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_dbmeter")					.animate({"opacity": "1.0"}, 350);
		$("#iphone_screens_tonegen")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_micpro")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audiocalc")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audioatlas")					.animate({"opacity": "0.0"}, 350);
		$("#description_wrapper .selection-arrow")		.animate({"left": "144"}, 350);
		$("#description-bubble ul")						.animate({"left": "-623px"}, 350);
		$("#description_wrapper .menuicon-audiotool")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-dbmeter")		.animate({"opacity": "1.0"}, 350);
		$("#description_wrapper .menuicon-tonegen")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-micpro")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audiocalc")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audioatlas")	.animate({"opacity": "0.5"}, 350);
	});
	// TONE GENERATOR PRO
	// ---------------------------------------------------------------------------------------------
	$("#description_wrapper .menuicon-tonegen")			.mouseenter(function() {
		$("#description_wrapper .menuicon-tonegen")		.animate({"opacity": "1.0"}, 350);
	});
	$("#description_wrapper .menuicon-tonegen")			.mouseleave(function() {
		if (selectedAppID != 3) {
			$("#description_wrapper .menuicon-tonegen")	.animate({"opacity": "0.5"}, 350);
		}
	});
	$("#description_wrapper .menuicon-tonegen")			.click(function() {
		clearInterval(featureMenuIntervalID);
		featureMenuIntervalID							= setInterval( "animateFeatureMenu('#iphone_screens_tonegen')" , 5000 );
		selectedAppID									= 3;
		$("#iphone_screens_main")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_dbmeter")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_tonegen")					.animate({"opacity": "1.0"}, 350);
		$("#iphone_screens_micpro")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audiocalc")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audioatlas")					.animate({"opacity": "0.0"}, 350);
		$("#description_wrapper .selection-arrow")		.animate({"left": "244"}, 350);
		$("#description-bubble ul")						.animate({"left": "-1246px"}, 350);
		$("#description_wrapper .menuicon-audiotool")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-dbmeter")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-tonegen")		.animate({"opacity": "1.0"}, 350);
		$("#description_wrapper .menuicon-micpro")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audiocalc")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audioatlas")	.animate({"opacity": "0.5"}, 350);
	});
	$("#textlink-tonegen")								.click(function() {
		event.preventDefault();
		clearInterval(featureMenuIntervalID);
		featureMenuIntervalID							= setInterval( "animateFeatureMenu('#iphone_screens_tonegen')" , 5000 );
		selectedAppID									= 3;
		$("#iphone_screens_main")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_dbmeter")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_tonegen")					.animate({"opacity": "1.0"}, 350);
		$("#iphone_screens_micpro")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audiocalc")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audioatlas")					.animate({"opacity": "0.0"}, 350);
		$("#description_wrapper .selection-arrow")		.animate({"left": "244"}, 350);
		$("#description-bubble ul")						.animate({"left": "-1246px"}, 350);
		$("#description_wrapper .menuicon-audiotool")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-dbmeter")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-tonegen")		.animate({"opacity": "1.0"}, 350);
		$("#description_wrapper .menuicon-micpro")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audiocalc")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audioatlas")	.animate({"opacity": "0.5"}, 350);
	});
	// MICROPHONE PRO
	// ---------------------------------------------------------------------------------------------
	$("#description_wrapper .menuicon-micpro")			.mouseenter(function() {
		$("#description_wrapper .menuicon-micpro")		.animate({"opacity": "1.0"}, 350);
	});
	$("#description_wrapper .menuicon-micpro")			.mouseleave(function() {
		if (selectedAppID != 4) {
			$("#description_wrapper .menuicon-micpro")	.animate({"opacity": "0.5"}, 350);
		}
	});
	$("#description_wrapper .menuicon-micpro")			.click(function() {
		clearInterval(featureMenuIntervalID);
		featureMenuIntervalID							= setInterval( "animateFeatureMenu('#iphone_screens_micpro')" , 5000 );
		selectedAppID									= 4;
		$("#iphone_screens_main")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_dbmeter")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_tonegen")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_micpro")						.animate({"opacity": "1.0"}, 350);
		$("#iphone_screens_audiocalc")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audioatlas")					.animate({"opacity": "0.0"}, 350);
		$("#description_wrapper .selection-arrow")		.animate({"left": "344"}, 350);
		$("#description-bubble ul")						.animate({"left": "-1869px"}, 350);
		$("#description_wrapper .menuicon-audiotool")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-dbmeter")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-tonegen")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-micpro")		.animate({"opacity": "1.0"}, 350);
		$("#description_wrapper .menuicon-audiocalc")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audioatlas")	.animate({"opacity": "0.5"}, 350);
	});
	$("#textlink-micpro")								.click(function() {
		event.preventDefault();
		clearInterval(featureMenuIntervalID);
		featureMenuIntervalID							= setInterval( "animateFeatureMenu('#iphone_screens_micpro')" , 5000 );
		selectedAppID									= 4;
		$("#iphone_screens_main")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_dbmeter")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_tonegen")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_micpro")						.animate({"opacity": "1.0"}, 350);
		$("#iphone_screens_audiocalc")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audioatlas")					.animate({"opacity": "0.0"}, 350);
		$("#description_wrapper .selection-arrow")		.animate({"left": "344"}, 350);
		$("#description-bubble ul")						.animate({"left": "-1869px"}, 350);
		$("#description_wrapper .menuicon-audiotool")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-dbmeter")		.animate({"opacity": "1.0"}, 350);
		$("#description_wrapper .menuicon-tonegen")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-micpro")		.animate({"opacity": "1.0"}, 350);
		$("#description_wrapper .menuicon-audiocalc")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audioatlas")	.animate({"opacity": "0.5"}, 350);
	});
	// BIT CALC PRO
	// ---------------------------------------------------------------------------------------------
	$("#description_wrapper .menuicon-audiocalc")		.mouseenter(function() {
		$("#description_wrapper .menuicon-audiocalc")	.animate({"opacity": "1.0"}, 350);
	});
	$("#description_wrapper .menuicon-audiocalc")		.mouseleave(function() {
		if (selectedAppID != 5) {
			$("#description_wrapper .menuicon-audiocalc").animate({"opacity": "0.5"}, 350);
		}
	});
	$("#description_wrapper .menuicon-audiocalc")		.click(function() {
		clearInterval(featureMenuIntervalID);
		featureMenuIntervalID							= setInterval( "animateFeatureMenu('#iphone_screens_audiocalc')" , 5000 );
		selectedAppID									= 5;
		$("#iphone_screens_main")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_dbmeter")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_tonegen")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_micpro")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audiocalc")					.animate({"opacity": "1.0"}, 350);
		$("#iphone_screens_audioatlas")					.animate({"opacity": "0.0"}, 350);
		$("#description_wrapper .selection-arrow")		.animate({"left": "444"}, 350);
		$("#description-bubble ul")						.animate({"left": "-2492px"}, 350);
		$("#description_wrapper .menuicon-audiotool")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-dbmeter")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-tonegen")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-micpro")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audiocalc")	.animate({"opacity": "1.0"}, 350);
		$("#description_wrapper .menuicon-audioatlas")	.animate({"opacity": "0.5"}, 350);
	});
	$("#textlink-calc")								.click(function() {
		event.preventDefault();
		clearInterval(featureMenuIntervalID);
		featureMenuIntervalID							= setInterval( "animateFeatureMenu('#iphone_screens_audiocalc')" , 5000 );
		selectedAppID									= 5;
		$("#iphone_screens_main")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_dbmeter")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_tonegen")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_micpro")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audiocalc")					.animate({"opacity": "1.0"}, 350);
		$("#iphone_screens_audioatlas")					.animate({"opacity": "0.0"}, 350);
		$("#description_wrapper .selection-arrow")		.animate({"left": "444"}, 350);
		$("#description-bubble ul")						.animate({"left": "-2492px"}, 350);
		$("#description_wrapper .menuicon-audiotool")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-dbmeter")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-tonegen")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-micpro")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audiocalc")	.animate({"opacity": "1.0"}, 350);
		$("#description_wrapper .menuicon-audioatlas")	.animate({"opacity": "0.5"}, 350);
	});
	// AUDIO ATLAS
	// ---------------------------------------------------------------------------------------------
	$("#description_wrapper .menuicon-audioatlas")		.mouseenter(function() {
		$("#description_wrapper .menuicon-audioatlas")	.animate({"opacity": "1.0"}, 350);
	});
	$("#description_wrapper .menuicon-audioatlas")		.mouseleave(function() {
		if (selectedAppID != 6) {
			$("#description_wrapper .menuicon-audioatlas").animate({"opacity": "0.5"}, 350);
		}
	});
	$("#description_wrapper .menuicon-audioatlas").click(function() {
		clearInterval(featureMenuIntervalID);
		featureMenuIntervalID							= setInterval( "animateFeatureMenu('#iphone_screens_audioatlas')" , 5000 );
		selectedAppID									= 6;
		$("#iphone_screens_main")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_dbmeter")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_tonegen")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_micpro")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audiocalc")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audioatlas")					.animate({"opacity": "1.0"}, 350);
		$("#description_wrapper .selection-arrow")		.animate({"left": "544"}, 350);
		$("#description-bubble ul")						.animate({"left": "-3115px"}, 350);
		$("#description_wrapper .menuicon-audiotool")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-dbmeter")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-tonegen")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-micpro")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audiocalc")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audioatlas")	.animate({"opacity": "1.0"}, 350);
	});
	$("#textlink-atlas")								.click(function() {
		event.preventDefault();
		clearInterval(featureMenuIntervalID);
		featureMenuIntervalID							= setInterval( "animateFeatureMenu('#iphone_screens_audioatlas')" , 5000 );
		selectedAppID									= 6;
		$("#iphone_screens_main")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_dbmeter")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_tonegen")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_micpro")						.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audiocalc")					.animate({"opacity": "0.0"}, 350);
		$("#iphone_screens_audioatlas")					.animate({"opacity": "1.0"}, 350);
		$("#description_wrapper .selection-arrow")		.animate({"left": "544"}, 350);
		$("#description-bubble ul")						.animate({"left": "-3115px"}, 350);
		$("#description_wrapper .menuicon-audiotool")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-dbmeter")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-tonegen")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-micpro")		.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audiocalc")	.animate({"opacity": "0.5"}, 350);
		$("#description_wrapper .menuicon-audioatlas")	.animate({"opacity": "1.0"}, 350);
	});
	// ---------------------------------------------------------------------------------------------
	$("#comments_body .write_button").mouseenter(function() {
		$(this).css("background-image", "url(/apps/images/comments/write-over.png)");
	}).mouseleave(function() {
		$(this).css("background-image", "url(/apps/images/comments/write.png)");
	}).hover(function() {
		$(this).css("cursor", "pointer");
	});

});

/* FEATURE MENU FUNCTIONS ----------------------------------------------------------------------- */
function animateFeatureMenu(listID) {
	// number of pixels to move
	var offset	= 256;
	// animation speed
	var time	= 700;
	if ( shouldAnimateFeatureMenu ) {
		$(listID + " li")								.animate({"left": "-="+offset}, time);
		$(listID + " li:first")							.animate({opacity: 1.0}, time, function() {
			$(this)										.appendTo(listID);
			$(listID + " li")							.css({"left": "0"});
		});
	}
}

