(function($){

	//Resize image on ready or resize
	$.fn.supersized = function() {
    	$.inAnimation = false;

        $(window).bind("load", function(){
            $('#loader').fadeOut();            
            loadNext();
            $('#supersize').show();
			
            
             if ($('#supersize .activeslide').length == 0) $('#supersize a:first').addClass('activeslide').fadeIn(4000, function(){
                 $.inAnimation = false;
                $('#supersize').oneTime(12000, 'trans',function(){gonextslide();});
             });


        }); //CLOSE WINDOW LOAD
				
		$(document).ready(function() {
			$('#supersize').resizenow();

			$('#logo a').live("click",function(){ 
                   $('#navigation1 ul li a.selected').removeClass();
                   $("#container").fadeOut('fast',function(){$(this).unload();});  
                   return false;  
               }); 
               
            $('a#profiles_link').live("click",function(){ 
                   $('#navigation1 ul li a.selected').removeClass();
                   $(this).addClass('selected');  
                   $("#loader").fadeIn(); 
                   $("#container").hide().unload().css({width:"333px",height:"550px",left:"365px"}).load('profiles.php',function(){
                        $(this).fadeIn();
                        $("#loader").fadeOut(); 
                   });  
                   return false;  
               }); 	
            $('a#about_link').live("click",function(){ 
                   $('#navigation1 ul li a.selected').removeClass();
                   $(this).addClass('selected');  
                   $("#loader").fadeIn(); 
                   $("#container").hide().unload().css({width:"470px",height:"190px",left:"280px"}).load('about.php',function(){
                        $(this).fadeIn();
                        $("#loader").fadeOut(); 
                   });  
                   return false;  
               });
            $('a#news_link').live("click",function(){ 
                   $('#navigation1 ul li a.selected').removeClass();
                   $(this).addClass('selected');  
                   $("#loader").fadeIn(); 
                   $("#container").hide().unload().css({width:"500px",height:"530px",left:"230px"}).load('news.php?s=News',function(){
                        $(this).fadeIn();
                        $("#loader").fadeOut(); 
                   });  
                   return false;  
               });
            $('a#mixes_link').live("click",function(){ 
                   $('#navigation1 ul li a.selected').removeClass();
                   $(this).addClass('selected');  
                   $("#loader").fadeIn(); 
                   $("#container").hide().unload().css({width:"500px",height:"530px",left:"320px"}).load('news.php?s=Mixes',function(){
                        $(this).fadeIn();
                        $("#loader").fadeOut(); 
                   });  
                   return false;  
               });
			$('a#gallery_link').live("click",function(){ 
                   $('#navigation1 ul li a.selected').removeClass();
                   $(this).addClass('selected');  
                   $("#loader").fadeIn(); 
                   $("#container").hide().unload().css({width:"650px",height:"530px",left:"425px"}).load('gallery.php',function(){
                        $(this).fadeIn();
                        $("#loader").fadeOut(); 
                   });  
                   return false;  
               });
				$('a#news_link').trigger("click");
		}); //close document ready
				
		$(window).bind("resize", function(){
    		  $('#supersize').resizenow(); 
		});
		
		$('#supersize').hide();
	};
	
	//Adjust image size
	$.fn.resizenow = function() {
		
	  	return this.each(function() {
	  		
			//Define image ratio
			var ratio = 3/4;
			
			//Gather browser and current image size
			var imagewidth = $(this).width();
			var imageheight = $(this).height();
			var browserwidth = $(window).width();
			var browserheight = $(window).height();
			var offset;
			
			//Resize image to proper ratio
			if ((browserheight/browserwidth) > ratio){
			    $(this).height(browserheight);
			    $(this).width(browserheight / ratio);
			    $(this).children().height(browserheight);
			    $(this).children().width(browserheight / ratio);
			} else {
			    $(this).width(browserwidth);
			    $(this).height(browserwidth * ratio);
			    $(this).children().width(browserwidth);
			    $(this).children().height(browserwidth * ratio);
			}
				$(this).children().css('left', (browserwidth - $(this).width())/2);
				$(this).children().css('top', (browserheight - $(this).height())/2);

			return false;
		});
	};
	
	
})(jQuery);

	//Slideshow Next Slide
	function gonextslide() {
		if($.inAnimation) return false;
		else $.inAnimation = true;
	    var currentslide = $('#supersize .activeslide');	    			
	    var nextslide =  currentslide.next().length ? currentslide.next() : $('#supersize a:first');
	    var prevslide =  nextslide.prev().length ? nextslide.prev() : $('#supersize a:last');
	    		
		if(nextslide.is('.notloaded')){
		  $('#loader').stopTime('controlled').fadeIn().everyTime(200, 'controlled', function(){
		      var curr  = $(this);
            if(nextslide.is('.loaded')){                            
                curr.stopTime('controlled').fadeOut();
                $.inAnimation = false;
                gonextslide();
            }}); 
		  return false;
        }


		currentslide.removeClass('activeslide');
		$('.prevslide').removeClass('prevslide');
		prevslide.addClass('prevslide').show();
				
	    nextslide.hide().addClass('activeslide').fadeIn(4000, function(){
	       $.inAnimation = false;
	       prevslide.addClass('prevslide').hide();
	       $('#supersize').oneTime(12000, 'trans',function(){gonextslide();});
	   });
	    		    	
	    $('#supersize').resizenow();//Fix for resize mid-transition

}