// JavaScript Document
$(document).ready(function(){
						    
							retreiveHomePage()
							ajaxLoader= new Image();
                            ajaxLoader.src="Images/ajax-loader.gif";  
	                        ajaxLoader.status="waiting";
				            ajaxLoader.id="ajaxLoader";
							$("div[@id=container]").append("<div id='ajaxLoaderDiv'><span class='processMsg'>Processing your request...</span></div>");
							$("div[@id=ajaxLoaderDiv]").prepend(ajaxLoader);
							});


function retreiveHomePage()
{
	$.ajax({
			 type:"post",
			 url:"Pages/retrievePage.php",
			 cache: false,
			 data:{valid:"7335786",channel:'Home',subChannel:'Home'},
			 success:function(data){
								   if(data!="")
									 {
									 //we will make ajax call to retrieve the page
								  	 if($("div[@info=db]").length>0)
										{
										$("div[@info=db]").remove();
										$("div[@id=text_container]").remove();
										}
									 $("div[@id=container]").append("<div id='text_container'></div>");
									 $("div[@id=text_container]").append(data);
									 }			
									  
			                       }//end data
		});
}//end of function


function retrieve_page(id)
{		  
var channel=$("a[@id="+id+"]").attr("channel");
$("div[@id=ajaxLoaderDiv]").fadeIn('fast',function(){$.ajax({ 
			 type:"post",
			 url:"Pages/retrievePage.php",
			 cache: false,
			 data:{valid:"7335786",channel:channel,subChannel:id},
			 success:function(data){
								 
								   if(data!="")
									 {
									 //we will make ajax call to retrieve the page
								  	 if($("div[@info=db]").length>0)
										{
										 $("div[@info=db]").fadeOut('slow',function(){$(this).remove()});
										 $("div[@id=text_container]").fadeOut('slow',function(){$(this).remove()
									     $("div[@info=db]").hide();	
									     $("div[@id=container]").append("<div id='text_container'></div>");
									     $("div[@id=text_container]").append(data);
									     $("div[@id=ajaxLoaderDiv]").fadeOut('fast');																		  
										});
										
										}
									
									 }			
									  
			                       }//end data
		});
});
}//end of function

function editText(elementId)
{	
  /*  alert(elementId);*/
	var pId=$("#"+elementId).find("span[@id]").attr("id");
/*    alert($("div[@id="+elementId+"]").find("span[@id]").attr("id"));*/
	var pos=$("body").offset();
	var top=pos.top;
    var left=pos.left;
    var height=$("body").height()+20;
    var width=$("body").width()+10;
	$("body").append("<div id='background' style='height:"+height+"px; width:"+width+"px; background-color:#000000; position:absolute; top:"+top+"px;left:"+left+"px; z-index:1002;'></div>");
	$("#background").css({   "opacity": "0.7"  });
	var editorTop=(height)/2;
	var editorLeft=(width-700)/2;
	$.ajax({ 
			 type:"post",
			 url:"Admin/pages/loadEditor.php",
			 cache: false,
			 data:{valid:"7335786",idtext:pId},
			 success:function(data){
			                        if(data!="")
									 {
									  $("body").append("<div id='textEditor' style='position:absolute;top:"+editorTop+"px; left:"+editorLeft+"px;height:230px;width:700px;z-index:1003;'>"+data+"</div>")
									 }
			                       }//end data
		});
	
}//end of function