$(function() {
	
	$('input#bmposttweet').click(function() {
		$('p.updateposted').css('background', 'url(http://cuthut.com/site/blog/wp-content/themes/cuthut/images/ajax-loader.gif) no-repeat 10px 12px');
	});
	
	$('form.bmautotweet').ajaxForm(function() {
		$('p.updateposted').css('background', 'none');
		$('p.updateposted').html('Update posted');
	});
	
	
	$('input[type=submit]').click(function() {
		$(this).blur();
	});
	
	$('form[name=privatestats] input[type=submit]').click(function() {
		$('.ajax').css('display', 'inline-block');
	});
	
	$('form#setprivatestats').ajaxForm(function() {
		$('.ajax').css('display', 'none');
		$('form#setprivatestats').append('<span class="saved"> Saved!</span>');
		$('form#setprivatestats span.saved').fadeOut(3500);
	});	
	

	
	$('form.delrow input.delete').click(function() {
		var shortcode = $(this).attr('id');
		
		
		$('form#delrow' + shortcode).ajaxForm(function() {
			$('li#delete' + shortcode).removeClass('even')
			$('li#delete' + shortcode).removeClass('odd').fadeOut(function() {
				
				$('li.odd').removeClass('odd').addClass('single');
				$('li.even').removeClass('even').addClass('single');
				
				$('li.single:odd').addClass('odd').removeClass('single');
				$('li.single:even').addClass('even').removeClass('single');
			});
		});
	});
	
	
	$('li.single:odd').addClass('odd').removeClass('single');
	$('li.single:even').addClass('even').removeClass('single');
	
	
	$('form[name=createShort] input[name=longurl]').focus();
	$('textarea').keyup(function() {
		var charLength = $(this).val().length;
		var charLeft = 140 - charLength;
		$('form#tweet p.bottom-text').html(charLeft + ' remaining');
				
		if($(this).val().length > 125) {
			$('form#tweet p.bottom-text').css({'color' : '#bb4f53', 'font-weight' : 'bold'});
		} else {
			$('form#tweet p.bottom-text').css({'color' : '#555', 'font-weight' : 'normal'});	
		}
	});
	
	$('a#desktopref').hover(function() {
		$('#desktophover').fadeIn(200);
	},function(){
		$('#desktophover').stop().fadeOut(200);
	});
	
	$('#bookmarklet p a').hover(function() {
		$('#bookmarklet p a img').attr('src', '/static/img/bookmarklet-hover.png');
	}, function() {
		$('#bookmarklet p a img').attr('src', '/static/img/bookmarklet.png');
	});
	
	$('#clicks h3 a').click(function() {
		$(this).addClass('on');
		$('#referrers h3 a').removeClass('on');
		$('#clicksinfo').css('display', 'block');
		$('#referrersinfo').css('display', 'none');
	});
	$('#referrers h3 a').click(function() {
		$(this).addClass('on');
		$('#clicks h3 a').removeClass('on');
		$('#clicksinfo').css('display', 'none');
		$('#referrersinfo').css('display', 'block');
	});
	
	$('#clicksinfo .times li').click(function() {
		$('#clicksinfo .times li').removeClass('on');
		$(this).addClass('on');
	});
	/* start time changes for clicks */
	$('#clicksinfo .times li a').click(function() {
		var timeper = $(this).attr('class');
		$('#theclicks li').css('display', 'none');
		$('#theclicks li.retweetnumber').css('display', 'block');
		$('#theclicks li.' + timeper).css('display', 'block');
	});
	
	$('#referrersinfo .times li').click(function() {
		$('#referrersinfo .times li').removeClass('on');
		$(this).addClass('on');
	});
	/* start time changes for clicks */
	$('#referrersinfo .times li a').click(function() {
		var timeper = $(this).attr('class');
		$('#referrers li').css('display', 'none');
		$('#referrers li.retweetnumber').css('display', 'block');
		$('#referrers li.' + timeper).css('display', 'block');
	});
	
	
	/* end analytics */
	$('input#retweet-btn').click(function() {
		$('#retweets').animate({'right' : '165px'}, 300);
		$('.ajax-load').css('display', 'block').animate({'opacity' : '0'}, 0).animate({'opacity' : '1'}, 300);
	});
	$('form#autotweet').ajaxForm(function() {
		$('#retweets').animate({'right' : '235px'}, 300);
		$('.ajax-load').css('display', 'none').animate({'opacity' : '0'}, 0);
		$('#updatedt').css('display', 'block').animate({'opacity' : '0'}, 0).animate({'opacity' : '1.0'}, 600);
	});
	
	$('input#postTweet').click(function() {
		$('#tweeted').html('').animate({'opacity' : '0'}, 0).css('display', 'none');
		$('.ajax-load').css({'display' : 'block', 'margin-left' : '160px'}).animate({'opacity' : '0'}, 0).animate({'opacity' : '1'}, 300);
	});
	
	$('form.homeautotweet').ajaxForm(function() {
		var content = $('form.homeautotweet textarea').val().length;
		if(content == 0) {
			$('#tweeted').css('display', 'block').animate({'opacity' : '1'}, 300);
			$("<span>Error: Please enter something to post.</span>").appendTo('p#tweeted');
			$('#tweeted').css('display', 'block').animate({'opacity' : '0'}, 3000);
			$('.ajax-load').css('display', 'none');
			//alert('Error: Please fill out the comment field.');
			
		} else {
			$('form.homeautotweet textarea').val('');
			$('.ajax-load').css('display', 'none');
			$('#tweeted').css('display', 'block').animate({'opacity' : '1'}, 300);
			$("<span>Update posted.</span>").appendTo('p#tweeted');
			$('#tweeted').css('display', 'block').animate({'opacity' : '0'}, 3000);
			var charLength = $(this).val().length;
			var charLeft = 140 - charLength;
			$('form#tweet p.bottom-text').html(charLeft + ' remaining');
		}
	});
		
	$('ul#feature-vid li').click(function() {
		$('ul#feature-vid li').removeClass('on');
		$('.video').css('display', 'none');
		$(this).toggleClass('on');
	});
	
	
	$('ul#feature-vid li#xml-create').click(function() {
		$('#xmlcreate').css('display', 'block');
	});
	$('ul#feature-vid li#xml-read').click(function() {
		$('#xmlread').css('display', 'block');
	});
	$('ul#feature-vid li#text-create').click(function() {
		$('#textcreate').css('display', 'block');
	});
	$('ul#feature-vid li#text-read').click(function() {
		$('#textread').css('display', 'block');
	});
	
	var numRand = Math.floor(Math.random()*5)
	
	$('#medium-rect-ad').cycle({startingSlide: numRand, random: 1, pause: 1, timeout: 10000});
	
	$('form#createShort #custom').css('display', 'none');
	
	var charLength = $('textarea').val().length;
	var charLeft = 140 - charLength;
	$('form#tweet p.bottom-text').html(charLeft + ' remaining');
		
			
	
	$('form#createShort .title a.moreOptions').click(function() {
		$(this).css('display', 'none');
		$('form#createShort .title a.lessOptions').css('display', 'block');
		$('form#createShort #custom').css('display', 'block');
		$('form#tweet textarea').css({'background' : 'url(http://cuthut.com/static/img/ta-l-bg.png) center bottom no-repeat', 'height' : '92px', 'font-size' : '18px',	'line-height' : '22px'});
		$('input#customlink').focus();
	});
	
	$('form#createShort .title a.lessOptions').click(function() {
		$(this).css('display', 'none');
		$('form#createShort .title a.moreOptions').css('display', 'block');
		$('form#createShort #custom').css('display', 'none');
		$('form#tweet textarea').css({'background' : 'url(http://cuthut.com/static/img/ta-l-bg.png) center top no-repeat', 'height' : '144px', 'font-size' : '18px',	'line-height' : '26px'});
		$('input#customlink').blur();
		$('input#customlink').val('');
	});
	
	$('form a.submit').click(function() {
		$('form#copyshort input').select();
	});
		
	
	
	$('form#post-comment input[type=submit]').click(function() {
		$('.ajax-load').css('display', 'block');
	});
	
	$('form#post-comment').ajaxForm(function() {
		var imgl = $('input#cmtimg').val();
		var author = $('input#cmtauthor').val();
		var thetime = $('input#cmttime').val();
		var cmtcontent = $('#cmtcontent').val().length;
		var thecontent = $('#cmtcontent').val();
		var postid = $('#cmtid').val();
		
		
		if(cmtcontent == 0) {
			$("<p>Error: Please fill out the comment field.</p>").appendTo('#add-comment');
			$('.ajax-load').css('display', 'none');
			// alert('Error: Please fill out the comment field.');
			
		} else {
			$('textarea#cmtcontent').val('');
			$('.ajax-load').css('display', 'none');
			// $("<li><img src=\"" + imgl + "\" width=\"40px\" height=\"40px\" class=\"profile-image\" /><img src=\"../wp-content/themes/cuthut/images/ro40-6.png\" width=\"40px\" height=\"40px\" class=\"profile-overlay\" /></li>").appendTo('ul#comments');
			$("<li><img src=\"" + imgl + "\" width=\"40px\" height=\"40px\" class=\"profile-image\" /><img src=\"../wp-content/themes/cuthut/images/ro40-6.png\" width=\"40px\" height=\"40px\" class=\"profile-overlay\" /><p>by <a href=\"http://twitter.com/<?php echo $cmt_author; ?>\">@" + author + "</a>" + thetime + "</p><form action=\"../wp-content/themes/cuthut/commenton.php\" method=\"post\" class=\"del-comment\" onsubmit=\"return confirm('Are you sure you want to delete this comment?')\"><input type=\"hidden\" value=\"" + postid + " name=\"postid\" />(<input type=\"submit\" name=\"del-cmt\" class=\"del-cmt\" value=\"delete\" />)</form><p>" + thecontent + "</p></li></li>").appendTo('ul#comments');
		}
	});
	
	
	
});