$(document).ready(function() {


	/*
	|
	|	list-n-earn post/confirm
	|
	*/

	$('div.rbremote-controls a.confirm-page').bind("click",function(){ 
					
			var t = $(this);
		
			var url = 'http://rapbank.com/api';
			var data = { source: 'rbremote', prod: t.find("div.product_id").html() , subremote: t.find("div.action").html() };
	
			$.post(url, data, function(r){ 
	
					alert(r.msg);
					if (r.resp==1) {
						t.css('display','none');
						t.parent().find("a."+t.find('div.next_div').html()).toggle();
					}
				},"json");
	
		})
		.addClass('pointer');



	var rb_loading_image = '<img src="/products/wp-content/themes/tipztheme/custom-images/ajax-loader.gif" alt="...working..." border="0" />';

	// alert('using rapbank.com/rb_core/js/jquery.rapbank.js file in footer!');

	var contlw = $(".container > div.SC > div.SL").css("width");
	$(".sidebar_click").bind("click",function(){
	
			var cont = $(".container"); 
			var contr = $(".container > div.SC > div.SR"); 
			var contl = $(".container > div.SC > div.SL"); 
			if (contr.css("display")=="none") {
				contr.css("display","block");
				contl.css("width",contlw);
			} else {
				contr.css("display","none");
				contl.css("width","100%");
			}	
		});



	$("a.click_to_promote").bind("click",function(){

			$(".promote_this_page_affiliate_link").slideToggle();

		});



	$("a.why_clicks_important").bind("click",function(){

			$(".why_clicks_important_box").slideToggle();

		});



	$("a.click_credit_trigger").bind("click",function(){

			$(".click_credit").slideToggle();

		});


	// grab 'we are loading' and fade it out slowly... 

	$("#waiting_for_domains").fadeOut('slow');



	$("a.adv_filter").bind("click",function(){

			$(this).parent().parent().find(".adv_filter_section").slideToggle();

		});


	$("div.coupon_options").bind("click",function(){

			$(".affiliate_links").slideToggle();

		}).addClass('pointer');



	$("div.affbonus_enabled").bind("click",function(){

			$(".affbonus_explanation").slideToggle();

		}).addClass('pointer');




	$("a.show_item_sub").live("click",function(){

			$(this).parent().parent().parent().find(".item_sub").toggle();

		});


	/* get exclusive coupon link detail */

	$("span.my_link").live("click",function(){

			$("."+$(this).parent().find(".dc_code").html()).toggle();

		});


	
	/* get how_it_works text to show */

	$("a.how_it_works").live("click",function(){

			$(".how_it_works_section").toggle();

		});


	


	$(".p-con div.option_title_cell h3").bind("click",function(){
			$(this).parent().parent().find(".p-con-explain").toggle();
		});

	$("a.add_another_paypal").bind("click",function(){

			$(".add_paypal").slideToggle();

		});


	$("a.add_my_comment_toggle").bind("click",function(){

			$(".add_my_comment").slideToggle();

		});


	$("a.vendor_search_toggle").bind("click",function(){

			$(".vendor_search_form").slideToggle();

		});


	$("a.edit_main_content_text").bind("click",function(){

			$(".main_content_text").slideToggle();

		});


	function close_displays() {

		$("div.display_message_timeout").slideToggle();

	}


	if ( $("div.display_message_timeout").length > 0 ) {

	//	setInterval(close_displays,2000);
		setTimeout(close_displays,6000);

	}


	$(".affiliate_section").each(function(){

			var t = $(this);
			var trow = t.find("div.rownum").html();
			t.find("a.create_aff_link").bind("click",function(){
					t.find("div.affiliate_links").slideToggle();
				});
			t.find(".create_aff_link").bind("click",function(){
					t.find("div.affiliate_links").slideToggle();
				});


		});



	$(".rb_site_header").bind("click",function(){

		//	$(this).parent().parent().parent().find(".rb_site_products").slideToggle('fast');
			$(this).parent().parent().parent().find(".rb_site_products").toggle();

		})
		.addClass('pointer');



	// gray hovers

	$('div.rb_site_section div.box').hover(
		function() {
			$(this).removeClass('box');
			$(this).addClass('box_ffe98e');
		}, 
		function() {
			$(this).removeClass('box_ffe98e');
			$(this).addClass('box');
		});

	$('div.rb_site_section div.box_none').hover(
		function() {
			$(this).removeClass('box_none');
			$(this).addClass('box_ffe98e');
		}, 
		function() {
			$(this).removeClass('box_ffe98e');
			$(this).addClass('box_none');
		});

	// action button..
	// button hovers...

	$('div.action_button div.orange_button').hover(
		function() {
			$(this).removeClass('orange_button').addClass('green_button');
			var hv = $(this).find("div.onHover_top_text").html();
			if ( hv != '' )
				$(this).find("div.button_text h2").html(hv);
			
			var hvsub = $(this).find("div.onHover_sub_text").html();
			if ( hvsub != '' )
				$(this).find("div.button_text p").html(hvsub);
		}, 
		function() {
			$(this).removeClass('green_button').addClass('orange_button');
			var hv = $(this).find("div.onHover_top_text").html();
			if ( hv != '' )
				$(this).find("div.button_text h2").html($(this).find("div.orig_top_text").html());
			var hvsub = $(this).find("div.onHover_sub_text").html();
			if ( hvsub != '' )
				$(this).find("div.button_text p").html($(this).find("div.orig_sub_text").html());
		});


	$(".search_box_toggle").bind("click",function(){

			var t = $(this);
			var tpar = t.parent();
			t.find("p.on").toggle();
			t.find("p.off").toggle();
			tpar.find(".search_box").slideToggle('fast');

		}).addClass('pointer');

	/*
	|
	|	point-n-click sections
	|
	*/

	$("div.section").each(function(){
			
			var t = $(this);
			var tt = t.find(".section_header")
				.bind("click",function(){
						t.find("div.section_content").slideToggle();
					})
					.addClass('pointer');
		});




	/*
	|
	|	add to my lists (fav, wish, have)s
	|
	*/
	
	$.fn.pause = function(duration) {
	    $(this).animate({ dummy: 1 }, duration);
	    return this;
	};


	$('a.manage_user_products div').bind("click",function(){ 
					
			var t = $(this);
			var tpar = t.parent();
		
			var rb_load = $("div#working-"+t.parent().find("div.rb_product_id").html());
			rb_load.find("div.working_image").html(rb_loading_image);
			rb_load.find("div.working_image").css("display","");

			var url = 'http://rapbank.com/';
			var data = { action: "manage_custom_page", meta_action: t.attr("class") , meta_type: t.parent().find("div.manage_type").html(), meta_rbpid: t.parent().find("div.rb_product_id").html(), meta_rb_post_id: t.parent().find("div.rb_post_id").html() };
	
			$.post(url, data, function(r){ 

					if (r.response==1) {

						if (t.attr("class")=="add") {
							t.toggle();
							tpar.find("div.del").toggle();
						} else {
							t.toggle();
							tpar.find("div.add").toggle();
						}

					}
					else
						alert(r.response_message);

					rb_load.find("div.working_image").html('added/removed');
					rb_load.find("div.working_image").pause(2000).fadeOut();

				//	tpar.find(".working").toggle();

			}, "json");
	//			});
	
		})
		.parent().addClass('pointer');





	/*
	|
	|	proflie paypal adding/removing
	|
	*/

	$('div.product_row a.submit_to_blog').bind("click",function(){ 
					
			var t = $(this);
			var tpar = t.parent();
			var tparpar = tpar.parent();
		
			var url = 'http://rapbank.com/wpauth';
			var data = { wp_action: "submit", product_id: tpar.find("span.product_id").html() };
	
			$.post(url, data, function(r){ 
	
					tparpar.find("p.response").empty();
					$("<a href='"+r.edit_url+"' target='_blank'>Edit, Tweak, Modify it here!</a>").appendTo(tparpar.find("p.response"));
					tparpar.find("p.response").fadeIn('slow');
		
				}, "json");
	
		})
		.addClass('pointer');


	/*
	|
	|	set_featured product.
	|
	*/

	$('div.product_row_stats div.product_affiliate_row').live("click",function(){ 
					

			var t = $(this);
			var tpar = t.parent();

			if ( tpar.parent().find(".trigger_allow").html() != 0 )
				tpar.find("div.product_affiliate_row_table").toggle();

		})
		.addClass('pointer');




	/*
	|
	|	set_featured product.
	|
	*/

//	$('div.rb_site_section div.site_product_item').live("click",function(){ 
	$('div.rb_site_section div.site_product_item_affiliates_toggle').live("click",function(){ 
					
			var t = $(this);
			var tpar = t.parent();
			var tparpar = tpar.parent();
		
			tparpar.find(".site_product_item_affiliates").toggle();


		});


	$('div.rb_site_section div.site_product_item_affiliates_toggle_extra').live("click",function(){ 
					
			var t = $(this);
			var tpar = t.parent();
			var tparpar = tpar.parent().parent().parent();
		
			tparpar.find(".site_product_item_affiliates").toggle();


		});


	$('div.rb_site_section div.site_product_item_details_toggle_extra').live("click",function(){ 
					
			var t = $(this);
			var tpar = t.parent();
			var tparpar = tpar.parent().parent().parent();
		
			tparpar.find(".product_details").toggle();


		});


	/*
	|
	|	set_featured product.
	|
	*/

	$('div.rb_site_section div.set_featured').live("click",function(){ 
					

			var t = $(this);
			var tpar = t.parent();
			var tparpar = tpar.parent();
			var tparparpar = tparpar.parent();
		
			var url = 'http://rapbank.com/';
			var data = { action: "set_featured", post_id: tpar.find("div.post_id").html(), debug: 1 };


			// trigger response - working...
			tpar.find(".working").toggle();

			// alert(tpar.find("div.post_id").html());

			$.post(url, data, function(r){ 
	
					if (r==1) {
					//	alert('yippee!');
						tparparpar.parent().find(".set_featured").css("display","block");
						tparparpar.parent().find(".already_featured").css("display","none");
						tpar.find(".set_featured").css("display","none");
						tpar.find(".already_featured").css("display","block");
					}
					else
						alert('uh-oh! something happened\n\nwe were not able to make this a featured product!');

					// trigger response - working...
					tpar.find(".working").toggle();
		
				});
		//		}, "json");
	
		})
		.addClass('pointer');



	/*
	|
	|	etc stuff section
	|
	*/


	$("div#cubepoints-top-users a.thickbox").attr("title","RAP Bank Point Status");
	$("div#wassup-widget ul > li:last").html('happy RAP Bank users online').css("font-size","9pt");
	$("a[href*=n2h.it]").empty();

	/*
	|
	|	show stats section
	|
	*/


	$(".view_stats").bind("click",function(){
			$(this).parent().find("div.stats_section").slideToggle();
		})
		.addClass('pointer');

	/*
	|
	|	extra seo otions for ref. link
	|
	*/

	$("p.url_options").live("click",function(){
			$(this).parent().find("div.seo_options").slideToggle();
		});


	/*
	|
	|	show stats section
	|
	*/


	$(".user_message div.user_message_notice").bind("click",function(){
			$(this).parent().find("div.user_message_content").slideToggle();
		})
		.addClass('pointer');



});
