//TABS
$(function() {
	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(0); //Fade in the active ID content
		return false;
	});
});

//MP3 PLAYER
	$(function(){
		$(".mp3").jmp3();
	});
	
//TOOLTIP
(function($) {
    $.fn.tipsy = function(options) {

        options = $.extend({}, $.fn.tipsy.defaults, options);
        
        return this.each(function() {
            
            var opts = $.fn.tipsy.elementOptions(this, options);
            
            $(this).hover(function() {

                $.data(this, 'cancel.tipsy', true);

                var tip = $.data(this, 'active.tipsy');
                if (!tip) {
                    tip = $('<div class="tipsy"><div class="tipsy-inner"/></div>');
                    tip.css({position: 'absolute', zIndex: 100000});
                    $.data(this, 'active.tipsy', tip);
                }

                if ($(this).attr('title') || typeof($(this).attr('original-title')) != 'string') {
                    $(this).attr('original-title', $(this).attr('title') || '').removeAttr('title');
                }

                var title;
                if (typeof opts.title == 'string') {
                    title = $(this).attr(opts.title == 'title' ? 'original-title' : opts.title);
                } else if (typeof opts.title == 'function') {
                    title = opts.title.call(this);
                }

                tip.find('.tipsy-inner')[opts.html ? 'html' : 'text'](title || opts.fallback);

                var pos = $.extend({}, $(this).offset(), {width: this.offsetWidth, height: this.offsetHeight});
                tip.get(0).className = 'tipsy'; // reset classname in case of dynamic gravity
                tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body);
                var actualWidth = tip[0].offsetWidth, actualHeight = tip[0].offsetHeight;
                var gravity = (typeof opts.gravity == 'function') ? opts.gravity.call(this) : opts.gravity;

                switch (gravity.charAt(0)) {
                    case 'n':
                        tip.css({top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-north');
                        break;
                    case 's':
                        tip.css({top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-south');
                        break;
                    case 'e':
                        tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}).addClass('tipsy-east');
                        break;
                    case 'w':
                        tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}).addClass('tipsy-west');
                        break;
                }

                if (opts.fade) {
                    tip.css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: 0.8});
                } else {
                    tip.css({visibility: 'visible'});
                }

            }, function() {
                $.data(this, 'cancel.tipsy', false);
                var self = this;
                setTimeout(function() {
                    if ($.data(this, 'cancel.tipsy')) return;
                    var tip = $.data(self, 'active.tipsy');
                    if (opts.fade) {
                        tip.stop().fadeOut(function() { $(this).remove(); });
                    } else {
                        tip.remove();
                    }
                }, 100);

            });
            
        });
        
    };
  
    $.fn.tipsy.elementOptions = function(ele, options) {
        return $.metadata ? $.extend({}, options, $(ele).metadata()) : options;
    };
    
    $.fn.tipsy.defaults = {
        fade: false,
		delayIn: 0,
    	delayOut: 0,
        fallback: '',
        gravity: 's',
        html: false,
		opacity: 0.0,
        title: 'title'
    };

    $.fn.tipsy.autoNS = function() {
        return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n';
    };
    
    $.fn.tipsy.autoWE = function() {
        return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
    };
    
})(jQuery);
  $(function() {
    
    $('#music1').tipsy({fade: true,html: true});
	$('#music2').tipsy({fade: true,html: true});
	$('#music3').tipsy({fade: true,html: true});
	$('#music4').tipsy({fade: true,html: true});
	$('#music5').tipsy({fade: true,html: true});
	$('#music6').tipsy({fade: true,html: true});
	$('#music7').tipsy({fade: true,html: true});
	$('#music8').tipsy({fade: true,html: true});
	$('#music9').tipsy({fade: true,html: true});
	$('#music10').tipsy({fade: true,html: true});
	$('#music11').tipsy({fade: true,html: true});
	$('#music12').tipsy({fade: true,html: true});
	$('#music13').tipsy({fade: true,html: true});
	$('#music14').tipsy({fade: true,html: true});
	$('#music15').tipsy({fade: true,html: true});
	$('#music16').tipsy({fade: true,html: true});
	$('#music17').tipsy({fade: true,html: true});
	$('#music18').tipsy({fade: true,html: true});
	$('#music19').tipsy({fade: true,html: true});
	$('#music20').tipsy({fade: true,html: true});
	$('#music21').tipsy({fade: true,html: true});

	$('#west').tipsy({gravity: 'w'});
    
    //$('#auto-gravity').tipsy({gravity: $.fn.tipsy.autoNS});
    //$('#example-fade').tipsy({fade: true});
    //$('#example-custom-attribute').tipsy({title: 'id'});
    //$('#example-callback').tipsy({title: function() { return this.getAttribute('original-title').toUpperCase(); } });
    //$('#example-fallback').tipsy({fallback: "Where's my tooltip yo'?" });
    //$('#example-html').tipsy({html: true }); 
  });

//JMP3
jQuery.fn.jmp3 = function(passedOptions){
	var playerpath = "http://www.ljudbyran.se/swf/";// SET THIS FIRST: path to singlemp3player.swf
	var options = {
		"filepath": "http://www.ljudbyran.se/swf/speakers/",// path to MP3 file (default: current directory)
		"backcolor": "111111",
		"forecolor": "ffffff",
		"width": "150",
		"repeat": "no",
		"volume": "100",
		"autoplay": "false",
		"showdownload": "false",
		"showfilename": "true"
	};
	if (passedOptions) {
		jQuery.extend(options, passedOptions);
	}
	return this.each(function(){
		// filename needs to be enclosed in tag (e.g. <span class='mp3'>mysong.mp3</span>)
		var filename = options.filepath + jQuery(this).html();
		// do nothing if not an .mp3 file
		var validfilename = filename.indexOf(".mp3");
		if (validfilename == -1) { return false; }
		// build the player HTML
		var mp3html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
		mp3html += 'width="' + options.width + '" height="20" ';
		mp3html += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">';
		mp3html += '<param name="movie" value="' + playerpath + 'singlemp3player.swf?';
		mp3html += 'showDownload=' + options.showdownload + '&file=' + filename + '&autoStart=' + options.autoplay;
		mp3html += '&backColor=' + options.backcolor + '&frontColor=' + options.forecolor;
		mp3html += '&repeatPlay=' + options.repeat + '&songVolume=' + options.volume + '" />';
		mp3html += '<param name="wmode" value="transparent" />';
		mp3html += '<embed wmode="transparent" width="' + options.width + '" height="20" ';
		mp3html += 'src="' + playerpath + 'singlemp3player.swf?'
		mp3html += 'showDownload=' + options.showdownload + '&file=' + filename + '&autoStart=' + options.autoplay;
		mp3html += '&backColor=' + options.backcolor + '&frontColor=' + options.forecolor;
		mp3html += '&repeatPlay=' + options.repeat + '&songVolume=' + options.volume + '" ';
		mp3html += 'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		mp3html += '</object>';
		// don't display filename if option is set
		if (options.showfilename == "true") { jQuery(this).html(""); }
		jQuery(this).prepend(mp3html+"&nbsp;");
		if(jQuery.browser.msie){ this.outerHTML = this.outerHTML; }
	});
};
