
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($) {

	$(document).ready(
		function() {
			$('table tr th:first').each(
				function() {
					$(this).addClass('first-child')
				}
			)
			$('table tr th:last').each(
				function() {
					$(this).addClass('last-child')
				}
			)
			$('input, textarea, select').each(
				function() {
					$(this).focus(
						function() {
							$(this).addClass('focused')
							$(this).siblings('label').addClass('focused')
						}
					)
					$(this).blur(
						function() {
							$(this).removeClass('focused')
							$(this).siblings('label').removeClass('focused')
						}
					)
				}
			)
			mypartdPrettify();
			$.fn.media.defaults.flvPlayer = '/player.swf';
			$('a[href$=flv]').each(function() {
				$(this).media({
					'autoplay': 1,
					'width':320,
					'height':260,
					'bgColor': 'transparent',
					'flashvars': {
						'image': $(this).find('img').attr('src')
					}
				});
			});
		}
	)
	
	function mypartdPrettify() {
	  if($.find('.home').length>0){
	    var testes = $('#sidebar .bg:eq(1)')
		  testes.click(function(){window.location='http://mypartdusa.com/page/testimonials'})
		                         .css('cursor','pointer')
		  testes.find('h3').after($('<p></p>').append(testes.find('a:last').clone().removeClass('read-more').html('See All &raquo;')))
		                         
		}
		if(!$('.testimonials').size()) {
			return
		}	
		
		var content = $('div.page-content').html()
		content = content.replace(/My Part D USA/gi, '<span class="mypartd">My Part D USA</span>')
		$('div.page-content').html(content)
	}
	
	wt.videoPlayer = function() {
		var links = $('a[href$=flv]');
		if(!links.size()) { return; }
		links.each(function() {
			var link = $(this);
			link.click(function(c) {
				c.preventDefault()
				wt.launchVideo(link)
			});
		});
	}

	wt.launchVideo = function(vid) {
		var video = vid.clone(true)
		if(!$('#popup').size()) {
			$('body').append('<div id="popup"></div>').append('<div id="overlay"></div>')
		}
		var popup = $('#popup')
		var overlay = $('#overlay')
		var videoViewer = $(jQuery('<div class="video-viewer"></div>'))
		popup.append(videoViewer)
		if(jQuery.browser.msie && jQuery.browser.version < 7) {
			popup.width($('body').width())
			popup.height($('html').height())
			popup.css({
				top: document.documentElement.scrollTop
			})
			overlay.width($('body').width())
			overlay.height($('html').height())
		}
		videoViewer.empty()
		videoViewer.append(video)
		var close = $(jQuery('<div />'))
		close
			.addClass('close')
			.click(function() {
				if(!wt.browerSucks) {
					overlay.fadeOut()
				} else {
					overlay.hide()
				}
				popup.empty();
				popup.fadeOut('fast', function() {})
			})
			.html('Close&nbsp;&times;')

		overlay.click(function() {
			popup.find('div.close').click()
		});

		popup.click(function() {
			popup.find('div.close').click()
		});

		videoViewer.append(close)

		if(!wt.browerSucks) {
			overlay.fadeIn()
		} else {
			overlay.show()
		}
		popup.fadeIn('normal', function() { 
			setTimeout(
				function() { video.media({'flvPlayer': '/mediaplayer.swf','autoplay': 1,'width':320,'height':260}); }
				,500
			)
		})
	}
	
})(jQuery);
