
	var navPosition 	= "out";
	var footerPosition	= "open"; 
	var loadedTimes	= 0;
	
	function getLoadedTimes	(){
		return loadedTimes;
	}	
/*	
	function updateZindex(position){
		navPosition = position;
		if(position == 'out') setTimeout(function(){if(navPosition == "out")$('#flashNav').parent().css({"z-index":"100"});},500);
		else if(position == 'in')$('#flashNav').parent().css({"z-index":"102"});
	}
*/
	function updateZindex(position){
		navPosition = position;
		if(position == 'out') setTimeout(function(){if(navPosition == "out")$('#flashNav').parent().css({"width":"28px"});},500);
		else if(position == 'in')$('#flashNav').parent().css({"width":"100%"});
	}

	function updateFooterZindex(position){
		footerPosition = position; ++loadedTimes;
		if(position == 'close'){$('#flashNav').parent().stop().animate({height:"570px"},100/*easeOutBack*/); setTimeout(function(){if(footerPosition == "close")$('#flashFooter').parent().css({"z-index":"-1"});},500);}
		else if(position == 'open'){$('#flashFooter').parent().css({"z-index":"103"});$('#flashNav').parent().stop().animate({height:"328px"},100);}
	}
	
	
	
	
	
	$.fn.extend({
	  buildMainMenu: function() {
			if($(this).children('li').length){
						
						
						var overSubMenu = false;
						var subMenu 	= $(this).next('div');
						
						
						subMenu.mouseover(function(){overSubMenu = true}).mouseout(function(){overSubMenu = false;setTimeout(function(){
																								if(!overSubMenu){																									
																									if(!subMenu.prev('ul').children('li.active').children('ul').children('li').length)subMenu.html('').css('visibility','hidden');
																									else subMenu.prev('ul').children('li.active').mouseover();
																								 }
																							},100	);});
						
						$(this).children('li')
							.each(function(index,element){
										   
										  	var left = $(this).position().left;	  
										     
										   
										  	$(this).mouseover(function(){
																	  	//   alert(left)
																	 	overSubMenu = true;
																		
																		if(subMenu.css('visibility') == 'hidden' && $(this).children('ul').length){
																			//alert($(this).html())
																			subMenu.css({'visibility':'visible'});
																			
																		}else if(subMenu.css('visibility') == 'visible' && !$(this).children('ul').length && !$(this).parent().children('li.active').children('ul').children('li').length){
																			overSubMenu = false;
																			setTimeout(function(){if(!overSubMenu)subMenu.html('').css('visibility','hidden');},100	);
																		}
																		
																		subMenu.html('<ul>'+ ($(this).children('ul').length ? $(this).children('ul').html() : '') +'</ul>');
																		//alert(subMenu.children('ul').length);
															if(subMenu.children("ul").children("li:last").position()){
															
																var subMenuLeft = subMenu.children('ul').children('li:first').position().left;
																
																if(subMenuLeft > left)subMenu.children('ul').css({'text-align':'left'}).children('li:first').css({marginLeft:left}); 	
																	
																
																
																//var fullWidth= subMenu.children('ul').width();
																
																/*			
																//subMenu.children('ul').children('li:first').css({marginLeft:left});
																var lastLeft = subMenu.children('ul').children('li:last').position().left + subMenu.children('ul').children('li:last').width();
																var fullWidth= subMenu.children('ul').width();
																		
					//if(lastLeft < left)subMenu.children('ul').children('li:first').css({marginLeft:'auto'}).parent('ul').css({'text-align':"right"});
					*/
													          }
																	  
																		})
										   			.mouseout(function(){
																	   	overSubMenu = false;
																	   	setTimeout(function(){
																								if(!overSubMenu){
																									 if(!subMenu.prev('ul').children('li.active').children('ul').children('li').length)subMenu.html('').css('visibility','hidden');
																									 else subMenu.prev('ul').children('li.active').mouseover();
																								 }
																							},100);
																	   
																	   	});
										   
										   
										   
										   
										   
										   
										   
										   
										   
										   
			   						//if($(this).children('ul').length){
										
										
										
										
										
										
										/*
										var active = false;
										
										
										$(this).mouseover(function(){
																  //alert($(this).parent().width()+"..."+$(this).position().left);
																 // alert((parseInt($(this).parent().width())-parseInt($(this).position().left))+"px");
																 //(parseInt($(this).parent().width())>950?1104:950)+"px"
											active = true;				   
											//$(this).children('ul').css({"left":"-"+(parseInt($(this).position().left))+"px","width":(parseInt($(this).parent().width())>950?1104:950)+"px","visibility":"visible"});
											if(!$(this).children('ul').length){
												$(this).prevAll('li.active').children('ul').css({"width":"950px","visibility":"hidden","z-index":"-1"});
												$(this).nextAll('li.active').children('ul').css({"width":"950px","visibility":"hidden","z-index":"-1"});
											}else{
											
												$(this).children('ul').css({"left":"-"+(parseInt($(this).position().left)+parseInt($(this).parent().position().left))+"px","width":parseInt($(window).width())+"px","visibility":"visible","z-index" :"25000","position":"absolute"});
											}
											
											if($(this).children('ul').length)$('.body-container-small, .body-container').stop().animate({"padding-top":"32px"});
										}).mouseout(function(){
											var element = $(this);
											if($(this).children('ul').length)$('.body-container-small, .body-container').stop().animate({"padding-top":"0px"});
											
											
											/*
											if(!$(this).children('ul').length){
															$(this).prevAll('li.active').children('ul').css({"left":"-"+(parseInt($(this).position().left)+parseInt($(this).parent().position().left))+"px","width":parseInt($(window).width())+"px","visibility":"visible","z-index" :"25000","position":"absolute"});
															$(this).nextAll('li.active').children('ul').css({"left":"-"+(parseInt($(this).position().left)+parseInt($(this).parent().position().left))+"px","width":parseInt($(window).width())+"px","visibility":"visible","z-index" :"25000","position":"absolute"});
											}
											*//*		
														
								setTimeout(function(){if(!active){
														$(element).children('ul').css({"width":"950px","visibility":"hidden","z-index":"-1"});
														$(element).parent().children('li.active').mouseover();														
														//$('.body-container-small').css()
														}},200);
											active = false;
										}).children('ul').mouseover(function(){
											active = true;
											$(this).parent().mouseover();
										}).children('ul').mouseout(function(){
											active = false;
											$(this).parent().mouseout();
										});		
									//}		*/
									
									
									
									
								});
							
							if($(this).children('li.active').length){
								$(this).children('li.active').mouseover();
								if($(this).children('li.active').children('ul').children('li').length)$('.body-container-small').stop().animate({"padding-top":"27px"});
							}
				}
			}
			//$(this).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
	  
	});
	
	$(document).ready(function(){
		  $('.top-menu-b > div').children('ul').buildMainMenu();																	 
																					 
	});
	
	
	
	
function showfriend() {
$("#sendToFriendDialog").dialog('open');
}	
		
		
function Sendtofriend(){
		//	alert('I AM INSIDE THE FUNCTIONS ') ;
			$("#frm_sendtofriend").find("[name=friendMail],[name=userMail],[name=submit]").attr('disabled',true);
			$('#sendToFriendDialogMessageFailure,#sendToFriendDialogMessagesuccess').hide();
			$('#sendToFriendDialogLoader').hide();
					$.ajax({
					url: "index.php?pg=sendtofriend&&plain=1&disable_rewrite=1",
					type:"POST",
					async: true,
					dataType:'json',
					data: {
						friendMail:$("#frm_sendtofriend").find("[name=friendMail]").val(),
						userMail:$("#frm_sendtofriend").find("[name=userMail]").val(),
						cur_url:$("#frm_sendtofriend").find("[name=cur_url]").val()
					},
					beforeSend: function(XMLHttpRequest) {
					},
					success: function(json){
								if(json.err) {
								$('#sendToFriendDialogMessageFailure').html(json.msg).show();
								}else{
									$('#sendToFriendDialogMessagesuccess').html(json.msg).show();
								}
								//alert('success') ;
								$('#sendToFriendDialogLoader').hide();
								$("#frm_sendtofriend").find("[name=friendMail],[name=userMail],[name=submit]").attr('disabled',false);	
						
								if(!json.err) {
								window.location.href=$("#frm_sendtofriend").find("[name=cur_url]").val();
								}
						
					
					},
					error: function (XMLHttpRequest, textStatus, errorThrown) {
						alert('Server Error') ;
						$('#sendToFriendDialogLoader').hide();
						$("#frm_sendtofriend").find("[name=friendMail],[name=userMail],[name=submit]").attr('disabled',false);
					}
				});
		}	
		
	function printdiv(printpage,logo){

		var disp_setting= "toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=800, height=700, left=0, top=0"; 
		var content_value= $('.html-Text').html(); 
		var docprint=window.open("","",disp_setting); 
		docprint.document.open(); 
		docprint.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Shady Pack</title>');
								
		docprint.document.write('</head><body onLoad="self.print()"><center><div><div style="width:100%;margin-left:0px; clear:left;float:left;"><img src="templates/cdn/images/6.png" align="left"/></div><div style="clear:left;float:left;">');          
		docprint.document.write('<table class="print-page"><thead></thead><tfoot valign="bottom" ></tfoot><tbody><tr><td class="page-tbody-container">'+content_value+'</td></tr></tbody></table></div>');          
		docprint.document.write('</div></center></body></html>'); 
		 
		docprint.focus(); 
		docprint.document.close();
	
	}	

	$(document).ready(function(){
	
		 $("#sendToFriendDialog").dialog({ modal: true ,resizable: false ,autoOpen: false });
			if ($('#map').length > 0)$('#map').setMapPoints();
			if($("#dialog").length)$("#dialog").dialog({ modal: true ,resizable: false ,autoOpen: false });
		}
	);
	
	
		function gup( name,url )
		{
		  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		  var regexS = "[\\?&]"+name+"=([^&#]*)";
		  var regex = new RegExp( regexS );
		  var results = regex.exec(url);
		  if( results == null )
		    return "";
		  else
		    return results[1];
		}	

	function changeLang(currUrl ,lang){
		
		var pos =currUrl.lastIndexOf('lang='+gup('lang',currUrl)) ;

	/**/	if(pos!=-1){
			    var newUrl = currUrl.slice(0,pos)+'lang='+lang ;
			}else{
				 var newUrl = currUrl+'?lang=ar' ;
			}


		  document.location.href=newUrl ;
	 
	}
	
	function chckValue(val){
		if(val == ''){
		 alert("please type your keyword") ;
		 return false;
		}
		return true ;
	}
