var Local = {

    onCommentReply: function(id) {
		Comments.openReply(id);
	},

    onCancelReply: function(id) {
		Comments.closeReply();
	}

};

if(!window['wt']) {
	window['wt'] = {};
	var wt = window['wt'];
}
wt.browserSucks = (jQuery.browser.msie && jQuery.browser.version < 7) ? true : false;


(function() {
	var $ = jQuery

	$(document).ready(function() {
		wt.videos();
		wt.newsletterSupport();
	});
	
	$(window).load(function(){
		if(window.location.hash) { $(window).animate({scrollTop: $('' + window.location.hash + '').offset().top - 10 }, 800)}
	});
	
	wt.newsletterSupport = function() {
		if($('div.newsletter').size() && $('div.article').size()) {
			$('div.article img').each(function(i){
				var img = $(this)
				img.wrap($(jQuery("<a />").attr({'href': img.attr('src'),'rel': 'lightbox', 'id': 'image-' + (i + 1)})))
			})
			$('a[rel=lightbox]').lightBox()
			if(window.location.hash && window.location.hash.match(/#image-*/)) {
				$('a' + window.location.hash).click();
			}
			
			
			var less = 'Show Less...'
			var more = 'Show More...'
			
			$('div.article').each(function() {
				var article = $(this)
				var container = $('<div class="more" id="more-"' + article.attr('id') + '" style="display:none"></div>')
				var link = $(jQuery('<a />'))
				link.attr({
					'href': '#',
					'id': 'read-more-' + article.attr('id'),
					'rel': 'link-' + article.attr('id')
				})
				.html(more)
				link.click(function(c) {
					c.preventDefault()
					container.slideToggle(300)
					link.html((link.html() == more ? less : more))
				})
				container.after(link)
				article.children().each(function(i) {
					if(i<3) {
						// Do nothing
					} else if(i==3) {
						if($(this).next().size()) {
							$(this).after(container)
							container.after(link)
						}
					} else {
						$(this).appendTo(container)
					}
				})
			})
			
			if(window.location.hash && window.location.hash.match(/#article-*/)) {
				$('a[rel=link-' + window.location.hash.substr(1) + ']').click();
			}
			
		}
	}
	
	$(window).load(function(){
		if(window.location.hash) { scrollTo(0,$('' + window.location.hash + '').offset().top - 10)}
	})

	wt.videos = function() {
		var links = $('a[href$=flv]');
		if(!links.size()) { return; }
		
		if(!$('#overlay').size()) {
			$('body').append($(jQuery('<div id="overlay" style="display: none; width: ' + $(document).width() + 'px; height: ' + $(document).height() + 'px;"></div>')));
			$(window).resize(function() {
				$('#overlay').width($(document).width()).height($(document).height());
			});
		}
		
		links.each(function(i) {
			var link = $(this);
			var container = $(jQuery('<div id="video-' + i + '" style="display: none;" class="video-container" href="' + link.attr('href') + '"></div>'));
			$('body').append(container);
			var video = $f('video-' + i, {src: '/FlowPlayerLight.swf', width: 640, height: 360}, {autoPlay: true, autoBuffering: true, videoFile: link.attr('href'), loop: false, usePlayOverlay: true, controlsOverVideo: 'ease', showFullScreenButton: true} );
			link.click(function(c) {
				c.preventDefault();
				$('#overlay').show().click(function() {
					video.pause();
					video.stopBuffering();
					$('#overlay').hide();
					container.hide();
				});
				video.startBuffering();
				container.show();
				video.play();
			});
		});
	}

})();



