(function() {
		  
jQuery.fn.ScrollPanel = function(settings) {

	var options = jQuery.extend({
		direction: "horizontal",
	 	minItems: 5,
		adjust: 0,
		adjustIE: 0,
		effect: true
	}, settings);	
	
	var scrolltrack;
	var scrollpanel;

	return this.each(function() {								
		
		scrolltrack = $(this);
		scrollpanel = "."+scrolltrack.attr('rel');	
		ul = $(scrollpanel+" ul");
	
		if(options.direction=="horizontal"){
			var $scrollItemWidth = $(scrollpanel+" .item").width() + (options.adjust);		
			if($.browser.msie) $scrollItemWidth = $scrollItemWidth + (options.adjustIE);
			var $viewableArea = $(scrollpanel).width();
		}else{
			var $scrollItemWidth = $(scrollpanel+" .item").height() + (options.adjust);	
			if($.browser.msie) $scrollItemWidth = $scrollItemWidth + (options.adjustIE);
			var $viewableArea = $(scrollpanel).height();
		}
		
		var $scrollTotalItems = $(scrollpanel+" .item").length;
		var $totalWidth = ($scrollTotalItems*$scrollItemWidth);

		if($scrollTotalItems > options.minItems){
			
			if(options.direction=="horizontal") $(scrollpanel+" ul").width($totalWidth);
			else $(scrollpanel+" ul").height($totalWidth);
			
			scrolltrack.slider({
				minValue:0,
				maxValue: ($totalWidth-$viewableArea), 
				startValue: 0,
				slide: function(e,ui) { 
							if(options.direction=="horizontal")  $(scrollpanel+" ul").css({"left":  - ui.value + "px"});
							else $(scrollpanel+" ul").css({"top": - ui.value + "px"});
						},
				stop: function(e,ui) { 
							if(options.direction=="horizontal") {
								if(options.effect) $(scrollpanel+" ul").animate({"left": - ui.value + "px"}, 0, 'linear');
								else $(scrollpanel+" ul").css("left",  - ui.value + "px");
							}else{
								if(options.effect)	$(scrollpanel+" ul").animate({"top":  - ui.value + "px"}, 0, 'linear' );
								else $(scrollpanel+" ul").css("top",  - ui.value + "px");
							}
						}
			});
			
			
		}else{
			
			$(this).hide();
			
			if(options.direction=="horizontal") {
				$(scrollpanel+" ul").css("width","auto");
			}else{
				scrollWidth = $(scrollpanel).width();
				scrollWidthLi = $(scrollpanel+ " li").width();
				
				$(scrollpanel+" ul").css("height","auto");
				$(scrollpanel).css("width",scrollWidth + 29 + "px");
				$(scrollpanel+ " li").css("width",scrollWidthLi + 29 + "px");
			}
			
			
			
		}
	
	
	});
	
}

jQuery.fn.Dropdown = function(settings) {

	var options = jQuery.extend({
		redirect: true, 
		classPrefix : '',
		closebutton : false, 
		callback: false
	}, settings);	
	
	return this.each(function(i) {								
		
		var el = this;
		var selectId = "#"+this.id;
		
		$(this).hide();
		
		$(this).before('<div id="'+this.id+'_container_'+i+'" class="'+((options.classPrefix!="")?options.classPrefix+"_":"")+'autocomplete_container"></div>');
		
		$(selectId+'_container_'+i).append('<input type="text" readonly="true" class="'+this.className+'" id="' + this.id + '_combo_'+i+'" />');
		$(selectId+'_container_'+i).append('<div id="' + this.id + '_options_'+i+'" class="'+((options.classPrefix!="")?options.classPrefix+"_":"")+'autocomplete"></div>');			

		$(selectId+'_options_'+i).append('<div class="scroll-pane"><ul></ul></div>');
				
		if(options.closebutton) {
			$(selectId+'_options_'+i).append('<p class="'+((options.classPrefix!="")?options.classPrefix+"_":"")+'autocomplete_close"><a id="'+this.id+'_container_'+i+'_close" href="javascript:void(0)">Close</a></p>'); 
			$('#'+this.id+'_container_'+i+'_close').click(function(){  $(selectId + '_options_'+i).hide();  });
		}
		
		$(selectId+' > option').each(function(j,n){
			$(selectId+'_options_'+i+' > div > ul').append('<li class="'+el.id+'-'+i+'-'+$(n).val()+'" rel="'+$(n).val()+'">'+$(n).html()+'</li>');
		});
		
		$(selectId+' > optgroup').each(function(j,n){			
			$(selectId+'_options_'+i+' ul').append('<li class="group" id="'+el.id+'_options_'+i+'_group_'+j+'"><span>'+$(this).attr('label')+'</span></li>');			
			$(this).find('option').each(function(k,m){
				$(selectId+'_options_'+i+' ul').append('<li class="child" name="'+$(m).attr('rel')+'" rel="'+$(m).val()+'">'+$(m).html()+'</li>');								 
			});		
		});
		
		if(this.selectedIndex >= 0) $('#'+this.id+'_combo_'+i).val(this.options[this.selectedIndex].innerHTML);
		
		var $elementHeight = $(selectId+'_options_'+i).height();
		var $elementTop = $(selectId+'_container_'+i).offset().top;
		var $documentHeight = $(document).height();
		
		
		if($documentHeight > ($elementHeight + $elementTop + 50)) {
			$(selectId+'_options_'+i).css('top',$(selectId+'_combo_'+i).height() + 5 +"px");		
		}else {
			$(selectId+'_options_'+i).css('top', "-" + $elementHeight + "px");
		}
				
		
		$(selectId+'_combo_'+i).click(function(){ 
									$(selectId+'_options_'+i).toggle().css('z-index',200);
									$(selectId+'_options_'+i+' .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth:15 });			
								})
							   .mouseover(function() { $(this).addClass('over-gold'); })
							   .mouseout(function(){ $(this).removeClass('over-gold'); });
	
		$(selectId+'_options_'+i+' li').not('li.group')
								 .mouseover(function(){ $(this).addClass('selected'); })
							     .mouseout(function(){ $(this).removeClass('selected'); })
								 .click(function(){ 
										
										if(options.redirect){
											document.location=$(this).attr('rel');
										
										}else if(options.redirect!=false && $(this).attr('name')!=""){
											document.location=$(this).attr('name')+'.php'+$(this).attr('rel');											
										
										}else{
											var liEl = this;
											var newIndex = 0;
											
											$(selectId+'_combo_'+i).val($(this).html());
											
											$(selectId+' option').each(function(i,n){											
												if($(n).val()==$(liEl).attr('rel')){
													newIndex = i;												
												}
											});
											
											el.selectedIndex = newIndex;
											$(selectId+'_options_'+i).hide();
											
											if(options.callback){
												eval(options.callback+'("'+this.className+'")');	
											}
										}										
								 });								 
		
		$(document).click(function(event){ 		
			var target = $(event.target);
			if (target.parents(selectId+'_container_'+i).length == 0) {				
				$(selectId+'_options_'+i).hide();
			}
		});	
		
		
	
	});
	
	
}
})(jQuery);


$(document).ready(function(){		
	
	$('#latestrelease-scrollbar').ScrollPanel({effect: true, adjust: 9, adjustIE: -6 });
	$('#artistsnews-scrollbar').ScrollPanel({ direction :'vertical', adjust: 11, adjustIE: 3, effect: true });
	$('#tourdates-scrollbar').ScrollPanel({ direction :'vertical', adjust: 9, adjustIE: 1, effect: true });
	//$('#islandstore-scrollbar').ScrollPanel({ direction :'vertical', adjust: 11, adjustIE: 1, effect: true });
	$('#artist-info-scrollbar').ScrollPanel({ direction :'vertical', adjust: 7, adjustIE: 1, minItems: 10, effect: true  });
	$('#artist-dates-scrollbar').ScrollPanel({ direction :'vertical', adjust: 9, adjustIE: 1, minItems: 8, effect: true  });
	
	
	$('#topstories_btns a').mouseover(function(event){
		
		$('#topstories_btns a').removeClass('active');
		$('#topstories_cntrs div').removeClass('active');
		$('#topstories_description div').removeClass('active');
		
		var linkIndex = $(event.target).attr('rel').replace('item-','');
		
		$('#topstory-img-'+linkIndex).addClass('active');
		$('#topstory-btn-'+linkIndex).addClass('active');
		$('#topstory-desc-'+linkIndex).addClass('active');										   
	});
	
	$('#artistnews_rss, #tourdates_rss').Dropdown();
	$('#artistnews_filter1, #artistnews_filter2').Dropdown();
	$('#tourdates_artists').Dropdown({redirect:false });
	$('#tourdates_date').Dropdown({redirect:false, classPrefix: "small"});	

	$('#newssignup-multiple').click(function(){ 
							$('.newssignup-form-ext').slideDown();
							$(this).hide(); 
							$('.newssignup-form-ext .scroll-pane2').jScrollPane({showArrows:true, scrollbarWidth:15 });
	});
	$('#newssignup-multiple2').click(function(){ $('.newssignup-form-ext').hide(); $('#newssignup-multiple').show(); });
	
	$('.newssignup-form button[class=submit]').mouseover(function(){ $(this).addClass('submit-over'); })
											  .mouseout(function(){ $(this).removeClass('submit-over'); })
	
	/* search filter */
	$('#search_genres_link').click(function(){ 
					$('#search_genres').toggle();
					$('#search_artists').hide();
					$('#search_formats').hide();
					
					$("#search_artists_link").html('Select artist');
					$("#search_artists_value").val('all');
					
					$("#search_genres div.scroll-pane3").jScrollPane({showArrows:true, scrollbarWidth:15 });
	});
	$("#search_genres li a").click(function(){ 					
					var el = $(this);
					$("#search_genres_value").val($(this).attr('rel')); 
					$("#search_genres_link").html($(this).html());
					$('#search_genres').hide(); 
					if(el.attr('rel')!="all") {
						$("#search_artists li").each(function(i,n){
								if($(n).attr('rel')!=el.attr('rel')) $(n).hide();
								else $(n).show();
						});
					}else{
						$("#search_artists li").show();		
					}
	});
	
	$('#search_artists_link').click(function(){ 
					$('#search_artists').toggle(); 
					$('#search_formats').hide();
					$('#search_genres').hide();
					$("#search_artists div.scroll-pane4").jScrollPane({showArrows:true, scrollbarWidth:15 });
	});
	$("#search_artists li a").click(function(){ 
					$("#search_artists_value").val($(this).attr('rel')); 
					$("#search_artists_link").html($(this).html());
					$('#search_artists').hide(); 
	});
	
	$('#search_formats_link').click(function(){ 
					$('#search_formats').toggle();
					$('#search_genres').hide();					
					$('#search_artists').hide();
					$("#search_formats div.scroll-pane3").jScrollPane({showArrows:true, scrollbarWidth:15 });
	});
	$("#search_formats li a").click(function(){ 
					$("#search_formats_value").val($(this).attr('rel'));
					$("#search_formats_link").html($(this).html());
					$('#search_formats').hide(); 
	});
	/* end search filter */
	
	$("li.item, li[class*=item]").mouseover(function() { $(this).addClass('over'); })
				.mouseout(function(){ $(this).removeClass('over'); });
	
	$(".artistsbands-items li").mouseover(function() { $(this).addClass('over');  })
							   .mouseout(function(){ $(this).removeClass('over'); });
	
	$(".release-other li").mouseover(function() { $(this).addClass('over');  })
							   .mouseout(function(){ $(this).removeClass('over'); });
				
	$("#search_form li label").click(function(){ $(this).parent().parent().find("ul").toggle();	});
	
	$("input.s_genre").click(function(){
		if($(this).attr('checked')==true){
			$(this).parent().parent().find("ul").find("input.s_artist").each(function(i,n){ $(this).attr('checked','true') });			
		}else{
			$(this).parent().parent().find("ul").find("input.s_artist").each(function(i,n){ $(this).attr('checked','') });	
		}
	})
	
	$(document).click(function(event){ 		
		var target = $(event.target);
		
		//if(target.attr('id')!='newssignup-multiple'){
		//	if (target.parents('.newssignup-form-ext').length == 0) { $('.newssignup-form-ext').hide(); }
		//}
		
		if(target.attr('class')!='releasesearch-artists-link'){
			if (target.parents('.releasesearch-artists-content').length == 0) { $('.releasesearch-artists-content').hide(); }
		}
		
		if(target.attr('class')!='releasesearch-formats-link'){
			if (target.parents('.releasesearch-formats-content').length == 0) { $('.releasesearch-formats-content').hide(); }
		}
	});
	
	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

	if (jQuery.browser.msie && (ie55 || ie6)) {
		$(document).not(".header_menu *").pngFix(); 
	}
	
});


function validateSignUpForm(frm){
	
	if($('#signupEmail').val()=="Enter email" || $('#signupEmail').val()=='' ) { alert('Please enter your email address'); return false; }
	if(validateEmail($('#signupEmail').val())==false) { alert('Please enter a valid email address'); return false; }
	if($('#dm_this').size()>0){
		if($('#dm_this').attr('checked')!=true) { alert('Please confirm that you agree our Privacy Policy terms before submit!'); return false; }
	}
	return true;	
}
	
function validateEmail(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){ return false }
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){  return false }
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ return false }
	if (str.indexOf(at,(lat+1))!=-1){ return false  }
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ return false }
	if (str.indexOf(dot,(lat+2))==-1){ return false }
	if (str.indexOf(" ")!=-1){ return false }
	
	return true					
}

function setSearch() {
	document.location = "releasesalbum.php?sartist="+$('#searchArtist').val()+"&sformat=" + $('#searchFormat').val()+'/';			
}	

function setSort(Column) {	                   
  var path= window.location.href.substr( window.location.href.lastIndexOf( "/" ) + 1);
  s=path.indexOf("s=");
  if (s>0) { oldSort=path.substr(s,3); path=path.replace(oldSort,"s="+Column); 
  }else{ (path.indexOf("?")>0)?path=path+"&s="+Column:path=path+"?s="+Column; }   
  document.location.href =path;                                         
}

