
// JavaScript for Cartoon Strip Module

$(document).ready(function() {
	$('#cartoon_strip_meta h1').bind('click', function() {
		$(".#cartoon_strip_meta #strip_show_names").animate({
			"height": "toggle", "opacity": "toggle"
		}, "slow");
	});

	$('.strip_buttons .button_share').bind('click', function() {
		hideAllPanels();
		$(".strip_sharelinks").animate({
			"height": "toggle", "opacity": "toggle"
		}, "slow");
	});

	$('.strip_buttons .button_email').bind('click', function() {
		hideAllPanels();
		$(".strip_email").animate({
			"height": "toggle", "opacity": "toggle"
		}, "slow");
	});

	$('.strip_buttons .button_embed').bind('click', function() {
		hideAllPanels();
		$(".strip_embed").animate({
			"height": "toggle", "opacity": "toggle"
		}, "slow");
	});

	$('.strip_buttons .button_hindi').bind('click', function() {
		var new_img_path = $(this).attr('rel');
		$(".strip_image").find('img').animate({
			"visibility": "toggle", "opacity": "toggle"
		}, "slow");
		$(".strip_image").find('img').attr('src', new_img_path);
		$(".strip_image").find('img').animate({
			"visibility": "toggle", "opacity": "toggle"
		}, "slow");

		$("#li_button_hi").hide();
		$("#li_button_en").show();
	});
	$('.strip_buttons .button_english').bind('click', function() {
		var new_img_path = $(this).attr('rel');
		$(".strip_image").find('img').animate({
			"visibility": "toggle", "opacity": "toggle"
		}, "slow");
		$(".strip_image").find('img').attr('src', new_img_path);
		$(".strip_image").find('img').animate({
			"visibility": "toggle", "opacity": "toggle"
		}, "slow");

		$("#li_button_en").hide();
		$("#li_button_hi").show();
	});

	// Hide all temporary feature
	$('.strip_buttons .button_hide').bind('click', function() {
		hideAllPanels();
	});

	// Binding close buttons

	$('.close').each(function() {
		$(this).bind('click', function() {
			$(this).parent().animate({
				"height": "toggle", "opacity": "toggle"
			}, "slow");
		});
	});

	// Email
	$('#btn_send_email').bind('click', function() {
		$('#strip_form_content').hide();
		$('#strip_form_msg').html('Sending email...').show();
		$.ajax({
			url: "cs_email_to_friend.php",
			global: false,
			type: "POST",
			data: ({txt_FromName : $('.strip_email #txt_FromName').val(), txt_Emails : $('.strip_email #txt_Emails').val(), txt_ComicStripId : $('.strip_email #txt_ComicStripId').val()}),
			//dataType: "html",
			cache: false,
			success: function(responseText){
				var json = eval('(' + responseText + ')');
				if (json.error) {
					$('#strip_form_msg').html('<div>'+json.error_msg+'</div><div><a id="btn_send_email_back" name="btn_send_email_back" class="strip_button" onclick="return(false);" href="#"><span>Back</span></a></div>');
				}
				else {
					if (json.email_sent)
					{
						$('#strip_form_msg').html('<div>Your email has been sent.</div>'
							+'<div style="width:180px; margin:0 auto; text-align:center;"><a style="float:left; width:90px;" id="btn_send_email_more" name="btn_send_email_more" class="strip_button" onclick="return(false);" href="#"><span>Send more</span></a>'
							+'<a style="margin-left:5px; float:left;" id="btn_send_email_back" name="btn_send_email_back" class="strip_button" onclick="return(false);" href="#"><span>Done</span></a>'
							+'<div class="clear"></div></div>');
					}
					else {
						$('#strip_form_msg').html('<div>Your email could not be sent at this time, please try again after some time.</div><div><a id="btn_send_email_back" name="btn_send_email_back" class="strip_button" onclick="return(false);" href="#"><span>Back</span></a></div>');
					}
				}
				
				// bind dynamic events
				$('#btn_send_email_more').bind('click', function() {
					$('#strip_form_msg').html('');
					$('#strip_form_msg').hide();
					$('#strip_form_content').show();
				});
				$('#btn_send_email_back').bind('click', function() {
					/*$('#strip_form_msg').html('');
					$('#strip_form_msg').hide();
					$('#strip_form_content').show();*/
					$('.strip_email .close').click();
				});
			}
		});
	});

	// ZeroClipboard ---------------------------------------[TN]
	$('.strip_embed').find('.embed_copy').each(function() {
		ZeroClipboard.setMoviePath( 'http://localhost/sabtv.com/ZeroClipboard10.swf' );

		var copyText = $(this).parents('.strip_embed').find('textarea').val();

		// Create our clipboard object as per usual
		clip = new ZeroClipboard.Client();
		clip.setHandCursor( true );
		
		clip.setText( copyText );
		//alert(copyText);
		
		clip.glue( 'button_embed_copy', 'embed_button_container' );


		/*
		var clip = new ZeroClipboard.Client();
		clip.setText( copyText );
		clip.setHandCursor( true );
		clip.glue('button_embed_copy');
		//clip.glue( $(this).parents('.strip_embed').find('.embed_copy').get(0) );
		*/

	});

});

hideAllPanels = function() {
	$('.strip_panel').hide();
}


