var currentUrl = "";

var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 


function changeMenu(menu, number, menu_prefix, sub_menu_prefix, url){
	for (var i=1; i < number + 1; i++){
		document.getElementById(menu_prefix + i).className = '';
	}
	
	document.getElementById(menu_prefix + menu).className = 'active';
	
	$(".sub_menu").slideUp();	
	$("#" + sub_menu_prefix + menu).slideDown();
	
	currentUrl = url;
	
	loadpage(url, "inner_container");	
}

function loadExternalSite(siteaccess){		
	window.location.href = "http://" + window.location.hostname + "/index.php/" + siteaccess;
}

function changeTabLoadPage(menu, number, menu_prefix, sub_menu_prefix, siteaccess){
	for (var i=1; i < number + 1; i++){
		document.getElementById(menu_prefix + i).className = '';
	}
	
	document.getElementById(menu_prefix + menu).className = 'active_tab';
	
	$(".tab-content").hide();	
	$("#" + sub_menu_prefix + menu).slideDown();
	
	loadpage("visitcounter/stats", sub_menu_prefix + menu, siteaccess);
}

function loadpage(page, usediv, siteaccess){
	var xmlhttp;
	
	try{
		xmlhttp = window.XMLHttpRequest? new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e){
		alert("Error: Could not load page.");
	}
	
	scroll(0,0);
	
	xmlhttp.onreadystatechange = function(){
		if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)){
			document.getElementById(usediv).innerHTML = xmlhttp.responseText;
			
			$("#loading2").hide('slow');
		}
	}
	
	xmlhttp.open("GET", "http://" + window.location.hostname + "/index.php" + "/c" + siteaccess + "/" + page);
 	xmlhttp.send(null);
  	$("#loading2").show('slow');
  	//return false;
}

function loadpagescript(page, usediv){
	var xmlhttp;
	
	try{
		xmlhttp = window.XMLHttpRequest? new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e){
		alert("Error: Could not load page.");
	}
	
	scroll(0,0);
	
	xmlhttp.onreadystatechange = function(){
		if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)){
			document.getElementById(usediv).innerHTML = xmlhttp.responseText;
			$("#loading").hide('slow');
		}
	}
	
	xmlhttp.open("GET", "http://" + window.location.hostname + "/mintour/index.php" + "/cmintour/" + page);
 	xmlhttp.send(null);
  	$("#loading").show('slow');
  	//return false;
}

function ajaxpage2(url, containerid, anchor){
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
		catch (e){}
		}
	}else
		return false;
		
	page_request.onreadystatechange=function(){
		loadpage(page_request, containerid);
		window.location.href = "#" + anchor;
	}
	
	if (bustcachevar) //if bust caching of external page
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
		
	page_request.open('GET', url+bustcacheparameter, true);
	page_request.send(null);
	$("#loading").show('slow');
} 

function slideShow(){
	$('#home_gallery a').css({opacity: 0.0});
	$('#home_gallery a:first').css({opacity: 1.0});
	$('#home_gallery .caption').css({opacity: 0.7});
	$('#home_gallery .caption').css({width: $('#home_gallery a').find('img').css('width')});
	
	//console.log(document.getElementById("jd"));
	//console.log($('#home_gallery .content').html($('#home_gallery a:first').find('img').attr('rel')));
	
	$('#home_gallery .content').html($('#home_gallery a:first').find('img').attr('rel')).animate({opacity: 0.7}, 400);
	setInterval('home_gallery()',6000);
}

function home_gallery(){
	var current = ($('#home_gallery a.show')?  $('#home_gallery a.show') : $('#home_gallery a:first'));
	
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#home_gallery a:first') :current.next()) : $('#home_gallery a:first'));
	
	var caption = next.find('img').attr('rel');
	
	next.css({opacity: 0.0})  
    .addClass('show')  
    .animate({opacity: 1.0}, 1000);
    
    current.animate({opacity: 0.0}, 1000)  
    .removeClass('show');
    
    $('#home_gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });
    
    $('#home_gallery .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
    
    $('#home_gallery .content').html(caption); 
}

function changeLanguage(lang, url_alias){
	if (lang == "eng") 
		window.location.href = "http://" + window.location.hostname + "/index.php/eng/" + url_alias;
	else 
		window.location.href = "http://" + window.location.hostname + "/index.php/fre/" + url_alias;
}

function changeTab(menu, number, menu_prefix, sub_menu_prefix){
	for (var i=1; i < number + 1; i++){
		document.getElementById(menu_prefix + i).className = '';
	}
	
	document.getElementById(menu_prefix + menu).className = 'active_tab';
	
	$(".tab-content").hide();	
	$("#" + sub_menu_prefix + menu).slideDown();
}

function changeTabNews(menu, number, menu_prefix, sub_menu_prefix){
	for (var i=1; i < number + 1; i++){
		document.getElementById(menu_prefix + i).className = '';
	}
	
	document.getElementById(menu_prefix + menu).className = 'active_tab';
	
	$(".news-tab-content").hide();	
	$("#" + sub_menu_prefix + menu).slideDown();
}

