
jQuery(document).ready(function($){
    $.get(rhp_vars.RHP_URL + "templates/rhp_sliding_panel.php", function(data){
		$('body').append(data);
		if(rhp_vars.rhp_title && rhp_vars.rhp_title!=''){
			$('.rhp_title').html(rhp_vars.rhp_title);
		}
    });
    $('body').addClass('cbp-spmenu-push');

    var    body = document.body;

    $('#showLeftPush').click(function(e){
        classie.toggle( body, 'cbp-spmenu-push-toright' );
         $('.cbp-spmenu').toggleClass('cbp-spmenu-open');
    });

    $('#showLeft').click(function(e){
        classie.toggle( this, 'active' );
        $('.cbp-spmenu').toggleClass('cbp-spmenu-open');
    });

    $('#showRight').click(function(e){
        $('.cbp-spmenu').toggleClass('cbp-spmenu-open');
    });

    $('#showRightPush').click(function(e){
        classie.toggle( body, 'cbp-spmenu-push-toleft' );
        $('.cbp-spmenu').toggleClass('cbp-spmenu-open');
    });

    function disableOther( button ) {
        if( button !== 'showLeft' ) {
            classie.toggle( showLeft, 'disabled' );
        }
        if( button !== 'showRight' ) {
            classie.toggle( showRight, 'disabled' );
        }
        if( button !== 'showLeftPush' ) {
            classie.toggle( showLeftPush, 'disabled' );
        }
        if( button !== 'showRightPush' ) {
            classie.toggle( showRightPush, 'disabled' );
        }
    }

	init_sharing_button();
	$('BODY').bind('dbox.loaded',function(){
		init_sharing_button();
	});
	$('BODY').bind('rhc.gridview.rendered',function(){
		init_sharing_button();
	});
});

function init_sharing_button(){
	jQuery(document).ready(function($){
		$('.fc-button-social-panels').each(function(i,el){
			if( '1' == $(el).data('rhp_init') )return false;//avoid double init.
			var    body = document.body;
			$(el).data('rhp_init','1');
			$(el).click(function(e){
				rhp_vars = $.extend({}, rhp_vars, $(this).data('rhp_vars'));
				init_social_panel();

				switch(rhp_vars.panel_style){
					case 'showLeftPush':
						$('BODY')
							.removeClass('cbp-spmenu-push-toleft')
							.addClass('cbp-spmenu-push-toright')
						;

						break;

					case 'showLeft':
			        	classie.toggle( this, 'active' );
						break;

					case 'showRight':
						break;

					case 'showRightPush':
						$('BODY')
							.removeClass('cbp-spmenu-push-toright')
							.addClass('cbp-spmenu-push-toleft')
						;
						break;
				}

				$('.cbp-spmenu')
					.removeClass('cbp-hidden')
				;
				setTimeout('toggle_social_panel()',0);//calling the function directly causes a bug.

				return true;
			});
			//--btn
			$(el).hover(function(){
				$(this).addClass('fc-state-hover');
			},function(){
				$(this).removeClass('fc-state-hover');
			})
		});

	});
}

function toggle_social_panel(){
	jQuery(document).ready(function($){
				$('.cbp-spmenu')
					.addClass('cbp-transition')
					.toggleClass('cbp-spmenu-open')
				;
	});
}

function init_social_panel(){
	//jQuery(document).ready(function($){
		 var menuDirection = rhp_vars.panel_style.replace(/([A-Z])/g, ' $1').split(' ').slice(1,2);
		//console.log(rhp_vars.panel_style + '   ' +menuDirection);
		if(menuDirection =="Right"){
		    panelDirection = 'cbp-spmenu-right';
		    panelID = 'cbp-spmenu-s2';
		} else {
		    panelDirection = 'cbp-spmenu-left';
		    panelID = 'cbp-spmenu-s1';
		}
//console.log( rhp_vars.panel_style );
		jQuery('.cbp-spmenu')
			.removeClass('cbp-transition')
			.removeClass('cbp-spmenu-right')
			.removeClass('cbp-spmenu-left')
			.addClass(panelDirection)
	        .css('z-index', '9999')
			.attr('id', panelID)
		;

		if( rhp_vars.enable_facebook=='1' ){
			jQuery('#rhp-facebook').show();
		    FB.init({appId: rhp_vars.fb_appID, status: true, cookie: true, version:'v2.4'});
		}else{
			jQuery('#rhp-facebook').hide();
		}

		if( rhp_vars.enable_twitter=='1' ){
			jQuery('#rhp-twitter').show();
		}else{
			jQuery('#rhp-twitter').hide();
		}

		if( rhp_vars.enable_linkedin=='1' ){
			jQuery('#rhp-linkedin').show();
		}else{
			jQuery('#rhp-linkedin').hide();
		}

		if( rhp_vars.enable_google=='1' ){
			jQuery('#rhp-google').show();
		}else{
			jQuery('#rhp-google').hide();
		}

		//if(rhp_vars.sliding_panel_contents == 1){
		if(true){
			// TEMPORARY.  Fill list items
			var holder_selector = '.rhp-link-holder';
			jQuery('.cbp-spmenu-vertical').addClass('has-rhp-custom-links');
			jQuery(holder_selector).empty();
			//jQuery('.rhp-custom-links').append('<h3>Share</h3>');
			if(rhp_vars.url1 && ''!=rhp_vars.url1){
				jQuery(holder_selector).append('<a id="rhp-link1" class="rhp-share-link" href=' + rhp_vars.url1 + '>'+ rhp_vars.link1 + '</a>');
			}
			if(rhp_vars.url2 && ''!=rhp_vars.url2){
				jQuery(holder_selector).append('<a id="rhp-link2" class="rhp-share-link" href=' + rhp_vars.url2 + '>' + rhp_vars.link2 + '</a>');
			}
			if(rhp_vars.url3 && ''!=rhp_vars.url3){
				jQuery(holder_selector).append('<a id="rhp-link3" class="rhp-share-link" href=' + rhp_vars.url3 + '>' + rhp_vars.link3 + '</a>');
			}
			if(rhp_vars.url4  && ''!=rhp_vars.url4){
				jQuery(holder_selector).append('<a id="rhp-link4" class="rhp-share-link" href=' + rhp_vars.url4 + '>' + rhp_vars.link4 + '</a>');
			}
			if(rhp_vars.url5  && ''!=rhp_vars.url5){
				jQuery(holder_selector).append('<a id="rhp-link5" class="rhp-share-link" href=' + rhp_vars.url5 + '>' + rhp_vars.link5 + '</a>');
			}
			if(rhp_vars.url6  && ''!=rhp_vars.url6){
				jQuery(holder_selector).append('<a id="rhp-link6" class="rhp-share-link" href=' + rhp_vars.url6 + '>' + rhp_vars.link6 + '</a>');
			}
			if(rhp_vars.url7  && ''!=rhp_vars.url7){
				jQuery(holder_selector).append('<a id="rhp-link7" class="rhp-share-link" href=' + rhp_vars.url7 + '>' + rhp_vars.link7 + '</a>');
			}
			if(rhp_vars.url8 && ''!=rhp_vars.url8){
				jQuery(holder_selector).append('<a id="rhp-link8" class="rhp-share-link" href=' + rhp_vars.url8 + '>' + rhp_vars.link8 + '</a>');
			}
			if(rhp_vars.url9 && ''!=rhp_vars.url9){
				jQuery(holder_selector).append('<a id="rhp-link9" class="rhp-share-link" href=' + rhp_vars.url9 + '>' + rhp_vars.link9 + '</a>');
			}
			if(rhp_vars.url10 && ''!=rhp_vars.url10){
				jQuery(holder_selector).append('<a id="rhp-link10" class="rhp-share-link" href=' + rhp_vars.url10 + '>' + rhp_vars.link10 + '</a>');
			}
		}
	//});
}
