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){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	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) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
};
	
$.videoPopup = function (settings){
	var defaults = {
		url:'',
		height:'385px',
		width:'480px',
		border:'0',
		overlayBgColor:	'#000',
		overlayOpacity:			0.8,
	};
	settings = $.extend(defaults,settings);
	append = 'http://www.youtube.com/v/'+settings.url+'?fs=1&amp;hl=en_US&amp;rel=0&amp;border='+settings.border;
	
	
	function _finish() {
		$('#popup').remove();
		$('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); });
		// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
		$('embed, object, select').css({ 'visibility' : 'visible' });
	}
	function _start(){
		$('embed, object, select').css({ 'visibility' : 'hidden' });
		
		html = '<div id="jquery-overlay"></div><div id="popup"><div id="innerpopup"><a href="#" id="popupclose"></a></div></div>';
		vid = '<object id="popupvid" type="application/x-shockwave-flash" data="http://www.youtube.com/v/'+settings.url+'?fs=1&amp;hl=en_US&amp;rel=0&amp;border='+settings.border+'" class="singleVid"> <param value="http://www.youtube.com/v/'+settings.url+'?fs=1&amp;hl=en_US&amp;rel=0&amp;border='+settings.border+'" name="movie"> </object>';
		$('body').append(html);
		$('#innerpopup').append(vid);
		$('#popupclose').click(function(event){
			event.preventDefault();
			_finish();
		});
		$('#innerpopup').animate(
			{'width':settings.width}
			,1000,function(){
					$('#popupvid').css({height:settings.height,width:settings.width});
				});
		var arrPageSizes = ___getPageSize();
		
		$('#jquery-overlay').css({
			backgroundColor:	settings.overlayBgColor,
			opacity:			settings.overlayOpacity,
			width:				arrPageSizes[0],
			height:				arrPageSizes[1]
		}).fadeIn();
		var arrPageScroll = ___getPageScroll();
		$('#popup').css({
			top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
			left:	arrPageScroll[0]
		}).show();	
		$('#jquery-overlay,#popup').click(function() {
			_finish();									
		});
		$(window).resize(function() {
			// Get page sizes
			var arrPageSizes = ___getPageSize();
			// Style overlay and show it
			$('#jquery-overlay').css({
				width:		arrPageSizes[0],
				height:		arrPageSizes[1]
			});
			// Get page scroll
			var arrPageScroll = ___getPageScroll();
			// Calculate top and left offset for the jquery-lightbox div object and show it
			$('#popup').css({
				top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
				left:	arrPageScroll[0]
			});
		});
	}	
	_start();
}

	
$.comandaPopup = function (settings){
	var defaults = {
		formurl:'sources/ajax.php?a=comanda&b=formular',
		submiturl:'sources/ajax.php?a=comanda&b=submit',
		border:'0',
		width:320,
		overlayBgColor:	'#000',
		overlayOpacity:			0.8,
	};
	settings = $.extend(defaults,settings);
	//append = 'http://www.youtube.com/v/'+settings.url+'?fs=1&amp;hl=en_US&amp;rel=0&amp;border='+settings.border;
	
	
	function _finish() {
		$('#popup').remove();
		$('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); });
		// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
		$('embed, object, select').css({ 'visibility' : 'visible' });
	}
	function _get_form(){
		$.get(settings.formurl,function(form){
			$('#innerpopup').append(form);
			_submission();
			$('#innerpopup').animate({width:(parseInt(settings.width)+30)+'px'},400,function(){
				$(this).animate({height:$('#comanda_form').innerHeight()},400,function(){
					$('#comanda_form').fadeIn();
				});
			});
		});	
	}
	function _submission(){
		$('#button_register').click(function(event){
			if($('#nume').val().length<4){
				alert('Numele trebuie sa contina minim 4 caractere.');
				return false;	
			}
			if($('#telefon').val().length<4){
				alert('Telefonul trebuie sa contina minim 4 caractere.');
				return false;	
			}
			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
			email = $('#email').val();
			
			if(email.length<5 || !emailReg.test(email)){
				alert('E-mail-ul nu este intr-un format corespunzator');
				return false;	
			}
			$.post(settings.submiturl,$(this).parents('form').serialize(),function(res){
				$('#comanda_form').fadeOut(function(){
					$(this).parent('form').remove();
					$('#innerpopup').animate({height:300},400,function(){
						$(this).append(res);
						_retry();
					});
				});
			});
			return false;
		});	
	}
	function _retry(){
		$('#comanda_esec a').click(function(){
			$('#comanda_esec').fadeOut(function(){
				$('#comanda_esec').parent('form').remove();
				_get_form();
			});
		});	
	}
	function _start(){
		$('embed, object, select').css({ 'visibility' : 'hidden' });
		
		html = '<div id="jquery-overlay"></div><div id="popup"><div id="innerpopup"><a href="#" id="popupclose"></a></div></div>';
		$('body').append(html);
		$('#popupclose').click(function(event){
			event.preventDefault();
			_finish();
		});
		
		_get_form();
		
			
		var arrPageSizes = ___getPageSize();
		
		$('#jquery-overlay').css({
			backgroundColor:	settings.overlayBgColor,
			opacity:			settings.overlayOpacity,
			width:				arrPageSizes[0],
			height:				arrPageSizes[1]
		}).fadeIn();
		var arrPageScroll = ___getPageScroll();
		$('#popup').css({
			top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
			left:	arrPageScroll[0]
		}).show();	
		$(window).resize(function() {
			// Get page sizes
			var arrPageSizes = ___getPageSize();
			// Style overlay and show it
			$('#jquery-overlay').css({
				width:		arrPageSizes[0],
				height:		arrPageSizes[1]
			});
			// Get page scroll
			var arrPageScroll = ___getPageScroll();
			// Calculate top and left offset for the jquery-lightbox div object and show it
			$('#popup').css({
				top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
				left:	arrPageScroll[0]
			});
		});
	}	
	_start();
}
$.fn.initMenu = function (options) {
	var defaults = {
		effectTime: 1000
	};
	var opts = $.extend(defaults, options);
    $(this).find('>li>ul').each(function(){
       var visible = false;
       if(!$(this).hasClass('display-sub-menu')){
         $(this).hide();
       }
    });
	$('.active').parents('ul').show();
    $(this).find(' > li > a').click(function(event){
		if($(this).next('ul').length>0)
			event.preventDefault();
		$(this).next('ul').slideToggle('normal');
		$(this).parent().siblings('li').find(' > ul').slideUp('fast');
	});
}
$.fn.slideSwitch =  function (options){
	var defaults = {
		effectTime: 1000
	};
	var opts = $.extend(defaults, options);
		$(this).each(function(){			
			var $active = $(this).children('img.active');			
			var $next = $active.next();			
			var $next =  $active.next().length ? $active.next(): $(this).children('img:first');
			$active.addClass('last-active');
			$next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, defaults.effectTime, function(){
				$active.removeClass('active last-active');
			});
		})
};
var images = ['header.png'];
$(document).ready(function() {
	$('<img src="files/images/' + images[Math.floor(Math.random() * images.length)] + '">').appendTo('#banner');					   
	$('#prodMenuEO ul').initMenu();
    $('#prodMenuEO ul li a.active').parents('ul').show();
	$('.scrollable').scrollable({'circular':true, 'steps' : 1}).autoscroll({'autoscroll':true});
	
	$('.open').click(function(){
		$.comandaPopup();
	});	
	$(function(){$('.lbox').lightBox();}); // LIGHTBOX
	$(function(){$('.lbox2').lightBox();}); // LIGHTBOX
	$(function(){$('.lbox3').lightBox();}); // LIGHTBOX
	$(function(){$('.thumb a').lightBox();}); // LIGHTBOX
	$(function(){$('.sthumb:not(.cloned) a').lightBox();}); // LIGHTBOX
	$(function(){$('a.new-window').click(function(){window.open(this.href);return false;});}); // NEW WINDOW SCRIPT
	//setInterval("$('#slideshow').slideSwitch({ effectTime: 1000 })",3000); // SLIDE SHOW
});
