function loadXmlPost (url, data, stateChangeName) {
  
  var http = false;
	//Use IE's ActiveX items to load the file.
	if(typeof ActiveXObject != 'undefined') {
		try {http = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {
			try {http = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (E) {http = false;}
		}
	//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
	} else if (XMLHttpRequest) {
		try {http = new XMLHttpRequest();}
		catch (e) {http = false;}
	}
      
  http.open("POST", url, true);
  
  //Send the proper header information along with the request
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", data.length);
  http.setRequestHeader("Connection", "close");
  
  http.onreadystatechange = function() {//Call a function when the state changes.
  	if(http.readyState == 4 && http.status == 200) {        		
      state_Change(stateChangeName, http);
  	}
  }
  
  http.send(data);
}

function loadXMLDoc (url, stateChangeName) {        
  xmlhttp = null;        
  if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc.
    xmlhttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) {// code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (xmlhttp != null) {
    xmlhttp.onreadystatechange = function() { 
      if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
          state_Change(stateChangeName, xmlhttp);
        }
      }
    }
  }
  xmlhttp.open("GET", url, true);
  xmlhttp.send(null);
}

function state_Change (stateChangeName, req) {
  text = req.responseText;
  if (window.DOMParser) {
    parser = new DOMParser();
    xmlDoc = parser.parseFromString(text, "text/xml");
  }
  // ie
  if (window.DOMParser == null) {
    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async = "true";
    xmlDoc.loadXML(text);
  }        
  //SWITCH
  if(stateChangeName == 'foto') {
    document.getElementById('T4').innerHTML = xmlDoc.getElementsByTagName("textR")[0].childNodes[0].nodeValue;
    document.getElementById('T5').innerHTML = xmlDoc.getElementsByTagName("messageR")[0].childNodes[0].nodeValue;
  }
  if(stateChangeName == 'blog_title') {
    document.getElementById('blogTitle').innerHTML = xmlDoc.getElementsByTagName("newTitle")[0].childNodes[0].nodeValue;
    document.getElementById('blogTitleEdit').style.display = 'none';
  }
  if(stateChangeName == 'article') {
    document.getElementById('articleRating').innerHTML = xmlDoc.getElementsByTagName("ratingText")[0].childNodes[0].nodeValue;          
  }
  if(stateChangeName == 'poll') {        
    pollId = xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue;          
    //zpráva, celkeové hlasy - již hlasoval
    if (xmlDoc.getElementsByTagName("result")[0].childNodes[0].nodeValue == 'FALSE') {          
      document.getElementById('pollVotesSum'+ pollId).innerHTML = xmlDoc.getElementsByTagName("message")[0].childNodes[0].nodeValue +"<br />"+ document.getElementById('pollVotesSum'+ pollId).innerHTML;
      return;          
    }          
    //zpráva, celkové hlasy
    document.getElementById('pollVotesSum'+ pollId).innerHTML = xmlDoc.getElementsByTagName("message")[0].childNodes[0].nodeValue +"<br />- hlasovalo "+ xmlDoc.getElementsByTagName("sum")[0].childNodes[0].nodeValue +" lidí";          
    i = 0;
    for (i = 1; i <= xmlDoc.getElementsByTagName("cnt")[0].childNodes[0].nodeValue; i++) {
      document.getElementById('pollAnswerOption'+ pollId +'-'+ i).innerHTML = xmlDoc.getElementsByTagName("voteText_opt"+ i)[0].childNodes[0].nodeValue;
      document.getElementById('pollAnswerStripe'+ pollId +'-'+ i).width = xmlDoc.getElementsByTagName("stripeWidth_opt"+ i)[0].childNodes[0].nodeValue;
    }          
  }      
}

function showMe (myId) { 
  x = document.getElementById(myId);        
  if (x.style.display != 'block') {
    x.style.display = 'block';      
      content = x.innerHTML;            
      if (content.search('Zavřít') == -1) {            
        x.innerHTML = "<a class='close' onclick=\"showMe('"+ myId +"')\"><span>Zavřít</span></a>"+ content;
      }          
  }
  else {
    x.style.display = 'none';
  }        
}

//highslide
hs.graphicsDir = 'parts/highslide/graphics/';      
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.fadeInOut = true;
hs.dimmingOpacity = 0.6;
hs.wrapperClassName = 'borderless floating-caption';
hs.captionEval = 'this.thumb.alt';
hs.marginLeft = 100; // make room for the thumbstrip
hs.marginBottom = 80 // make room for the controls and the floating caption
hs.numberPosition = 'caption';
hs.lang.number = '%1/%2';      
// Add the slideshow providing the controlbar and the thumbstrip
hs.addSlideshow({
	//slideshowGroup: 'group1',
	interval: 4000,
	repeat: false,
	useControls: true,
	overlayOptions: {
		className: 'text-controls',
		position: 'bottom center',
		relativeTo: 'viewport',
		offsetX: 50,
		offsetY: -5      
	},
	thumbstrip: {
		position: 'middle left',
		mode: 'vertical',
		relativeTo: 'viewport'
	}
});
// Add the simple close button
hs.registerOverlay({
	html: '<div class="closebutton" onclick="return hs.close(this)" title="Close"></div>',
	position: 'top right',
	fade: 2 // fading the semi-transparent overlay looks bad in IE
});
      
function CheckDelete(req_handle) {
  if(confirm('Smazat tuto položku?')) location.href=''+req_handle;
}

function delete_it (url) {
  CheckDelete(url);
}

function gmap_initialize() {
	
  if (GBrowserIsCompatible()) {
  
    var map = new GMap2(document.getElementById("mojeMapa"));
    map.setCenter(new GLatLng(49.800, 15.500), 7);
    map.setUIToDefault();
    //map.addControl(new GSmallMapControl());    map.addControl(new GMapTypeControl());
    map.enableContinuousZoom();
    //map.enableGoogleBar();
    map.enableScrollWheelZoom();
    
    $('.bubble').each(function() {
      this.PARposition = $(this).attr('title');
      this.PARposition = this.PARposition.split(",");
      this.PARx = this.PARposition[0];
      this.PARy = this.PARposition[1]; 
      this.PARpositionObj = new GLatLng(this.PARx, this.PARy);
      
      this.PARmarker = new GMarker(this.PARpositionObj);
      this.PARmarker.bindInfoWindowHtml( $(this).html().toString(), {maxWidth: 320} );
      map.addOverlay(this.PARmarker);
      
    });
    
    $('.mapBubbles select').change(function () {
    	this.PARposition = $('option:selected', this).attr('title');
      this.PARposition = this.PARposition.split(",");
      this.PARx = this.PARposition[0];
      this.PARy = this.PARposition[1]; 
      this.PARpositionObj = new GLatLng(this.PARx, this.PARy);
    	map.setCenter(this.PARpositionObj, 12);			                               
    });

  }
}

$(document).ready(function() {
	
	$('textarea').elastic();
	
	$('a[rel=external]').attr('target', '_blank');
	
	//popup
	$('div.inlinePopUp a.close').click(function () {
  	$(this).closest('div.inlinePopUp').slideUp(300);
  });
	$('.showSmiles', this).click(function () {
 		$('#smilepopup').slideToggle(300);
	})
	$('.showHelp', this).click(function () {
 		$('#helppopup').slideToggle(300);
	})  
  $('#smilepopup img', this).click(function (e) {
  	$(this).closest('fieldset').find('textarea').append( ' **'+ $(this).attr('alt') +' ' );
  });

	//tip na aktualitu
  $('#toggleNewsSuggest').click(function() {
    $('#newsSuggest').slideToggle(400);
  });

	//kalendář
	$('.myCalendar td.action').hover(function () {
		$('.eventDiv', this).fadeIn(200);  				          
	}, function () {
	  $('.eventDiv', this).fadeOut(200);
	});
	
	//login
	$('#loginTrigger .trigger').click(function () { 		
 		$('#loginForm').slideToggle(400);
  });
	
  gmap_initialize();


});
