(function($){$.fn.lightBox=function(settings){settings=jQuery.extend({overlayBgColor:'#000',overlayOpacity:0.8,fixedNavigation:false,imageLoading:'images/lightbox-ico-loading.gif',imageBtnPrev:'images/lightbox-btn-prev.gif',imageBtnNext:'images/lightbox-btn-next.gif',imageBtnClose:'images/lightbox-btn-close.gif',imageBlank:'images/lightbox-blank.gif',containerBorderSize:10,containerResizeSpeed:400,txtImage:'Image',txtOf:'of',keyToClose:'c',keyToPrev:'p',keyToNext:'n',imageArray:[],activeImage:0},settings);var jQueryMatchedObj=this;function _initialize(){_start(this,jQueryMatchedObj);return false;}
function _start(objClicked,jQueryMatchedObj){$('embed, object, select').css({'visibility':'hidden'});_set_interface();settings.imageArray.length=0;settings.activeImage=0;if(jQueryMatchedObj.length==1){settings.imageArray.push(new Array(objClicked.getAttribute('href'),objClicked.getAttribute('title')));}else{for(var i=0;i<jQueryMatchedObj.length;i++){settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title')));}}
while(settings.imageArray[settings.activeImage][0]!=objClicked.getAttribute('href')){settings.activeImage++;}
_set_image_to_view();}
function _set_interface(){$('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="'+settings.imageLoading+'"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="'+settings.imageBtnClose+'"></a></div></div></div></div>');var arrPageSizes=___getPageSize();$('#jquery-overlay').css({backgroundColor:settings.overlayBgColor,opacity:settings.overlayOpacity,width:arrPageSizes[0],height:arrPageSizes[1]}).fadeIn();var arrPageScroll=___getPageScroll();$('#jquery-lightbox').css({top:arrPageScroll[1]+(arrPageSizes[3]/10),left:arrPageScroll[0]}).show();$('#jquery-overlay,#jquery-lightbox').click(function(){_finish();});$('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function(){_finish();return false;});$(window).resize(function(){var arrPageSizes=___getPageSize();$('#jquery-overlay').css({width:arrPageSizes[0],height:arrPageSizes[1]});var arrPageScroll=___getPageScroll();$('#jquery-lightbox').css({top:arrPageScroll[1]+(arrPageSizes[3]/10),left:arrPageScroll[0]});});}
function _set_image_to_view(){$('#lightbox-loading').show();if(settings.fixedNavigation){$('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();}else{$('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();}
var objImagePreloader=new Image();objImagePreloader.onload=function(){$('#lightbox-image').attr('src',settings.imageArray[settings.activeImage][0]);_resize_container_image_box(objImagePreloader.width,objImagePreloader.height);objImagePreloader.onload=function(){};};objImagePreloader.src=settings.imageArray[settings.activeImage][0];};function _resize_container_image_box(intImageWidth,intImageHeight){var intCurrentWidth=$('#lightbox-container-image-box').width();var intCurrentHeight=$('#lightbox-container-image-box').height();var intWidth=(intImageWidth+(settings.containerBorderSize*2));var intHeight=(intImageHeight+(settings.containerBorderSize*2));var intDiffW=intCurrentWidth-intWidth;var intDiffH=intCurrentHeight-intHeight;$('#lightbox-container-image-box').animate({width:intWidth,height:intHeight},settings.containerResizeSpeed,function(){_show_image();});if((intDiffW==0)&&(intDiffH==0)){if($.browser.msie){___pause(250);}else{___pause(100);}}
$('#lightbox-container-image-data-box').css({width:intImageWidth});$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({height:intImageHeight+(settings.containerBorderSize*2)});};function _show_image(){$('#lightbox-loading').hide();$('#lightbox-image').fadeIn(function(){_show_image_data();_set_navigation();});_preload_neighbor_images();};function _show_image_data(){$('#lightbox-container-image-data-box').slideDown('fast');$('#lightbox-image-details-caption').hide();if(settings.imageArray[settings.activeImage][1]){$('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][1]).show();}
if(settings.imageArray.length>1){$('#lightbox-image-details-currentNumber').html(settings.txtImage+' '+(settings.activeImage+1)+' '+settings.txtOf+' '+settings.imageArray.length).show();}}
function _set_navigation(){$('#lightbox-nav').show();$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({'background':'transparent url('+settings.imageBlank+') no-repeat'});if(settings.activeImage!=0){if(settings.fixedNavigation){$('#lightbox-nav-btnPrev').css({'background':'url('+settings.imageBtnPrev+') left 15% no-repeat'}).unbind().bind('click',function(){settings.activeImage=settings.activeImage-1;_set_image_to_view();return false;});}else{$('#lightbox-nav-btnPrev').unbind().hover(function(){$(this).css({'background':'url('+settings.imageBtnPrev+') left 15% no-repeat'});},function(){$(this).css({'background':'transparent url('+settings.imageBlank+') no-repeat'});}).show().bind('click',function(){settings.activeImage=settings.activeImage-1;_set_image_to_view();return false;});}}
if(settings.activeImage!=(settings.imageArray.length-1)){if(settings.fixedNavigation){$('#lightbox-nav-btnNext').css({'background':'url('+settings.imageBtnNext+') right 15% no-repeat'}).unbind().bind('click',function(){settings.activeImage=settings.activeImage+1;_set_image_to_view();return false;});}else{$('#lightbox-nav-btnNext').unbind().hover(function(){$(this).css({'background':'url('+settings.imageBtnNext+') right 15% no-repeat'});},function(){$(this).css({'background':'transparent url('+settings.imageBlank+') no-repeat'});}).show().bind('click',function(){settings.activeImage=settings.activeImage+1;_set_image_to_view();return false;});}}
_enable_keyboard_navigation();}
function _enable_keyboard_navigation(){$(document).keydown(function(objEvent){_keyboard_action(objEvent);});}
function _disable_keyboard_navigation(){$(document).unbind();}
function _keyboard_action(objEvent){if(objEvent==null){keycode=event.keyCode;escapeKey=27;}else{keycode=objEvent.keyCode;escapeKey=objEvent.DOM_VK_ESCAPE;}
key=String.fromCharCode(keycode).toLowerCase();if((key==settings.keyToClose)||(key=='x')||(keycode==escapeKey)){_finish();}
if((key==settings.keyToPrev)||(keycode==37)){if(settings.activeImage!=0){settings.activeImage=settings.activeImage-1;_set_image_to_view();_disable_keyboard_navigation();}}
if((key==settings.keyToNext)||(keycode==39)){if(settings.activeImage!=(settings.imageArray.length-1)){settings.activeImage=settings.activeImage+1;_set_image_to_view();_disable_keyboard_navigation();}}}
function _preload_neighbor_images(){if((settings.imageArray.length-1)>settings.activeImage){objNext=new Image();objNext.src=settings.imageArray[settings.activeImage+1][0];}
if(settings.activeImage>0){objPrev=new Image();objPrev.src=settings.imageArray[settings.activeImage-1][0];}}
function _finish(){$('#jquery-lightbox').remove();$('#jquery-overlay').fadeOut(function(){$('#jquery-overlay').remove();});$('embed, object, select').css({'visibility':'visible'});}
function ___getPageSize(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;}
var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth;}else{windowWidth=self.innerWidth;}
windowHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;}
if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}
if(xScroll<windowWidth){pageWidth=xScroll;}else{pageWidth=windowWidth;}
arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize;};function ___getPageScroll(){var xScroll,yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;xScroll=self.pageXOffset;}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;xScroll=document.documentElement.scrollLeft;}else if(document.body){yScroll=document.body.scrollTop;xScroll=document.body.scrollLeft;}
arrayPageScroll=new Array(xScroll,yScroll);return arrayPageScroll;};function ___pause(ms){var date=new Date();curDate=null;do{var curDate=new Date();}
while(curDate-date<ms);};return this.unbind('click').click(_initialize);};})(jQuery);

/*Temporarility adding $j to make it works */
(function($){
$.fn.bgIframe = $.fn.bgiframe = function(s) {
	// This is only for IE6
	if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
		s = $.extend({
			top     : 'auto', // auto == .currentStyle.borderTopWidth
			left    : 'auto', // auto == .currentStyle.borderLeftWidth
			width   : 'auto', // auto == offsetWidth
			height  : 'auto', // auto == offsetHeight
			opacity : true,
			src     : 'javascript:false;'
		}, s || {});
		var prop = function(n){return n&&n.constructor==Number?n+'px':n;},
		    html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
		               'style="display:block;position:absolute;z-index:-1;'+
			               (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
					       'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
					       'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
					       'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
					       'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
					'"/>';
		return this.each(function() {
			if ( $('> iframe.bgiframe', this).length == 0 )
				this.insertBefore( document.createElement(html), this.firstChild );
		});
	}
	return this;
};

})(jQuery);

var $j = jQuery.noConflict();
$j(document).ready(function(){
	if($j.browser.msie && $j.browser.version=="6.0") {
	
	$j("#nav ul li.drop").hover(
      		function () {
        		$j(this).find("ul").css("display","block");
        		$j(this).find("ul").css("z-index","9999");
        		$j("#select-areas").css("z-index","1");
        		$j("#nav").css("z-index","99");
      		}, 
      		function () {
        		$j(this).find("ul").css("display","none");
        		$j("#nav").css("z-index","99");
        		$j("#select-areas").css("z-index","105");
      		}
    	);
		
		$j("#select-areas li.drop").hover(
      		function () {
        		$j(this).find("ul").css("display","block");
        		$j(this).find("ul").bgiframe(); 
        		$j("#nav").css("z-index","1");
      		}, 
      		function () {
      			$j(this).find("ul").css("display","none");
        		$j("#nav").css("z-index","99");
      		}
    	);
   }
   
   if($j.browser.msie && $j.browser.version=="7.0") {
 
   	$j("#nav ul li.drop").hover(
      		function () {
        		$j("#select-areas").css("z-index","1");
        		$j("#nav").css("z-index","99");
      		}, 
      		function () {
        		$j("#select-areas").css("z-index","9999");
        		$j("#nav").css("z-index","99");
      		}
    	);
   }

	
	$j('#news-recipes-toggle').click(function () {
		$j('#news-recipes-content').slideToggle("slow");
		return false;
	});
	
	$j('#more-about-btn').click(function () {
		$j('#more-about').slideToggle("slow");
		return false;
	});	
	$j('#logo').click(function () {
		return false;
	});

	if($j(".inner-homepage").length <= 0){
		if($j(".message_list") != null){
			var list = $j(".message_list");
			$j.each(list, function(i, val){
			$j(val).find("li:gt(2)").hide();
			});
		}
		//show all messages
		if($j(".show_all_message") != null) {
		var links = $j(".show_all_message");
		$j.each(links, function(i, val){
			$j(val).click(function(){
				var div = $j(this).parent().parent();
				$j(div).find(".message_list li:gt(2)").slideDown();
				$j(this).hide();
				$j(div).find(".show_recent_only").show();
				return false;
			});
		});

		
		//show recent messages only
	if($j(".show_recent_only") != null) {
		var links = $j(".show_recent_only");
		$j.each(links, function(i, val){
			$j(val).click(function(){
				var div = $j(this).parent().parent();
				$j(div).find(".message_list li:gt(2)").slideUp();
				$j(this).hide();
				$j(div).find(".show_all_message").show();
				return false;
			});
		});
	}
		}
		
		
	}	
	if($j(".tabs .message_list") != null)	
		$j(".tabs .message_list li:gt(2)").hide();
	if($j(".show_recent_only") != null)
		$j(".show_recent_only").hide();
	
	//collapse all messages
	if($j(".collpase_all_message") != null) {
		$j(".collpase_all_message").click(function(){
			$j(".message_body").slideUp(500);
			return false;
		});
	}

	
	//show all messages
	if($j(".tabs .show_all_message") != null) {
		$j(".tabs .show_all_message").click(function(){
			$j(this).hide();
			$j(".tabs .show_recent_only").show();
			$j(".tabs .message_list li:gt(2)").slideDown();
			return false;
		});
	}
		
	//show recent messages only
	if($j(".tabs .show_recent_only") != null) {
	$j(".tabs .show_recent_only").click(function(){
		$j(this).hide();
		$j(".tabs .show_all_message").show();
		$j(".tabs .message_list li:gt(2)").slideUp();
		return false;
	});
	}
	
	/*Slide for inner homepage */
	/* Local restaurants BOX */
	
	//hide local li after the 5th
	if($j(".inner-homepage").length > 0){
	if($j(".message_list") != null) {
		$j(".message_list li:gt(4)").hide();
		$j(".show_recent_local_only").hide();
	}
	

	//show all local
	if($j(".show_all_message") != null) {
		$j(".show_all_message").click(function(){
			//alert('show_all_message');
			$j(this).hide();
			$j(".show_recent_only").show();
			$j(".message_list li:gt(4)").slideDown();
			return false;
		});
	}
	//show recent local only
	if($j(".show_recent_only") != null) {
		$j(".show_recent_only").click(function(){
			$j(this).hide();
			//alert('show_recent_only');
			$j(".message_list li:gt(4)").slideUp();
			$j(".show_all_message").show();
			return false;
		});
	}
	}
	/*End*/
	
	
	/* Local restaurants BOX */
	
	//hide local li after the 5th
	if($j(".local_list") != null) {
		$j(".local_list li:gt(4)").hide();
		$j(".show_recent_local_only").hide();
	}
	
	//collapse all local
	if($j(".collpase_all_local") != null) {
		$j(".collpase_all_local").click(function(){
			$j(".local_body").slideUp(500);
			return false;
		});
	}
	//show all local
	if($j(".show_all_local") != null) {
		$j(".show_all_local").click(function(){
			$j(this).hide();
			$j(".show_recent_local_only").show();
			$j(".local_list li:gt(4)").slideDown();
			return false;
		});
	}
	//show recent local only
	if($j(".show_recent_local_only") != null) {
		$j(".show_recent_local_only").click(function(){
			$j(this).hide();
			$j(".show_all_local").show();
			$j(".local_list li:gt(4)").slideUp();
			return false;
		});
	}
	//Restaurants listings
	if($j("#map-ops") != null) {

		$j("#expand-map-intro").click(function(e){
			e.preventDefault();
			$j("#map-intro").css("height","auto");
			$j("#map-intro").css("overflow","hidden");
		});
		
		$j("#map-intro").css("height","56px");
		$j("#map-intro").css("overflow","hidden");
	}
	

	$j("#logo").click(function(e){
			window.location.href = $j("#logo a:first").attr("href");
	});
	
	$j('.my-skinnable-select').each(
      function(i) {
        selectContainer = $j(this);
        //Remove the class for non JS browsers
        selectContainer.removeClass('my-skinnable-select');
        // Add the class for JS Browers
        selectContainer.addClass('skinned-select');
        // Find the select box
        selectContainer.children().before('<div class="select-text">a</div>').each(
          function() {
            $j(this).prev().text(this.options[0].innerHTML)
          }
        );
        // Store the parent object
        var parentTextObj = selectContainer.children().prev();
        // As we click on the options
       selectContainer.children().click(function() {
          // Set the value of the html
         parentTextObj.text(this.options[this.selectedIndex].innerHTML);
      })        
      }
    );
    
   if($j("#search-rest-form").length > 0) {
   $j("select#cuisine option:first").attr("selected","selected");
   $j("select#city option:first").attr("selected","selected");
   var postcode = '0';
   var cuisine = '0';
   var current_cuisine = '';
   $j.ajaxSetup({ cache: false });
   $j.getJSON("AJAX/getOption.aspx",'',function(data){
   
   		$j('#counter').html('');
			$j('#counter').append('<strong>'+data.couterdata[0]["values1"]+'</strong>');
			$j('#counter').append('<strong>'+data.couterdata[0]["values2"]+'</strong>');
			$j('#counter').append('<strong>'+data.couterdata[0]["values3"]+'</strong>');
   });
   
   
    $j('select#city').change(function(){
    	var k = 0;
    	$j("select#cuisine").html('');
    		var options = '<option value="0">by Cuisine</option>';
    		$j("select#cuisine").append(options);
			var res = $j.getJSON("AJAX/getOption.aspx",{cityId: $j('select#city option:selected').val(),cuisineId: cuisine,action: 'getCuisine'}, function(data){
			  k = 0;
			  
			 
			  $j.each(data.cuisinedata, function(i,user){
			   	if(user.optionValue === cuisine){
			   		 k=i+1;
			   		 options = '<option value="'+user.optionValue+'" selected="selected">' + user.optionDisplay + '</option>';
			   	 }
			   	 else{
			   		 options = '<option value="'+user.optionValue+'">' + user.optionDisplay + '</option>';
			   	 }
			   	 $j("select#cuisine").append(options);
			  });
			//$j("select#cuisine").html(options);
			
			$j('#counter').html('');
			$j('#counter').append('<strong>'+data.couterdata[0]["values1"]+'</strong>');
			$j('#counter').append('<strong>'+data.couterdata[0]["values2"]+'</strong>');
			$j('#counter').append('<strong>'+data.couterdata[0]["values3"]+'</strong>');
			if($j.browser.msie && $j.browser.version=="6.0") {
				document.getElementById("cuisine").selectedIndex = 0;
			}
			else{
				$j("select#cuisine option:eq("+k+")").attr("selected","selected");
			}
			});
		});
    
    
		$j('select#cuisine').change(function(){
			cuisine = $j('select#cuisine option:selected').val();
			$j.getJSON("AJAX/getOption.aspx",{cityId: $j('select#city option:selected').val(),cuisineId: cuisine}, function(data){
			
			$j('#counter').html('');
			$j('#counter').append('<strong>'+data.couterdata[0]["values1"]+'</strong>');
			$j('#counter').append('<strong>'+data.couterdata[0]["values2"]+'</strong>');
			$j('#counter').append('<strong>'+data.couterdata[0]["values3"]+'</strong>');
		 			
			});
		});
		
		var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
		if(is_chrome || $j.browser.safari){
			var cuisine_wrapper = $j("select#cuisine").prev();
			$j("select#cuisine").change(function(e){
				$j(cuisine_wrapper).text($j('#cuisine :selected').text());
			});
			
			var city_wrapper = $j("select#city").prev();
				$j("select#city").change(function(e){
					$j(city_wrapper).text($j('#city :selected').text());
				});
			
		}
	}
	
	$j(function(){
		$j(".restaurant-guide").each(function(){
			var hideDelay = 100;
			var hideDelayTimer = null;
			var trigger = $j('.cuisine', this);
			var popup = $j('.cuisinebox', this);
			var beingShown = false;
			
			$j([trigger.get(0),popup.get(0)]).click(function(){
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				
				if(beingShown){
					return true;
				}
				else{
					beingShown = true;
					popup.css({
						display:'block',
						top:150,
						left:-40
					});
				}
			}).mouseover(function(){
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
			}).mouseout(function(){
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				
				hideDelayTimer = setTimeout(function () {
					hideDelayTimer = null;
					beingShown = false;
					popup.css({
						display:'none'
					});
				}, hideDelay);
			});
		});
	});
	
	$j(function(){
		$j(".restaurant-guide").each(function(){
			var hideDelay = 100;
			var hideDelayTimer = null;
			var trigger = $j('.area', this);
			var popup = $j('.areabox', this);
			var beingShown = false;
			
			$j([trigger.get(0),popup.get(0)]).click(function(){
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				
				if(beingShown){
					return true;
				}
				else{
					beingShown = true;
					popup.css({
						display:'block',
						top:150,
						left:50
					});
				}
			}).mouseover(function(){
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
			}).mouseout(function(){
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				
				hideDelayTimer = setTimeout(function () {
					hideDelayTimer = null;
					beingShown = false;
					popup.css({
						display:'none'
					});
				}, hideDelay);
			});
		});
	});
	
	if($j("#slideshow").length > 0){$j("#slideshow").cycle({fx:'fade',timeout:5000});}
	if($j("#carousel div.carousel-content").length > 0){$j("#carousel div.carousel-content").jCarouselLite({btnNext: "#carousel div.next",btnPrev: "#carousel div.prev",scroll:6,visible:6,circular:false});}
	/*if($j(".gallery").length > 0){$j(".gallery a").lightBox();}
	$j("a.hide,a.menu").lightBox();*/
});