//this is jquery  //////////////////////////////////////////////////////////////////////////////////////
 $(document).ready(function(){	
////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	// Initialise the music players
	var player41 = $("#jquery_jplayer41");
	var player42 = $("#jquery_jplayer42");
	var player43 = $("#jquery_jplayer43");
	var player44 = $("#jquery_jplayer44");
	
	var player61 = $("#jquery_jplayer61");
	var player62 = $("#jquery_jplayer62");
	var player63 = $("#jquery_jplayer63");
	var player64 = $("#jquery_jplayer64");
	var player65 = $("#jquery_jplayer65");
	var player66 = $("#jquery_jplayer66");
	
	player41.jPlayer( {nativeSupport: true, oggSupport: false, ready: function () {this.element.jPlayer("setFile", $('#spot-4-1-img').attr('rel'));},swfPath: "/script"}).jPlayer("onSoundComplete", function() {this.element.jPlayer("play");});
	player42.jPlayer( {nativeSupport: true, oggSupport: false, ready: function () {this.element.jPlayer("setFile", $('#spot-4-2-img').attr('rel'));},swfPath: "/script"}).jPlayer("onSoundComplete", function() {this.element.jPlayer("play");});
	player43.jPlayer( {nativeSupport: true, oggSupport: false, ready: function () {this.element.jPlayer("setFile", $('#spot-4-3-img').attr('rel'));},swfPath: "/script"}).jPlayer("onSoundComplete", function() {this.element.jPlayer("play");});
	player44.jPlayer( {nativeSupport: true, oggSupport: false, ready: function () {this.element.jPlayer("setFile", $('#spot-4-4-img').attr('rel'));},swfPath: "/script"}).jPlayer("onSoundComplete", function() {this.element.jPlayer("play");});
	
	player61.jPlayer( {nativeSupport: true, oggSupport: false, ready: function () {this.element.jPlayer("setFile", $('#spot-6-1-img').attr('rel'));},swfPath: "/script"}).jPlayer("onSoundComplete", function() {this.element.jPlayer("play");});
	player62.jPlayer( {nativeSupport: true, oggSupport: false, ready: function () {this.element.jPlayer("setFile", $('#spot-6-2-img').attr('rel'));},swfPath: "/script"}).jPlayer("onSoundComplete", function() {this.element.jPlayer("play");});
	player63.jPlayer( {nativeSupport: true, oggSupport: false, ready: function () {this.element.jPlayer("setFile", $('#spot-6-3-img').attr('rel'));},swfPath: "/script"}).jPlayer("onSoundComplete", function() {this.element.jPlayer("play");});
	player64.jPlayer( {nativeSupport: true, oggSupport: false, ready: function () {this.element.jPlayer("setFile", $('#spot-6-4-img').attr('rel'));},swfPath: "/script"}).jPlayer("onSoundComplete", function() {this.element.jPlayer("play");});
	player65.jPlayer( {nativeSupport: true, oggSupport: false, ready: function () {this.element.jPlayer("setFile", $('#spot-6-5-img').attr('rel'));},swfPath: "/script"}).jPlayer("onSoundComplete", function() {this.element.jPlayer("play");});
	player66.jPlayer( {nativeSupport: true, oggSupport: false, ready: function () {this.element.jPlayer("setFile", $('#spot-6-6-img').attr('rel'));},swfPath: "/script"}).jPlayer("onSoundComplete", function() {this.element.jPlayer("play");});
	
	
	// Initialise the titles
	$('#spot-4-1 .titleBox').css('bottom', ($('#spot-4-1 .titleBox span').outerHeight() * -1));
	$('#spot-4-3 .titleBox').css('bottom', ($('#spot-4-3 .titleBox span').outerHeight() * -1));
	$('#spot-4-4 .titleBox').css('bottom', ($('#spot-4-4 .titleBox span').outerHeight() * -1));

	$('#spot-6-2 .titleBox').css('bottom', ($('#spot-6-2 .titleBox span').outerHeight() * -1));
	$('#spot-6-3 .titleBox').css('bottom', ($('#spot-6-3 .titleBox span').outerHeight() * -1));
	$('#spot-6-1 .titleBox').css('bottom', ($('#spot-6-1 .titleBox span').outerHeight() * -1));
	$('#spot-6-5 .titleBox').css('bottom', ($('#spot-6-5 .titleBox span').outerHeight() * -1));
	
	$('.eq').css('right', -14);
	
	//function for mouseOver
	function showOverlay (){
	
		// add the overlay to all the elements
		$('.overlay').stop(true, false).fadeTo(200, '.8');
		//remove it from the current one
		$(this).children('.overlay').hide();
		
		// make sure all titles are down
		$('#spot-4-1 .titleBox').stop(true, true).animate({'bottom': ($('#spot-4-1 .titleBox span').outerHeight() * -1)},{duration:200,easing:'easeOutExpo'});
		$('#spot-4-3 .titleBox').stop(true, true).animate({'bottom': ($('#spot-4-3 .titleBox span').outerHeight() * -1)},{duration:200,easing:'easeOutExpo'});
		$('#spot-4-4 .titleBox').stop(true, true).animate({'bottom': ($('#spot-4-4 .titleBox span').outerHeight() * -1)},{duration:200,easing:'easeOutExpo'});
		
		$('#spot-6-2 .titleBox').stop(true, true).animate({'bottom': ($('#spot-6-2 .titleBox span').outerHeight() * -1)},{duration:200,easing:'easeOutExpo'});
		$('#spot-6-3 .titleBox').stop(true, true).animate({'bottom': ($('#spot-6-3 .titleBox span').outerHeight() * -1)},{duration:200,easing:'easeOutExpo'});
		$('#spot-6-1 .titleBox').stop(true, true).animate({'bottom': ($('#spot-6-1 .titleBox span').outerHeight() * -1)},{duration:200,easing:'easeOutExpo'});
		$('#spot-6-5 .titleBox').stop(true, true).animate({'bottom': ($('#spot-6-5 .titleBox span').outerHeight() * -1)},{duration:200,easing:'easeOutExpo'});
		$('.eq').css('right', -14);
		
		// animate this title up
		$(this).find('div.titleBox').stop(true, true).animate({'bottom': 0},{duration:200,easing:'easeOutExpo'});
		$(this).find('.eq').stop(true, true).animate({'right': 0}, {duration:200, easing:'easeOutExpo'});
		
		// Make sure all the players have stopped playing
		player41.jPlayer('pause');
		player42.jPlayer('pause');
		player43.jPlayer('pause');
		player44.jPlayer('pause');
		
		player61.jPlayer('pause');
		player62.jPlayer('pause');
		player63.jPlayer('pause');
		player64.jPlayer('pause');
		player65.jPlayer('pause');
		player66.jPlayer('pause');
		// start playing the correct music player
		var whichPlayer = $("#jquery_jplayer" + $(this).attr('rel'));
		whichPlayer.jPlayer("play"); 

	}

	// function for mouseOut
	function removeOverlay(){
		// remove overlays
		$('.overlay').stop(true, false).fadeTo(200, 0, function() {});
		//pause music players
		player41.jPlayer('pause');
		player42.jPlayer('pause');
		player43.jPlayer('pause');
		player44.jPlayer('pause');
		
		player61.jPlayer('pause');
		player62.jPlayer('pause');
		player63.jPlayer('pause');
		player64.jPlayer('pause');
		player65.jPlayer('pause');
		player66.jPlayer('pause');
		//remove titles
		$('#spot-4-1 .titleBox').stop(true, true).animate({'bottom': ($('#spot-4-1 .titleBox span').outerHeight() * -1)},{duration:200,easing:'easeOutExpo'});
		$('#spot-4-3 .titleBox').stop(true, true).animate({'bottom': ($('#spot-4-3 .titleBox span').outerHeight() * -1)},{duration:200,easing:'easeOutExpo'});
		$('#spot-4-4 .titleBox').stop(true, true).animate({'bottom': ($('#spot-4-4 .titleBox span').outerHeight() * -1)},{duration:200,easing:'easeOutExpo'});
		
		$('#spot-6-2 .titleBox').stop(true, true).animate({'bottom': ($('#spot-6-2 .titleBox span').outerHeight() * -1)},{duration:200,easing:'easeOutExpo'});
		$('#spot-6-3 .titleBox').stop(true, true).animate({'bottom': ($('#spot-6-3 .titleBox span').outerHeight() * -1)},{duration:200,easing:'easeOutExpo'});
		$('#spot-6-1 .titleBox').stop(true, true).animate({'bottom': ($('#spot-6-1 .titleBox span').outerHeight() * -1)},{duration:200,easing:'easeOutExpo'});
		$('#spot-6-5 .titleBox').stop(true, true).animate({'bottom': ($('#spot-6-5 .titleBox span').outerHeight() * -1)},{duration:200,easing:'easeOutExpo'});
		
		$('.eq').stop(true, true).animate({'right': -14}, {duration:200, easing:'easeOutExpo'});
	}
	
	// listener for mouse events, using hoverIntent allows for a slight delay so we don't get too much happening when moving from one box to another
	$('.floatyBox').hoverIntent({
		over: showOverlay,
		timeout: 10,
		out: removeOverlay
	});
	
	// function for clicking
	$('.floatyBox').click(function(){
		
	});




	//THIS STUFF FOR MY ACCOUNTS SECTION
	function dottedLine(){
		$('.h-border440').remove();
		$('.h-border880').remove();
		$('.h-border309').remove();
		$('.accountBox').each(function(){
			$(this).css({
				'border-left': 'none',
				'border-right': 'none',
				'border-bottom': 'none',
				'border-top': 'none'
			}).before('<span class="h-border440"></span>').after('<span class="h-border440"></span>').css({
				'background-image': 'url(/images/branding/v-border440.gif)',
				'background-repeat': 'repeat-y',
				'padding-top': '5px',
				'padding-bottom': '5px'
			});
			var extraHeight = (4 - ($(this).outerHeight() % 4)) + 5;
			$(this).css('padding-bottom', extraHeight);
			
		});
		$('.accountBoxWide').each(function(){
			$(this).css({
				'border-left': 'none',
				'border-right': 'none',
				'border-bottom': 'none',
				'border-top': 'none'
			}).before('<span class="h-border880"></span>').after('<span class="h-border880"></span>').css({
				'background-image': 'url(/images/branding/v-border880.gif)',
				'background-repeat': 'repeat-y',
				'padding-top': '5px',
				'padding-bottom': '5px'
			});
			var extraHeight = (4 - ($(this).outerHeight() % 4)) + 5;
			$(this).css('padding-bottom', extraHeight);
			
		});
		$('.accountBoxNarrow').each(function(){
			$(this).css({
				'border-left': 'none',
				'border-right': 'none',
				'border-bottom': 'none',
				'border-top': 'none'
			}).before('<span class="h-border309"></span>').after('<span class="h-border309"></span>').css({
				'background-image': 'url(/images/branding/v-border309.gif)',
				'background-repeat': 'repeat-y',
				'padding-top': '5px',
				'padding-bottom': '5px'
			});
			var extraHeight = (4 - ($(this).outerHeight() % 4)) + 5;
			$(this).css('padding-bottom', extraHeight);
			
		});
	}
	//dottedLine();
	setTimeout(dottedLine, 50);
	
	$('.twoStageRegister').before('<p class="registersubheading registerControl"><span class="loginError"><a href="#">New customers please click here.</a></span></p>');
	$('.registerControl').click(function(){
		$('.registersubheading').hide();
		$('.twoStageRegister').fadeIn("300");
		$('.h-border440').remove();
		dottedLine();
		return false;
	});
	
	$('.signinButton').click(function(){
		$('.loginError span:visible').css('display', 'block');
		$('.h-border309').remove();
		$('.h-border440').remove();
		$('.h-border880').remove();
		dottedLine();
	});
	
	$('.textinput').blur(function(){
		$('.loginError span:visible').css('display', 'block');
		$('.h-border309').remove();
		$('.h-border440').remove();
		$('.h-border880').remove();
		dottedLine();
	});
	
	if (!($('.twoStageRegister .loginError span').is(':visible'))){
		$('.twoStageRegister').hide();
	} else {
		$('.registersubheading').hide();
	}
	
	$('.loginError span:visible').css('display', 'block');

	//Accordion for FAQ page
	$('.faq').accordion({
			autoHeight: false,
			collapsible: true,
			navigation: true,
			active: false 
		});
		
	//Fixes for product  listing
	$('ul#smallthumbgrid > li:nth-child(3n+1)').css('clear', 'both');
	//$('ul#smallthumbgrid > li:nth-child(3n+1)').before('<br style="clear:both;" />');
	$('ul#smallthumbgridfullwidth > li:nth-child(5n+1)').css('clear', 'both');
	//back button
	
	
	
	/* MUSIC DETAILS PAGE JPLAYER STUFF */
	$("#preview_jplayer").jPlayer({
		ready: function () {
			this.element.jPlayer();
		},
		swfPath: "/script",
		volume: 50
	});
	
	$('.jPlay').click(function(){
		$("#previewAll_jplayer").jPlayer("stop");
		$('.pauseall').hide();
		$('.playall').show();
		$('.jPlay').show();
		$('.jPause').hide();
		$(this).hide().next().show();
		$("#preview_jplayer").jPlayer("setFile", $(this).attr('href'));
		$("#preview_jplayer").jPlayer('play').jPlayer("onSoundComplete", function() {
			$('.jPlay').fadeIn('slow', function(){$('.jPause').hide();});
		});;
		return false;
	});
	
	$('.jPause').click(function(){
		$(this).hide().prev().show();
		$("#preview_jplayer").jPlayer('stop');
		return false;
	});
	
	/* play all */
	var playItem = 0;
	var playList = [];
	$('.jPlay').each(function(){
		playList.push($(this).attr('href'));
	});
	
	function nextTrack(){
		playItem ++;
		
		if(playItem <= playList.length){
			$("#previewAll_jplayer").jPlayer("setFile", playList[playItem]);
			$("#previewAll_jplayer").jPlayer("play");
			$('#tracklist .jPlay').eq(playItem - 1).show();
			$('#tracklist .jPause').eq(playItem - 1).hide();
			$('#tracklist .jPlay').eq(playItem).hide();
			$('#tracklist .jPause').eq(playItem).show();
		} else {
			$("#previewAll_jplayer").jPlayer("stop");
			$('#tracklist .jPlay').eq(playItem - 1).show();
			$('#tracklist .jPause').eq(playItem - 1).hide();
		}
	}
	
	$("#previewAll_jplayer").jPlayer({
		ready: function () {
			this.element.jPlayer("setFile", playList[playItem]);
		},
		swfPath: "/script",
		volume: 50
	});

	$('.playall').click(function(){
		$("#preview_jplayer").jPlayer('stop');
		$('.jPause').hide();
		$('.jPlay').show();
		$("#previewAll_jplayer").jPlayer("play").jPlayer("onSoundComplete", function() {
			nextTrack();
		});
		$(this).hide().next().show();
		$('#tracklist .jPlay').eq(playItem).hide();
		$('#tracklist .jPause').eq(playItem).show();
		return false;
	});
	
	$('.pauseall').click(function(){
		$("#previewAll_jplayer").jPlayer("pause");
		$(this).hide().prev().show();
		$('.jPause').hide();
		$('.jPlay').show();
		return false;
	});
	
	/* fashion listing page view all fix */
	if (window.location.href.indexOf('fashion/listlarge') != -1){
		var filterURL = $('.pagination a:contains("View All")').attr('href');
		$('.pagination a:contains("View All")').attr('href', '/fashion/listsmall/' + $('.fashionsubnav .active').text() + filterURL);
	}
	
	/* fix active tab on tabs */
	$('.tabnav a:first-child').addClass('active');
	
	/* back to top button */
	$('a[href=#top]').click(function(){
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	});
	
	$('a[href=#info]').click(function(){
		var scrollTo = $('.albuminfo').offset();
		$('html, body').animate({scrollTop:scrollTo.top}, 'slow');
		return false;
	});
	
	/* fix for charts etc */
	
	$('.chartentry').each(function(){
		$(this).append('<span class="chartTooltip">' + $(this).find('.trackname').text() + '<span class="chartTooltipArrow"></span></span>');
		$(this).find('.chartTooltip').css('margin-left', ($(this).find('.chartTooltip').outerWidth() / 2) * -1);
	});
	
	$('.chartentry').hover(function(){
		$(this).find('.chartTooltip').stop(true, true).fadeIn('250');
	}, function(){
		$(this).find('.chartTooltip').stop(true, true).fadeOut('250');
	});
	
	
	$('#filternav .singleinfo .trackname').each(function(){
		var trackName = $(this).text().split(' (');
		var track = trackName[0]
		if(track.length > 12){
			track = track.substring(0, 12) + '...'
		}
		$(this).text(track);
	});
	
	$('#singlessidenav .singleinfo .trackname').each(function(){
		var trackName = $(this).text().split(' (');
		var track = trackName[0]
		if(track.length > 20){
			track = track.substring(0, 20) + '...'
		}
		$(this).text(track);
	});
	
	/* active states in music section product details */
	if ($('.downloadContainer').length) {
		$('#digitalalbums').addClass('active');
	} else if ($('.albumContainer').length) {
		$('#albums').addClass('active');
	}

	/* remove price on download tracks we cant buy */
	$('.downloadTracks').each(function(){
		if(!($(this).find('.tinyaddtobag').length)){
			$(this).find('.downloadPriceCell').text('Album Only');
		}
	});
	
	/* remove other formats box if empty */
	if (!($('.otherformats a').length)) {
		$('.otherformats').remove();
	}
	
	/* remove other products pane at bottom if empty */
	if (!($('.featuredownloads a').length)) {
		$('.featuredownloads').remove();
	}
	
	/* remove more info */
	$('.albuminfo').text($('.albuminfo').text().replace(/^\s+/, '').replace(/\s+$/, ''));
	if ($('.albuminfo').text() == ''){
		$('.albuminfo').prev().remove();
		$('.albuminfo').remove();
		$('a[href=#info]').remove();
	}
	
	/* remove tickets table and add message if there is no events */
	if ($('#partylistcontainer table td').length == 0){
		$('#partylistcontainer table').before('<p class="error">There are currently no events in this region</p>');
		$('#partylistcontainer table').remove();
	}
	



// SCRIPT FOR MEET THE TEAM
	if (window.location.href.indexOf('meettheteam') != -1){
	$('h2.partiesheading').css('background-image','url(../images/branding/headings/heading_meettheteam.jpg)');
	}

// add the hover states behind
$('#meettheteam a.teammember').each(function(){
$(this).append('<img src="' + ($(this).find("img").attr("alt")) + '" class="hoverover" />');
});

// polaroid hover function
$('#meettheteam a.teammember').hover(function(){
		 $(this).find('img.hoverover').stop(true, true).fadeIn('medium');
	},function(){

	 $(this).find('img.hoverover').stop(true, true).fadeOut('medium');
	});


// take out the #hash from the href

 $('#meettheteam a.teammember').click(function(){
var teammembername = $(this).attr('href');
teammembername = teammembername.replace(/#/i, "");

//var teammemberlargeimage = ($(this).find('img').attr('mainsrc'));
var teammemberlargeimage = ($(this).find('img').attr('alt')).replace('hover', 'Large');
 
 var teammemberdetails =  $('#meettheteampopupcontent').find("span."+teammembername + " p").html();
var teammemberpopup = "<div id='teammemberpopup' ><img src='" + teammemberlargeimage +  "' width='305' height='305' alt=''/><p> " + teammemberdetails + "  </p><br class='clear'/></div> ";
$.fancybox( teammemberpopup, { 'autoDimensions'	: false, 'width': 720, 'height': 'auto', 'transitionIn': 'none', 'transitionOut': 'none' }	); return false;    
});  




// some sales text on the thumbs
//$('#partylistcontainer table').html('<p class="error">There is currently no events in this region</p>');

//      

$('.smallthumbimage img').each(function(){
	if ( $(this).attr('src') !== "/uploads/products/fashion/HDR02003 Black Front_28481_BlackFashionProduct1_jpg_Small.jpg") {
		// empty blocks are bad mmmmk
	} else {
    	$(this).parent().append('<img src="/images/fakeassets/makeastatement/getthelook_arrow.png" style="position:absolute; top:-33px; left:100px;" class="thesalestext"/><img src="/images/fakeassets/makeastatement/getthelook_largetext.png" style="position:absolute; top:-43px; left:120px; display:none; z-index:99999;" class="thelargesalestext"/>');
	}
});

$('.smallthumbimage').hover(function(){
	$(this).find('.thesalestext').hide(); $(this).find('.thelargesalestext').show(); }, function(){ $(this).find('.thesalestext').show();  $(this).find('.thelargesalestext').hide();
});




}); // DO NOT DELETE THIS LINE ///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////



