var SiteGlobalPath = "http://www.boulevardrestaurant.com/";
var SiteSecureGlobalPath = "https://www.boulevardrestaurant.com/";
var SiteRootPath = "/";
var fadeOutduration = 300;
var fadeInduration = 1000;
var hei = 535;
var wid = 380;
var bgstyle = "url("+SiteRootPath+"webapp/views/images/menu_scrollbar.png) no-repeat scroll 0 0 transparent";
var totaltabs = new Array("welcome_tab","menu_img_tab","info_img_tab","bangurt_img_tab","ambiance_img_tab");
var totalinnertabs = new Array("audiffred-building_style","design_style","chef_style","cookbook_style","giftcard_style", "contact_style", "lunch_style", "dinner_style", "dessert_style", "wine_style", "gallery_style");
var menu_over = false;
var info_over = false;
var banquet_over = false;
var ambiance_over = false;

$(document).ready(function(){
	$("#preload_images").hide();

	/* Menu Show hide option */
	/* Hide to set mapping */
	$("#m1").hide();
	$(".menu,#m1").mouseover(function(){
		for(var i=1;i<=4;i++){
			if(i != 1){
				$("#m"+i).hide();
			}else{
				$("#m"+i).show();
			}
		}
	});
	$(".menu,#m1").mouseout(function(){
		$("#m1").hide();
	});
	$("#m2").hide();
	$(".info,#m2").mouseover(function(){
		for(var i=1;i<=4;i++){
			if(i != 2){
				$("#m"+i).hide();
			}else{
				$("#m"+i).show();
			}
		}
	});
	$(".info,#m2").mouseout(function(){
		$("#m2").hide();
	});
	$("#m3").hide();
	$(".bangurt,#m3").mouseover(function(){
		for(var i=1;i<=4;i++){
			if(i != 3){
				$("#m"+i).hide();
			}else{
				$("#m"+i).show();
			}
		}
	});
	$(".bangurt,#m3").mouseout(function(){
		$("#m3").hide();
	});
	$("#m4").hide();
	$(".ambiance,#m4").mouseover(function(){
		for(var i=1;i<=4;i++){
			if(i != 4){
				$("#m"+i).hide();
			}else{
				$("#m"+i).show();
			}
		}
		hei = 220;
		wid = 380;
	});
	$(".ambiance,#m4").mouseout(function(){
		$("#m4").hide();
	});
	$(".reservations").mouseover(function(){
		for(var i=1;i<=4;i++){
			$("#m"+i).hide();
		}
	});
	
	/* Menu Show hide option */
	function changebackground(bgimage){
		$("#backgroundimagediv").css("background", "url('" + bgimage + "')").fadeIn(fadeInduration);
	}
	$(".menu_action").click(function(){
		window.location.hash = $(this).attr("rel");
		var hash_value = $(this).attr("rel");
		if(hash_value == "info-giftcard"){
			window.location.href = SiteSecureGlobalPath+"giftcard.php#info-giftcard";
		}else{
			//if(document.URL.indexOf("https") > -1){
			if(document.URL.indexOf("giftcard.php") > -1){
				window.location.href = SiteGlobalPath+"index.php#"+hash_value;
			}
		}
		if(hash_value == ""){
			$.ajax({
			   type: "POST",
			   url: SiteGlobalPath,
			   data: "action=home",
			   success: function(msg){
					var responseArray = msg.split("||");
					var delay = function(){changebackground(responseArray[2]);}
					$("#backgroundimagediv").fadeOut(fadeOutduration);
					setTimeout(delay, fadeOutduration);
					for(var j=0;j<totaltabs.length;j++){
						$("#"+totaltabs[j]).hide();
					}
					for(var k=0;k<totalinnertabs.length;k++){
						$("#"+totalinnertabs[k]).removeClass("current");
					}
					$("#"+responseArray[0]).show();
					$("#"+responseArray[1]).addClass("current");
					switch_tabs($("#"+responseArray[1]));
					switch_info_tabs($("#"+responseArray[1]));
					switch_amb_tabs($("#"+responseArray[1]));
					switch_tabs_scroll($("#"+responseArray[1]));
					menu_tabs_scroll($("#"+responseArray[1]));
					amb_tabs_scroll($("#"+responseArray[1]));
					gift_tabs_scroll($("#"+responseArray[1]));
					
					
					/*var responseArray = jQuery.parseJSON(msg);
					var delay = function(){changebackground(responseArray.bgimage);}
					$("#backgroundimagediv").fadeOut(fadeOutduration);
					setTimeout(delay, fadeOutduration);
					for(var j=0;j<totaltabs.length;j++){
						$("#"+totaltabs[j]).hide();
					}
					for(var k=0;k<totalinnertabs.length;k++){
						$("#"+totalinnertabs[k]).removeClass("current");
					}
					$("#"+responseArray.page_tab).show();
					$("#"+responseArray.selected_inner_menu).addClass("current");*/
			   }
			 });
		}else{
			$.ajax({
			   type: "POST",
			   url: SiteGlobalPath,
			   data: "action="+hash_value,
			   success: function(msg){
				   	var responseArray = msg.split("||");
					var delay = function(){changebackground(responseArray[2]);}
					$("#backgroundimagediv").fadeOut(fadeOutduration);
					setTimeout(delay, fadeOutduration);
					for(var j=0;j<totaltabs.length;j++){
						$("#"+totaltabs[j]).hide();
					}
					for(var k=0;k<totalinnertabs.length;k++){
						$("#"+totalinnertabs[k]).removeClass("current");
					}
					$("#"+responseArray[0]).show();
					$("#"+responseArray[1]).addClass("current");
					switch_tabs($("#"+responseArray[1]));
					switch_info_tabs($("#"+responseArray[1]));
					switch_amb_tabs($("#"+responseArray[1]));
					switch_tabs_scroll($("#"+responseArray[1]));
					menu_tabs_scroll($("#"+responseArray[1]));
					amb_tabs_scroll($("#"+responseArray[1]));
					gift_tabs_scroll($("#"+responseArray[1]));
					
					/*if(responseArray[0] == "ambiance_img_tab"){
						$('#menu_content_div #pane3').jScrollPane({scrollbarWidth:20, scrollbarMargin:10});
					}*/
					
					/*var responseArray = jQuery.parseJSON(msg);
				   	var delay = function(){changebackground(responseArray.bgimage);}
					$("#backgroundimagediv").fadeOut(fadeOutduration);
					setTimeout(delay, fadeOutduration);
					for(var j=0;j<totaltabs.length;j++){
						$("#"+totaltabs[j]).hide();
					}
					for(var k=0;k<totalinnertabs.length;k++){
						$("#"+totalinnertabs[k]).removeClass("current");
					}
					$("#"+responseArray.page_tab).show();
					$("#"+responseArray.selected_inner_menu).addClass("current");
					switch_tabs($("#"+responseArray.selected_inner_menu));
					switch_info_tabs($("#"+responseArray.selected_inner_menu));
					switch_amb_tabs($("#"+responseArray.selected_inner_menu));*/
			   }
			 });
		}
	});

	if(window.location.hash) {
		var hash_value = window.location.hash.replace('#', '');
		var setSitePath = "";
		if(hash_value == "info-giftcard"){
			setSitePath = SiteSecureGlobalPath;
		}else{
			setSitePath = SiteGlobalPath;
		}
		$.ajax({
		   type: "POST",
		   url: setSitePath,
		   data: "action="+hash_value,
		   success: function(msg){
			   	var responseArray = msg.split("||");
				var delay = function(){changebackground(responseArray[2]);}
				$("#backgroundimagediv").fadeOut(fadeOutduration);
				setTimeout(delay, fadeOutduration);
				for(var j=0;j<totaltabs.length;j++){
					$("#"+totaltabs[j]).hide();
				}
				for(var k=0;k<totalinnertabs.length;k++){
					$("#"+totalinnertabs[k]).removeClass("current");
				}
				$("#"+responseArray[0]).show();
				$("#"+responseArray[1]).addClass("current");
				switch_tabs($("#"+responseArray[1]));
				switch_info_tabs($("#"+responseArray[1]));
				switch_amb_tabs($("#"+responseArray[1]));
				switch_tabs_scroll($("#"+responseArray[1]));
				menu_tabs_scroll($("#"+responseArray[1]));
				amb_tabs_scroll($("#"+responseArray[1]));
				gift_tabs_scroll($("#"+responseArray[1]));
				
				/*if(responseArray[0] == "ambiance_img_tab"){
					$('#menu_content_div #pane3').jScrollPane({scrollbarWidth:20, scrollbarMargin:10});
				}*/
				
				/*var responseArray = jQuery.parseJSON(msg);
				var delay = function(){changebackground(responseArray.bgimage);}
				$("#backgroundimagediv").fadeOut(fadeOutduration);
				setTimeout(delay, fadeOutduration);
				for(var j=0;j<totaltabs.length;j++){
					$("#"+totaltabs[j]).hide();
				}
				for(var k=0;k<totalinnertabs.length;k++){
					$("#"+totalinnertabs[k]).removeClass("current");
				}
				$("#"+responseArray.page_tab).show();
				$("#"+responseArray.selected_inner_menu).addClass("current");
				switch_tabs($("#"+responseArray.selected_inner_menu));
				switch_info_tabs($("#"+responseArray.selected_inner_menu));
				switch_amb_tabs($("#"+responseArray.selected_inner_menu));*/
		   }
		 });
		//{showArrows:true, scrollbarWidth:30}
		$('.scroll-pane').jScrollPane(
			{
				verticalDragMinHeight: 20,
				verticalDragMaxHeight: 20,
				horizontalDragMinWidth: 20,
				horizontalDragMaxWidth: 20
			}
		);
		$('.info-scroll-pane').jScrollPane(
			{
				verticalDragMinHeight: 20,
				verticalDragMaxHeight: 20,
				horizontalDragMinWidth: 20,
				horizontalDragMaxWidth: 20
			}
		);
		$('.ambiance-scroll-pane').jScrollPane(
			{
				verticalDragMinHeight: 20,
				verticalDragMaxHeight: 20,
				horizontalDragMinWidth: 20,
				horizontalDragMaxWidth: 20
			}
		);
	}else{
		
		$.ajax({
		   type: "POST",
		   url: SiteGlobalPath,
		   data: "action=index",
		   success: function(msg){
				var responseArray = msg.split("||");
				var delay = function(){changebackground(responseArray[2]);}
				$("#backgroundimagediv").fadeOut(fadeOutduration);
				setTimeout(delay, fadeOutduration);
				for(var j=0;j<totaltabs.length;j++){
					$("#"+totaltabs[j]).hide();
				}
				for(var k=0;k<totalinnertabs.length;k++){
					$("#"+totalinnertabs[k]).removeClass("current");
				}
				$("#"+responseArray[0]).show();
				$("#"+responseArray[1]).addClass("current");
				
				/*var responseArray = jQuery.parseJSON(msg);
				var delay = function(){changebackground(responseArray.bgimage);}
				$("#backgroundimagediv").fadeOut(fadeOutduration);
				setTimeout(delay, fadeOutduration);
				for(var j=0;j<totaltabs.length;j++){
					$("#"+totaltabs[j]).hide();
				}
				for(var k=0;k<totalinnertabs.length;k++){
					$("#"+totalinnertabs[k]).removeClass("current");
				}
				$("#"+responseArray.page_tab).show();
				$("#"+responseArray.selected_inner_menu).addClass("current");*/
		   }
		 });
		$('.scroll-pane').jScrollPane(
			{
				verticalDragMinHeight: 20,
				verticalDragMaxHeight: 20,
				horizontalDragMinWidth: 20,
				horizontalDragMaxWidth: 20
			}
		);
		$('.info-scroll-pane').jScrollPane(
			{
				verticalDragMinHeight: 20,
				verticalDragMaxHeight: 20,
				horizontalDragMinWidth: 20,
				horizontalDragMaxWidth: 20
			}
		);
		$('.ambiance-scroll-pane').jScrollPane(
			{
				verticalDragMinHeight: 20,
				verticalDragMaxHeight: 20,
				horizontalDragMinWidth: 20,
				horizontalDragMaxWidth: 20
			}
		);
	}
	$('.menu_links a').click(function(){
		switch_tabs($(this));
		window.location.hash = $(this).attr("title");
		for(var k=0;k<totalinnertabs.length;k++){
			$("#"+totalinnertabs[k]).removeClass("current");
		}
		$(this).addClass("current");
		/*$("#menu_img_tab").css("margin-left", "838px");
		alert($("#menu_img_tab").css("margin-left"));*/
	});

	$('.info_links a').click(function(){
		if($(this).attr("title") == "info-giftcard"){
			window.location.href = SiteSecureGlobalPath+"giftcard.php#info-giftcard";
		}else{
			//if(document.URL.indexOf("https") > -1){
			if(document.URL.indexOf("giftcard.php") > -1){
				window.location.href = SiteGlobalPath+"index.php#"+$(this).attr("title");
			}
		}
		switch_info_tabs($(this));		
		window.location.hash = $(this).attr("title");

		/*var hash_value = $(this).attr("title");
		if(hash_value == "info-giftcard"){
			window.location.href = SiteSecureGlobalPath+"giftcard.php#info-giftcard";
		}else{
			if(document.URL.indexOf("https") > -1){
				window.location.href = SiteGlobalPath+"index.php#"+hash_value;
			}
		}*/

		for(var k=0;k<totalinnertabs.length;k++){
			$("#"+totalinnertabs[k]).removeClass("current");
		}
		$(this).addClass("current");
	});
	
	$('.ambiance_links a').click(function(){
		switch_amb_tabs($(this));
		window.location.hash = $(this).attr("title");
		for(var k=0;k<totalinnertabs.length;k++){
			$("#"+totalinnertabs[k]).removeClass("current");
		}
		$(this).addClass("current");
	});
	
	$('.info_links a').click(function(){		
		switch_tabs_scroll($(this));
		
	});
	
	$('.menu_links a').click(function(){		
		menu_tabs_scroll($(this));
		
/*		if($("#gallery_style"))
		{
		$("#floral_design").hide();
		}
		else
		{
		$("#floral_design").show();	
		}*/
		
	});
	
	$('.ambiance_links a').click(function(){		
		amb_tabs_scroll($(this));
		
	});
	
$(".position").hide();
$(".menu_data").hide();
$(".amb_data").hide();
$(".gift_data").hide();


/*Newsticker CMS */
$('#testimonials .slide');
setInterval(function(){
	$('#testimonials .slide').filter(':visible').fadeOut(2000,function(){
		if($(this).next('li.slide').size()){
			$(this).next().fadeIn(1000);
		}
		else{
			$('#testimonials .slide').eq(0).fadeIn(1000);
		}
	});
},9000);
/*Newsticker CMS */

});


/* mouse position */
//$(document).mousemove(function(e){
	/* Menu Main positions */
	/*menu_main_points = [
		{x: 282, y: 135},
		{x: 276, y: 205},
		{x: 186, y: 234},
		{x: 193, y: 158},
		{x: 282, y: 135}
	];*/
	/* Menu Main positions */
	/* Info Main positions */
	/*info_main_points = [
		{x: 377, y: 113},
		{x: 410, y: 163},
		{x: 301, y: 205},
		{x: 325, y: 133},
		{x: 377, y: 113}
	];*/
	/* Info Main positions */
	/* Banquet Main positions */
	/*banquet_main_points = [
		{x: 525, y: 78},
		{x: 545, y: 130},
		{x: 415, y: 170},
		{x: 418, y: 103},
		{x: 525, y: 78}
	];*/
	/* Banquet Main positions */
	/* Ambiance Main positions */
	/*ambiance_main_points = [
		{x: 668, y: 36},
		{x: 695, y: 95},
		{x: 560, y: 143},
		{x: 561, y: 73},
		{x: 668, y: 36}
	];*/
	/* Ambiance Main positions */
	
	/* Menu positions */
	/*menu_points = [
		{x: 284, y: 130},
		{x: 377, y: 370},
		{x: 255, y: 433},
		{x: 164, y: 200},
		{x: 182, y: 160},
		{x: 284, y: 130}
	];*/
	/* Menu positions */
	/* Info positions */
	/*info_points = [
		{x: 394, y: 104},
		{x: 420, y: 216},
		{x: 445, y: 217},
		{x: 485, y: 320},
		{x: 378, y: 350},
		{x: 290, y: 137},
		{x: 394, y: 104}
	];*/
	/* Info positions */
	/* Banquet positions */
	/*banquet_points = [
		{x: 523, y: 70},
		{x: 570, y: 200},
		{x: 482, y: 230},
		{x: 420, y: 210},
		{x: 399, y: 102},
		{x: 523, y: 70}
	];*/
	/* Banquet positions */
	/* Ambiance positions */
	/*ambiance_points = [
		{x: 665, y: 43},
		{x: 680, y: 75},
		{x: 750, y: 110},
		{x: 695, y: 230},
		{x: 590, y: 258},
		{x: 535, y: 80},
		{x: 665, y: 43}
	];*/
	/* Ambiance positions */
	/* Reservations positions */
	/*reservation_points = [
		{x: 880, y: 8},
		{x: 975, y: 68},
		{x: 772, y: 137},
		{x: 703, y: 40},
		{x: 880, y: 8}
	];*/
	/* Reservations positions */
	/*if(isPointInPoly(menu_main_points, {x: e.pageX, y: e.pageY})){
		menu_over = true;
		info_over = false;
		banquet_over = false;
		ambiance_over = false;
	}else if(isPointInPoly(info_main_points, {x: e.pageX, y: e.pageY})){
		menu_over = false;
		info_over = true;
		banquet_over = false;
		ambiance_over = false;
	}else if(isPointInPoly(banquet_main_points, {x: e.pageX, y: e.pageY})){
		menu_over = false;
		info_over = false;
		banquet_over = true;
		ambiance_over = false;
	}else if(isPointInPoly(ambiance_main_points, {x: e.pageX, y: e.pageY})){
		menu_over = false;
		info_over = false;
		banquet_over = false;
		ambiance_over = true;
	}
	
	if(isPointInPoly(menu_points, {x: e.pageX, y: e.pageY}) && menu_over == true){
		$("#m1").show();
		$("#m2").hide();
		$("#m3").hide();
		$("#m4").hide();
	}else if(isPointInPoly(info_points, {x: e.pageX, y: e.pageY}) && info_over == true){
		$("#m2").show();
		$("#m1").hide();
		$("#m3").hide();
		$("#m4").hide();
	}else if(isPointInPoly(banquet_points, {x: e.pageX, y: e.pageY}) && banquet_over == true){
		$("#m3").show();
		$("#m1").hide();
		$("#m2").hide();
		$("#m4").hide();
	}else if(isPointInPoly(ambiance_points, {x: e.pageX, y: e.pageY}) && ambiance_over == true){
		$("#m4").show();
		$("#m1").hide();
		$("#m2").hide();
		$("#m3").hide();
	}else{
		menu_over = false;
		info_over = false;
		banquet_over = false;
		ambiance_over = false;
		$("#m4").hide();
		$("#m1").hide();
		$("#m2").hide();
		$("#m3").hide();	
	}
	
}); */
/* mouse position */


function switch_tabs(obj)
{
	$('.tab-content').hide();
	
	var id = obj.attr("rel");
 
	$('#photo_tabs #'+id).show();
	
}
function switch_info_tabs(obj)
{
	$('.info_tab-content').hide();
	
	var id = obj.attr("rel");

	$('#info_tabs #'+id).show();
}

function switch_amb_tabs(obj)
{
	$('.amb_tab-content').hide();
	
	var id = obj.attr("rel");

	$('#bangurt_tabs #'+id).show();
	
}


function switch_tabs_scroll(obj)
{
	$('.position').hide();
	
	var id = obj.attr("rel");
 
	$('#'+id).show();
	
}


function menu_tabs_scroll(obj)
{
	$('.menu_data').hide();
	
	var id = obj.attr("rel");
	
	$('#'+id).show();
	
	if(id == 'tabs5')
	{
	$("#floral_design").hide();		
	}
	else
	{
	$("#floral_design").show();		
	}
	
}

function amb_tabs_scroll(obj)
{
	$('.amb_data').hide();
	
	var id = obj.attr("rel");
 
	$('#'+id).show();
	
}

function gift_tabs_scroll(obj)
{
	$('.gift_data').hide();
	
	var id = obj.attr("rel");
 
	$('#'+id).show();
	
}

function changeopacity(element, opacity_value){
	$(element).css('opacity', parseFloat(opacity_value/100));
	$(element).css('filter', 'alpha(opacity='+opacity_value+')');
}

function validate_giftcard(){
	var error = "";
	if($("#giftcard_name").val() == ""){
		$("#giftcard_name_error").html("Enter valid name");
		error += "Enter valid name";
	}else{
		$("#giftcard_name_error").html("");
	}
	if($("#giftcard_email").val() == ""){
		$("#giftcard_email_error").html("Enter valid email");
		error += "Enter valid email";
	}else{
		$("#giftcard_email_error").html("");
	}
	if($("#giftcard_amount").val() == ""){
		$("#giftcard_amount_error").html("Enter valid amount");
		error += "Enter valid amount";
	}else{
		$("#giftcard_amount_error").html("");
	}
	if($("#giftcard_cardname").val() == ""){
		$("#giftcard_cardname_error").html("Enter valid card name");
		error += "Enter valid card name";
	}else{
		$("#giftcard_cardname_error").html("");
	}
	if($("#giftcard_cardnumber").val() == ""){
		$("#giftcard_cardnumber_error").html("Enter valid card number");
		error += "Enter valid card number";
	}else{
		$("#giftcard_cardnumber_error").html("");
	}
	if($("#giftcard_cardexpiry").val() == ""){
		$("#giftcard_cardexpiry_error").html("Enter valid card expiry date");
		error += "Enter valid card expiry date";
	}else{
		$("#giftcard_cardexpiry_error").html("");
	}
	if($("#giftcard_cardid").val() == ""){
		$("#giftcard_cardid_error").html("Enter valid card id");
		error += "Enter valid card id";
	}else{
		$("#giftcard_cardid_error").html("");
	}
	if($("#giftcard_cardcaptcha").val() == ""){
		$("#giftcard_cardcaptcha_error").html("Enter valid text");
		error += "Enter valid card id";
	}else{
		$("#giftcard_cardcaptcha_error").html("");
	}
	if(error == ""){
		return true;
	}
	return false;
}

function isPointInPoly(poly, pt){
	for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i)
		((poly[i].y <= pt.y && pt.y < poly[j].y) || (poly[j].y <= pt.y && pt.y < poly[i].y))
		&& (pt.x < (poly[j].x - poly[i].x) * (pt.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x)
		&& (c = !c);
	return c;
}


function limitText(limitField, limitCount, limitNum) {
	if (document.getElementById(limitField).value.length > limitNum) {
		document.getElementById(limitField).value = document.getElementById(limitField).value.substring(0, limitNum);
	} else {
		//document.getElementById(limitCount).value = limitNum - document.getElementById(limitField).value.length;
		document.getElementById(limitCount).innerHTML = limitNum - document.getElementById(limitField).value.length;
	}
}

function strstr (haystack, needle, bool) {
    // Finds first occurrence of a string within another  
    // 
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/strstr    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strstr('Kevin van Zonneveld', 'van');
    // *     returns 1: 'van Zonneveld'    // *     example 2: strstr('Kevin van Zonneveld', 'van', true);
    // *     returns 2: 'Kevin '
    // *     example 3: strstr('name@example.com', '@');
    // *     returns 3: '@example.com'
    // *     example 4: strstr('name@example.com', '@', true);    // *     returns 4: 'name'
    var pos = 0;
 
    haystack += '';
    pos = haystack.indexOf(needle);    if (pos == -1) {
        return false;
    } else {
        if (bool) {
            return haystack.substr(0, pos);        } else {
            return haystack.slice(pos);
        }
    }
}
