// JavaScript Document
$(document).ready(function(){
						     if (document.images)
                                {
                                 down01= new Image();
                                 down01.src="Images/down_01.png";  
	                             down01.status="temp";
								 down01.id="01";
								 
								 down02= new Image();
                                 down02.src="Images/down_02.png";  
	                             down02.status="temp";
								 down02.id="02";
								 
								 down03= new Image();
                                 down03.src="Images/down_03.png";  
	                             down03.status="temp";
								 down03.id="03";
								 
								 down04= new Image();
                                 down04.src="Images/down_04.png";  
	                             down04.status="temp";
								 down04.id="04";
								 
								 down05= new Image();
                                 down05.src="Images/down_05.png";  
	                             down05.status="temp";
								 down05.id="05";
								 
								 down06= new Image();
                                 down06.src="Images/down_06.png";  
                                 down06.status="temp";
								 down06.id="06";
								 
								 down07= new Image();
                                 down07.src="Images/down_07.png";  
                                 down07.status="temp";
								 down07.id="07";
								 
								 down08= new Image();
                                 down08.src="Images/down_08.png";  
	                             down08.status="temp";
								 down08.id="08";
								 
								 down09= new Image();
                                 down09.src="Images/down_09.png";  
	                             down09.status="temp";
								 down09.id="09";
								 
								 down10= new Image();
                                 down10.src="Images/down_10.png";  
	                             down10.status="temp";
								 down10.id="10";
								 
								 down11= new Image();
                                 down11.src="Images/down_11.png";  
	                             down11.status="temp";
								 down11.id="11";
								 
                                }
								   
								   $("img[class=up]").each(function(){
																      $(this).mouseover(function(){
																								  var id=this.id;
																								  if (id!="down_01")
																								    {
																								    $("img#down_01").hide();
																									$("img#up_01").show();
																									down_id=id.replace("up","down");
																								    $("img#"+id).hide();
																								    $("img#"+down_id).show();
																									}
																								  									  
																								  });
																      																	 
																	 });
								   
							       $("img[class=down]").each(function(){
																	  if(this.id=='up_01')
																	   {
																	    $(this).mouseover(function(){
																								     $("img#up_01").hide();
																									 $("img#down_01").show();
																									
																									});
																	   }
																	  else
																      $(this).mouseout(function(){
																								  var id=this.id;
																								  
																								 
																						$("img[class=up]").each(function(){
																														   if(this.id=='down_01')
																														      $(this).hide();
																															else  
																															  $(this).show();
																															
																															})
																						
																						$("img[class=down]").each(function(){
																														    
																														   if(this.id=='up_01')
																														      $(this).show();
																															else  
																															  $(this).hide();
																															
																															})
																						
																									 up_id=id.replace("down","up");
																								     $("img#"+id).hide();
																								     $("img#"+up_id).show();
																									
																								 
																								  });
																      																	 
																	 });
								   $("table#subTabs").find("td").each(function(){
																			     $(this).mouseover(function(){
																											 $(this).css('color','#FFFFFF');
																											 });
																				 $(this).mouseout(function(){
																											 $(this).css('color','#000000');
																											 });
																				
																				});
								   
							
							
							$(document).ready(function(){
													      retrieve_page('Main','on');
														});
							
							});

function fetchSubTabs(id)
{
	var flag=false;
	switch(id)
	{
	 case "Restaurant":
	  flag='Main';  
	 break;
	 case "Menus":
	  flag='Menu';
	  break;
	case "Specials":
	 flag='Chef_Specials';
	 break;
	case "Guestbook":
	 flag='Read_Comments';
	 break;
	case "Shop":
	 flag='Merchandise';
	 break; 
	case "Events":
	 flag='Valentines_day';
	 break;
	case "Gallery":
	 flag='Dishes';
	 break;
    case "Reservation":
	 flag='Reservation';
	 break; 
	case "Downloads":
	 flag='Downloads';
	 break; 
	case "Contacts Us":
	 flag='Contact';
	 break;  
	case "Log In / Register":
	 flag='Register';
	 break;  
	 
	}//end switch
	/*if(id=='Restaurant')
	  flag='Main';
    else
	if(id=='Menus')
      flag='Menu';*/
 //we will have ajax call
 $.ajax({ 
			 type:"post",
			 url:"Pages/getSubTab.php",
			 cache: false,
			 data:{valid:"7335786",channel:id},
			 success:function(data){
			                        if(data!="")
									 {
									  $("table#subTabs").remove();
									  $("div#center").append("<table id='subTabs' channel='"+id+"'>"+data+"</table>");
									 
									 if(flag!=false)
									 retrieve_page(flag);
									 
									 }
			                       }//end data
		});
}//end of function


function mouse_over(id)
{
$("table#subTabs").find("div#"+id).css("color","#FFFFFF");
}

function mouse_out(id)
{
$("table#subTabs").find("div#"+id).css("color","#000000");
}//end of function

function retrieve_page(id,flag)
{
	
	$("div[@id=pscroller1]").hide();
	NavId=id;
	id=id.replace(/_/g," "); 
	
	$("table#subTabs").find("div").css("background-image","");
	$("table#subTabs").find("div#"+NavId).css("background-image","url(Images/LeftNavMover.png)");
var channel=$("table#subTabs").attr("channel");
if (flag!='on')
{
ajaxLoader= new Image();
                   ajaxLoader.src="Images/ajax-loader.gif";  
	               ajaxLoader.status="waiting";
				   ajaxLoader.id="ajaxLoader";
	             $("body").append(ajaxLoader);			   
}//end if 
$.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]").remove();
										}
									 $("img#ajaxLoader").fadeOut('fast');
									 $("img#ajaxLoader").remove();
									 $("body").append(data);	
									  }
			                       }//end data
		});

}//end of function

function findTempImgTd()
{
var tempImgId=$("#tempImg").children().eq(0);
return tempImgId.attr("id");
}//end of function

function replaceTempImg(imgId)
{
var id=imgId.substring(imgId.indexOf("_")+1,imgId.length);
var table=$("#tabs");
var td=table.find("td");
td.each(function(){
				   var kids=$(this).children();
				   kids.each(function(){
									   var 	TempImg=$(this).attr("id");
									        if(TempImg.match(id))
											  {
												 $(this).remove();
												 var imgKids=$("#tempImg").children(); 
											     var parent=$(this).parent();
												     parent.empty();
													 parent.append("wow");
											  }//end if 
											
									   });
				  });
}//end of function



function editText(elementId)
{
	var pId=$("#"+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

function editTable(elementId,subCh)
{
	var pos=$("body").position();
    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/editMenuPage.php",
			 cache: false,
			 data:{valid:"7335786",tableId:elementId,subCh:subCh},
			 success:function(data){
			                        if(data!="")
									 { 
									  $("body").append("<div id='tableEditor' style='color:#ffffff; position:absolute;top:"+editorTop+"px; left:"+editorLeft+"px;height:230px;width:380px;z-index:1003;'>"+data+"</div>")
									 }
			                       }//end data
		});
	
}//end of function

function tableUpdate()
{
	var description;
	var priceR;
	var low;
	var high;
	var vol;
	var cur_id;
	var cur_rates;
	$("table#curTable").find("input").each(function(){
													 $.ajax({
														   type:"post",
														   url:"Admin/pages/updateCur.php",
														   cache: false,
														   data:{valid:"7335786",recId:this.id,rate:this.value},
														   success:function(data){
															                     
																				 }
															});
													 });
	
$("div#tableEditor").find("tr").each(function(){
											   if (this.id!="")
											    {
												  $(this).find("input").each(function(){
																					   switch(this.id)
																						  {
																						   case "description": 
																						         description=this.value;
																								break; 
																						   case "priceR":
																						         priceR=this.value;
																						        break; 
																						   case "low":
																						         low=this.value;
																						        break; 
																						   case "high":
																						         high=this.value;
																						        break; 
																						   case "vol":
																						         vol=this.value;
																						        break;
																						  
																						  }
																				       //alert(description);
																						});
												   
												   $.ajax({
														   type:"post",
														   url:"Admin/pages/updateMenu.php",
														   cache: false,
														   data:{valid:"7335786",recId:this.id,desc:description,priceR:priceR,low:low,high:high,vol:vol},
														   success:function(data){
															                     
																				 }
														  });
												}//endif
											  
											   });
	
$("span#sucMsg").remove();
 $("div#tableEditor").append("<span id='sucMsg' style='position:relative;top:-25px;left:80px;color:#c6cfe1;'>update succeded...</span>");

}//end of function