// JavaScript Document
var map;
var news;

function initialize(){	
	//menu item handlers
	$('#menu > li').bind('mouseenter', menu_open);
	$('#menu > li').bind('mouseleave', menu_close);
	$('#menu > li').bind('click', menu_click);
	
    $('body').delegate('.newsTitle', 'click', toggleNews);
				
	$.ajax({
		url: 'server/loadcontent.php',
   		type: 'POST',
		cache: false,
		dataType: 'html',
   		success: injectContent
 	});
}

function injectContent(data)
{
	$('#content').remove();
	$(data).insertBefore('#footer');
}

function getContent(pid)
{
		$.ajax({
		url: 'server/loadcontent.php',
   		type: 'POST',
		cache: false,
		dataType: 'html',
		data: 'pid=' + pid,
   		success: injectContent
 	});
}

function getArticle(aid)
{
		$.ajax({
		url: 'server/loadarticles.php',
   		type: 'POST',
		cache: false,
		dataType: 'html',
		data: 'aid=' + aid,
   		success: injectArticle
 	});
}

function injectArticle(data)
{
	$('#articleImage').fadeOut(200, replaceArticle(data))
}

function replaceArticle(data)
{
	$('#articleImage').remove();
	$(data).css('display','none');
	$(data).insertAfter('#articlesThumbs');
	$('#articleImage').fadeIn(200);
}

function toggleMap()
{
	if (map){
		$('#map').html('<div id="mapGlobalContainer">'
       				 + '<a href="javascript:toggleMap()">Podrobna karta</a>'
        			 + '<a href="resource/misc/flycom.kmz">Prenesi Google earth lokacijo</a>'
        			 + '<p>E: 14°08\'01\" N: 46°24\'21\" </p></div>'
					 + '<div class="clearer"></div>');
		map = 0;
	}
	else{
		$('#map').html('<div id="mapLocalContainer">'
        			 + '<a href="javascript:toggleMap()">Velika karta</a>'
        			 + '<a href="resource/misc/flycom.kmz">Prenesi Google earth lokacijo</a>'
        			 + '<p>Moste 26b, 4274 Žirovnica</p></div>'
					 + '<div class="clearer"></div>');
		map = 1;
	}	
}

function toggleNews()
{
	if (!news){
		$(this).toggleClass('newsTitleDown'); 
		$(this).next().slideToggle(200);
		
		news = $(this);
	}
	else{
		$(news).toggleClass('newsTitleDown'); 
		$(news).next().slideToggle(200);
		
		$(this).toggleClass('newsTitleDown'); 
		$(this).next().slideToggle(200);
		
		news = $(this);
	}
}

function center(url, name, width, height, otherfeatures)
{
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  newwin = window.open(url, name, str + ',' + otherfeatures);
  if(parseInt(navigator.appVersion) >= 4)
  {
 	setTimeout('newwin.focus();',250);
  }
}

