<?php

add_action('admin_enqueue_scripts','wp_superlike_admin_scripts_styles');

	/* Register and enqueue backend styles/scripts */
	function wp_superlike_admin_scripts_styles(){
	
		global $wp_superlike;

		/* plugin css */
		wp_register_style( 'wp_superlike',get_template_directory_uri() . '/includes/plugins/wp-superlike/css/wp-superlike.css');
		wp_enqueue_style('wp_superlike');
		
		/* rtl */
		if ($wp_superlike->get_option('rtl') == 1) {
			wp_register_style( 'wp_superlike_rtl',get_template_directory_uri() . '/includes/plugins/wp-superlike/css/wp-superlike-rtl.css');
			wp_enqueue_style('wp_superlike_rtl');
		}
		
		/* admin panel css */
		wp_register_style( 'wp_superlike_admin',get_template_directory_uri() . '/includes/plugins/wp-superlike/admin/css/wp-superlike-admin.css');
		wp_enqueue_style('wp_superlike_admin');
		
		/* metabox panel css */
		wp_register_style( 'wp_superlike_metabox',get_template_directory_uri() . '/includes/plugins/wp-superlike/admin/css/wp-superlike-metabox.css');
		wp_enqueue_style('wp_superlike_metabox');
		
		/* google fonts */
		wp_register_style( 'wp_superlike_googlefont', 'http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700&subset=latin,latin-ext');
		wp_enqueue_style('wp_superlike_googlefont');
		
		/* admin panel script */
		wp_register_script( 'wp_superlike_admin',get_template_directory_uri() . '/includes/plugins/wp-superlike/admin/js/admin.js', array('jquery', 'wp-color-picker'));
		wp_enqueue_script( 'wp_superlike_admin' );

		/* include the color picker in admin */
		wp_enqueue_style( 'wp-color-picker' );

	}
	
add_action('admin_footer','wp_superlike_admin_ajax');
function wp_superlike_admin_ajax() {

	global $wp_superlike;

	/* load font for rtl */
	$font = 'Open Sans';
	$arrow_direction = null;
	if ($wp_superlike->get_option('rtl') == 1) {
		$font = 'Tahoma';
		$arrow_direction = '-rtl';
	}

		?>

			<script type="text/javascript">		
			jQuery(document).ready(function($) {
				
				/**
				* @Should fire on when user changes skin
				* @Load live preview of button
				* @done via AJAX sends style
				*/
				$('#style').change(function(){
					$('.ajax-live-preview').parent().show();
					var style = $(this).val();
					$.ajax({
						url: '<?php echo get_template_directory_uri() . '/includes/plugins/wp-superlike/admin/ajax/preview.php'; ?>',
						type: 'post',
						data: {style: style},
						success: function(data){
							$('.ajax-live-preview').html(data);
						}
					});
				});
				
				/**
				* init color pickers
				*/
				var myOptions = {
					change: function(event, ui){
					
						$('.ajax-live-preview-custom').parent().show();

						/* attributes to modify live colors */
						button_text_color = $('#button_text_color').val();
						button_border_color = $('#button_border_color').val();
						button_border_color_hover = $('#button_border_color_hover').val();
						button_bg_color = $('#button_bg_color').val();
						button_bg_color2 = $('#button_bg_color2').val();
						button_bg_color_hover = $('#button_bg_color_hover').val();
						button_bg_color_hover2 = $('#button_bg_color_hover2').val();
						count_bg_color = $('#count_bg_color').val();
						count_text_color = $('#count_text_color').val();
						count_border_color = $('#count_border_color').val();
						
						/* change the superlike button */
						div_preview = $('.ajax-live-preview-custom');
						div_preview.find('.wp-superlike-button').css({
							'color': button_text_color,
							'border-color' : button_border_color,
							'background': button_bg_color
						});
						var i, l, backgrounds = [
							'-moz-linear-gradient(top,  '+button_bg_color+' 0%, '+button_bg_color2+' 100%)', 
							'-webkit-gradient(linear, left top, left bottom, color-stop(0%,'+button_bg_color+'), color-stop(100%,'+button_bg_color2+'))',
							'-webkit-linear-gradient(top,  '+button_bg_color+' 0%,'+button_bg_color2+' 100%)',
							'-o-linear-gradient(top,  '+button_bg_color+' 0%,'+button_bg_color2+' 100%)',
							'-ms-linear-gradient(top,  '+button_bg_color+' 0%,'+button_bg_color2+' 100%)',
							'linear-gradient(top,  '+button_bg_color+' 0%,'+button_bg_color2+' 100%)'
						];
						for( i = 0, l = backgrounds.length ; i < l ; i++ ) {
							div_preview.find('.wp-superlike-button').css({ background: backgrounds[i] });
						}
						div_preview.find('.wp-superlike-button').css({
							'filter': "progid:DXImageTransform.Microsoft.gradient( startColorstr='"+button_bg_color+"', endColorstr='"+button_bg_color2+"',GradientType=0 )"
						});
						
						/* change the bubble styles */
						div_preview.find('.wp-superlike-count, .wp-superlike-count-box').css({
							'color': count_text_color,
							'border-color': count_border_color,
							'background': count_bg_color
						});
						
						/* images */
						div_preview.find('.wp-superlike-button i').css({
							'background-image': 'url(<?php echo get_template_directory_uri() . "/includes/plugins/wp-superlike/images/default/icon.png"; ?>)'
						});
						
						div_preview.find('.wp-superlike-arrow').css({
							'background-image': 'url(<?php echo get_template_directory_uri() . "/includes/plugins/wp-superlike/images/default/arrow".$arrow_direction.".png"; ?>)'
						});
						
						div_preview.find('.wp-superlike-arrow-box').css({
							'background-image': 'url(<?php echo get_template_directory_uri() . "/includes/plugins/wp-superlike/images/default/arrow-down.png"; ?>)'
						});
						
					}
				};
				$('.my-color-field').wpColorPicker(myOptions);
				
				$('.ajax-live-preview-custom .wp-superlike-button').mouseenter(function() {
				
						$(this).css({
							'color': button_text_color,
							'border-color' : button_border_color_hover,
							'background': button_bg_color_hover
						});
						
						var i, l, backgrounds2 = [
							'-moz-linear-gradient(top,  '+button_bg_color_hover+' 0%, '+button_bg_color_hover2+' 100%)', 
							'-webkit-gradient(linear, left top, left bottom, color-stop(0%,'+button_bg_color_hover+'), color-stop(100%,'+button_bg_color_hover2+'))',
							'-webkit-linear-gradient(top,  '+button_bg_color_hover+' 0%,'+button_bg_color_hover2+' 100%)',
							'-o-linear-gradient(top,  '+button_bg_color_hover+' 0%,'+button_bg_color_hover2+' 100%)',
							'-ms-linear-gradient(top,  '+button_bg_color_hover+' 0%,'+button_bg_color_hover2+' 100%)',
							'linear-gradient(top,  '+button_bg_color_hover+' 0%,'+button_bg_color_hover2+' 100%)'
						];
						for( i = 0, l = backgrounds2.length ; i < l ; i++ ) {
							$(this).css({ background: backgrounds2[i] });
						}
						$(this).css({
							'filter': "progid:DXImageTransform.Microsoft.gradient( startColorstr='"+button_bg_color_hover+"', endColorstr='"+button_bg_color_hover2+"',GradientType=0 )"
						});
				
				}).mouseleave(function(){
				
						$(this).css({
							'color': button_text_color,
							'border-color' : button_border_color,
							'background': button_bg_color
						});
						var i, l, backgrounds = [
							'-moz-linear-gradient(top,  '+button_bg_color+' 0%, '+button_bg_color2+' 100%)', 
							'-webkit-gradient(linear, left top, left bottom, color-stop(0%,'+button_bg_color+'), color-stop(100%,'+button_bg_color2+'))',
							'-webkit-linear-gradient(top,  '+button_bg_color+' 0%,'+button_bg_color2+' 100%)',
							'-o-linear-gradient(top,  '+button_bg_color+' 0%,'+button_bg_color2+' 100%)',
							'-ms-linear-gradient(top,  '+button_bg_color+' 0%,'+button_bg_color2+' 100%)',
							'linear-gradient(top,  '+button_bg_color+' 0%,'+button_bg_color2+' 100%)'
						];
						for( i = 0, l = backgrounds.length ; i < l ; i++ ) {
							$(this).css({ background: backgrounds[i] });
						}
						$(this).css({
							'filter': "progid:DXImageTransform.Microsoft.gradient( startColorstr='"+button_bg_color+"', endColorstr='"+button_bg_color2+"',GradientType=0 )"
						});
						
				});

			});
			</script>
		
		<?php

}