$(document).ready(function() {
	
	// handle refresh background image
	var hash = '#'+window.location.hash.slice(1);
    switch(hash) {
        case '#home':
            $('#wrapper').css('background', 'url(../images/backgrounds/home3.jpg) center center no-repeat #000');
            break;
        case '#bio':
            $('#wrapper').css('background', 'url(../images/backgrounds/biog.jpg) center center no-repeat #000');
            break;
	    case '#grey-sky-blue':
	        $('#wrapper').css('background', 'url(../images/backgrounds/discography.jpg) center center no-repeat #000');
	        break;
    	case '#gallery':
    	    $('#wrapper').css('background', 'url(../images/backgrounds/media.jpg) center center no-repeat #000');
    	    break; 
        case '#news':
        	$('#wrapper').css('background', 'url(../images/backgrounds/news2.jpg) center center no-repeat #000');
        	break;
        case '#dates':
            $('#wrapper').css('background', 'url(../images/backgrounds/dates.jpg) center center no-repeat #000');
            break;
        case '#links':
            $('#wrapper').css('background', 'url(../images/backgrounds/links.jpg) center center no-repeat #000');
            break;
        case '#press':
            $('#wrapper').css('background', 'url(../images/backgrounds/press.jpg) center center no-repeat #000');
            break;
        case '#contact':
            $('#wrapper').css('background', 'url(../images/backgrounds/contact.jpg) center center no-repeat #000');
            break;        	            	       	              	            
    }	
	
    /* Scroll Content */
    $(function() {
        $('.contentScroll').jScrollPane({
            mouseWheelSpeed:5
        });
    });

    $(function() {
        $('.albumText').jScrollPane({
            mouseWheelSpeed:5
        });
    });	
	
	// tiptip
    $(function(){
        $(".tiptip").tipTip({
            maxWidth: "auto", 
            edgeOffset: 5,
            attribute: 'alt',
            defaultPosition: 'top'
        });
    });
	
	
	/* Latest Gig Ticker */
	$(function(){
		$("ul#ticker").liScroll({travelocity: 0.05});
	});
		
	/* Gallery */
    $('#carousel').jcarousel({
        auto: 4,
		animation: 'slow',
		wrap: 'last',
		scroll: 1,
		visible: 3
    });
    
    $(function() {
    	$('a.lightbox').lightBox();
    });	
	
    /* Handle Anchor link clicks */
    $('#menu a').click(function(){
        var sPage = $(this).attr('href');
        switch(sPage) {
            case '#home':
                $('#wrapper').css('background', 'url(../images/backgrounds/home3.jpg) center center no-repeat #000');
                break;
	        case '#bio':
	            $('#wrapper').css('background', 'url(../images/backgrounds/biog.jpg) center center no-repeat #000');
	            break;
    	    case '#grey-sky-blue':
    	        $('#wrapper').css('background', 'url(../images/backgrounds/discography.jpg) center center no-repeat #000');
    	        break;
        	case '#gallery':
        	    $('#wrapper').css('background', 'url(../images/backgrounds/media.jpg) center center no-repeat #000');
        	    break; 
            case '#news':
            	$('#wrapper').css('background', 'url(../images/backgrounds/news2.jpg) center center no-repeat #000');
            	break;
            case '#dates':
                $('#wrapper').css('background', 'url(../images/backgrounds/dates.jpg) center center no-repeat #000');
                break;
            case '#links':
                $('#wrapper').css('background', 'url(../images/backgrounds/links.jpg) center center no-repeat #000');
                break;
            case '#press':
                $('#wrapper').css('background', 'url(../images/backgrounds/press.jpg) center center no-repeat #000');
                break;
            case '#contact':
                $('#wrapper').css('background', 'url(../images/backgrounds/contact.jpg) center center no-repeat #000');
                break;        	            	       	              	            
	    }
	});	
	
	/* home page news clicks */
	$('.homeNewsLink').click(function(){
	    $('#wrapper').css('background', 'url(../images/backgrounds/news2.jpg) center center no-repeat #000');
	});
	
	/* home page news clicks */
	$('#footerPigskin').click(function(){
	    $('#wrapper').css('background', 'url(../images/backgrounds/discography.jpg) center center no-repeat #000');
	});	
	
	/* Handle album page links */
    $('.anchorLink').click(function(){
        var sPage = $(this).attr('href');
        switch(sPage) {
    	    case '#grey-sky-blue':
    	        $('#wrapper').css('background', 'url(../images/backgrounds/discography.jpg) center center no-repeat #000');
    	        break;
        	case '#gone':
        	    $('#wrapper').css('background', 'url(../images/backgrounds/discography.jpg) center center no-repeat #000');
        	    break;  
            case '#coming-home':
            	$('#wrapper').css('background', 'url(../images/backgrounds/discography.jpg) center center no-repeat #000');
            	break;        	      	        	            
	    }
	});
	
	/* Dates Nav */
	$('.dateContainer').mouseenter(function() {
  		$(this).find('.brown').attr('style', 'color:#fff !important;');
	});
	
	$('.dateContainer').mouseleave(function() {
  		$(this).find('.brown').attr('style', 'color:#8D5D4B !important;');
	});	
	

	
	
	$('.dateContainer2').click(function(){
	   
	   $('#wrapper').css('background', 'url(../images/backgrounds/dates.jpg) center center no-repeat #000');
	   
	   var nId = $(this).attr('title');
	       
       // get date info from db
       $.ajax({
            url: 'ajax/getDateInfo.php',
            type: 'POST',
            data: 'id='+nId,
            success: function(xml) {
                $('#dateInfoVenue').html($(xml).find('venue').text());
                $('#dateInfoLoc').html($(xml).find('location').text()+' : '+$(xml).find('thedate').text());
                $('#dateInfoMore').html($(xml).find('moreinfo').text());
            
                $('#dateInfoExtra').empty();
            
                if ($(xml).find('time').text().length > 0) {
                    $('#dateInfoExtra').append('<strong>Time:</strong> '+$(xml).find('time').text()+'<br/><br/>');
                }
            	                
                if ($(xml).find('price').text().length > 0) {
                    $('#dateInfoExtra').append('<strong>Price:</strong> '+$(xml).find('price').text()+'<br/><br/>');
                }
            
                if ($(xml).find('link').text().length > 0) {
                    $('#dateInfoExtra').append('<strong>Link:</strong> <a href="'+$(xml).find('link').text()+'" target="_blank">'+$(xml).find('link').text()+'</a>');
                }
            
                $('#dateList').css('display', 'none');
        	}
        });	       	       
       // show date info
       $('#dateInfo').css('display', '');

	});
	
    $('.dateContainer').click(function(){
	   
	   var nId = $(this).attr('title');
	   
	   $('#dateList').fadeOut('fast', function(){
	       
	       // get date info from db
           $.ajax({
	            url: 'ajax/getDateInfo.php',
	            type: 'POST',
	            data: 'id='+nId,
	            success: function(xml) {
	                $('#dateInfoVenue').html($(xml).find('venue').text());
	                $('#dateInfoLoc').html($(xml).find('location').text()+' : '+$(xml).find('thedate').text());
	                $('#dateInfoMore').html($(xml).find('moreinfo').text());
	                
	                $('#dateInfoExtra').empty();
	                
	                if ($(xml).find('time').text().length > 0) {
	                    $('#dateInfoExtra').append('<strong>Time:</strong> '+$(xml).find('time').text()+'<br/><br/>');
	                }
	                	                
	                if ($(xml).find('price').text().length > 0) {
	                    $('#dateInfoExtra').append('<strong>Price:</strong> '+$(xml).find('price').text()+'<br/><br/>');
	                }
	                
	                if ($(xml).find('link').text().length > 0) {
	                    $('#dateInfoExtra').append('<strong>Link:</strong> <a href="'+$(xml).find('link').text()+'" target="_blank">'+$(xml).find('link').text()+'</a>');
	                }
	                
	                // show date info
                    $('#dateInfo').fadeIn('fast');
	        	}
	        });	       
	   });
	   
	});	
	
	/* Date Back */
	$('#dateBackLink').click(function(){
	   $('#dateInfo').fadeOut('fast', function(){
	      $('#dateList').fadeIn('fast'); 
	   });
	});	
	
	/* Mailing List Signup */
	$('.mailingList').click(function(){
    	$("#dialog").dialog({
    	    width: '450',
    		title: 'Mailing List',
    		resizable: false,
    		show: { effect:'fade', duration:500 },
    		hide: { effect:'fade', duration:400},			
    		modal: true,
            open: function() { 
                $('#mailingName').focus();
    		},
    		close: function() {
    		    $(this).dialog('destroy');
    		    $('#mlResponse').empty();
			    $('#mailingEmail,#mailingName').val('');
    		},
    		buttons: {
    			"Close": function() {
    			    $(this).dialog('destroy');
    			    $('#mlResponse').empty();
    			    $('#mailingEmail,#mailingName').val('');
    			},
    			"Sign Up": function() {
    			    if ($('#mlForm').valid()) {
                        
                        $('#mlResponse').html('Adding email address...');

                		// Prepare query string and send AJAX request
                		$.ajax({
                			url: 'ajax/store-address.php',
                			data: 'name='+escape($('#mailingName').val())+'&email='+escape($('#mailingEmail').val()),
                			success: function(msg) {
                				$('#mlResponse').html(msg);
                			}
                		});
    			    }  				
    			}
    		}
    	});	    
	});
	
    // form validate user licences	
	$("#mlForm").validate({
		rules: {
			mailingName: { required: true },
			mailingEmail: { required: true, email:true }
	  	},
	  	messages: {
	  	    mailingEmail: "Invalid e-mail address"
	  	}
	});		
});

/* Audio */
AudioPlayer.setup("player.swf", {  
    width: 220,  
    initialvolume: 100,  
    transparentpagebg: "yes",  
    left: "000000",  
    lefticon: "FFFFFF",
    bg: '191413',
    leftbg: '191413',
    rightbg: '191413',  
    track: '191413',
    border: '191413',
    text: 'dddddd',
    tracker: '4c403e',
    loader: '282221'
});
