/*! 
 * Created in 2010-12 by Juxtaprose, http://juxtaprose.com/
 */ 

var TX = TX || {};
/*! version number for lib.js and video.js */
TX.jsver = '-20110823'; 
/*! */
TX.glossaryTBQ = '?height=300&amp;width=300';
TX.ajaxMoreURL = '/site/ajax-whats-new/';
TX.viewMore = 'view more';
TX.loadingImg = '/scripts/ajax-loader2.gif';
TX.sbcnt = 0;

/* 
	parseURI and cookie functions moved to lib.js on 8/23/2011
	note that this is now set in lib.js:
	
	TX.pageurl = TX.parseUri(window.location.href);

*/

/* don't show MailChimp evil popup on these pages */
TX.noPopup = ['/terms/','/privacy/','/site/thank-you/'];
TX.evilPopupWait = 20; //seconds before showing evil popup
TX.evilPopupMinWidth = 700; // min pixel width of screen on which popup will pop

$LAB
//.script('/scripts/jquery-1.4.4.min.js').wait()
//.script('/scripts/jquery.colorbox-min.js','/scripts/jquery.tools-validator.min.js','/scripts/jquery.dumbcrossfade-2.0.min.js','/scripts/jquery.textTruncate.js','/browse-topics/js/'+TX.browse_topics_ts+'/')
.script('/scripts/lib'+TX.jsver+'.js','/browse-topics/js/'+TX.browse_topics_ts+'/')
.wait(function() {

	$txjQ(document).ready(function($) {	
		/* clean-up for ads that don't display in sidebar */
		$.each($('.sidebar .box-slot'), function() {
			h = $(this).height();
			if (h==0) {
				$(this).css('display','none');
			}
		});
		
		/* clean-up IE cufon issue */
		$('.cufon-vml').parent('span').css('vertical-align','top');
		
			/* browse topics overlay */
		$('#util_browse a').colorbox({
			width: 854,
			height: 554, //579
			initialWidth: 854,
			initialHeight: 200,
			scrolling: false,
			opacity: 0.4,
			speed: 200,
			transition: 'elastic',
			html: '<div id="bmenu">'+TX.menu_items + TX.menu_bottom+'</div>',
			onOpen: function() {
				$.each($('iframe,object,embed'), function() {
					v = $(this).css('visibility');
					if (v=='visible') {
						$(this).addClass('txobjhide');
					}
				})					
			},
			onComplete: function () {
				Cufon.replace('#cboxTitle');
				try {
					_gaq.push(['_trackPageview', '/browse-topics/js/']);
				} catch(c) {}					
			},
			onClosed: function() {
				$('.txobjhide').removeClass('txobjhide');
			}
		});
		
		/* large image (and glossary?) overlay */
		$('.imagelarge').colorbox({
			initialWidth: 100,
			initialHeight: 100,		
			scrolling: false,
			opacity: 0.7,
			speed: 100,
			transition: 'fade',
			onOpen: function() {
				$('#colorbox').addClass('popimage');
				$('#cboxClose').css('visibility','hidden');
				$.each($('iframe,object,embed'), function() {
					v = $(this).css('visibility');
					if (v=='visible') {
						$(this).addClass('txobjhide');
					}
				})
			},		
			onComplete: function() {
				$('#cboxClose').css('visibility','visible');			
			},
			onClosed: function() {
				$('.txobjhide').removeClass('txobjhide');
				$('#colorbox').removeClass('popimage');
			}
		});
	
		
		/* text wrapping in boxes (sizes are -5px) */
		$('.boxwide .excerpt p').textTruncate(500,'&hellip;');		
		$('.w388 .excerpt p').textTruncate(485,'&hellip;');
				
		/* MailChimp mailing list sign-up referer / source tracking */
		(function() {
			//var u = TX.parseUri(window.location.href);
			var updateParams = function(id,qkey) {
				var elm = $('#'+id);
				if (elm.size() > 0 && $(elm).val()=='') {
					if (TX.pageurl.queryKey[qkey]) {
						var s = decodeURI(TX.pageurl.queryKey[qkey]).replace('+', ' ');
						$(elm).val(s);
					} else if (document.referrer) {
						$(elm).val(document.referrer);			
					}			
				}
			}
			updateParams('mc_source','utm_source');
			updateParams('mc_subid','subid');
			updateParams('mc_optin','s');			
		})();

		/* MyPoints mailing list sign-up referer / source tracking */
		(function() {
			var cookie = 'mypvisit';
			var pvisit = TX.pageurl.queryKey['visit_id'];
			if (pvisit) {
				TX.setCookie(cookie,pvisit);
			}					
			var elm = $('#mypoints');
			if (elm.size() > 0) {
				var cvisit = pvisit || TX.getCookie(cookie);
				if (cvisit) {
					$(elm).html('<img src="http://www.mypoints.com/emp/u/'+cvisit+'/A/ctr.gif" height="1" width="1">');
				}			
			}
		})();

		
		/* Email form validation */
		$('.esubform').validator({
			position: 'bottom center', 
			offset: [-1, 10],
			message: '<div><em/></div>'
		});		
	
		/* slide boxes */
		$.each($('.slideboxfull'), function() {
			TX.sbcnt++;
	
			$(this).attr('id','sb'+TX.sbcnt);
			var sb = $('.slide',this);
			var sb_size = sb.size();
			if (sb_size > 0) {
				$(sb).dumbCrossFade({
					slideType:'fade',
					showTime: 5000,
					transitionTime: 500,
					slideDirection: 'forward',
					slideChange: function(i) {
						var num = i+1;
						$('.slidecontrol a').removeClass('on');
						$('#sb'+TX.sbcnt+'_i'+num).addClass('on');
					}
				});	
				var controls = '<div class="slidecontrol">';
				for (i=0; i<sb_size; i++) {
					var num = i+1;
					controls += '<a href="#'+num+'" class="iselect';
					if (num==1) {
						controls += ' on';
					}
					controls += '" id="sb'+TX.sbcnt+'_i'+num+'">'+num+'</a>';
				}
				controls += '<a href="#play-pause" class="pause" id="sb'+TX.sbcnt+'pp"><span>Play / Pause</span></a>';
				controls += '</div>';	
				
				$(this).append(controls);	
				$('.iselect',this).click(function(e) {
					e.preventDefault();
					var iof = this.id.indexOf('i');
					if (iof > -1) {	
						$(sb).dumbCrossFade('jump', parseInt(this.id.substring(iof+1))-1);
					}
				});
				$('#sb'+TX.sbcnt+'pp').click(function(e) {	
					e.preventDefault();
					c = $(this).attr('class');
				//	console.log(c);
					if (c=='pause') {
						$(sb).dumbCrossFade('stop');
						$(this).removeClass('pause').addClass('play');
					} else {
						$(sb).dumbCrossFade('start');			
						$('.slide img, .slide .caption').css('display','block');
						$(this).removeClass('play').addClass('pause');
					}
				});
				
			}	
		});	
		
		TX.commentSetup = function() {
			/* clean-up for closed comments that don't display in main column */
			$.each($('.main .comment-container'), function() {
				h = $(this).height();
				if (h<13) {
					$(this).css('border','0');
				}
			});
					
			/* Show "reply to" links and bind to the click event */
			$('.reply a').click(function() {
		
			  var id = $(this).attr('href').substring(1); 
			  
	//		  console.log($(this).attr('href').substring(1), $(this).attr('href'));
			  
			  // Change the value of weever-parent-id
			  $('#weever-parent-id').val(id);
			  
			  // Now we'll move the form
			  $('#comment_form')
				.insertAfter(    // Insert the comment form after div.entry
				  $(this)
				  .parent()    // The containing p tag
					  // div.entry
				  );
		
			  return false;
			});
			
			$('.reply').css('visibility','visible');			
		}	
		TX.commentSetup();
		
	
		/* glossary links
		$.each($('a.glossary'), function() {
			$(this).attr('href',$(this).attr('href') + TX.glossaryTBQ);
			$(this).attr('title','click to read a definition for this term');
		});
	 */	

		/* view more listing */
		var ucnt = 0;
		$.each($('ul.listing'),function() {
			ucnt++;
			$(this).attr('id', 'u'+ucnt);
			var c = $(this).attr('class');
			
			var lilen = $(this).children('li').length;
			lim = TX.moreArray(c)['limit'];
	
			if (lilen==lim) {
				c = 'morebut ' + c.replace(/listing /,'');
				$(this).addClass('listmore').after('<a id="d'+ucnt+'" class="'+c+'"  href="#"><span>'+TX.viewMore+'</span></a>');
				$('#d'+ucnt).data('offset',lim);
				$('#d'+ucnt).data('loading',false);			
				
				$('#d'+ucnt).click(function(e) {
					e.preventDefault();
					if (!$(this).data('loading')) {
						var c = $(this).attr('class');
						var p = TX.moreArray(c);
						var url = TX.ajaxMoreURL + p['cat_url'] + '/';
						url += p['source'] + '/';
						var tlim = p['limit'];
						url += tlim + '/';
						var lastOffset = $(this).data('offset');
						url += lastOffset + '/';				
						url += p['cat_id'] + '/';				
						var nextOffset =  parseInt(lastOffset) + parseInt(p['limit']);
						$(this).data('offset', nextOffset);
						$(this).data('loading', true);
						var hold = $(this).html();
						$(this).html('<img src="'+TX.loadingImg+'" border="0" />');					
						var holdid = $(this).attr('id');
						var uid = 'u'+holdid.substring(1)
	
						$.ajax({
							url : url,
							success: function (data) {
								$('#'+holdid).data('loading', false);
								$('#'+uid).append(data);
								if ($('li','<ul>'+data+'</ul>').length < tlim) {
									$('#'+uid).removeClass('listmore');
									$('#'+holdid).css('display','none');
								} else {
									$('#'+holdid).html(hold);	
								}	
							},
							error: function () {
								$('#'+holdid).data('loading', false);	
								$('#'+holdid).html(hold);																												
							}						
						});
						try {
							_gaq.push(['_trackPageview', url]);	
						} catch(c) {}									
					}	
				});		
			}	
		});	
		
		/* member register form clean-up 
		$.each($(
			'#register_member_form select[name=m_field_id_6],  #register_member_form select[name=m_field_id_7], #register_member_form select[name=m_field_id_8], #register_member_form select[name=m_field_id_9], #register_member_form select[name=m_field_id_10], #register_member_form select[name=m_field_id_11]'),
			function() {
				$(this).attr('name','z'+$(this).attr('name'));
				var p = $(this).parents('tr').get(0);
				$(p).css('display','none');
					
		});
		*/
		
		/* fix for crazy-ass out of date Amazon code follows 
		//document.write = TX.docwrite;
		//$('body').append('<script type="text/javascript">jQuery.noConflict(true)</script><script type="text/javascript"  src="http://www.assoc-amazon.com/s/link-enhancer?tag=techlicious-20&amp;o=1"></script><div id="dude-wtf-amazon"></div>');	
		*/	
		
	/*	$('#register_member_form').submit(function() {
			var chk = $('#register_member_form input[name=m_field_id_6]').attr('checked');
			if (chk != 'checked' || chk != 'true') {
				$('#register_member_form input[name=m_field_id_7]').attr('value','no');
			}	
			return true;
		}); */
	});

})
.script('/scripts/video'+TX.jsver+'.js')
.script('/scripts/waypoints.min.js').wait(function() {
	// For Comments load via AJAX & Product Details Sticky

	/* Comments and Comment Form loading via AJAX
		
		On a page with comments, note that
			- the loading spinner image is on the page and visible
			- the comments are faded to 0.5 opacity in CSS
			- the form placeholder is set to display none in CSS
			
		When these scripts fire, they always will result in the
			- the spinner image being hidden
			- the comments set to full 1.0 opaicty
			- the form placeholder if filled with the form and displayed
	*/

	$txjQ(document).ready(function($) {	
		
		/* Function to see if it's a comment page, and if so, load comments & form */
		TX.commentPage = function() {

			/* 	Test to see if this page has comments on it
				if so, run the commentRefresh function:
					- right away if the URL has a #comments fragment
					- when the bottom of the article (at the sharethis icons)
						scrolls into view
			*/			
		
			if($('#commentfun').length > 0) {
				
				//need to make sure the comment refresh happens only once on page
				TX.commentsRefreshed = false; 

				/* 	the URL includes the comment page count, if multiple pages,
					and is used in the hidden values & action of the comment form
					
					the entry_id is used in the ajax calls to both the commetns
					and comment form, and which gets the correct set of
					comments and the correct comment form
				*/
				
				
				/* 	throw a note on the page about the comment form loading 
					we'll delete it when the form loads
				*/
				$('#cf-placeholder').after('<div id="cf-loading" style="text-align: center; font-style: italic"><p>One moment please, comment form loading...</p><p><img src="/images/site2/ajax-loader.gif" width="42" height="42" alt="loading" id="comments-loading-spinner" /></p></div>');
				
				var url = TX.pageurl.path;
				var entry_id = $('#commentfun').attr('class').substring(1);
		
				/* 	if #comments in the page URL, immediately refresh comments
					and load comment form
				*/
				if(TX.pageurl.anchor=='comments') {
					TX.commentRefresh(url, entry_id);
					TX.commentForm(url,entry_id);
					TX.commentsRefreshed = true;					
				}
				
				/* 	use waypoints library to determine if the page is scrolled to
					or past the bottom of the article, at the bottom
					Share This icon block (which is near the top of the comments)
				*/
				
				$('.sharethis-bottom').waypoint(function(event) {
					// just in case it's already fired above, don't fire again				
					if (!TX.commentsRefreshed) {
						TX.commentRefresh(url, entry_id);
						TX.commentForm(url,entry_id);
						TX.commentsRefreshed = true; 
					}	
					
				},{
					offset: '100%', // bottom of the screen, or higher
					triggerOnce: true // only trigged once
				});
			}	
		}	
		
		/* Function to Load the Comment Form */
		TX.commentForm = function(url, entry_id) {			
			$('#cf-placeholder').load('/blog/comment-form/'+entry_id+url+' #cf-ajax', function() {		
				/* after Comments and Form loaded:
					- hide cf-loading spinner
					- change the form parameters to match actual page
					- init the FB Connect script
					- show form 
				*/											

				$('#comment_form').attr('action', url);
				$('#comment_form input[name=RET]').attr('value', url+'#comments');
				$('#comment_form input[name=URI]').attr('value', url);

				/*
				
				- used to add Facebook Connect scripts to page here,
				but not working in IE, so the script is coded in the HTML
				in the site/.v2-footer.php template
				*/

				$('#cf-loading').css('display','none');
				$('#cf-placeholder').css('display','block');								

				 // new Facebook API!
				if(FB.XFBML) {
					 FB.XFBML.parse();		
				}
			});		
		}

		/* Function to Load the Latest Comments */	
		TX.commentRefresh = function(url,entry_id) {							
			if  ($('.more-comments').length == 0 ||
				 $('.more-comments strong ~ a').length == 0 ) {
				
				/* Only load new comments if:
					- this is the only page of comments OR
					- this is the last page of comments				
				*/
				
				/* 	decided not to keep this test for 
					the page having at least one comment
					$('#weever-comments').length > 0 &&
				*/	
		
				$('#commentfun').load('/blog/comments-ajax/'+entry_id+url+' #comments-ajax', function() {
				
					/* 	Comments are reloaded, so
						need to re-rerun the reply and other comment functions!
					*/	
					TX.commentSetup();				
					
					// set the comments to display at full opacity
					$('#commentfun').fadeTo('fast',1.0);			
					
					// hide the top spinner
					$('#comments-loading-spinner').css('visibility','hidden');
				});	
				
			} else {
				/* 	Not loading new comments, so just go to full opacity */				
				$('#commentfun').fadeTo('fast',1.0);	
				$('#comments-loading-spinner').css('visibility','hidden');				
			}			
		}
		
		/* Do the comment page test / refreshes */
		TX.commentPage();		
		
		/* Product Details Sticky 
		$('.proddeets').waypoint(function(event, direction) {
			$(this).toggleClass('pdsticky', direction === "down");
			event.stopPropagation();		
		},{
			offset: -60
		});
		
		*/
	});
})
.script('/scripts/store.min.js').wait(function() {

	$txjQ(document).ready(function($) {	
	
		/* Also Load the Join the Conversation / Latest Comments */
		TX.lastestComments = function() {
		
			var lc = $('.latest-comments');
			// force reset for testing			store.clear();


			/* 	only run on pages with the Latest Comments /
				Join the Conversation widget
			*/	
			if (lc.length > 0) {			
				var lc_reload = false; // by default, don't reload from server

				var stored = store.get('lc_date');
				var	lc_html = store.get('lc_html');				
				var lc_now = new Date();	
				
				if (!stored) {
					// this is a first page load or no localstorage
					
					try {
						store.set('lc_date', lc_now.getTime());
						stored = store.get('lc_date');
						
						if (stored) {
							// OK, need to reload, and can then store!
							lc_reload = true;						
							
						}
						/* 	ELSE since can't store
							we don't bother reloading as localstorage 
							is not supported and
							it's probably an old browser
						*/				
						
					} catch(e) {
						// if user in privacy mode, or out of space
						// out of space is e.code == 22
						// console.log(e);
					}					
				} else {				
					// welcome back and yay localstorage!
					
					var test = new Date(parseInt(stored,10));

					if (lc_now.getTime() - test.getTime() > (2*60*1000)) {
						// reload from server after 2 minutes

						lc_reload = true;
					}				
				}
				
				if (lc_reload) {
					$.ajax({
						url: '/widgets/latest-comments-ajax/',
						dataType: 'html',
						success: function(data) {
							lc_html = $('#comments-ajax',data).html();
							store.set('lc_html', lc_html);
							store.set('lc_date', lc_now.getTime());							
							TX.showLatestComments(lc, lc_html, stored);
						}					
					});
				} else {
					TX.showLatestComments(lc, lc_html, stored);
				}
			}	
		}
				
		TX.showLatestComments = function(elm, lc_html, stored) {
			$.each(elm, function() {
				// usually only one per page, but using $.each just in case
				if (stored) {
					// replace with the ajax or localstorage HTML
					// and show it
					$(this).html(lc_html).fadeTo('slow',1);	
					
				} else {
				
					// if not loading in via ajax or localstorage
					// just show what's already there
					$(this).fadeTo('slow',1);	
				}
			});
			
			 // new Facebook API!
			if(FB.XFBML) {
				 FB.XFBML.parse();		
			}	 
		}
		

		TX.lastestComments();
	});
})
.script('http://platform.twitter.com/widgets.js')
.script('http://static.ak.fbcdn.net/connect.php/js/FB.Share')
.wait().script('http://www.techlicious.com/scripts/mc-jquery.form-n-validate.js')
.wait(function() {
	/* MailChimp Evil Popup */
	
	var fnames = new Array();var ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';fnames[3]='AGE';ftypes[3]='text';fnames[4]='GENDER';ftypes[4]='text';fnames[5]='CHILDREN';ftypes[5]='text';fnames[6]='INCOME';ftypes[6]='text';fnames[7]='SOURCE';ftypes[7]='text';fnames[8]='SIGNUP';ftypes[8]='text';fnames[9]='ZIPCODE';ftypes[9]='text';fnames[10]='SUBID';ftypes[10]='text';
			

	mce_init_form();	
	
	function mce_init_form() {
		$txjQ(document).ready( function($) {

/* conditional added to restirct popup to some pages */
			var show=true;

/* and don't show popup if the user agent is Google (e.g., Google web preview) */			
			var ua = navigator.userAgent.toLowerCase();

/* 	
	TX.pageurl.user.indexOf('www.techlicious.com/site/thank-you/')==0

	is kluge thrown in because pageurl isn't parsed correctly on 
	URLs like /site/thank-you/e=abc@example.com	
	
*/		
			if (
				($.inArray(TX.pageurl.directory, TX.noPopup) > -1) ||
				TX.pageurl.user.indexOf('www.techlicious.com/site/thank-you/')==0 ||				
				(ua.indexOf('google') > -1) 
				) {		
				show = false;
			}		
			
/* and don't show popup on small screens */			
			if ($txjQ(window).width() < TX.evilPopupMinWidth) {
				show = false;
			}
			

			var options = { errorClass: 'mce_inline_error', errorElement: 'div', onkeyup: function(){}, onfocusout:function(){}, onblur:function(){}  };
			var mce_validator = $("#mc-embedded-subscribe-form").validate(options);
			$("#mc-embedded-subscribe-form").unbind('submit');//remove the validator so we can get into beforeSubmit on the ajaxform, which then calls the validator
			options = { url: 'http://techlicious.us2.list-manage2.com/subscribe/post-json?u=9ca09c90643a88148a5df20dc&id=5ee95b0b14&c=?', type: 'GET', dataType: 'json', contentType: "application/json; charset=utf-8",
			beforeSubmit: function(){
				$('#mce_tmp_error_msg').remove();
				$('.datefield','#mc_embed_signup').each(
					function(){
						var txt = 'filled';
						var fields = new Array();
						var i = 0;
						$(':text', this).each(
							function(){
								fields[i] = this;
								i++;
							});
						$(':hidden', this).each(
							function(){
								if (fields.length == 2) fields[2] = {'value':1970};//trick birthdays into having years
								if ( fields[0].value=='MM' && fields[1].value=='DD' && fields[2].value=='YYYY' ){
									this.value = '';
								} else if ( fields[0].value=='' && fields[1].value=='' && fields[2].value=='' ){
									this.value = '';
								} else {
									this.value = fields[0].value+'/'+fields[1].value+'/'+fields[2].value;
								}
							});
					});
				return mce_validator.form();
			}, 
			success: mce_success_cb
			};
			
			$('#mc-embedded-subscribe-form').ajaxForm(options);      
			$('#mc_embed_signup').hide();

			cks = document.cookie.split( ';' );			
			
			for(i=0;i<cks.length;i++){
				parts = cks[i].split('=');
				if( parts[0].indexOf('MCEvilPopupClosed')!= -1 ) show = false;
			}
			
			if (show){
				$('#mc_embed_signup a.mc_embed_close').show();
				setTimeout( function(){ $('#mc_embed_signup').fadeIn();} , TX.evilPopupWait*1000);
				$('#mc_embed_signup a.mc_embed_close').click(function(e){ 
				e.preventDefault();
				mcEvilPopupClose();});
			}
	
			$(document).keydown(function(e){
				if (e == null) { 
				  keycode = event.keyCode;
				} else { 
				  keycode = e.which;
				}
				if(keycode == 27){
					mcEvilPopupClose();
				}
			});
	
			function mcEvilPopupClose(){
				$('#mc_embed_signup').hide();
				var now = new Date();
				var expires_date = new Date( now.getTime() + 31536000000 );
				document.cookie = 'MCEvilPopupClosed=yes;expires=' + expires_date.toGMTString()+';path=/';
			}
			
			function mce_success_cb(resp){
				$('#mce-success-response').hide();
				$('#mce-error-response').hide();
				if (resp.result=="success"){
					$('#mce-'+resp.result+'-response').show();
					$('#mce-'+resp.result+'-response').html(resp.msg);
					$('#mc-embedded-subscribe-form').each(function(){
						this.reset();
					});
				} else {
					var index = -1;
					var msg;
					try {
						var parts = resp.msg.split(' - ',2);
						if (parts[1]==undefined){
							msg = resp.msg;
						} else {
							i = parseInt(parts[0]);
							if (i.toString() == parts[0]){
								index = parts[0];
								msg = parts[1];
							} else {
								index = -1;
								msg = resp.msg;
							}
						}
					} catch(e){
						index = -1;
						msg = resp.msg;
					}
					try{
						if (index== -1){
							$('#mce-'+resp.result+'-response').show();
							$('#mce-'+resp.result+'-response').html(msg);            
						} else {
							err_id = 'mce_tmp_error_msg';
							html = '<div id="'+err_id+'" style="'+err_style+'"> '+msg+'</div>';
							
							var input_id = '#mc_embed_signup';
							var f = $(input_id);
							if (ftypes[index]=='address'){
								input_id = '#mce-'+fnames[index]+'-addr1';
								f = $(input_id).parent().parent().get(0);
							} else if (ftypes[index]=='date'){
								input_id = '#mce-'+fnames[index]+'-month';
								f = $(input_id).parent().parent().get(0);
							} else {
								input_id = '#mce-'+fnames[index];
								f = $().parent(input_id).get(0);
							}
							if (f){
								$(f).append(html);
								$(input_id).focus();
							} else {
								$('#mce-'+resp.result+'-response').show();
								$('#mce-'+resp.result+'-response').html(msg);
							}
						}
					} catch(e){
						$('#mce-'+resp.result+'-response').show();
						$('#mce-'+resp.result+'-response').html(msg);
					}
				}
			}        
	
		});
	}	
	
});
//.script('http://connect.facebook.net/en_US/all.js#xfbml=1')


/* helper for view more listing */
TX.moreArray = function(cstr) {
	var lim, catu, catid, src;
	var Cs = cstr.split(' ');	
	for (i=0;i<Cs.length;i++) {
		if (Cs[i].indexOf('lim-')==0) {
			lim = Cs[i].substring(4);
		} else if (Cs[i].indexOf('s-')==0) {
			src = Cs[i].substring(2);
		} else if (Cs[i].indexOf('catu-')==0) {
			catu = Cs[i].substring(5);
		} else if (Cs[i].indexOf('catid-')==0) {
			catid = Cs[i].substring(6);
		}
	}
	if (catu=='') catu = '-';
	if (catid=='') catid = '-';
	return {limit: lim, cat_url: catu, cat_id: catid, source: src};
};

/*
TX.docwrite = function(str) {
//	console.log(str);
	var moz = !window.opera && !/Apple/.test(navigator.vendor);
	
	// Watch for writing out closing tags, we just
	// ignore these (as we auto-generate our own)
	if ( str.match(/^<\//) ) return;

	// Make sure & are formatted properly, but Opera
	// messes this up and just ignores it
	if ( !window.opera )
		str = str.replace(/&(?![#a-z0-9]+;)/g, "&amp;");

	// Watch for when no closing tag is provided
	// (Only does one element, quite weak)
	str = str.replace(/<([a-z]+)(.*[^\/])>$/, "<$1$2></$1>");
	
	// Mozilla assumes that everything in XHTML innerHTML
	// is actually XHTML - Opera and Safari assume that it's XML
	if ( !moz )
		str = str.replace(/(<[a-z]+)/g, "$1 xmlns='http://www.w3.org/1999/xhtml'");
	 
	// The HTML needs to be within a XHTML element
	var div = document.createElementNS("http://www.w3.org/1999/xhtml","div");
	div.innerHTML = str;
	
	// Find the last element in the document
	var pos;
	
	// Opera and Safari treat getElementsByTagName("*") accurately
	// always including the last element on the page
	if ( !moz ) {
		pos = document.getElementsByTagName("*");
		pos = pos[pos.length - 1];
		
	// Mozilla does not, we have to traverse manually
	} else {
		pos = document;
		while ( pos.lastChild && pos.lastChild.nodeType == 1 )
			pos = pos.lastChild;
	}
	
	// Add all the nodes in that position
	var nodes = div.childNodes;
	while ( nodes.length )
		pos.parentNode.appendChild( nodes[0] );
};
*/
