/* BRAVADO */
/* Transmission Page Javascript
--------------------------------------------------------------------------------- */


	var cursorX;
	var cursorY;

	$(window).load(function() {


		$('body').mousemove(function(position) {
	
			cursorX = position.pageX;
			cursorY = position.pageY;

		});

		$('#cart:hidden').slideDown();


/* ACTIONS
--------------------------------------------------------------------------------- */


	$('a.toggle').toggle(function() {

		$('#compact').prev().slideUp(function() {
		
			$('#compact').slideDown('fast');
			$('a.toggle').addClass('back');
		
		});
	
	}, function() {

		$('#compact').slideUp(function() {
		
			$('#compact').prev().slideDown('fast');
			$('a.toggle').removeClass('back');
		
		});
	
	});


/* ALBUM BROWSER - COVERS
--------------------------------------------------------------------------------- */


	$('#carousel dt.pressure').remove();

	$('#carousel ul.items > li').each(function() {
	
		$(this).children('dl').children('dt:contains($)').text( $(this).children('dl').children('dt:contains($)').text() + ' / BUY NOW');

		if (parseInt( $(this).children('a').children('img').height() ) > 278) {
			$(this).children('a').children('img').addClass('hover');
		}
	
	});

	$().mousemove(function() {

		$('#tooltip:not(.flipped)').css({ top: cursorY - 37 + 'px', left: cursorX + 20 + 'px' });
		$('#tooltip.flipped').css({ top: cursorY - 37 + 'px', left: cursorX - 260 + 'px' });

	});

	function addTooltip() {

		$(this).parent().siblings('dl').clone().attr('id','tooltip').appendTo('body');

		if (cursorX > $(window).width() / 1.75) {
			$('#tooltip').addClass('flipped');
		} else {
			$('#tooltip').removeClass('flipped');
		}

		$('#tooltip:not(.flipped)').css({ top: cursorY - 37 + 'px', left: cursorX + 20 + 'px' });
		$('#tooltip.flipped').css({ top: cursorY - 37 + 'px', left: cursorX - 260 + 'px' });

		if ($(this).hasClass('.hover')) {

			$(this).animate({ marginTop: "-278px" }, 'slow');

			$('#tooltip').fadeIn();
			
		} else {

			$('#tooltip').fadeIn();

		}
	
	}
	
	function removeTooltip() {

		$('#tooltip').remove();

		if ($(this).hasClass('.hover')) {
			$(this).animate({ marginTop: "0" }, 'slow');
		}
	
	}
	
	$('#carousel ul.items > li img').hoverIntent({
	
		sensitivity: 1,
		timeout: 100,
		over: addTooltip,
		out: removeTooltip
	
	});

	if ($('#carousel ul.items > li').length > 3 ) {
		$('#carousel ul.items').css('width', $('#carousel ul.items li').length * 324 - 190 + 'px' );
		$('#carousel').jScrollHorizontalPane({ scrollbarHeight: 28, dragMinWidth: 205, dragMaxWidth: 205 });
		
		var endOfCarousel = parseInt($('#carousel ul.items').width()) - 990 + 'px';
		var endOfScrollbar = parseInt($('div.jScrollPaneTrack').width()) - 213 + 'px';

		function respinCarousel() {

			setTimeout(function() {
				$('#carousel, div.jScrollPaneDrag').animate({ left: '0' }, 200, "swing");
				$('#carousel').animate({ left: '-' + endOfCarousel }, 40000, "linear");
				$('div.jScrollPaneDrag').animate({ left: endOfScrollbar }, 40000, "linear", respinCarousel);
			}, 500);

		}

		function spinCarousel() {

			$('#carousel:not(.scrolling)').animate({ left: '-' + endOfCarousel }, 40000, "linear");
			$('div.jScrollPaneDrag:not(.scrolling)').animate({ left: endOfScrollbar }, 40000, "linear", respinCarousel);

		}
		
		spinCarousel();

		$('#albums').hover(function() {
			$('#carousel, div.jScrollPaneDrag').stop();
		}, spinCarousel);

		$('div.jScrollPaneDrag').mousedown(function() {
			$('#carousel, div.jScrollPaneDrag').stop();
			$('#carousel, div.jScrollPaneDrag').addClass('scrolling');		
		});

	} else {
		$('#carousel ul.items').css('width', $('#carousel ul.items li').length * 324 - 15 + 'px' );
	}


/* ALBUM BROWSER - TITLES
--------------------------------------------------------------------------------- */


	$('div.widget-item.compact dt:contains($)').remove();
	$('div.widget-item.compact dt.pressure').remove();


/* ALBUM VIEWER
--------------------------------------------------------------------------------- */


	if (topic.length > 0) {

		if ($('div.topic strong.reduced').length > 0) {

			var price = $('#album div.topic strong del').text();
			$('#album div.topic strong del').remove();
			var reduced = $('#album div.topic strong').text().split('.');

			$('<strong class="reduced"><del>' + price + '</del> ' + reduced[0] + '<span>' + reduced[1] + '</span></strong>').insertBefore('#album div.purchase ul.actions');

		} else {

			var price = $('#album div.topic strong').text().split('.');

			$('<strong>' + price[0] + '<span>.' + price[1] + '</span>' + '</strong>').insertBefore('#album div.purchase ul.actions');

		}

		/*
		
			// PLUGIN: CLIQUE ITEM WIDGET
			try {
			$('#photos').cliqueItemWidget({
			
				checkStock: true,
				pressure: true,
				browser: 'thumbnails', // thumbnails / slideshow
				removeEmptyThumbs: true, // Removes rows of empty thumbnails
				viewer: true, // Shows enlarged images
				preview: false, // Preview enlarged images when hovering thumbnails
				zoom: 'drag' // loupe / drag / none
				
			});
			$('.widget-item.browse.tooltip').cliqueItemWidget();
			$('.widget-item.filter').cliqueItemWidget();
			} catch (error) { alert('Error: Missing Clique Item Plugin'); }

		*/

		$('input.notify, input.wishlist').parent().remove();
		$('#album div.topic strong').remove();
		$('div.purchase label.email + br, div.purchase label.email').remove();
		$('div.purchase strong:contains("stock") + br').remove();
		$('div.purchase strong:contains("stock")').remove();
		$('div.purchase strong:contains("pre-order") + br').remove();
		$('div.purchase strong:contains("pre-order")').remove();

		$('<div class="album"></div>').insertBefore('#album div.details');
		$('div.topic').appendTo('div.album');
		$('div.purchase').appendTo('div.album');
		$('#photos li a').parent().addClass('photo');
	
		if ($('div.details div.markup').length > 0) {
	
			var $details = $('#album div.details div.markup');

			if ($details.html().match(/<HR>/g)) {
				var $credits = $details.html().split(/<HR>/g);
			} else {
				var $credits = $details.html().split(/<hr>/g);
			}
			
			$details.empty();
			$.each($credits, function(index, value) {

				$('<div>' + this + '</div>').appendTo($details);
			
				if (index == 1 | index == 3 | index == 5) {
					$('<hr />').appendTo($details);
				}
			
			});
			
			$('div.details hr:last-child').remove();

		}

	}


/* OPT IN
--------------------------------------------------------------------------------- */


	$('div.widget-subscribe li.submit a').text('Get Updates');
	$('div.widget-subscribe label').each(function() {

		$(this).children('input').addClass('prompt').val( $(this).children('em').text() ).attr('title', $(this).children('em').text() );
	
	});

	$('div.widget-subscribe label input').focus(function() {
	
		if ($(this).hasClass('prompt')) { $(this).val(''); }
	
	});

	$('div.widget-subscribe label input').blur(function() {

		if ($(this).val().length > 0 && $(this).val() != $(this).attr('title')) {
			$(this).removeClass('prompt');
		}

		if ($(this).val() == '') {
			$(this).val( $(this).attr('title') );
		} else {
			$(this).attr('title', $(this).val());
		}

	});
	
	if ($('div.widget-subscribe').hasClass('placeholder')) {
		$('#id, #cart').remove();
	}
	

/* REVEAL CONTENT
--------------------------------------------------------------------------------- */


	$('#albums div.purchase').css('visibility','visible');


});
