//lightbox = null;
image_set = null;
a_image_set = new Array();
function getContent(div, script, qstring){
	if (image_set != null) image_set = null;
	
	var params = {			
		asynchronous:true, 
		method: 'post', 
		parameters: qstring,
		evalScripts: true, 
		onComplete: function(){
			//var scr = $$('.flexcroll');
			//if (scr.length > 0) 
			//fleXenv.fleXcrollInit();
			//if (lightbox != null) lightbox = null;
			var j = qstring.toQueryParams();
			
			hideLoading();			
			
            if ($$("a.offer-promotions").length > 0){
                //jQuery('.offer-promotions').fancybox('destroy');
                jQuery('.offer-promotions').fancybox();
            }
                
			if (script == 'offer'){
                if (jQuery.browser.msie){
                    jQuery('.offer-popup-prices-content').removeAttr('fire');
                }
                
                //jQuery('.offer-popup-prices-content').css({'display': 'none'});
				var tabs = new Fabtabs('tabs_' + j.id);
                jQuery('.gals-imgs').fancybox();
                
                jQuery(".offer-prices-popup").fancybox();
                
                jQuery('.hotel-gal-caller').fancybox();
                
                jQuery(".hotel-image-init").fancybox();
			}
			else{
				$$("ul.tabs").each(function(el) { new Fabtabs(el); });
			}
		}
	};
	
	if (script != 'offer_blocks'){
		if ($(div).visible())
			showLoading($(div));
	}
	
	$(div).innerHTML = '';
	
	new Ajax.Updater(div, 'content/' + script + '.php', params);
}

window.onload = function(){
	var colors = new Array('transparent url("menu/lenta1.png") no-repeat top left', 
						   'transparent url("menu/lenta2.png") no-repeat top left', 
						   'transparent url("menu/lenta3.png") no-repeat top left', 
						   'transparent url("menu/lenta4.png") no-repeat top left', 
						   'transparent url("menu/lenta5.png") no-repeat top left', 
						   'transparent url("menu/lenta6.png") no-repeat top left');
	var subs = $$('.menu_item');
	for (var i = 0; i < subs.length; i++){
		subs[i].style.background = colors[i];
	}
	expandMenu(subs[0].id.split('_')[1]);
	if ($$("a.offer-promotions").length > 0)
        jQuery('.offer-promotions').fancybox();
	
    //jQuery('#subscribe').css({ 'display': 'none' });
    //{'width': '280px', 'height':'100px'}
	jQuery('a#subscribe-a').fancybox();
}

expandMenu = function(num){
	var subs = $$('.subcontainer');
	for (var i = 0; i < subs.length; i++){
		if (subs[i].id.split('_')[1] == num && $('subcontainer_' + num).visible()) return;
		else{
			if (subs[i].visible()){
				$('content_' + subs[i].id.split('_')[1]).innerHTML = '';
				jQuery('#' + subs[i].id).fadeOut(500);
				jQuery('#content_' + subs[i].id.split('_')[1]).slideUp(510);
			}
		}
	}
	
	if (!$('subcontainer_' + num)) return;
	
	if ($('subcontainer_' + num).visible()){
		return;
	}
	
	if ($('subcontainer_' + num)){
		resetMenu('submenu_' + num)
		jQuery('#subcontainer_' + num).fadeIn(500);
		//jQuery('#content_' + num).css('visibility', 'hidden');
		//jQuery('#content_' + num).css({'opacity': 0, 'visibility': 'visible'});
		jQuery('#content_' + num).slideDown(490, function(){
			//jQuery('#content_' + num).animate({'visibility': "visible"},300);
			//jQuery('#content_' + num).css({'opacity': 0}).fadeIn();
		});
	}
}

activateItem = function(parent, item){
	var items = Element.immediateDescendants($(parent));
	
	for (var i = 0; i < items.length; i++){
		if (items[i].className = 'active') items[i].className = 'inactive';
	}
	
	item.parentNode.className = 'active';
}

resetMenu = function(parent){
	var items = Element.immediateDescendants($(parent));
	
	for (var i = 0; i < items.length; i++){
		if (items[i].className = 'active') items[i].className = 'inactive';
	}
}

function checkInitalContent(id, script, qstr){
	getContent('content_' + id, script, qstr);
	expandMenu(id);
}

function showBlocker(){
	var block = $('blocker');
	block.style.left = '0';
	block.style.top = '0';
	
	block.style.width = document.body.getWidth() + 'px';
	block.style.height = document.body.getHeight() + 'px';
	
	//$('blocker').show();
	new Effect.Appear('blocker', {duration: 0.3});
}

function hideBlocker(){
	//$('blocker').hide();
	new Effect.Fade('blocker', {duration: 0.3});
}

function showCustomBlocker(div){
	var block = $('custom-blocker');
	calculateCustomBlockerPos(div);	
	new Effect.Appear('custom-blocker', {duration: 0.3});
	//block.show();
}

function calculateCustomBlockerPos(div){
	var block = $('custom-blocker');
	
	block.style.left = findPosX(div) + 'px';
	block.style.top = findPosY(div) + 'px';
	
	block.style.width = div.getWidth() + 'px';
	block.style.height = div.getHeight() + 'px';
}

function hideCustomBlocker(){
	new Effect.Fade('custom-blocker', {duration: 0.3});
	//$('custom-blocker').hide();
}


function showLoading(div){
	showCustomBlocker(div);	
	//calculateLoadingPos(div);
	//$('my-loading').show();
}

function calculateLoadingPos(div){
	//$('my-loading').style.top = (findPosY(div) + 20) + 'px';
	//$('my-loading').style.left = ((div.getWidth()) - (findPosX(div) - 10)) + 'px';
}

function hideLoading(){
	hideCustomBlocker();
	//$('my-loading').hide();
}

function showPopup(){
	var pdim = Element.getDimensions('popup');
	var vport = document.viewport.getDimensions();
	var soff = document.viewport.getScrollOffsets();
	
	$('popup').style.left = (vport.width - pdim.width) / 2 + 'px';
	$('popup').style.top = (((vport.width - pdim.width) / 4) + soff.top) + 'px';
	
	Element.clonePosition($('blocker'), $('container'));
	Element.show('popup');
	Element.show('blocker');
}

function closePopup(){
	Element.hide('popup');	
	Element.hide('blocker');
}

function loadHotelGalery(hotel, offer){
    var params = {
        method: 'post', 
        parameters: '&hotel=' + hotel + '&offer=' + offer, 
        onComplete: function(response){
            Dialog.alert('', {
                onLoad: function(dlg){
                    $('DlgMainContent').update(response.responseText);
                }
            });
        }
    };
    new Ajax.Request('content/hotel_pics.php', params);
}

function submitQ(){
	var form = $('addq');	
	if (form.name.value == "" || form.email.value == "" || form.question.value == ""){
		alert("Сите полиња се задолжителни");
		return;
	}
	
	var params = {
		parameters: Form.serialize(form), 
		asynchronous:true, 
		method: 'post', 
		contentType: 'application/x-www-form-urlencoded', 
		onComplete: function(){
			alert('Вашето прашање е поставено.');
			getContent(form.parentNode, 'qa', '');
		}
	}
	//showLoading();
	new Ajax.Request('admin/do/qa.php', params);
}

function qaPage(form){
	getContent(form.parentNode, 'qa', '&page=' + $('page_num').value);
	return false;
}

function qaPage1(form){
	getContent(form.parentNode, 'qa', '&page=' + $('page_num1').value);
	return false;
}

function dealNewsletter(form){
	if (form.name.value == '' || form.email.value == ''){ 
		alert('Внесете ги сите податоци'); 
		return false;
	} 
	else { 
		Form.request(form, { 
			onComplete: function(response){
				var rsp = response.responseText.evalJSON();
				if (rsp.success == 1){
					alert('Вашата регистрација е успешна'); 
					FancyZoomBox.hide();
				}
				else{
					alert(rsp.error);
				}
				return false;
			} 
		}); 
	}
	return false;
}
