function browserWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && document.documentElement.clientWidth ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && document.body.clientWidth ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
  
}

/* if(navigator.userAgent.search(new RegExp('(^iPad|Android|iPhone|palm|palmos|palmsource|blackberry|nokia|phone|midp|mobi|pda|wap|java|nokia|hand|symbian|chtml|wml|ericsson|lg|audiovox|motorola|samsung|sanyo|sharp|telit|tsm|mobile|mini|windows ce|smartphone|mobileexplorer|j2me|sgh|portable|sprint|vodafone|docomo|kddi|softbank|pdxgw|jphone|astel|minimo|plucker|netfront|xiino|mot-v|mot-e|portalmmm|sagem|sie-s|sie-m|ipod)','gi')) > -1 &&  browserWidth() < 1024)
{
	window.location = 'http://m.casadelsole.ro/';
	document.write('');
} */

CufonFontList = new Array(
	new Array('.cufon-GothamLight','GothamLight'),
	new Array('.cufon-GothamMedium','GothamMedium'),
	new Array('.cufon-GothamBook','GothamBook'),
	new Array('.cufon-GothamBold','GothamBold')
);
var openCount 				= 0;
var reservationFrameLoad 	= false;
function cufonReplace(){	
	
	for(i=0;i < CufonFontList.length;i++){
		cufonReReplace(CufonFontList[i][0], {fontFamily: CufonFontList[i][1], hover: true});
	}	
}


function openHeaderMask(val){
	
	
	openCount += val;
	//console.log('val :'+val,'openCount :'+openCount);

		if(openCount < 1){
			$('.modal-mask').stop(1,1).fadeOut();
			openCount = 0;
		}else{		
			$('.modal-mask').stop(1,1).fadeIn();
		};
	
};

function cufonReReplace(item,ops){
	/* if( navigator.userAgent.indexOf('MSIE') > 0 ){
		return false;	
	} */
	Cufon.replace(item,ops);
}


// Plug-in's


////////////////////////////////////yeti tab menu

(function($) {
	$.fn.extend({

		tabmenu : function(options) {

			var defaults = {
				global		: '.tabs:not(.noJS)',
				container 	: '.heading',
				selector 	: 'ul li a',
				active		: 'active'
			};

			var options 	= $.extend(defaults, options);
			var selected 	= null;
			var selectedId 	= null;

			var o 			= options;
			var obj			= $(o.global);
			var clickObj	= obj.find(o.selector);
			var tabCont		= obj.find(o.container);
			
			var selectedTab = null;
			var selectedId 	= null;
			var setUrl 		= null;
			
			selectedTab = tabCont.find('ul li.active a');
			clickObj.click(function(){
				
				if(selectedTab != null){
					selectedTab.parent().removeClass('active');
					obj.find(selectedId).removeClass('active');
				}
				
				selectedTab = $(this);	
				selectedId  = $(this).attr('tabID');
				selectedTab.addClass(o.active);

				var splitHref = selectedTab.attr('href').split('index.html');
				
				setUrl = splitHref[splitHref.length - 1];		
				
				$(selectedTab).parent().addClass('active');
				$(selectedId).addClass('active');
				
				headingChanger();
				cufonReReplace($('.tabs .heading a.cufon-GothamLight'),{fontFamily: 'GothamLight', hover: true});
				locationChanger(splitHref[splitHref.length - 1]);
				
				return false;
			});
			
			function clickFirsItem(obj){	
				//console.log(obj);
				if(tabCont.find('ul li').hasClass('active')){
					selectedTab.click();
				}else{
					if(window.location.hash == ''){
						$(obj+':first').click();
					}else{
						//console.log($(obj).parent().parent());
						$(obj).parent().parent().find('a[href="'+window.location.href.replace('#','')+'"]').click();
					}
				}
			}
			
			function locationChanger(str){
				window.location.hash = '/'+str;
			}
			
			/*function headingChanger(){
				
				span = tabCont.find('span');
				if(span.html() != null){
					span.html(selectedTab.attr('total') + ' ' + selectedTab.text());
				}
			}*/
			
			function headingChanger(){
				
				span = tabCont.find('span');
				if(span.html() != null)
				{
					span.html(selectedTab.attr('total') + ' ' + span.text().replace(new RegExp('[0-9]','g'),''));
				}
			}
			
			clickFirsItem(o.global+' '+o.container+' '+o.selector);
		}
	});
})(jQuery);

//////////////////////////////////////yeti explorerMenuHoverPlugin
(function($) {
	$.fn.extend({
		explorerHover : function(options) {

			var defaults = {
				content		: '',
				imgContent	: '',
				selectItem	: ''
			};

			var options 		= $.extend(defaults, options);
			var selected 		= null;
			var selectedImg 	= null;

			return this.each(function() {
				var o 			= options;
				var obj			= $(this);
				var content		= $(o.content);
				var imgContent	= $(o.imgContent);
				var selectItem	= o.selectItem;
				var hoverObj	= content.find(selectItem);
				
				selected 		= content.find('.active');
				
				var splitId = selected.attr('id').split('-');
				var id = splitId[splitId.length-1];
				selectedImg = $(imgContent.find('#img-' + id));
				selectedImg.addClass('hover');

				hoverObj.hover(overHandler,outHandler);
								
				function overHandler(){
									
					if(selectedImg != null){
						selectedImg.removeClass('hover');
					}
					
					selected = $(this);	
					splitId = selected.attr('id').split('-');
					
					id = splitId[splitId.length-1];
					selectedImg = $(imgContent.find('#img-' + id));	
					selectedImg.addClass('hover');
					
					imgContent.find('.heading h1').text(selected.text());														
				}
				
				function outHandler(){			
					$(content.find('#a-' + id).addClass('active'));					
				}
						
				return false;			
			});
		}
	});
})(jQuery);

///////////////////////////////////////////modalWin 
(function($) {
	$.fn.extend({

		modalWindow : function(options) {

			var defaults = {
				modal			: '',
				close			: '',
				maskTopPos		: 400,
				mask			: '',				
				maskType 		: 'normal',
				maskH			: '150',
				align			: 'center',
				callBack		: function(){},
				callBefore		: function(){},
				callClose		: function(){},
				callCloseBefore : function(){ return true; },
				ajax			: null,
				fixTop 			: false
				
			};

			var options = $.extend(defaults, options);
			var o 		= options; 
			var obj     = $(o.modal);
			var mask	= $(o.mask);
			var close	= obj.find(o.close);
			
			var objW	= obj.width();
			var objH	= obj.height();		
			
			var winW 	= $(window).width();
			var winH 	= $(window).height();									
			var docW 	= $(document).width();
			var docH 	= $(document).height();
			
		
			
			function openModal()
			{
				obj.stop(0,1).fadeIn('normal');
				if(o.align == 'center'){
					obj.css({
						'left': winW/2 - objW/2,
						'top' : (o.fixTop ? o.fixTop : (winH/2 - objH/2)) 	
					});
				}				
				
				close.click(function(){
					if(!o.callCloseBefore()){ console.log('Wait ...');return false; }
					obj.stop(0,1).fadeOut('normal');
					openHeaderMask(-1);
//					mask.stop(0,1).fadeOut('normal');
					$(window).unbind('scroll',popWindowEvent);
					
					if($('#ajaxContentPopup')){
						$('#ajaxContentPopup').remove();
					};			
					o.callClose();
					return false;
				});
				
				maskClickEvent = function(){
					close.click();
				};
				
				mask.click(maskClickEvent);
				
				mask.css({
					'display'	: 'block'
				});		
				
				popWindowEvent = function(){
					if($(window).scrollTop() < docH){
						$(window).resize();
					}
				};
				
				$(window).scroll(popWindowEvent);
				
				$(window).resize(function(){
					
					winW 	= $(window).width();
					winH 	= $(window).height();									
					docW 	= $(document).width();
//					docH 	= $(document).height();
					
					mask.css({
						width	: winW +'px',
						height	: docH +'px'
					});
					
					obj.stop(0,1).animate({
						'left': winW/2 - objW/2,
						'top' : (o.fixTop ? o.fixTop : (winH/2 - objH/2 +  $(window).scrollTop()+40))
					},300);
				});
				
				$(window).resize();
				
				o.callBack();
			}
			
			$(this).click(function(){
				
				openHeaderMask(1);
				
				o.callBefore();
				if(o.ajax != null)
				{
					$.ajax({
					  url		: o.ajax,
					  context	: document.body,
					  success	: function(data){
						
						$('body').append(data);
						obj     = $(o.modal);
						mask	= $(o.mask);
						close	=  obj.find(o.close);
						objW	= obj.width();
						objH	= obj.height();
						modalType = $(o.modalType);
						openModal();
					  }
					});
					
					return false;
				}
				openModal();
				return false;
			});
		}
	});
})(jQuery);


(function($) {
	$.fn.extend({

		focuser : function(options) {

			var defaults = {
				input		: '.input:not(.datepicker) input,.textarea textarea'
			};

			var options = $.extend(defaults, options);

			var o 			= options;
			var input		= $(o.input);
			
			input.each(function(){
				$(this).attr('orjVal',($(this).text() ? $(this).text() : $(this).val()));
				
				$(this).focus(function(){
					if($(this).val() == $(this).attr('orjVal'))
					{
						$(this).val('');
					}
				});
				$(this).focusout(function(){
					if($(this).val() == '')
					{
						$(this).val($(this).attr('orjVal'));
					}
				});
			});
		}
	});
})(jQuery);


//-----------------------------------------------------------------------------------------

$(document).ready(function(){
	
	
	cufonReplace();
	// Datepicker 
	if($().datepick)
	{
		$('.line-col .datepicker input, .datepicker input').datepick({changeMonth: false,alignment:'bottomLeft'});
		
		$('.smallcol .input input').datepick({changeMonth: false, minDate: 0,alignment:'top',onSelect:function(target){
			$(target).css('top','850');
		}});
	}
	
	exploreTimer = setTimeout('void(0)',1);	
	
	$('#langSelect').modalWindow({
		'modal' : '.language-modal',
		'align'	: 'center',
		'close'	: '.modalclose',
		'mask'	: '#headermask'
	});
	
	
	
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) {
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){
	 $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide();
	  });
	}


	var config = {
		 sensitivity: 2,		// number = sensitivity threshold (must be 1 or higher)    
		 interval: 0, 			// number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver,   // function = onMouseOver callback (REQUIRED)    
		 timeout: 0, 			// number = milliseconds delay before onMouseOut    
		 out: megaHoverOut 		// function = onMouseOut callback (REQUIRED)    
	};

	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);
	
	// Add class to the current element
	$("ul#topnav li").click(function(){
		$("ul#topnav").find("li.current").removeClass().removeAttr("class");
		$(this).addClass("current");
	});
	
	/* // Change arrow on hover
	$("li.liSub").hover(function(){
		$(this).find("span img").attr("src", "../../img/menu/arrow_hover.png");
	},function(){
		$(this).find("span img").attr("src", "../../img/menu/arrow.png");
	}); */
	
	// Delete the border for the last li of the submenu
	$("ul#topnav .sub ul li:last-child a").css("border", "none");
	
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	$('#our_locations').modalWindow({
		'modal' : '.our_locations-modal',
		'align'	: 'center',
		'close'	: '.modalclose',
		'mask'	: '.modal-mask'
	});
	
	$('#menu-of-the-day').modalWindow({
		'modal' : '.menu-of-the-day-modal',
		'align'	: 'center',
		'close'	: '.modalclose',
		'mask'	: '.modal-mask'
	});
	
	$('#weekly-menu').modalWindow({
		'modal' : '.weekly-menu-modal',
		'align'	: 'center',
		'close'	: '.modalclose',
		'mask'	: '.modal-mask'
	});
	
	$('.orderNowBlock #getOrder').click(function() {
		$('#formGo').submit();
	});

});
