url = 'http://www.brokenrecords.co.za/';

//preloader function for images
$.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    $('<img>').attr('src', arguments[i]);
  }
}

//preload images
$.preloadImages('images/broken-records-logo.png', 'images/news-link.png', 'images/hover-news-link.png', 'images/artists-link.png', 'images/hover-artists-link.png', 'images/about-link.png', 'images/hover-about-link.png', 'images/contact-link.png', 'images/hover-contact-link.png', 'images/store-link.png', 'images/hover-store-link.png', 'images/feature-prev-arrow.png', 'images/feature-next-arrow.png', 'images/prev-arrow.png', 'images/next-arrow.png', 'images/feature-bg.png', 'images/section-title-bg.png', 'images/feature-center-bg.png', 'images/more-button.png', 'images/buy-now-button.png','images/textured-bg.jpg', 'images/come-out-fighting-cover.png', 'images/ontskemer-cover.png', 'images/ter-wille-van-die-opdaag-cover.png', 'images/11th-street-sessions-cover.png', 'images/follow-link.png', 'images/signup-button.png', 'images/john-ellis-artist-profile-pic.png', 'images/play-button.png', 'images/jan-hoogendyk-artist-profile-pic.png', 'images/koos-van-der-merwe-artist-profile-pic.png', 'images/reason-artist-profile-pic.png', 'images/ambulants-artist-profile-pic.png', 'images/trefpunt-artist-profile-pic.png', 'images/beweeg-artist-profile-pic.png', 'images/full-list-link.png', 'images/send-message-button.png');

$(document).ready(function(){

	//smooth scrolling
	smoothScroll();
	//
	
	//content sliders
	$("#feature-slider").codaSlider()
	$("#article-slider").codaSlider()
	$("#artist-slider").codaSlider()
	//
	
	//automate feature slider  
	var autoSlide = setInterval(function(){

	$(".stripNavR#stripNavR0 a").click();
	
	}, 5000);
	
	//accordian menus
	accordianMenu('2','0');
	accordianMenu('3','0');
	accordianMenu('4','0');
	accordianMenu('5','0');
	accordianMenu('6','0');
	accordianMenu('7','0');
	accordianMenu('8','0');
	accordianMenu('9','0');
	accordianMenu('10','0');
	//
	
	$("a.thumbnail").fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	true
		});

	$("a.video-thumbnail").click(function() {
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'title'			: this.title,
				'width'		: 600,
				'height'		: 400,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
				'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
				}
			});
	
		return false;
	});
	
	$('.play-link').toggle(function(){

		$(this).find('img').attr('src','images/pause-button.png');
		song = $(this).attr("id");
		
		//start player
		document.getElementById('mp3Player').SetVariable('player:jsUrl', url + song);
		document.getElementById('mp3Player').SetVariable('player:jsPlay', '');
		
	},function(){
		
		$('.play-link img').attr('src','images/play-button.png');
		song = $(this).attr("id");
		
		//stop player    
		document.getElementById("mp3Player").SetVariable("player:jsStop", "");
		
	});
	
});
function smoothScroll()
{
	// jQuery SmoothScroll | Version 10-04-30
	$('a[href*=#]').click(function() {
	
		 // duration in ms
		 var duration=1000;
	
		 // easing values: swing | linear
		 var easing='swing';
	
		 // get / set parameters
		 var newHash=this.hash;
		 var target=$(this.hash).offset().top;
		 var oldLocation=window.location.href.replace(window.location.hash, '');
		 var newLocation=this;
	
		 // make sure it's the same location      
		 if(oldLocation+newHash==newLocation)
		 {
				// animate to target and set the hash to the window.location after the animation
				$('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() {
	
					 // add new hash to the browser location
					 window.location.href=newLocation;
				});
	
				// cancel default click action
				return false;
		 }
	});
}
function accordianMenu($menu, $item)
{
	$('#accordian-menu-' + $menu + ' ul:eq(' + $item + ')').show();
	$('#accordian-menu-' + $menu + ' li a').click(function(){
			var checkElement = $(this).next();
			if ((checkElement.is('ul.accordian-element')) && (checkElement.is(':visible'))) {
					return false;
			}
			if ((checkElement.is('ul.accordian-element')) && (!checkElement.is(':visible'))) {
					$('#accordian-menu-' + $menu + ' ul.accordian-element:visible').slideUp('normal');
					checkElement.slideDown('normal');
					return false;
			}
	});
}
