summaryrefslogtreecommitdiff
path: root/static/js/supersized.js
blob: 7b0e44dad217cca0ce67dfa0468c1bcdfb75ec39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
Supersized - Full Screen Background/Slideshow jQuery Plugin
supersized.1.0.js
February 2009
By Sam Dunn
www.buildinternet.com / www.onemightyroar.com
*/
(function($){

	//Resize image on ready or resize
	$.fn.supersized = function() {
	
		var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);
		
		if (options.slideshow == 1){
			setInterval("theslideshow()", options.slideinterval);
		}
		
		$().ready(function() {
			$('#supersize').resizenow(); 
		});
		$(window).bind("resize", function(){
    		$('#supersize').resizenow(); 
		});
	};
	
	//Adjust image size
	$.fn.resizenow = function() {
		
		var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);
		
	  	return this.each(function() {
	  		
			//Define image ratio & minimum dimensions
			var minwidth = options.minsize*(options.startwidth);
			var minheight = options.minsize*(options.startheight);
			var ratio = options.startheight/options.startwidth;
			
			//Gather browser and current image size
			var imagewidth = $(this).width();
			var imageheight = $(this).height();
			var browserwidth = $(window).width();
			var browserheight = $(window).height();
			
			//Check for minimum dimensions
			if ((browserheight < minheight) && (browserwidth < minwidth)){
				$(this).height(minheight);
				$(this).width(minwidth);
			}
			else{	
				//When browser is taller	
				if (browserheight > browserwidth){
				    imageheight = browserheight;
				    $(this).height(browserheight);
				    imagewidth = browserheight/ratio;
				    $(this).width(imagewidth);
				    
				    if (browserwidth > imagewidth){
				    	imagewidth = browserwidth;
				    	$(this).width(browserwidth);
				    	imageheight = browserwidth * ratio;
				    	$(this).height(imageheight);
				    }
				
				}
				
				//When browser is wider
				if (browserwidth >= browserheight){
				    imagewidth = browserwidth;
				    $(this).width(browserwidth);
				    imageheight = browserwidth * ratio;
				    $(this).height(imageheight);
				    
				    if (browserheight > imageheight){
				    	imageheight = browserheight;
				    	$(this).height(browserheight);
				    	imagewidth = browserheight/ratio;
				    	$(this).width(imagewidth);
				    }
				}
			}
			return false;
		});
	};
	
	$.fn.supersized.defaults = { 
			startwidth: 640,  
			startheight: 480,
			minsize: .5,
			slideshow: 1,
			slideinterval: 5000  
	};
	
})(jQuery);

//Slideshow Add-on
function theslideshow() {
    
    var currentslide = $('#supersize .activeslide');
    		
    if ( currentslide.length == 0 ) currentslide = $('#supersize :last');
		
    var nextslide =  currentslide.next().length ? currentslide.next() : $('#supersize :first');
		
    nextslide.addClass('activeslide');
    currentslide.removeClass('activeslide');

}