/*_..............................................................................._*/
var podPressBackendURL = location.protocol;
if(location.port != "80" && location.port != "443") {
   podPressBackendURL = podPressBackendURL+location.port; 
} 
//podPressBackendURL = podPressBackendURL+"//"+location.hostname+"/bhungr/secured/"; // for local host 
podPressBackendURL = podPressBackendURL+"//"+location.hostname+"/secured/"; //for main site 
var podPressDefaultPreviewImage = podPressBackendURL+"players/images/vpreview_center.png";
var podPressMP3PlayerOptions = "&amp;bg=0x9999ff&amp;leftbg=0xCCCCCC&amp;rightbg=0xCCCCCC&amp;rightbghover=0x999999&amp;lefticon=0x666666&amp;righticon=0x666666&amp;righticonhover=0xFFFFFF&amp;text=0x666666&amp;slider=0x666666&amp;track=0xFFFFFF&amp;loader=0x9FFFB8&amp;border=0x666666&amp;listenWrapper=on&amp;";
var podPressMP3PlayerWrapper = true;
var podPressText_PlayNow = "Play Now";
var podPressText_HidePlayer = "Hide Player";
var images;
var StopAtEnd;
/*_..............................................................................._*/
function search_auto() {
	 //var arrays = $('autocomplethere').innerHTML;
	 //var ret = arrays.split('~~~');
	 //var ret = req.responseText.split('~~~');
	 var list3 = document.createElement('div');
	 list3.id = 'sac4update22';
	 list3.className = 'sac4update';
     document.body.appendChild(list3);
	 $('sac4update22').setStyle({display:'none'});

     var list4 = document.createElement('div');
	 list4.id = 'sac4update11';
	 list4.className = 'sac4update';
     document.body.appendChild(list4);
	 $('sac4update11').setStyle({display:'none'});
     
	 
	 new Autocompleter.Local('sac4','sac4update11', ret0, {choices:20, fullSearch: false, partialSearch: true });
	 new Autocompleter.Local('city4','sac4update22', ret1, {choices:20, fullSearch: false, partialSearch: true });
	 //new Autocompleter.Local('sac4','sac4update11', eval(ret[0]), {choices:20, fullSearch: false, partialSearch: true });
	 //new Autocompleter.Local('city4','sac4update22', eval(ret[1]), {choices:20, fullSearch: false, partialSearch: true });
	 
	 
	// var onlycat = eval(ret[2]);
	 var onlycat = ret2;

     var ulli = '<ul>';
	 onlycat.each(function(catname){
		         ulli += '<li onmouseover="javascript:hoverDo(event,\'onlycategory\');" onclick="javascript:use_value(\''+catname.replace(/\'/g,"\\'")+'\');">'+catname+'</li>';
				 });
	 ulli += '</ul>';
	 
	 //var onlycity = eval(ret[3]);
     
	 var onlycity = ret3;
	 var ulli1 = '<ul>';
	 onlycity.each(function(cityname){
		         ulli1 += '<li onmouseover="javascript:hoverDo(event,\'onlycitylist\');" onclick="javascript:use_value1(\''+cityname.replace(/\'/g,"\\'")+'\');">'+cityname+'</li>';
				 });
	 ulli1 += '</ul>';
     
	 var list = document.createElement('div');
	 var pos = Position.cumulativeOffset($('city4'));  
	 list.id = 'onlycategory';
	 list.className = 'sac4update';
     document.body.appendChild(list);
	 $('onlycategory').setStyle({display:'none',left:pos[0]+'px',top:pos[1]+22+'px'});
	 $('onlycategory').innerHTML = ulli;	 
	 
     var list1 = document.createElement('div');
	 var pos1 = Position.cumulativeOffset($('sac4'));  
	 list1.id = 'onlycitylist';
	 list1.className = 'sac4update';
     document.body.appendChild(list1);
	 $('onlycitylist').setStyle({display:'none',left:pos1[0]+'px',top:pos1[1]+22+'px'});
	 $('onlycitylist').innerHTML = ulli1;	 
	 document.body.style.cursor = "default";
}

/*_--------------------------------------------------------------------------------------------------------_*/

function use_value(values) { 
   $('city4').value = values; 
   $('onlycategory').hide();
   $('fromdropdown').value = 1;
  // var parms = 'fromdropdown=1'; 
   //new Ajax.Request('./searchInMenu.php', {method: 'post', parameters: parms});
}
function use_value1(values) { 
   $('sac4').value = values; 
   $('onlycitylist').hide();
}

/*_..............................................................................._*/

function checkit(obj) {
  if (obj == 'sac4') { if ( $(obj).value == '          Choose City' ) { $(obj).value = '';}} 
//  if (obj == 'sac4') { if ( $(obj).value == '       City or Zip Code' ) { $(obj).value = '';}} 
  else {if ( $(obj).value == '       Choose Cuisine' ) { $(obj).value = '';}}
}
function checkit1(obj) {
	if (obj == 'sac4') {if ( $(obj).value == '' ) { $(obj).value = '          Choose City';}} 
//	if (obj == 'sac4') {if ( $(obj).value == '' ) { $(obj).value = '       City or Zip Code';}} 
    else {if ( $(obj).value == '' ) { $(obj).value = '       Choose Cuisine';} }
}

/*_..............................................................................._*/

function removeAllAudio() {
  clearTimeout(StopAtEnd);
  $$('span.msg').each(function(elm){$(elm).update('AUDIO INTERVIEW');});
  $$('span.msg2').each(function(elm){$(elm).update('AUDIO INTERVIEW');});
  $$('span.allvideo').each(function(elm){$(elm).update('&nbsp;');$(elm).setStyle({display:'none'});});
  $$('a.allfirstimage').each(function(elm){$(elm).setStyle({display:'block'});});
}


/*_..............................................................................._*/
function playnow(file_to_play, type, id, duration, IsInsideFile) { 
  ap_stopAll();
  removeAllAudio();
  if ( type == 'audio' ) { 
     var strPlayerDiv = id+'_audioplayer';
	 if (IsInsideFile == 'Y')
	   $(strPlayerDiv).update(podPressGeneratePlayer(1, podPressBackendURL+'audios/'+file_to_play, 50, 20, 1, 1));
     else 
	   $(strPlayerDiv).update(podPressGeneratePlayer(1, file_to_play, 50, 20, 1, 1));
	 
  }
  else { 
     var strPlayerDiv = id+'_videoplayer';
	 var strfirstimg = id+'_firstimg';
	 Element.setStyle(strPlayerDiv,{display:'block'});
	 
	 if ($(strfirstimg))
	   Element.setStyle(strfirstimg,{display:'none'});
	 if (IsInsideFile == 'Y') {
	   $(strPlayerDiv).update(podPressGeneratePlayer(1, podPressBackendURL+'videos/'+file_to_play, 345, 245, 1, 1));
	 }
	 else { 
	    var w = $(strPlayerDiv).offsetWidth - 2;
		file_to_play = file_to_play + '&amp;autoplay=1';
		var txt = '<div style="background:#0D1D61; width:'+w+'px;height:245px;top:0"><object width="'+w+'" height="245"><param name="movie" value="'+file_to_play+'"></param><param name="wmode" value="transparent"></param><embed src="'+file_to_play+'" type="application/x-shockwave-flash" wmode="transparent" width="'+w+'" height="245"></embed></object></div>';
		$(strPlayerDiv).update(txt);
	 
	 }
  }
  StopAtEnd = setTimeout("removeAllAudio()", (duration * 1000) );
}

/*_....................................................................................._*/

function check_search_form() { 
//  if ( ($F('sac4') == '       City or Zip Code') || ($F('sac4') == '') || ($F('sac4').length < 4)   )   { 
  if ( ($F('sac4') == '          Choose City') || ($F('sac4') == '') || ($F('sac4').length < 4)   )   { 
	  //alert("Type in a City or Zip Code");
	  alert("Choose or Type in a City");
	 return false;
  }
  var intval = parseInt($F('sac4'));
  if ( intval >= 0  ) { 
     if ( $F('sac4').length < 5 ) {
	    alert("Invalid Zip Code");
	    return false;
	 }
  }
  var ck = ( $F('city4') == '       Choose Cuisine' || $F('city4') == 'All Restaurants' )  ? '/all' : '/'+$F('city4');
  var cz =  '/'+$F('sac4');
  var srchText = / /g;
  var replacement = "-";
  cz = cz.replace(srchText,replacement);
  ck = ck.replace(srchText,replacement);
  //$('searchform').action = 'http://www.bhungry.com/results'+cz+ck+'/0';
  window.location.href = 'http://www.bhungry.com/results'+cz+ck+'/0';
  //$('searchform').submit();
}

/*_....................................................................................._*/
var blr, clr;
var curSelectedCity = -1; 
var curSelectedRes = -1;

function hoverDo(event,type) {
   var element = Event.findElement(event, 'LI');
   if (type == 'onlycategory') { 
        if ( curSelectedRes != element.autocompleteIndex) {
           curSelectedRes = element.autocompleteIndex;
		   randerNewLi(type,curSelectedRes);
        }
   }
   else {
        if ( curSelectedCity != element.autocompleteIndex) {
           curSelectedCity = element.autocompleteIndex;
		   randerNewLi(type,curSelectedCity);
        }
   }
   Event.stop(event);
}


var  UpDownArrow1 = function (event) {
   if ( event.keyCode == 38 ) {  // up
	  if(curSelectedRes > 0) curSelectedRes--
      else curSelectedRes = $('onlycategory').firstChild.childNodes.length-1;
       randerNewLi('onlycategory', curSelectedRes);
	   getLiElement(curSelectedRes,'onlycategory').scrollIntoView(true);
   }
   else if ( event.keyCode == 40 ) { // down
	   if(curSelectedRes <  $('onlycategory').firstChild.childNodes.length-1) curSelectedRes++
       else curSelectedRes = 0;
	   randerNewLi('onlycategory', curSelectedRes);
	   getLiElement(curSelectedRes,'onlycategory').scrollIntoView(false);
   }
   else if ( event.keyCode == 13 ) { 
	  $('city4').value = getLiElement(curSelectedRes,'onlycategory').innerHTML;
	  new Effect.Fade('onlycategory', { duration: 0.5}); 
	  
   }
   Event.stop(event);

}
// for resname menutype and others
function show_food_type(event) {
  curSelectedRes = -1;
  clearTimeout(blr);
  if ( $('onlycategory')) {
     $('onlycategory').show();
     $('dummybox').focus();
     Event.observe($('dummybox'), "keydown", UpDownArrow1);
     resetAllLi('onlycategory');
  }
}
function OnBlur() {
  clearTimeout(blr);
  Event.stopObserving($('dummybox'), 'keydown', UpDownArrow1); // Won't work!
  blr = setTimeout(function(){$('onlycategory').hide();}, 250 );	
}


// for city ------------------------------------------------------------------
function UpDownArrow(event) {
   if ( event.keyCode == 38 ) {  // up
	  if(curSelectedCity > 0) curSelectedCity--
      else curSelectedCity = $('onlycitylist').firstChild.childNodes.length-1;
       randerNewLi('onlycitylist', curSelectedCity);
	   getLiElement(curSelectedCity,'onlycitylist').scrollIntoView(true);
   }
   else if ( event.keyCode == 40 ) { // down
	   if(curSelectedCity <  $('onlycitylist').firstChild.childNodes.length-1) curSelectedCity++
       else curSelectedCity = 0;
       randerNewLi('onlycitylist', curSelectedCity);
	   getLiElement(curSelectedCity,'onlycitylist').scrollIntoView(false);
   }
   else if ( event.keyCode == 13 ) { // return 
	  $('sac4').value = getLiElement(curSelectedCity,'onlycitylist').innerHTML;
	  new Effect.Fade('onlycitylist', { duration: 0.5}); 
   }
   Event.stop(event);
}

function resetAllLi(outerElm) {
    for (var i = 0; i < $(outerElm).firstChild.childNodes.length; i++)
          Element.removeClassName(getLiElement(i,outerElm),"selected");	
}
function randerNewLi(outerElm, index) {
     for (var i = 0; i < $(outerElm).firstChild.childNodes.length; i++)
         index == i ? 
          Element.addClassName(getLiElement(i,outerElm),"selected") : 
          Element.removeClassName(getLiElement(i,outerElm),"selected");	
}

function getLiElement(index,outerElm) {
    return $(outerElm).firstChild.childNodes[index];
}
function show_citylist() {
  curSelectedCity = -1;
  clearTimeout(clr);
  if ($('onlycitylist')) {
     $('onlycitylist').show();
     $('dummybox1').focus();
     Event.observe($('dummybox1'), "keydown", UpDownArrow);
     resetAllLi('onlycitylist');
  }
}
function OnBlur1() {
  clearTimeout(clr);
  Event.stopObserving($('dummybox1'), 'keydown', UpDownArrow); // Won't work!
  clr = setTimeout(function(){$('onlycitylist').hide();}, 250 );	
}

/*_---------------------------------------------------------------------------------------------------------------------------_*/
//Images preloader
function OnImgUpdate( iProgress ) {   
	var percent = ((iProgress + 1) * 200) / allImages.length;
	$('barr').setStyle({width: percent+'px'}).update(iProgress + 1 + ' / ' + allImages.length);
}

function OnCompletion() {   
   $('progress').remove();
   setInterval("playImages()", 7000);
}
function ImagePreload( p_aImages, p_pfnPercent, p_pfnFinished ) {   
	var pos = Position.cumulativeOffset($('result-img-right')); 
	var showLoading = document.createElement('div');
	showLoading.id = 'progress';
	document.body.appendChild(showLoading);
	$('progress').setStyle({top:pos[1]+5+'px', left:pos[0]-150+'px'});
	$('progress').update('<div class="bar" id="barr" style="width:200px;">Loading Images Please Wait....</div>');
   this.m_pfnPercent = p_pfnPercent;
   this.m_pfnFinished = p_pfnFinished;
   // Class Member Vars
   this.m_nLoaded = 0;
   this.m_nProcessed = 0;
   this.m_aImages = new Array;
   this.m_nICount = p_aImages.length;
   for( var i = 0; i < p_aImages.length; i++ )
       this.Preload( p_aImages[i] );
}

ImagePreload.prototype.Preload = function( p_oImage ) {   
   var oImage = new Image;
   this.m_aImages.push( oImage );
   oImage.onload = ImagePreload.prototype.OnLoad;
   oImage.oImagePreload = this;  // Give the Image Object a Reference to our Class..
   oImage.bLoaded = false;       // Custom value added to track state
   oImage.source = p_oImage;     // Original Source Path to Image (for later use)
   oImage.src = p_oImage;        // Image Object Source Path 
}

ImagePreload.prototype.OnComplete = function() {   
   this.m_nProcessed++;
   if ( this.m_nProcessed == this.m_nICount )
       this.m_pfnFinished();
   else
       this.m_pfnPercent( this.m_nProcessed );
}

ImagePreload.prototype.OnLoad = function() {   
   this.bLoaded = true;
   this.oImagePreload.m_nLoaded++; 
   this.oImagePreload.OnComplete();
}

/*_---------------------------------------------------------------------------------------------------------------------------_*/

function sendFeedBackNow() {
 if ( ($F('CityZip') == '')  ) { 
   alert('Please Enter Your Zip or City '); return false;
 }
 if ( ($F('MyCommnents') == '') ) { 
   alert('Please Enter Some Comments'); return false;
 }
 
 
 $('sendfeedback').submit();
}
/*_---------------------------------------------------------------------------------------------------------------------------_*/

function closeResSpe() {
  new Effect.Fade('overlay1', { duration: 0.5}); $('ResSpe').remove();
}

function showResSpecial(type, rid) { 
	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay1');
	objOverlay.style.display = 'none';
	objOverlay.onclick = closeResSpe
	objBody.appendChild(objOverlay);
	
	var aPageSize = getPageSize();
	Element.setWidth('overlay1', aPageSize[0]);
	Element.setHeight('overlay1', aPageSize[1]);
	new Effect.Appear('overlay1', { duration: 1.0, from: 0.0, to: 0.5 });

	var aoll = getPageScroll();
	var aTop = aoll[1] + (aPageSize[3] / 10);
	var aLeft = aoll[0] + (aPageSize[0] / 2 - 250);
	var datacont = document.createElement("div");
	datacont.setAttribute('id','ResSpe');
	objBody.appendChild(datacont);
	$('ResSpe').setStyle({position:'absolute',backgroundColor:'#FFFFFF',width:'450px', height:'auto',top:aTop+'px',left:aLeft+'px',zIndex:10000});
	datacont.innerHTML = '<div style="padding-left:20px;padding-top:50px;padding-bottom:50px;">Loading Please Wait...<img src="./images/loading.gif" border="0" alt="Loading" /></div>';
    var parms = 'type='+type+'&resid='+rid; 
    new Ajax.Request('./get-res-spe-text.php', {method: 'post', parameters: parms, onComplete: function(e) { 
	   $('ResSpe').innerHTML = e.responseText;
/*		Event.observe(window, "keydown", function(event){ 
		     if (event.keyCode == 27) {
	             if ($('ResSpe')) {
	       new Effect.Fade('overlay1', { duration: 0.5}); 
		   $('ResSpe').remove();
		}
        }});																													
*/																																
	}});
	return false; 

}
/*_---------------------------------------------------------------------------------------------------------------------------_*/
function init_formpost() {
  document.onkeydown = postnt; 
  search_auto();
  var pat = new RegExp("maps.php","i");
  if(pat.test(location.href)) {
	initialize();
  }
  
  // use showdox only for those page that has the shadowbox efffect
  var pageList = ['index','contact-us','news','sitemap','terms-of-use','privacy','copyrights'];
  var showShowBox = true;
  for (i = 0; i < pageList.length ; i++ ) {
	 p =  pageList[i]+'.php';
	 pa = new RegExp(p,"i");
     if(pa.test(location.href)) {
 	   showShowBox = false;
     }
     var b =  new RegExp("bhungry.com/blog","i");
     if (b.test(location.href)) {
          showShowBox = false;
     }
  }
  if ( (window.location.href == 'http://www.bhungry.com') || (window.location.href == 'http://bhungry.com') || (window.location.href == 'http://www.bhungry.com/') || (window.location.href == 'http://bhungry.com/') ) {
	 showShowBox = false;
  }
  
  if (showShowBox) {
     Shadowbox.init();
  }
  
  
  
}
function postnt(e) {
	if (e == null) { // ie
		keycode = event.keyCode;
		onObject = event.srcElement;
	} else { // mozilla
		keycode = e.keyCode;
		onObject = e.target;
	}
 	if ( keycode == 13)  {
	   if ( !($('ResSpe')) ) {
	      check_search_form();
	      //Event.stop(event);
	   }
	   
    }
    if ( keycode == 27) {
	   if ($('ResSpe')) {
	      new Effect.Fade('overlay1', { duration: 0.5}); 
		 $('ResSpe').remove();
	  }
    }
}
/*_---------------------------------------------------------------------------------------------------------------------------_*/
window.onload = init_formpost;


