// NEWSFLASH (c) 2010 Jesanua Web Solutions Ltd


	function newsflash(nid,del,dur){

		var cookiename="nf"+nid;

		// Ajax call...
		$.ajax({
			type: "GET",
			url: "newsflash/newsflash.php",
			cache: false,
			data:{id:nid},
			success: callback,
			error: err,
			timeout:10000
		});
		

		// Close the dialog...
		function closebox() {
			$("#fulldiv").slideUp("fast",function(){
				$("#fulldiv").empty();
				$("#fulldiv").remove();
				$("#newsflashContainer").fadeTo(400,0,function(){
					$(this).remove();
				});
			});
		}




		// Ajax Success!!
		// 	Displays the helptext in a dialog type box...
		function callback(data,status)
		{
			if (data!="")
			{
				var fullpath = $(this).attr("href");
				var y = $(window).scrollTop()+100;

				// Create the container divs...
				$("<div>").attr("id", "newsflashContainer").appendTo("body");
				$("<div>").attr("id", "openclose").appendTo("#newsflashContainer");
				$("<div>").appendTo("#openclose").text("Info");
				
				
				$("<div>").attr("id", "newsflashInnerContainer").appendTo("#newsflashContainer").css({opacity:0.92});
				$("<div>").attr("id", "newsflash").appendTo("#newsflashInnerContainer");
					
					// Populate with html from ajax call...
					$("#newsflash").html(data).hide().slideDown("normal");
					// bind close event
					$("#newsflash").bind("click",closebox);
				
				// If not seen before then show it, else decide if should be open or closed...
				initialCookie=$.cookie(cookiename);
				closeNF(0);
				if (initialCookie=='o')
				{
					openNF(0);
				}
				else if (initialCookie=='c')
				{
					closeNF(0);
					
				}
				else
				{
					if (del==0)
					{
						openNF(700);
					}
					else
					{
						setTimeout(function() {
							openNF(700);
						}, (del*1000));
					}
				
				}
			}
		}



		// Open the newsflash bar
		function openNF(speed){
			if (speed==0)
				$("#newsflashInnerContainer").show();
			else
				$("#newsflashInnerContainer").slideDown(speed);
			
			$("#openclose").addClass("closed");
			$("#openclose").removeClass("open");
			$("#openclose").unbind("click");
			$("#openclose").bind("click",function(){
				closeNF(700);
			});
			$.cookie(cookiename,"o");
		}

		// Close the newsflash bar
		function closeNF(speed){
			
			// figure out if should hide quickly or not...
			if(speed==0)
				$("#newsflashInnerContainer").hide();
			else
				$("#newsflashInnerContainer").slideUp(speed);
			$("#openclose").removeClass("closed");
			$("#openclose").addClass("open");
			$("#openclose").unbind("click");
			$("#openclose").bind("click",function(){
				openNF(700);
			});
			$.cookie(cookiename,"c");
		}



		// ajax error
		function err(xhr,reason,ex)
		{
			//alert("Sorry, there's been a problem with the AJAX request giving the following error: "+reason);
		}


		
		
	}

