window.onunload = function(){};

/*
 * jQuery Easing Plugin
 *
 * website:			http://gsgd.co.uk/sandbox/jquery/easing/
*/
jQuery.easing['jswing']=jQuery.easing['swing'];jQuery.extend(jQuery.easing,{def:'easeOutQuad',swing:function(x,t,b,c,d){return jQuery.easing[jQuery.easing.def](x,t,b,c,d)},easeInQuad:function(x,t,b,c,d){return c*(t/=d)*t+b},easeOutQuad:function(x,t,b,c,d){return-c*(t/=d)*(t-2)+b},easeInOutQuad:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t+b;return-c/2*((--t)*(t-2)-1)+b},easeInCubic:function(x,t,b,c,d){return c*(t/=d)*t*t+b},easeOutCubic:function(x,t,b,c,d){return c*((t=t/d-1)*t*t+1)+b},easeInOutCubic:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t+b;return c/2*((t-=2)*t*t+2)+b},easeInQuart:function(x,t,b,c,d){return c*(t/=d)*t*t*t+b},easeOutQuart:function(x,t,b,c,d){return-c*((t=t/d-1)*t*t*t-1)+b},easeInOutQuart:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t*t+b;return-c/2*((t-=2)*t*t*t-2)+b},easeInQuint:function(x,t,b,c,d){return c*(t/=d)*t*t*t*t+b},easeOutQuint:function(x,t,b,c,d){return c*((t=t/d-1)*t*t*t*t+1)+b},easeInOutQuint:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t*t*t+b;return c/2*((t-=2)*t*t*t*t+2)+b},easeInSine:function(x,t,b,c,d){return-c*Math.cos(t/d*(Math.PI/2))+c+b},easeOutSine:function(x,t,b,c,d){return c*Math.sin(t/d*(Math.PI/2))+b},easeInOutSine:function(x,t,b,c,d){return-c/2*(Math.cos(Math.PI*t/d)-1)+b},easeInExpo:function(x,t,b,c,d){return(t==0)?b:c*Math.pow(2,10*(t/d-1))+b},easeOutExpo:function(x,t,b,c,d){return(t==d)?b+c:c*(-Math.pow(2,-10*t/d)+1)+b},easeInOutExpo:function(x,t,b,c,d){if(t==0)return b;if(t==d)return b+c;if((t/=d/2)<1)return c/2*Math.pow(2,10*(t-1))+b;return c/2*(-Math.pow(2,-10*--t)+2)+b},easeInCirc:function(x,t,b,c,d){return-c*(Math.sqrt(1-(t/=d)*t)-1)+b},easeOutCirc:function(x,t,b,c,d){return c*Math.sqrt(1-(t=t/d-1)*t)+b},easeInOutCirc:function(x,t,b,c,d){if((t/=d/2)<1)return-c/2*(Math.sqrt(1-t*t)-1)+b;return c/2*(Math.sqrt(1-(t-=2)*t)+1)+b},easeInElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);return-(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b},easeOutElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);return a*Math.pow(2,-10*t)*Math.sin((t*d-s)*(2*Math.PI)/p)+c+b},easeInOutElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d/2)==2)return b+c;if(!p)p=d*(.3*1.5);if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);if(t<1)return-.5*(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b;return a*Math.pow(2,-10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p)*.5+c+b},easeInBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;return c*(t/=d)*t*((s+1)*t-s)+b},easeOutBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b},easeInOutBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;if((t/=d/2)<1)return c/2*(t*t*(((s*=(1.525))+1)*t-s))+b;return c/2*((t-=2)*t*(((s*=(1.525))+1)*t+s)+2)+b},easeInBounce:function(x,t,b,c,d){return c-jQuery.easing.easeOutBounce(x,d-t,0,c,d)+b},easeOutBounce:function(x,t,b,c,d){if((t/=d)<(1/2.75)){return c*(7.5625*t*t)+b}else if(t<(2/2.75)){return c*(7.5625*(t-=(1.5/2.75))*t+.75)+b}else if(t<(2.5/2.75)){return c*(7.5625*(t-=(2.25/2.75))*t+.9375)+b}else{return c*(7.5625*(t-=(2.625/2.75))*t+.984375)+b}},easeInOutBounce:function(x,t,b,c,d){if(t<d/2)return jQuery.easing.easeInBounce(x,t*2,0,c,d)*.5+b;return jQuery.easing.easeOutBounce(x,t*2-d,0,c,d)*.5+c*.5+b}});

/*
 * jQuery swfObject Plugin
 *
 * website:			http://jquery.thewikies.com/swfobject/downloads
*/

(function(E,B){var C=function(G){var F,H=[];for(F in G){H.push(F+'="'+G[F]+'"')}return H.join("")},D=function(H){var F,J,I=[],G;for(F in H){if(typeof H[F]=="object"){G=[];for(J in H[F]){G.push([J,"=",encodeURIComponent(H[F][J])].join(""))}H[F]=G.join("&amp;")}I.push(['<param name="',F,'" value="',H[F],'" />'].join(""))}return I.join("")},A=false;E[B]=(function(){var F="0,0,0",G=navigator.plugins["Shockwave Flash"]||ActiveXObject;F=G.description||(function(){try{return(new G("ShockwaveFlash.ShockwaveFlash")).GetVariable("$version")}catch(H){}}());F=F.match(/^[A-Za-z\s]*?(\d+)[\.|,](\d+)(?:\s+r|,)(\d+)/);return{available:F[1]>0,activeX:!G.name,version:{major:F[1]*1,minor:F[2]*1,release:F[3]*1},hasVersion:function(I){var L=this.version,J="major",K="minor",H="release";I=(/string|number/.test(typeof I))?I.toString().split("."):I||[0,0,0];I=[I[J]||I[0]||L[J],I[K]||I[1]||L[K],I[H]||I[2]||L[H]];return(I[0]<L[J])||(I[0]==L[J]&&I[1]<L[K])||(I[0]==L[J]&&I[1]==L[K]&&I[2]<=L[H])},expressInstall:"expressInstall.swf",create:function(H){if(!E[B].available||A||!typeof H=="object"||!H.swf){return false}if(H.hasVersion&&!E[B].hasVersion(H.hasVersion)){H={swf:H.expressInstall||E[B].expressInstall,attrs:{id:"SWFObjectExprInst",height:Math.max(H.height||137),width:Math.max(H.width||214)},params:{flashvars:{MMredirectURL:location.href,MMplayerType:(E[B].activeX)?"ActiveX":"PlugIn",MMdoctitle:document.title.slice(0,47)+" - Flash Player Installation"}}};A=true}else{H=E.extend(true,{attrs:{height:H.height||180,width:H.width||320},params:{wmode:H.wmode||"opaque",flashvars:H.flashvars}},H)}return"<object "+(C(H.attrs))+(E[B].activeX?' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="movie" value="'+H.swf+'" />':' type="application/x-shockwave-flash" data="'+H.swf+'">')+(D(H.params))+"</object>"}}}());E.fn[B]=function(F){if(typeof F=="object"){this.each(function(){var G=document.createElement(B);G.innerHTML=E[B].create(F);if(G.childNodes[0]){this.appendChild(G.childNodes[0])}})}else{if(typeof F=="function"){this.find("object").andSelf().filter("object").each(function(){var H=this,G="jsInteractionTimeoutMs";H[G]=H[G]||0;if(H[G]<660){if(H.clientWidth||H.clientHeight){F.call(this)}else{setTimeout(function(){E(H)[B](F)},H[G]+66)}}})}}return this}}(jQuery,"flash"));

$(document).ready(function(){
					
/*
 * SITEWIDE USED FUNCTIONS
*/

	/* MODAL UTILS */
	
		//center element specified, must be in center of screen
		function centerBox(ele, animate){			
			var offset = $(window).scrollTop();
			var top = ($(window).height() / 2 - ele.outerHeight() / 2) + offset;
			var left = ($(window).width() / 2 - ele.outerWidth() / 2);
			
			if(animate){
				ele.animate({'top': top, 'left': left/*, 'opacity': opac*/}, {queue: false, duration: 500, easing: 'easeOutBack'});
			}else{
				ele.css({'top': top, 'left': left});	
			}
		}
		
		//setup resize and scroll "listener"
		function adjustBox(ele){			
			//recenter modal on scroll and resize
			$(window).scroll(function(){
				if(ele.is(':visible')) centerBox(ele, true);									  
			});	
			$(window).resize(function(){
				if(ele.is(':visible')) centerBox(ele, true);
			});
		}
		
		//add close to modals
		function addClose(ele){
			var close_link = ele.prepend($('<a href="#close" class="close">close</a>'));
			
			close_link.find('.close').click(function(){
				ele.animate({opacity: 0}, {duration: 200, easing: 'easeOutQuad', queue: false, complete: function(){$(this).css({display: 'none'})}});	
				
				return false;
			});
			
			return close_link.find('.close');
		}
		
		function closeModal(ele){
			ele.animate({opacity: 0}, {duration: 200, easing: 'easeOutQuad', queue: false, complete: function(){$(this).css({display: 'none'})}});					
			return false;
		}
		
		//show modal
		function displayModal(ele){
			centerBox(ele);
			ele.css({opacity: 0, display: 'block'});
			ele.animate({opacity: 1}, {duration: 400, easing: 'easeOutQuad', queue: false});	
		}
		
	/* END OF MODAL UTILS */
	
	/* ----------------------------------------- */
					
	/* SHARE STORY MODAL */		
	
		$share_story_modal = $('#share-story-modal');
	
		addClose($share_story_modal);
		
		$('.share-story').click(function(){										 
			displayModal($share_story_modal);
			return false;
		});
		
		//share story modal close
		$('#share-story-modal .share-your-stories').click(function(){											
			$share_story_modal.animate({opacity: 0}, {duration: 200, easing: 'easeOutQuad', queue: false, complete: function(){$(this).css({display: 'none'})}});	
		});		
		
		adjustBox($share_story_modal);
		
		//google analytics
		$('#home .share-story').click(function(){
			pageTracker._trackEvent('modal-home', 'share-open');
		});
		$('#home #terms').click(function(){
			pageTracker._trackEvent('modal-home', 'share-terms');
		});
		$('#home #privacy').click(function(){
			pageTracker._trackEvent('modal-home', 'share-privacy');
		});
		$('#home #share-story-modal .share-your-stories').click(function(){
			pageTracker._trackEvent('modal-home', 'share-story');
		});
		$('#detail .share-story').click(function(){
			pageTracker._trackEvent('modal-article', 'share-open', $('#detail #title').attr('title'));
		});
		$('#detail #terms').click(function(){
			pageTracker._trackEvent('modal-article', 'share-terms', $('#detail #title').attr('title'));
		});
		$('#detail #privacy').click(function(){
			pageTracker._trackEvent('modal-article', 'share-privacy', $('#detail #title').attr('title'));
		});
		$('#detail #share-story-modal .share-your-stories').click(function(){
			pageTracker._trackEvent('modal-article', 'share-story',  $('#detail #title').attr('title'));
		});
		
	
	/* END OF MODAL */	
	
	/* ----------------------------------------- */	
	
	/* PASS IT ON MODAL */
	
		$pass_it_on_modal = $('#pass-it-on-modal');
	
		addClose($pass_it_on_modal);
		
		adjustBox($pass_it_on_modal);
	
	/* END OF MODAL */	
	
	/* ----------------------------------------- */	
	
	/* SUBSCRIBE MODAL */
	
		$subscribe_modal = $('#subscribe-modal');
	
		addClose($subscribe_modal);	
		
		adjustBox($subscribe_modal);
		
	/* END OF MODAL */	
	
	/* ----------------------------------------- */
	
	/* ABOUT SEE THE GOOD MODAL */
	
		$about_modal = $('#about-modal');
	
		$('#about').html('&nbsp;&nbsp;&nbsp;&nbsp;');
		
		$('#about').click(function(){								 
			displayModal($about_modal);		
			return false;
		});
		
		addClose($about_modal);
		
		adjustBox($about_modal);
		
		//analytics
		$('#home #about').click(function(){
			pageTracker._trackEvent('modal-home', 'header-open');
		});
		
	
	/* END OF MODAL */
	
	/* ----------------------------------------- */	
	
	/* AUTOMATE MODAL DISPLAY */
	
		if($('#home').length > 0){
		
			switch(window.location.hash.substr(1)){
				
				case 'pass-it-on':											 
					displayModal($pass_it_on_modal);
					
					pageTracker._trackEvent('modal-home', 'refer', 'pass it on');
					break;
					
				case 'subscribe':											 
					displayModal($subscribe_modal);					
					pageTracker._trackEvent('modal-home', 'refer', 'subscribe');
					break;
					
				case 'share-story':
					displayModal($share_story_modal);				
					pageTracker._trackEvent('modal-home', 'refer', 'share-story');
					break;
			}
			
		}		
	
	/* END OF AUTOMATION */
	
	/* ----------------------------------------- */
	
	/* 
	 * JQUERY CSS3 EMULATOR 
	 * author: 	Chris Gonzales, Provenance Digital Media
	 * desc:	allow browsers to use css3 selectors that don't support it, jquery css3 not actual css3
	*/
	
		function jqueryCSS3(file){
		// css file that will be parsed, to make parse and cache css on server, 
		// remove all lines, spaces (except font names), comments and 
		// remove all styles without selectors listed below
		// and use just the parseAsCss3()
		var css_doc = file;
		//chars to check for that exist in css3, mush slashify all chars and separated by |
		var css_selectors = '\[|\\]|\=|\"|\~|\^|\$|\*|\||\:|\(|\)|\>|\+';
		//exceptions to css that already work in most browsers
		var css_exceptions = ':hover|:active|:link|:visited';
		
		//ajax call to load and parse css
		$.ajax({
			url		: css_doc,
			cache	: true,
			success	: parseCleanCss
		});
		
		function parseCleanCss(data){
			
			var css_str = cleanCss(data);
			
			var css_ary = parseCss(css_str);
			
			applyCss(css_ary);
		}
		
		//apply all css to document
		function applyCss(ary){
			//kinda a hack to get ie6 to update display
			$('#container').attr('style', '');
			for(style in ary){
				//alert(ary[style][0] + " --- " + ary[style][1]);
				$(ary[style][0]).attr('style', ary[style][1]);
			}
		}
		
		//parse css function
		function parseCss(str, checklines){	
		
			//if true will skip checking and just push styles into array
			var checklines = checklines ? true : false;
			
			//array that will hold all styles to be applied
			var css_ary = []
			
			tmp_ary = str.split('}');
			
			for(line in tmp_ary){
				var css_line = tmp_ary[line].split('{');
				var selector = css_line[0];
				
				if(checklines == false){
					if( selector.search(RegExp('[' + css_selectors + ']+', 'g')) > -1 && selector.search(RegExp('(' + css_exceptions + ')', 'g')) == -1){
						css_ary.push( css_line );
					}
				}else{
					css_ary.push( css_line );
				}
			}
			
			//$('#debug').text(css_ary.join("\r\n"));		
			return css_ary;
		}
		
		//clean css function
		function cleanCss(str){
			var css_str = str;
			
			//remove comments
			css_str = css_str.replace(/\/\*[\s\S]+?\*\//g, '');
			
			//remove newlines
			css_str = css_str.replace(/[\n]*/g, '');		
			
			//remove duplicate spaces
			css_str = css_str.replace(/[\s]+/g, ' ');
	
			return css_str;
		}
	}
	
		if($(document.body).attr('id') == 'home'){
			jqueryCSS3('/css/global.css');
		}else if($(document.body).attr('id') == 'detail'){
			jqueryCSS3('/css/article_detail.css');
		}else if($(document.body).attr('id') == 'archive' || $(document.body).attr('id') == 'search'){
			jqueryCSS3('/css/archive-search.css');
		}else if($(document.body).attr('id') == 'shorts'){
			jqueryCSS3('/css/shorts.css');
		}else if($(document.body).attr('id') == 'ecards'){
			jqueryCSS3('/css/ecards.css');
		}
	
	/* END OF EMULATOR */
	
	/* ----------------------------------------- */
	
	/* 
	 * VIDEO PLAYER REPLACER
	 * desc:	uses jquery swfobject to add play button, when pressed replace image with video player if they have flash, else this does nothing
	*/
	
		if($('#video .video').length > 0){
			
			//check bandwidth 
			var imgsize = 20;
			//start time
			var time = new Date();
			var start_time = time.getTime();	
			//load image
			var img	 = new Image();
			$(img).load(function(){
				var end_time = getEndTime();		
				calcBandwidth(start_time, end_time);
			}).attr('src', '/bw.php');	
			//end time
			function getEndTime(){
				var time = new Date();
				return time.getTime();
			}	
			//calc 
			function calcBandwidth(start, end){	
				//calc down time
				var download_time = (start == end) ? .01 : ( (end - start) / 1000 );
				var bw_Kbps = imgsize*10 / download_time;
				
				//calc bw				
				
				if(bw_Kbps >= 300){
						//add video player play button
						$('#video').each(function(){
							var img = new Image();
							img.src = '/images/content/video-player-play.png';				
							$(img).addClass('play');
							$(img).css({left: 132, top: 91});
							if($('#detail').length > 0){
								$(img).css({left: 210, top: 134});	
							}
							$('#video').append(img);
							$(img).hover(
								function(){
									$(img).animate({opacity:.8}, {duration: 300});
								},
								function(){
									$(img).animate({opacity:1}, {duration: 300});
								}
							);
						});
						
						//add google analytics event tracking
						$('#home #sidebar #video img').click(function(){
							var title = $(this).parent().attr('title');
							pageTracker._trackEvent('video-home', 'sidebar', title);
						});			
						$('#home #featured #video img').click(function(){
							var title = $(this).parent().attr('title');
							pageTracker._trackEvent('video-home', 'featured', title);
						});		
						$('#detail #video img').click(function(){
							var title = $(this).parent().attr('title');
							pageTracker._trackEvent('video-article', 'detail', title);
						});
						
						//when button is click setup and start video
						$('#video img').click(function(){							  
							$(this).parent().flash({
								swf	: '/media/flash/player.swf',
								params:	{
									wmode				: 'transparent',
									allowfullscreen		: 'true',
									allowscriptaccess	: 'always'				
								},
								height	: $('#video img:first').attr('height'),
								width	: $('#video img:first').attr('width'),
								flashvars:	{
									file		: $('#video a').attr('href'),
									image		: $('#video img').attr('src'),
									skin		: '/media/flash/modieus.swf',
									autostart	: true,
									fullscreen	: true,
									stretching	: 'uniform',
									controlbar	: 'over',
									backcolor	: '000000',
									frontcolor	: 'ffffff',
									lightcolor	: '99CC00',
									screencolor	: '000000'
								}
							});
						});
				}
			}
			
			
			
			
		}
	
	/* END OF REPLACER */
	
	/* ----------------------------------------- */
	
	/*
	 * TEXTAREA AUTO GROW
	*/
		
		$('textarea:not(.ignore)').each(function() {		
			var $this       = $(this),
				minHeight   = $this.height(),
				lineHeight  = $this.css('lineHeight');
			
			var shadow = $('<div></div>').css({
				position:   'absolute',
				top:        -10000,
				left:       -10000,
				width:      $(this).width(),
				fontSize:   $this.css('fontSize'),
				fontFamily: $this.css('fontFamily'),
				lineHeight: $this.css('lineHeight'),
				resize:     'none'
			}).appendTo(document.body);
			shadow.hide();
			
			var update = function() {
				
				var val = this.value.replace(/</g, '&lt;')
									.replace(/>/g, '&gt;')
									.replace(/&/g, '&amp;')
									.replace(/\n/g, '<br/>');
				
				shadow.html(val);
				shadow.hide();
				$(this).css('height', Math.max(shadow.height() + 20, minHeight));
				$(this).css({overflow: 'hidden'});
			}
			
			$(this).change(update).keyup(update).keydown(update);
			
			update.apply(this);		
		});
		
	/* END OF AUTOGROW */
	
	/* ----------------------------------------- */
	
	/*
	 * EXIT NOTICE MODAL
	*/
	
		$('#article-content a[target="_blank"]:not([class=disable-exit-msg]), #article-content a[href*="http://"]:not([class=disable-exit-msg])').click(function(){
			
			var overlay = $('<div id="exit-notice-overlay">&nbsp;</div>');
			overlay.css({width: ($(window).width()), height: ($(document).height()), display: 'block', opacity: .8});
			
			var modal = $('<div id="exit-notice"><p>You are leaving the seethegood.com web site and are now entering an external web site. Seethegood.com provides links to other web sites merely and strictly for your convenience. The site you are entering is operated or controlled by a third party that is unaffiliated with seethegood.com.</p><p>Seethegood.com does not monitor the linked web site and has no responsibility whatsoever for or control over the content provided on the linked web site. The privacy policies and security at the linked web site may differ from seethegood.com\'s privacy and security policies and procedures. Seethegood.com suggests you consult the privacy disclosures at the linked web site for further information.</p></div>');
			
			var link_yes 	= $('<a href="' + $(this).attr('href') + '">continue</a>');
			var link_no		= $('<a href="#cancel">cancel</a>');
			
			link_no.click(function(){
				overlay.css({opacity: 0});
				$('#exit-notice').animate({opacity: 0}, {duration: 700, easing: 'easeOutQuad', queue: false, complete: function(){$('#exit-notice-overlay, #exit-notice').remove();}});	
			});
			
			overlay.click(function(){ link_no.trigger('click');});
			
			modal.append('<span></span');
			modal.find('span').eq(0).append(link_yes, link_no);
			
			$(document.body).append(overlay, modal);
			
			centerBox(modal);
			
			
			return false;
		});
		
		//recenter modal on scroll and resize
		$(window).scroll(function(){
			var modal = $('#exit-notice:visible');
			if(modal.length > 0) centerBox(modal, true);
		});	
		$(window).resize(function(){
			var modal = $('#exit-notice:visible');
			if(modal.length > 0) centerBox(modal, true);
		});
	
	
	/* END OF NOTICE */	
	
	/* ----------------------------------------- */
	
	/*
	 * CLEAR DEFAULT FROM FORM FIELD
	*/
	
		$('.default').each(function(){
			$(this).css({'color' : '#777'});
			var _default = $(this)[0].defaultValue;//document.getElementById($(this).attr('id')).defaultValue;
			$(this).focus(function(){
				$(this).css({'color' : '#000'});
				if($(this).val() == _default){
					$(this).val('');	
				}
			});
			$(this).blur(function(){
				if($(this).val() == ''){
					$(this).val(_default);	
					$(this).css({'color' : '#777'});
				}
			});						
		});
		
	/* END OF DEFAULT */
	
	/* ----------------------------------------- */
	
	/* 
	 * SIMPLE HINTS
	*/
	
		$('.hint').each(function(){
			var hint = $('<div style="position:absolute; padding:0 0 5px; background:url(/images/content/sprite.png) 0 -816px;"><p style="background:#5d9732; color:#fff; padding:2px 6px; margin:0; font-size:11px; font-family:Arial, Helvetica, sans-serif; line-height:20px;">' + $(this).attr('title') + '</p></div>');
			$(this).attr('title', '');
			hint.css({opacity: 0});
			var timeout;
			
			$(this).hover(
				function(){
					$(document.body).append(hint);
					var opac = hint.css('opacity');
					hint.css({backgroundPosition: (hint.outerWidth()/2 - 5) + 'px -816px', left: $(this).offset().left  - hint.outerWidth()/2 + $(this).outerWidth()/2, top: $(this).offset().top - hint.height() - 5, opacity: 0});
					if(opac == 0){
						hint.animate({opacity: 1}, {duration: 300, queue: false});
					}else{						
						hint.css({opacity: 1});
					}
					clearTimeout(timeout);
				},
				function(){		
					timeout = setTimeout(function(){hint.animate({opacity: 0}, {duration: 400, queue: false, complete: function(){ $(this).remove();}});}, 500);
				}
			);
		});
						
	
	/* END OF HINTS */
		
	/* ----------------------------------------- */	
	
	/* OTHER GOOGLE ANALYTICS*/
	
		$('#home #share-comments .share-comment').click(function(){
			pageTracker._trackEvent('mailto-home', 'comment');
		});
		$('#detail #article-links .email').click(function(){
			pageTracker._trackEvent('mailto-article', 'email-this',  $('#detail #title').attr('title'));
		});
		$('#detail #article-links .comments').click(function(){
			pageTracker._trackEvent('article', 'comments',  $('#detail #title').attr('title'));
		});
		$('#detail #article-links .print').click(function(){
			pageTracker._trackEvent('article', 'print',  $('#detail #title').attr('title'));
		});
		$('#detail #article-links .return').click(function(){
			pageTracker._trackEvent('article', 'home-footer',  $('#detail #title').attr('title'));
		});
		$('#detail #article-links .share').click(function(){
			pageTracker._trackEvent('share-click', 'open',  $('#detail #title').attr('title'));
		});
		$('#detail #top-nav .previous').click(function(){
			pageTracker._trackEvent('article', 'previous',  $('#detail #title').attr('title'));
		});
		$('#detail #top-nav .next').click(function(){
			pageTracker._trackEvent('article', 'next',  $('#detail #title').attr('title'));
		});
		$('#detail #top-nav .home, #detail #top-nav .home-alt').click(function(){
			pageTracker._trackEvent('article', 'home-top',  $('#detail #title').attr('title'));
		});
		$('#detail #top-nav .archive').click(function(){
			pageTracker._trackEvent('article', 'archive',  $('#detail #title').attr('title'));
		});
	
	/* END OF ANALYTICS */
	
/*
 * INDEX PAGE FUNCTIONS & ETC...
*/

	/* 
	 * ARTICLE SLIDER
	 * desc:	slider for homepage articles quicklist
	*/
	
		$('#article-quicklist').each(function(){
											  
			var item_width = 142;
											  
			//function to set click events
			function bindQuicklistNav(){
				//check nav buttons
				checkButtons()
				//set event for next link
				$('#article-quicklist .next').click(function(){	
					pageTracker._trackEvent('quicklist', 'next');
					var offset = evaluateQuicklist('right');	
					if(offset !== false){
						unbindQuicklistNav();
						$('#article-quicklist ul').animate({marginLeft: offset}, {duration: 1300, easing: 'easeInOutQuad', queue: false, complete: bindQuicklistNav});
					}
					return false;
				});
				
				//set event for previus link
				$('#article-quicklist .previous').click(function(){		
					pageTracker._trackEvent('quicklist', 'previous');
					var offset = evaluateQuicklist('left');
					if(offset !== false){
						unbindQuicklistNav();
						$('#article-quicklist ul').animate({marginLeft: offset}, {duration: 1300, easing: 'easeInOutQuad', queue: false, complete: bindQuicklistNav});	
					}
					return false;
				});
			}
			
			//function to remove events
			function unbindQuicklistNav(){
				$('#article-quicklist .next, #article-quicklist .previous').unbind('click');
			}
			
			//adjust items in list to compensate for next or previous slide
			function evaluateQuicklist(move){						
				var offset = false;
				
				if(move == 'right'){
					
					if(step*6 < quicklist_items.length && (quicklist_items.length%6 == 0 || Math.ceil(quicklist_items.length/6) > step+1)){
						offset = -6 * item_width;
					}else if(step*6 < quicklist_items.length){
						offset = -((quicklist_items.length - (step*6) )%6 * item_width);
					}
					
					if(offset){
						offset = (offset + parseInt($('#article-quicklist ul').css('marginLeft')));
						step++;
					}
					
				}else if(move == 'left'){
					
					if(step > 1 && step*6 <= quicklist_items.length){
						offset = 6 * item_width * (step-1);
					}else if(step*6 > quicklist_items.length){
						offset = quicklist_items.length%6 * item_width;	
					}															
					
					if(offset){
						offset = (offset + parseInt($('#article-quicklist ul').css('marginLeft')));
						step--;
					}
				}
				
				return offset;
			}
			
			//check if nav items need to be hidden
			function checkButtons(){
				$(link_previous).animate({opacity: 1},{duration: 300});
				$(link_next).animate({opacity: 1},{duration: 300});
				$(link_previous).css({cursor: 'pointer'});
				$(link_next).css({cursor: 'pointer'});
				if(step == 1){
					link_previous.animate({opacity: .2},{duration: 300});
					$(link_previous).css({cursor: 'default'});
				}else if(step == Math.ceil(quicklist_items.length/6)){
					link_next.animate({opacity: .2},{duration: 300});	
					$(link_next).css({cursor: 'default'});
				}
			}
			
			//current step of slide
			var step = 1;
			
			//previous button
			var link_previous = $('<a href="#previous" class="previous">previous</a>').css({visibility: 'hidden'});
			//next button
			var link_next = $('<a href="#next" class="next">next</a>').css({visibility: 'hidden'});			
			
			//add buttons
			$(this).prepend(link_previous);			
			$(this).append(link_next);
			
			//store quicklist items for future use
			var quicklist_items = $('#article-quicklist ul li');
			
			//check if buttons needed
			if(quicklist_items.length > 6){
				$(this).find('.next, .previous').css({visibility: 'visible'});	
			}
			
			//swap the slide to active styles
			$('#article-quicklist>div').addClass('active');		
			
			//get width needed for quicklist
			var quicklist_width = (quicklist_items.length)* item_width;
			
			//adjust article quicklist width to fit all items
			$('#article-quicklist ul').css({width: quicklist_width});
			
			//init controls
			bindQuicklistNav();
			
		});
	
	/* END OF SLIDER */	
	
	/* ----------------------------------------- */
	
	/*
	 * COMMENTS VERTICAL SLIDER
	*/
	
		$('#share-comments').each(function(){
										   
			var steps = [];			
			var comments = $(this).find('.comment');			
			var step = [];
			
			if(comments.length <= 2){
				$('#share-comments>div>div').css({position: 'relative'});
				$('#share-comments>div>div').parent().height($('#share-comments>div>div').height());
				return false;
			}
			
			for(i=0; i<comments.length; i++){
				if(step.length == 2){
					steps.push(step);
					step = [];
				}
				step.push(comments[i]);
			}
			steps.push(step);
			
			var current_step = 0;
			
			$('#comments').css({height: getHeight(current_step, steps)});
			
			var controls = $('<div class="controls"></div>');
			var prev = $('<a href="#prev" class="prev-inactive">prev</a>');    
			var next = $('<a href="#next" class="next">next</a>');
			
			prev.click(function(){					
				
				pageTracker._trackEvent('comments-home', 'previous');
								
				if(!$(this).hasClass('prev-inactive')){
					current_step--;
					var top = current_step > 0 ? -getTop(current_step-1, steps) : 0;
					
					$('#comments>div').animate({top: top});
					$('#comments').animate({height: getHeight(current_step, steps)});						
				}				
				
				if(current_step == 0){
					$(this).addClass('prev-inactive');
					$(this).removeClass('prev');
				}else{
					$(this).removeClass('prev-inactive');
					$(this).addClass('prev');
				}
				
				if(current_step < steps.length){
					next.removeClass('next-inactive');	
					next.addClass('next');
				}else{
					next.addClass('next-inactive');		
					next.removeClass('next');
				}
			});
			
			next.click(function(){				
				
				pageTracker._trackEvent('comments-home', 'next');
				
				if(!$(this).hasClass('next-inactive')){
					$('#comments>div').animate({top: -getTop(current_step, steps)});
					current_step++;
					$('#comments').animate({height: getHeight(current_step, steps)});					
				}				
				
				if(current_step == steps.length-1){
					$(this).addClass('next-inactive');	
					$(this).removeClass('next');
				}else{
					$(this).removeClass('next-inactive');
					$(this).addClass('next');
				}
				
				if(current_step > 0){
					prev.removeClass('prev-inactive');	
					prev.addClass('prev');	
				}else{
					prev.addClass('prev-inactive');	
					prev.removeClass('prev');	
				}
			});
			
			$(controls).append(prev, next);
			
			$(this).append(controls)
			
		});
			
		function getTop(step, ary){
			var h = 0;
			for(i=0; i<=step; i++){
				for(div in ary[i]){
					h+= $(ary[i][div]).height();	
					h+= parseInt($(ary[i][div]).css('marginBottom'));
				}	
			}			
			return h-2;
		}
		
		function getHeight(step, ary){
			var h = 0;
			for(div in ary[step]){
				h+= $(ary[step][div]).height();	
				h+= parseInt($(ary[step][div]).css('marginBottom'));
			}	
			return h;
		}
	
	/* END OF SLIDER */
	
	/* ----------------------------------------- */
	
	/*
	 * HIDE SUBSCRIBE SUCCESS MESSAGE
	*/
	
		$('#frm_subscribe .msg').animate({opacity: 1}, {duration: 5000}).animate({opacity: 0}, {duration: 700, complete: function(){ $(this).remove();}});
	
	/* END OF MESSAGE */
	
/*
 * ARTICLE DETAIL FUNCTIONS & ETC...
*/
	
	/*
	 * MISC
	 */
 
		//any print link with the class link with print
		$('.print').click(function(){
			window.print();
		});

	/* END OF MISC
	
	/* ----------------------------------------- */
	
	/*
	 * SOCIAL SHARE DROPDOWN
	 * desc:	dropdown list of social sites
	*/
	
		//display drop down box for share social sites
		function displayShareSocial(){
			
			//display overlay
			$('#share-social-overlay').css({width: ($(window).width()), height: ($(document).height()), display: 'block', opacity: 0});
			$('#share-social-overlay').unbind('click').click(function(){
				$('.share-active').trigger('click');
			});
			
			
			var offset = $('.share').offset();
			var filler = $('<li class="filler">&nbsp;</li>');
			
			$('#share-social').css({width: 130});
			
			if(offset.top + 100 + $('#share-social').height() > $(document).height()){
				$('#share-social').css({top: offset.top-5 - $('#share-social').height(), left: offset.left-10});		
				filler.css({borderTop: '1px solid #000', background: 'none', cursor: 'pointer'});
				$('#share-social').append(filler);
			}else{
				$('#share-social').css({top: offset.top-5, left: offset.left-10});
				filler.css({borderBottom: '1px solid #000', background: 'none', cursor: 'pointer'});
				$('#share-social').prepend(filler);
			}		
			
			$('#share-social').css({display: 'block', opacity: 0});
			$('#share-social').animate({opacity: 1}, {duration: 400, easing: 'easeOutQuad', queue: false});
			
			filler.click(function(){
				$('.share-active').trigger('click');
			});
			
			$('#share-social a').unbind('click').click(function(){	
				pageTracker._trackEvent('share-select', $(this).attr('title'),  $('#detail #title').attr('title'));
				$('.share-active').trigger('click');		
			});
			//ie fix filler for li bg
			$('#share-social li').width($('#share-social').width());
			
			
		}
		
		//hide drop down box for share social sites
		function hideShareSocial(){		
		
			$('#share-social').animate({opacity: 0}, {duration: 300, easing: 'easeOutQuad', queue: false, complete: function(){
				$('#share-social, #share-social-overlay').css({display: 'none'});	
				$('#share-social .filler').remove();
			}});
			
		}
		
		//apply share social events
		$('.share').click(function(){
			if($(this).hasClass('share')){
				displayShareSocial();
				$(this).attr('class', 'share-active');
			}else{				
				hideShareSocial();
				$(this).attr('class', 'share');
			}
			return false;
		});
	
	/* END OF DROPDOWN */
	
	/* ----------------------------------------- */
	
	/*
	 * SIMPLE FORM VALIDATION
	 *
	*/	
	
		$('form.valid').submit(function(){
			var msg = '';
			
			$(this).find('label.required').each(function(){
				$input = $('#' + $(this).attr('for')).eq(0);
				
				if($input.val() == $input[0].defaultValue) $input.val('');
				
				if($input.val() == ''){
					msg+= $(this).text() + " is required\n";
				}else if($input.attr('name') == 'email'){
					if($input.val().search(/([^\/.]+)@([^\/.]+)\.([^\/.]+)/) == -1){
						if($input.attr('title')){
							msg+= $input.attr('title') + 'is invalid';	
						}else{
							msg+= $(this).text() + " is invalid";
						}
					}
				}
			});
			
			if(msg){
				alert(msg);
				return false;	
			}
			
			return true;
		});
	
	/* END OF VALIDATION */
	
	/* ----------------------------------------- */
	
	/*
	 * JUMP TO MSG AND HIDE
	*/
	
		if($('#msg').length > 0) window.location.hash = 'msg';
		$('#msg').animate({opacity: 1}, {duration: 5000}).animate({opacity: 0, height: 0, paddingTop: 0, paddingBottom: 0, marginBottom: 0}, {duration: 700, complete: function(){ $(this).remove();}});
	
	/* END OF JUMP TO */
	
	/* ----------------------------------------- */
	
	/* REMOVE AUDIO PLAYER */
	
	$('#audio').each(function(){
	
		//remove player if bandwidth is to slow 
			var imgsize = 20;
			//start time
			var time = new Date();
			var start_time = time.getTime();	
			//load image
			var img	 = new Image();
			$(img).load(function(){
				var end_time = getEndTime();		
				calcBandwidth(start_time, end_time);
			}).attr('src', '/bw.php');	
			//end time
			function getEndTime(){
				var time = new Date();
				return time.getTime();
			}	
			//calc 
			function calcBandwidth(start, end){	
				//calc down time
				var download_time = (start == end) ? .01 : ( (end - start) / 1000 );
				var bw_Kbps = imgsize*10 / download_time;
				
				//calc bw				
				
				if(bw_Kbps < 300){
					$('#audio').remove();
				}
			}
			
	});
	/* REMOVE PLAYER */
	
	/* ----------------------------------------- */
	
	/* ARCHIVE DROP DOWN */
	var archive_cat_width = 0;
	var archive_cat_intv = 0;
	
	$('#archive #nav ul ul li a, #search #nav ul ul li a').each(function(){
		if(archive_cat_width < $(this).outerWidth()) archive_cat_width = $(this).outerWidth();
	});
	$('#archive #nav ul ul, #search #nav ul ul').css({width: archive_cat_width});
	$('#archive #nav ul ul li a, #search #nav ul ul li a').css({width: archive_cat_width - 10});
	
	$('#archive #categories, #search #categories').find('+ul').css({opacity: 0}).end().hover(
		function(){
			clearTimeout(archive_cat_intv);
			$(this).find('+ul').css({visibility: 'visible'}).animate({opacity: 1}, {duration: 300, queue: false});
		},
		function(){
			archive_cat_intv = setTimeout(hideArchiveCat, 300);
		}
	);
	$('#archive #categories +ul, #search #categories +ul').hover(
		function(){
			clearTimeout(archive_cat_intv);
		},
		function(){
			archive_cat_intv = setTimeout(hideArchiveCat, 300);
		}
	);
	
	
	function hideArchiveCat()
	{
		$('#archive #categories, #search #categories').find('+ul').animate({opacity: 0}, {duration: 200, queue: false, complete: function(){$(this).css({visibility: 'hidden'});	}});	
	}
	
	/* END - ARCHIVE DROP DOWN */	
	
	/* ----------------------------------------- */
	
	/* ECARDS */
	$chooser 	= $('#content #chooser');
	$cards		= $chooser.find('.cards');
	$more		= $('.e-cards-more');
	$back		= $('.e-cards-back');
	
	$more.click(function(){
		$cards.animate({left: -896}, {duration: 600, queue: false, easing: 'easeInOutQuad'});
		$more.animate({opacity: .2}, {queue: false});
		$back.animate({opacity: 1}, {queue: false});
	});	
	$back.click(function(){
		$cards.animate({left: 10}, {duration: 600, queue: false, easing: 'easeInOutQuad'});	
		$back.animate({opacity: 0}, {queue: false});
		$more.animate({opacity: 1}, {queue: false});
	}).css({opacity: 0});	
	
	$('#content #create').submit(function(){
		$text = $(this).find('input[type=text]:not([name=ecard_check])');
		r = true;
		msg = '';
		$text.each(function(){
			var $this = $(this);
			if($this.val() == ''){
				msg+= $this.attr('title') + " is required \n";
				r = false;
			}
			if($this.hasClass('email') && $this.val().search(/([^\/.]+)@([^\/.]+)\.([^\/.]+)/) == -1 && $this.val() != ''){
				msg+= $this.attr('title') + " is invalid \n";	
				r = false;
			}			
		});
		
		if(msg) alert(msg);
		
		return r;
	});
	
	$('#content #create .select').click(function(){
		displayModal($('#modal'));		
		return false;
	}).each(function(){
		var $modal = $('#modal');
		adjustBox($modal);
		$close = addClose($modal);
		
		$modal.find('li a').click(function(){
			var val = $(this).attr('href').split('/');
			val.pop();
			var id = val.pop();			
			$('#content #create input[name=ecard]').val(id);			
			$('span.img img').attr('src', '/images/ecards/' + cards[id][2]);
			$close.trigger('click');
			return false;
		});
	});
	
	$('#content #create input[name=email_to]').change(function(){
		var val = $(this).val();	
		val = val.replace(/([^\/]+)@([^\/.]+)\.([^\/.]+)/, "$2");
		$('.error').css({display: 'none'});
		
		if(val == 'aol'){
			if($('.error').length == 1){
				$('.error').css({display: 'block'});
			}else{
				$('<strong class="error">We are sorry for the inconvenience, but AOL addresses are not able to receive See the Good E-Cards at this time</strong>').insertAfter($('span'));
			}
			
			$(this).val('');
		}
	});
	
	//	
	
	/* ENF OF ECARDS */
	
	/* ----------------------------------------- */
	
	/* GOOD SHORTS */
	$shorts_modal = $('form#submit-short');
	adjustBox($shorts_modal);
	addClose($shorts_modal);
	
	$('.short-modal').click(function(){
		displayModal($shorts_modal);	
		
		return false;
	});
	
	
});