//var spy;
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {windowHeight = window.innerHeight;}
	else {if (document.documentElement && document.documentElement.clientHeight) {windowHeight = document.documentElement.clientHeight;}
	else {if (document.body && document.body.clientHeight) {windowHeight = document.body.clientHeight;}}}
	return windowHeight;
}
var detailsVisible = 0;
function showDetailsNoLoad() {
    detailsVisible = 1;
    document.getElementById('tooltip').style.visibility = "hidden";
    var windowHeight = getWindowHeight();
    var content_var = document.getElementById('content');
    var details_var = document.getElementById('details');
    var footer_button_var = document.getElementById('footer-button');
    content_var.style.height = (windowHeight / 2) *0.7 + 'px';
    footer_button_var.style.top = ((windowHeight / 2) *0.7 ) - 25 + 'px';
    details_var.style.height = ((windowHeight / 2) * 1.3) - 5 + 'px';
    details_var.style.overflow = 'auto';
    footer_button_var.innerHTML = "<a href='javascript:showFullMAP();'  id='bLINK'><div id='bDOWN'></div></a>";
    document.getElementById('weather').style.bottom = (parseInt(details_var.style.height,10) + 22) + 'px';
    document.getElementById('links_about').style.bottom = (parseInt(details_var.style.height,10) + 45) + 'px';
}
function showDetailsBelow(page) {
	//console.trace();
	showDetailsNoLoad();
	var getPage = BASE_URL + '/code/category/masters/city-page.php?city=' + lastCity['l'] + "&lat=" + lastCity['lt'] + "&lon=" + lastCity['ln'] + "&country=" + lastCity['ct'] + "&flickr=" + lastCity['f'];
	if (gmap.getZoom() >= 12) { getPage = BASE_URL + '/code/maps/' + context + 'Handlers.php?list=1&city=' + lastCity['l'] + "&lat=" + lastCity['lt'] + "&lon=" + lastCity['ln'] + "&country=" + lastCity['ct'] + "&sort=" + sort + "&filter=" + filter + "&sub=" + contextShow; }
	if (page.length > 0) { getPage = BASE_URL + '/code/category/' + page; }
	document.getElementById('details').innerHTML = document.getElementById('loading').innerHTML;
	//spy = getPage;
    new Ajax.Updater("details", getPage, { method: "post", evalScripts: true });
	gmap.checkResize();
}
function showFullMAP() {
    detailsVisible = 0;
	var windowHeight            = getWindowHeight();
	var content_var             = document.getElementById('content');
	var details_var             = document.getElementById('details');
	var footer_button_var       = document.getElementById('footer-button');
	content_var.style.height    = windowHeight + 'px';
	details_var.style.height    = 0 + 'px';
	footer_button_var.style.top = windowHeight - 25 + 'px';
	footer_button_var.innerHTML = "<a href='javascript:showDetailsBelow(\"\");'  id='bLINK'><div id='bUP'></div></a>";
	document.getElementById('weather').style.bottom = (parseInt(details_var.style.height, 10) + 22) + 'px';
	document.getElementById('links_about').style.bottom = (parseInt(details_var.style.height, 10) + 45) + 'px';
	document.getElementById('details').innerHTML = "";
	gmap.checkResize();
}
function mapResize() {
    if (detailsVisible) {showFullMAP();}
    else {showDetailsNoLoad();}
}
function closeWhite() {
    document.getElementById('locationpopup').style.display = 'none';
    document.getElementById('fullscreen').style.display = 'none';
    document.getElementById('fade').style.display = 'none';
}

function ShowFull(page) {
    showFullMAP();
    document.getElementById('fade').style.display       = 'block';
    document.getElementById('fullscreen').style.display = 'block';
    new Ajax.Updater("fullscreen", BASE_URL + "/code/" + page, { method: 'post' });
}

//====================================================================================
//autocomplete for the balloon location change
//====================================================================================
function autocompleteBal(data) {
    if (data.length > 0) {
        document.getElementById('suggestionsBal').style.display = 'block';
        document.getElementById('autoSuggestionsListBal').innerHTML = data;}
}
function lookupBal(inputString) {
    if (inputString.length == 0) {document.getElementById('suggestionsBal').style.display = 'none';}
    else { GDownloadUrl(BASE_URL + "/code/maps/jquery_autocomplete_city.php?id=frmAutoBal&where=" + inputString, autocompleteBal); }
}
function fillBal(thisValue) {
    setTimeout("document.getElementById('suggestionsBal').style.display = 'none';", 200);
}


//====================================================================================
//autocomplete for the search location change
//====================================================================================
function autocompleteSearch(data) {
    if (data.length > 0) {
        document.getElementById('suggestionsSearch').style.display = 'block';
        document.getElementById('autoSuggestionsListSearch').innerHTML = data;}
}
function lookupSearch(inputString) {
    if (inputString.length == 0) {document.getElementById('suggestionsSearch').style.display = 'none';}
    else { GDownloadUrl(BASE_URL + "/code/maps/jquery_autocomplete_city.php?id=frmAutoSearch&where=" + inputString, autocompleteSearch); }
}

function fillSearch(thisValue) {
    setTimeout("document.getElementById('suggestionsSearch').style.display = 'none';", 200);
}


//====================================================================================
// search function start
//====================================================================================

function what_menu_open() {
	var search_div = document.getElementById('menu_u');
	search_div.style.display = 'block';
}
function what_menu_close() {
	var search_value = document.getElementById('what');
	var search_value_actual = document.getElementById('what').value;
}
function what_menu_close_all() {
	var search_div = document.getElementById('menu_u');
	search_div.style.display = 'none';
}
function what_menu_select(to_select) {
	var search_value = document.getElementById('what');
	search_value.value = to_select
	var searchdiv = document.getElementById('menu_u');
	searchdiv.style.display = 'none';
}
function where_menu_select() {
	var search_value = document.getElementById('where');
	var search_value_actual = document.getElementById('where').value;
	if(search_value_actual == ''){search_value.value = 'enjoy (eg.london)';}
}
function DataControl() {
	var where_var = document.frmAutoSearch.where.value;
	var rad_val = '';
	for (var i=0; i < document.frmAutoSearch.search.length; i++) 
		{if (document.frmAutoSearch.search[i].checked) 
		{var rad_val = document.frmAutoSearch.search[i].value;}
	}
	if((where_var == '') || (where_var == 'enjoy (eg.london)'))
		{window.alert("ooops! please enter a location and a category below");return false;} 
		else if(rad_val == '') 
		{window.alert("ooops! please enter a location and a category below");document.frmAutoSearch.where.focus();}
		else { showDetailsBelow('/code/maps/' + rad_val + 'Handlers.php?list=1&city=' + where_var); }
}
function changeLocationPage() {
	var where_var = document.frmAutoSearch.where.value;
	if((where_var == '') || (where_var == 'enjoy (eg.london)')) {window.alert("ooops! please enter a location below");}
	else { showDetailsBelow(BASE_URL + '/code/category/masters/city-page.php?city=' + where_var + '&flickr=' + where_var + '+nightlife'); }
}


//====================================================================================
// search function end
//====================================================================================

function buttondown( buttonname, imgname ) {
    document[buttonname].src = BASE_URL + "/code/category/weather/" + imgname;
}
function buttonup ( buttonname, imgname ) {
    document[buttonname].src = BASE_URL + "/code/category/weather/" + imgname;
}



//====================================================================================
// twitter function start
//====================================================================================

function fPopup(){
		window.open('', 'myNewWin', 'width=800,height=400,status=yes,resizable=yes,scrollbars=yes');
		var a = window.setTimeout("document.form1.submit();",200);
}
function conta(){
	var lenMax=140
	var strlength=document.form1.message.value.length
	total = eval("140")
	char = eval(document.form1.message.value.length)
	left = eval(total - char)
	if (left <= "-1")
	{
	var dif = eval(char - 140)
	var value = document.form1.message.value.substr(0,char-dif);
	document.form1.message.value = value;
	var left = "0"
	}
	document.getElementById('lengthBox').innerHTML = left;
}
function clear_text(){
	document.form1.textarea_msg.value = '';
}

//====================================================================================
// twitter function end
//====================================================================================
