$(document).ready(function(){

	// jCarousel for band gallery.
	jQuery('#mycarousel').jcarousel({
        'scroll':1,
        'animation':'slow',
        'easing':'easeOutExpo',
        'buttonNextHTML':'<div><a href="#_">Next</a></div>',
        'buttonPrevHTML':'<div><a href="#_">Prev</a></div>'
    });
    
    // Right lanyard
    if($('#right-lanyard').size()==1){
	    resizeLanyard();
	    $(window).resize(resizeLanyard);
    }
    
    // Road to V search.
    $("#main-nav form input[type='text']").focus(function(){
    	$(this).attr('value','');
    });
    
    // Add hover states to elements.
    addHoverToElements('table.band-list tbody tr, #content input.submit');
    
    // Search results table click event.
    $('table.band-list tbody tr').click(function(){
    	location.href = $('a', this)[0];
    });
    
    // Most Viewed (hover and click events).     
    addHoverToList($('#content .playing li, #content .tracklist li'));
    
    // The Bands/Search Results: Show/hide filter.
    var filterTrigger = $('#the-bands .filter p.title');
    var filterSlide = $('#the-bands .filter .slide-me');
	filterTrigger.addClass('trigger');	
	filterSlide.slideUp(0);
    filterTrigger.click(function(){
		filterSlide.slideToggle('fast');
    });
    
    // Track deletion
    $('.tracklist .minus').click(function(){
    	
    	if (!confirm('Are you sure you want to delete this track?'))
    		return false;
    	
    });

	// gallery image deletion
    $('#band-profile .jcarousel-item a').click(function(){
    	
    	if (!confirm('Are you sure you want to delete this image?'))
    		return false;
    	
    });

});


function addHoverToList(list){

	$(list).each(function(){
    
    	if($('a', this)[0]){
    	
    		$(this).hover(
		    	function(){
		    		$(this).addClass('hover');
		    		window.status = $('a', this)[0].href;
			    },
			    function(){
				    $(this).removeClass('hover');
		    });
		    $(this).click(function(){
		    	location.href = $('a', this)[0];
		    });

    	}

    });

}


function addHoverToElements(el){

	$(el).hover(
		function(){ $(this).addClass('hover'); },
	    function(){ $(this).removeClass('hover');
    });

}


function resizeLanyard(){

	// IE6 doesn't calcuate the offset properly (disregards the padding).
	if(jQuery.browser.version=='6.0') padding = 5;
	else padding = 0;

	var lanWidth = $('#page').offset().left - 1 + padding;

	$('#right-lanyard').width(lanWidth);
	$('#right-lanyard').addClass('right-lanyard');

}