/**
 * Main code to initialize javascript interaction on bitsofparag.com
 *
 * @category    Javascript
 * @author     Parag Majumdar <admin@bitsofparag.com>
 * @copyright  Jan 01, 2010 Bitsofparag.com
 * @link  		www.bitsofparag.com
 *  
 */

$(function(){
	$('#nav a').eP().sketchHover();
	$('#ad-toggle').eP().toggleAds();
	$('#work-slide-wrapper').eP().setupSlides({"slides":4});
	$('#style-switch-canvas').eP().setupStyleSwitcher();
});


$(function(){
	
	if($('#work-slide-wrapper').length !== 0){
		/* Work slides event binding */
		$('#work-slide-prev').bind('click.previous.work', function(e){
			e.preventDefault();
			$('#work-slide-wrapper').trigger('previous');
			$.ePCache['click.previous.work'] = arguments.callee;
		});
		$('#work-slide-next').bind('click.next.work', function(e){
			e.preventDefault();
			$('#work-slide-wrapper').trigger('next');
			$.ePCache['click.next.work'] = arguments.callee;
		});
	}
	
	
	if($('#comments').length !== 0)
	{
		$('.post-comments-reply-link').die('click.commentreply')
			.live('click.commentreply',function(e){
			    e.preventDefault();
			    var $replyformdiv = $(e.target).parent().css({'display':'block'}).next('.post-comments-reply-form');
			    $replyformdiv.eP().prepareReplyForm({linkToLoad:$(e.target).attr('href') + ' .comment-form-new',
			    								  captchaDiv:'#captcha-action',
			    								  mainComment: $.ePCache['mainComment']},
			    	function(){
			    		$(this).eP().setupCommentForm().trigger('formsetup');
			    });
			    
			});
		
		$('.captcha_img_refresh').live('click.refresh', function(e)	{
			$(this).eP().refreshCaptcha();
		});
	}
	
	if($('#answer').length !== 0)
	{
		$('#answer-box').css({'display' : 'none'});
		$('#answer').one('click',function(){
			$('#answer-box').slideDown('slow');
		});
	}

});


/**
 * @desc This block of code runs when the page is fully loaded
 */
$(window).load(function() {
	
	if(ePUtil.isIE6()) {
		$('.profile-badge a,#cooltypo, #content-canvas, .bd-wrap, .bd-box, #ad-toggle, .pagination a, .bubble-border-top, #contact-form-new, #style-switch, .work-desc-header, #work-slide-nav a, #player_container').fixPNG();
	}
	
	$('.footer-tweets').eP().startTweeting({'username':'paragmajum'});
	
	if($('#style-switch-canvas').length !== 0){
		$('#style-switch').bind('click.blogstyles', function(e){
			e.preventDefault();
			($(this).width() < 200)? $('#style-switch-canvas').trigger('openstylebar') : $('#style-switch-canvas').trigger('closestylebar');
		});
	}
	
	if($('.comment-form-main', $('#comments')).length !== 0){
		var $mainform = $('.comment-form-main', $('#comments'));
		$.ePCache['mainComment'] = $mainform;
		$mainform.eP().setupCommentForm().trigger('formsetup');
	}

	$.fn.renderQuoteBox = function(){
		return this.each(function(){
			var $this = $(this),
			    content = $this.html();
			if(this.nodeName !== "DIV"){
				$this.replaceWith("<div class='quote-box'><div class='style-box quotes-top-left-box'>-</div><p>" + content + "</p><div class='style-box quotes-bottom-right-box'>-</div></div>");
			}
		});
	};

	$(".quote-box").renderQuoteBox();
});		

