// JavaScript Document
$(function(){
	selectPage();
	
	/* je.com */
	FB.init({
		appId  : '135718287140',
		status : true, // check login status
		cookie : true, // enable cookies to allow the server to access the session
		xfbml  : true,  // parse XFBML
	});
	
	/*je.red*/
	 /*FB.init({
		appId  : '134788575274',
		status : true, // check login status
		cookie : true, // enable cookies to allow the server to access the session
		xfbml  : true,  // parse XFBML
		//logging: true
	 });*/
	
	$('.input-signin-top, .input-box').example(function() {
		var text = $(this).attr('title');
			return text;
		},
		{className: 'input-hint'}
	);	
	
	// Actions for Internet Explorer
	if (!$.browser.webkit) {
	  if (!$.browser.mozilla) {
			  
		var fileref=document.createElement("link");
 			fileref.setAttribute("rel", "stylesheet");
  			fileref.setAttribute("type", "text/css");
  			fileref.setAttribute("href", themePath + '/css/ie.css');
		document.getElementsByTagName("head")[0].appendChild(fileref);	  
			  
		$('#main-nav ul li a span').each(function(){
			$(this).after('<div class="right-corner" style="display:none"></div>');
		});
		$('#main-nav ul li a span').mouseover(
		  function () {
			$(this).addClass('spanOver');
			$(this).next('div').show().css({'display':'inline'});
		 });
		
		 $('#main-nav ul li a span').mouseout( 
		  function () {
			$(this).removeClass('spanOver');
			$(this).next('div').hide();
		  });
		 
	   }
	 }
	 
	$('.authorisationPanel').submit(function(){
		$(this).find('input[name=backto]').val(location.pathname + '' + location.search);
		return true;
	});
	 
});

function selectPage() {
 var path = location.pathname;
 path = path.toLowerCase();
switch (path) {
	case '/':
		$('#s-menu-home').addClass('selected');
		
		if ($('#je-restaurant-search-city-zip').length != 0) {
			$('#je-restaurant-search-city-zip').autocomplete({ 
				serviceUrl:'index.php?mod=restaurants&act=view&what=quick&sub=cityregion2',
				minChars:1, 
				maxHeight:200,
				width:179,
				onSelect: function(value, data){
					$('#je-restaurants-search-city-value').val(data);
					$('#city_not_select').hide();
				},
				beforeSend : function () {
//					dataAutoComp  = {regionid : $('#je-restaurant-search-region').val()}
				}
			});
		}
		$('#je-restaurants-search').submit( function() {
			var cityID = parseInt($('#je-restaurants-search-city-value').val());
			if (cityID && cityID > 0) {
				return true;
			}
			$('#city_not_select').show();
			return false;
		});
		
	break;
	case '/restaurants/':
		$('#s-menu-restaurants').addClass('selected');
	break;
	case '/iphone-users.html' :
		$('#s-menu-iphone-users').addClass('selected');
	break;
	case '/community.html' :
		$('#s-menu-community').addClass('selected');
	break;
	case '/restaurant-owners.html':
		$('#s-menu-restaurant-owners').addClass('selected');
	break;
	case '/je-tour.html':
	case '/jetour-mobile-marketing.html':
	case '/jetour-mobile-messaging.html':
	case '/jetour-social-networking.html':
	case '/jetour-mobile-ordering.html':
	case '/jetour-data-capture.html':
		$('#s-menu-je-tour').addClass('selected');
	break;
	case '/justenjoy-company.html':
	case '/justenjoy-solution.html':
	case '/justenjoy-value.html':
	case '/about-just-enjoy.html':
	case '/careers.html':
	case '/press-room.html':
	case '/go-green.html':
		$('#s-menu-je-company').addClass('selected');
	break;
	case '/contacts-us.html' :
		$('#s-menu-contacts-us').addClass('selected');
	break;
 }
}

function initFB(back) {
 FB.login(function(response) {
  if (response.session) {
    if (response.perms) {
      // user is logged in and granted some permissions.
      // perms is a comma separated list of granted permissions
    } else {
      // user is logged in, but did not grant any permissions
    }
	//location.href='/?session=' + response.session;
	window.location.reload();
  } else {
    // user is not logged in
  }
 }, {perms:'email,status_update'});
}

function logoutFB() {
   FB.getLoginStatus(function(response) {
	if (response.session) {
	  FB.logout(function(response) {
		location.href="/?act=logout";
	  });
	} else {
		location.href="/?act=logout";
	}
   });
}


function openLoginDialog()
{
	loginDialog = $('#login-dialog').dialog({
		autoOpen: false,
		closeOnEscape: true,
		resizable: true,
		width: 350,
		zIndex: 1000,
		open: function(event, ui) {
			createOverlay();
		},
		close: function(event, ui) {
			$('#exDialogOverlay').remove();
		},
		buttons: {
			//{/literal}
			'Cancel': 
			//{literal}
			function() {
				$(this).dialog('close');
				
			}
		}
	});
	
	loginDialog.dialog('open');
}
