1var boozurkScripts;
2
3(function($) {
4
5boozurkScripts = {
6
7	init : function( in_modules ) {
8
9		var modules = in_modules.split(',');
10
11		for (i in modules) {
12
13			switch(modules[i]) {
14
15				case 'postexpander':
16					boozurkScripts.post_expander();
17					break;
18
19				case 'thickbox':
20					boozurkScripts.init_thickbox();
21					break;
22
23				case 'tooltips':
24					boozurkScripts.tooltips();
25					boozurkScripts.cooltips(boozurk_l10n.cooltips_selector);
26					break;
27
28				case 'quotethis':
29					boozurkScripts.init_quote_this();
30					break;
31
32				case 'animatemenu':
33					boozurkScripts.animate_menu();
34					break;
35
36				case 'scrolltopbottom':
37					boozurkScripts.scroll_top_bottom();
38					break;
39
40				case 'commentvariants':
41					boozurkScripts.comment_variants();
42					break;
43
44				case 'resizevideo':
45					boozurkScripts.resize_video();
46					break;
47
48				case 'tinynav':
49					boozurkScripts.tinynav();
50					break;
51
52				case 'tinyscrollbar':
53					boozurkScripts.tinyscrollbar();
54					break;
55
56				default :
57					//no default action
58					break;
59
60			}
61
62		}
63
64	},
65
66
67	post_expander : function() {
68
69		return $('#posts_content').find('a.more-link').each(function() {
70
71			$(this).unbind().click(function() {
72
73				var link = $(this);
74
75				$.ajax({
76					type: 'POST',
77					url: link.attr("href"),
78					beforeSend: function(XMLHttpRequest) { link.html(boozurk_l10n.post_expander).addClass('ajaxed'); },
79					data: 'boozurk_post_expander=1',
80					success: function(data) { link.parents(".storycontent").hide().html($(data)).fadeIn(600); }
81				});
82
83				return false;
84
85			});
86
87		});
88
89	},
90
91
92	animate_menu : function() {
93
94		return $('#mainmenu').children('.menu-item-parent').each(function() {
95
96			$this = $(this);
97
98			var d = $this.children('ul'); //for each main item, get the sub list
99
100			d.css( {'opacity' : 0 } );
101
102			$this.hoverIntent(
103
104				function(){ //when mouse enters, slide down the sub list
105
106					d.css( {'display' : 'block' } ).animate( { 'opacity' : 0.95 } );
107
108				},
109
110				function(){ //when mouse leaves, hide the sub list
111
112					d.stop().animate( { 'opacity' : 0 }, 200, 'swing', function(){ d.css( {'display' : '' } ); } );
113
114				}
115			);
116
117		});
118
119	},
120
121
122	tooltips : function() {
123
124		return $('#posts_content').find('.bz-tooltip').each(function() {
125
126			var p = $(this).parent();
127			var self = $(this);
128			var timeoutID;
129
130			self.hide();
131
132			p.unbind().hoverIntent(
133
134				function(){
135
136					window.clearTimeout(timeoutID);
137					self.stop().css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: 0.9});
138
139				},
140
141				function(){
142
143					timeoutID = window.setTimeout( function(){self.fadeOut()}, 200);
144
145				}
146			);
147
148		});
149
150	},
151
152
153
154	init_thickbox : function() {
155
156		$('#posts_content').find('.storycontent a img').parent('a[href$=".jpg"],a[href$=".png"],a[href$=".gif"]').addClass('thickbox');
157
158		$('#posts_content').find('.storycontent .gallery').each(function() {
159			$('a[href$=".jpg"],a[href$=".png"],a[href$=".gif"]',$(this)).attr('rel', $(this).attr('id'));
160		});
161
162	},
163
164
165	scroll_top_bottom : function() {
166
167		top_but = $('#navbuttons').find('.minib_top a');
168		bot_but = $('#navbuttons').find('.minib_bottom a');
169
170		// smooth scroll top/bottom
171		top_but.click(function() {
172			$("html, body").animate({
173				scrollTop: 0
174			}, {
175				duration: 400
176			});
177			return false;
178		});
179		bot_but.click(function() {
180			$("html, body").animate({
181				scrollTop: $('#footer').offset().top - 80
182			}, {
183				duration: 400
184			});
185			return false;
186		});
187	},
188
189
190	comment_variants : function() {
191		$('#commentform').find('.comment-variants label').click(function() {
192			$('#comment').removeClass( 'style-default style-blue style-pink style-orange style-yellow style-green style-gray style-white' );
193			$('#comment').addClass( $('input', this).val() );
194			$('input', this).attr('checked',true);
195		});
196	},
197
198
199	init_quote_this : function() {
200		if ( document.getElementById('reply-title') && document.getElementById("comment") ) {
201			bz_qdiv = document.createElement('small');
202			bz_qdiv.innerHTML = ' - <a id="bz-quotethis" href="#" onclick="boozurkScripts.quote_this(); return false" title="' + boozurk_l10n.quote_tip + '" >' + boozurk_l10n.quote + '</a>';
203			bz_replink = document.getElementById('reply-title');
204			bz_replink.appendChild(bz_qdiv);
205		}
206	},
207
208
209	quote_this : function() {
210		var posttext = '';
211		if (window.getSelection){
212			posttext = window.getSelection();
213		}
214		else if (document.getSelection){
215			posttext = document.getSelection();
216		}
217		else if (document.selection){
218			posttext = document.selection.createRange().text;
219		}
220		else {
221			return true;
222		}
223		posttext = posttext.toString().replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
224		if ( posttext.length !== 0 ) {
225			document.getElementById("comment").value = document.getElementById("comment").value + '<blockquote>' + posttext + '</blockquote>';
226		} else {
227			alert( boozurk_l10n.quote_alert );
228		}
229	},
230
231
232	resize_video : function() {
233		// https://github.com/chriscoyier/Fluid-Width-Video
234		var $fluidEl = $("#posts_content").find(".storycontent");
235		var $allVideos = $("iframe[src^='http://player.vimeo.com'], iframe[src^='http://www.youtube.com'], object, embed",$fluidEl);
236
237		$allVideos.each(function() {
238			$(this)
239				// jQuery .data does not work on object/embed elements
240				.attr('data-aspectRatio', this.height / this.width)
241				.removeAttr('height')
242				.removeAttr('width');
243		});
244
245		$(window).resize(function() {
246			var newWidth = $fluidEl.width();
247			$allVideos.each(function() {
248				var $el = $(this);
249				$el
250					.width(newWidth)
251					.height(newWidth * $el.attr('data-aspectRatio'));
252			});
253		}).resize();
254	},
255
256	tinynav : function() {
257		$(".nav-menu").tinyNav({
258			label: '<i class="icon-align-justify"></i>', // String: Sets the <label> text for the <select> (if not set, no label will be added)
259			header: '' // String: Specify text for "header" and show header instead of the active item
260		});
261	},
262
263	tinyscrollbar : function() {
264		var $sidebar_primary_scrollable = $('#sidebar-primary.fixed');
265		var $sidebar_secondary_scrollable = $('#sidebar-secondary.fixed');
266		var doit;
267
268		function resize_sidebar(){
269			if ($sidebar_primary_scrollable.length)
270				$sidebar_primary_scrollable.tinyscrollbar_update();
271
272			if ($sidebar_secondary_scrollable.length)
273				$sidebar_secondary_scrollable.tinyscrollbar_update();
274		}
275
276		if ($sidebar_primary_scrollable.length) {
277			$('.viewport', $sidebar_primary_scrollable).prepend( '<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div>' );
278			$sidebar_primary_scrollable.removeClass('fixed').addClass('tinyscroll');
279			$sidebar_primary_scrollable.tinyscrollbar();
280			$sidebar_primary_scrollable.hover(function () {$('.scrollbar', this).fadeIn()},function () {$('.scrollbar', this).stop().fadeOut()});
281		}
282
283		if ($sidebar_secondary_scrollable.length) {
284			$('.viewport', $sidebar_secondary_scrollable).prepend( '<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div>' );
285			$sidebar_secondary_scrollable.removeClass('fixed').addClass('tinyscroll');
286			$sidebar_secondary_scrollable.tinyscrollbar();
287			$sidebar_secondary_scrollable.hover(function () {$('.scrollbar', this).fadeIn()},function () {$('.scrollbar', this).stop().fadeOut()});
288		}
289
290		$(window).resize(function() {
291			clearTimeout(doit);
292			doit = setTimeout(function() {
293				resize_sidebar();
294			}, 100);
295		});
296	}
297
298};
299
300//$(document).ready(function($){ boozurkScripts.init(boozurk_l10n.script_modules); });
301
302$('body').on('post-load', function(event){ //Jetpack Infinite Scroll trigger
303	// boozurkScripts.init(boozurk_l10n.script_modules_afterajax);
304	cooltips("en");
305});
306
307})(jQuery);