$().ready(function() {
				   

//jQuery(document).bind('keydown', 'F5',function (evt){ window.location.href=window.location.href; return false; });


//$("a[rel='item_page_gallery']").colorbox({slideshow:true, slideshowStart: 'تشغيل',slideshowStop: 'ايقاف', current:"{current}/{total}"});


	$().piroBox({
			my_speed: 400,
			bg_alpha: 0.3, 
			slideShow : true,
			slideSpeed : 4, 
			close_all : '.piro_close,.piro_overlay'

	});
	
	

$("#print_link").click( function(){ window.open($("#print_link").attr("href"),"print_item","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=670, height=530"); return false});

	$('.comment_bit_title').click(function() {
				$('.comment_bit_content').slideUp();
				this_id = $(this).attr('id').split("comment-title-")[1];
				$('#comment-content-' + this_id).slideDown();
	
	}) ;

$('.comment_report').click(function() { $(this).colorbox({width:'40%',height:'250px', href: 'ar/report-comment/' + $(this).attr("id").split('-')[1] + '.html'});});


$('.comment_delete').click(function(){comment_delete($(this)); });
$('.comment_edit').click(function(){comment_edit($(this)); });
$('.comment_ban').click(function(){user_ban($(this)); });

animate_poller();

});


function comment_delete(e)
{
	var id = e.attr("rel");

	if(confirm("delete ?"))
		$.post("be_comment.php",{ "do": "delete", "id": id }, function(data){ alert(data.split("|=|")[0]); if(data.split("|=|")[1] == "1") window.location.reload(); });

}

function comment_edit(e)
{
	var id = e.attr("rel");
	
		$.post("be_comment.php",{ "do": "edit", "id": id }, function(data){
																	 

							if(data.split("|=|")[2] == "1")
							{
								$("#comment-btext-" + id).html('<textarea class="comment_text_input" cols="58" rows="8" name="comment_new_text" id="comment-new-text-' + id + '">' + data.split("|=|")[0] + '</textarea><div align="left"><input type="button" class="button" onclick="comment_edit_save('+id+')" value="save"  /></div>');
								
								$("#comment-btitle-" + id).html('<input name="comment_new_title" id="comment-new-title-' + id + '" size="45" class="comment_title_input" value="' + data.split("|=|")[1] + '" maxlength="100" type="text">');
							}
							
					});

}

function comment_edit_save(id)
{
	var new_txt = $("#comment-new-text-" + id).val();
	var new_title = $("#comment-new-title-" + id).val();
	
	$.post("be_comment.php",{ "do": "update", "id": id, "txt": new_txt, "title": new_title }, function(data){
				
				if(data.split("|=|")[1] == "1")
					{
						$("#comment-btext-" + id).html(new_txt);
						$("#comment-btitle-" + id).html(new_title);
					}
																 
																 
		});
}

function user_ban(e)
{
	var id = e.attr("rel");

	if(confirm("ban this user ?"))
		$.post("be_comment.php",{ "do": "ban", "id": id }, function(data){ alert(data.split("|=|")[0]); if(data.split("|=|")[1] == "1") window.location.reload(); });

}

function animate_poller()
{

poller_option_cc = 1;

$('.poller_bar').each(function(){
							   		
									width_factor = ($(this).parent().width() - 6)/100;
									poller_width = $(this).attr("rel")*width_factor;
									poller_per = $(this).attr("rel");
									//alert($(this).attr("rel"));

							
									$(this).everyTime(10, 'controlled', function() {

										newval = parseInt($(this).html()) + 1;
										if(newval <= $(this).attr("rel"))
										{
												$(this).width(newval+'%');
												$(this).html(newval+'%' );
										}

									
							   		 });


			poller_option_cc++;
		});


$("#poller_form").submit( function(){
								   
										var selected_choice = $("input[@name='vote_choice']:checked").val();
									   
										if(selected_choice == null)
										{
										   if($("#vote-choice:disabled").length > 0)
											   	alert("عذرا، لقد قمت بالتصويت مسبقا على هذا الاستفتاء");
											else
												alert("poller_please_select_an_option");
										   
										}
										
										else{
												
												$.post("poller.php", { poller_id: $("#poller_id").val(), choice: selected_choice },
														
														function(data){
																		
																		poller_res_array = data.split("|");
																		if(poller_res_array[0] != "" && poller_res_array[0] != "-")
																			alert(poller_res_array[0]);

																		if(typeof(poller_res_array[1]) != "undefined")
																			{
																				$('#poller-' + $("#poller_id").val()).html(poller_res_array[1]);
																				 animate_poller();
																				
																			}
																		

																	  });
											}
										
										
										   return false;
									} );
}



